egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to get version

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Nadae
Voice


Joined: 24 Mar 2021
Posts: 5

PostPosted: Wed Mar 24, 2021 8:35 pm    Post subject: How to get version Reply with quote

Hello,

I would like that for each person who connects, we can get their ctcp version. And that if the person is not the nickname "John" and the version of the person does not correspond to what I want it is gline for 30 minutes.

How to do ?
Back to top
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Thu Mar 25, 2021 12:02 am    Post subject: Reply with quote

First of all: this is "Scripting Help" this post is better in "Script Requests"

Second:
Code:


# set allow nicks
set bv_nicks {"john" "paddy"}

# Set allow versions
set bv_versions {"version1" "version2"}

bind raw - NOTICE Client_Connect
bind ctcr - VERSION ctcr:bv_ctcp

proc Client_Connect {from key arg} {
  putserv "PRIVMSG $from :\001VERSION\001"
}
proc ctcr:bv_ctcp {nick host hand dest key arg} {
global bv_versions bv_nicks
   if {![isbotnick $nick]} {
   foreach nicks $bv_nicks {
     if {![string match -nocase "$nicks"]} {
        return 0
     }
      foreach version $bv_versions {
         if {![string match -nocase "*[string tolower $version]*"]} {
         return 0
         }
      }
    putquick "gline $host 30m :Bad Version"
   }
 }
}

Untested Wink
_________________
ComputerTech


Last edited by ComputerTech on Thu Mar 25, 2021 5:42 pm; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Mar 25, 2021 2:29 am    Post subject: Reply with quote

1. string match expects two arguments (two strings), while in:
Code:

if {![string match -nocase "$nicks"]} {

and:
Code:

if {![string match -nocase "*[string tolower $version]*"]} {

you are missing one of them. You should ditch looping over a list and use lsearch (that means list search) directly instead.
Code:

% set bv_nicks {"john" "paddy"}
"john" "paddy"
% set nick "something"
something
% lsearch -nocase $bv_nicks $nick
-1
% set nick Paddy
Paddy
% lsearch -nocase $bv_nicks $nick
1

2. In this code
Code:

foreach nicks $bv_nicks {
     if {![string match -nocase "$nicks"]} {
        return 0
     }

if you want to stop the iteration or skip one element use break or continue, depending on what you want to achieve. For example:
Code:

% set numbers { 1 2 3 4 5 6 }
 1 2 3 4 5 6
% foreach number [split $numbers] {
        if {$number == 3} {
                continue
        }
        puts $number
}
1
2
4
5
6

Notice that 3 is missing, and in this:
Code:

% foreach number [split $numbers] {
        if {$number == 3} {
                break
        }
        puts $number
}
1
2

notice that the execution has been stopped when number is 3.

3. In this code:
Code:

if {![isbotnick $nick]} {

you can test the TRUE state instead of FALSE one and return, so this saves you of the keeping in mind you have one } to add somewhere at the end.

4. In this code:
Code:

proc Client_Connect {from key arg} {
  putserv "PRIVMSG $from :\001VERSION\001"
}

I have my doubts that using $from is the client you want to version check, most likely that's the server itself sending you something in the $arg (avoid using arg as it has some special meaning in TCL) with client information and you need to parse the details from the line it sends. Might want to do some research first.

Oh, and don't use return 0 if you don't want to have an actual 0 (zero) returned in a function or whatnot.

I've moved the topic to the correct section.
_________________
Once the game is over, the king and the pawn go back in the same box.


Last edited by caesar on Thu Mar 25, 2021 12:53 pm; edited 1 time in total
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Thu Mar 25, 2021 8:19 am    Post subject: Reply with quote

well first you need to know what IRCD is it running in and does bot have IRCOP
privileges
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Thu Mar 25, 2021 8:37 am    Post subject: Reply with quote

If you use unrealircd, you can use the ban version feature
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Thu Mar 25, 2021 8:56 am    Post subject: Reply with quote

Thats even a better approach thanks CrazyCat
Back to top
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Thu Mar 25, 2021 11:07 am    Post subject: Reply with quote

heh yeah, was doing that code this morning at 5am and hadn't slept, will try fix it after work.

Thanks caesar Very Happy
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Nadae
Voice


Joined: 24 Mar 2021
Posts: 5

PostPosted: Thu Mar 25, 2021 2:54 pm    Post subject: Reply with quote

CrazyCat wrote:
If you use unrealircd, you can use the ban version feature


CrazyCat with unrealircd is it possible to choose: if the version is different from ...?
In this case it is written how?
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Thu Mar 25, 2021 6:44 pm    Post subject: Reply with quote

No, the ban version block is here to forbid some client version, not to forbid all but one or two.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Fri Mar 26, 2021 8:53 am    Post subject: Reply with quote

perhaps this will be of use:

Code:

 

set acnick {
    "John"
}



bind raw - NOTICE server:notices
proc server:notices {from keyword text} {
    global  acnick
      if {[string match -nocase "*client connecting on*" $text]} {
        set nick [lindex [split $text] 9]
        set hostmask [lindex [split $text] 10]
    foreach i [string tolower $acnick] {
   if {![string match -nocase  $i $nick]} {
          putserv "PRIVMSG $nick :\001VERSION\001"
   }
}
        return 0
      }

      if {[string match -nocase "*client connecting at*" $text]} {
        set nick [lindex [split $text] 8]
        set hostmask [lindex [split $text] 9]
   foreach i [string tolower $acnick] {
   if {![string match -nocase  $i $nick]} {
          putserv "PRIVMSG $nick :\001VERSION\001"
   }
}
        return 0
      }
}

set badclient {
   "mirc"
}


bind ctcr -|- "VERSION" ctcr:check
proc ctcr:check {nick host hand dest keyword text} {
 if {$keyword == "VERSION"} {
       foreach checknick $::badclient {
           if {[string match -nocase *$checknick* [stripcodes bcruag $text]]} {
                              putquick "GLINE $host 1h :You match a Bad Client. This is not Permitted on \017\002\00306 $::network. \017  Please Use another Client and Reconnect."
           }
       }
   }
}

Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Fri Mar 26, 2021 10:50 am    Post subject: Reply with quote

Nadae asked me an example of script which forbid all clients version different of (in example) "Kiwi IRC" and "mIRC", working for everybody but "lololo".

I did it (sorry guys, with french comments) : https://gitlab.com/-/snippets/2095934
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber