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 

[resolved] comparing two hosts w/ wildcards

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
krystal
Voice


Joined: 05 Oct 2009
Posts: 3
Location: Spain

PostPosted: Mon Oct 05, 2009 7:04 am    Post subject: [resolved] comparing two hosts w/ wildcards Reply with quote

hi there.. new to tcl, but experienced in mirc (and lamp)

want to do something when eggy joins a channel

Code:
#settings from config file
global my-hostname
global my-ip

if {($uhost != my-hostname) && ($uhost != my-ip)}


I know this isn't right.. what's the best way to compare two hosts, and can I bring in these two settings from the config file?


Last edited by krystal on Mon Oct 05, 2009 10:33 am; edited 1 time in total
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Oct 05, 2009 7:37 am    Post subject: Reply with quote

You can use any of the settings in the bot's .conf file.

Generally speaking, a direct test of equality or inequality using == or != respectively can lead to problems because they are case sensitive. This would not be an issue with a numeric IP but may well be a problem with a hostname. A better way would be to use 'string equal' or 'string match' command with the -nocase option. The former would be used to test exact equality.

The second problem with your code is that you are not comparing like for like. The variable uhost is generally used as an argument (variable) name passed to a proc by a bind and represents user@host whilst the global variables my-hostname and my-ip are a host only.

You would always need to use the dollar symbol to bring about variable substitution (replacement of a variable name by its value). So the following is incorrect anyway. It compares the value of the variable named uhost with the string my-hostname.

Code:

if {$uhost != my-hostname} {


I'm not sure I see the point of the code anyway, because generally I would expect a nick to be passed to the same proc and this is easy to test if it is or is not the bot. I had a quick scan through the various bind types and didn't see any that pass user@host but not nick.

Code:

if {![isbotnick $nick]} {
  # code here
}

_________________
I must have had nothing to do
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Oct 05, 2009 7:52 am    Post subject: Reply with quote

Just as an aside, if you did want to use the global variables my-ip and/or my-hostname, I would expect an issue to arise during substitution if simply used as $my-ip and/or $my-hostname. The interpreter will stop at the hyphen assuming the end of the variable name had been reached. They would have to be used as ${my-ip} and/or ${my-hostname}.
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
krystal
Voice


Joined: 05 Oct 2009
Posts: 3
Location: Spain

PostPosted: Mon Oct 05, 2009 8:26 am    Post subject: Reply with quote

thanks for your reply. the hyphens did cause an issue, and the brackets fixed that. I was wondering what the best way to compare the uhost to the host so that I know for sure it's my bot joining.

this code works, but I'm open to suggestion if there is a better way.

Code:
set our_chan "#mychan"
bind join - *!*@* join_handler
proc join_handler {nick uhost hand chan} {

  global our_chan
  global {my-hostname}
  global {my-ip}

  # only respond to joining $our_chan
  if {[string tolower $chan] != $our_chan} {
    return 0
  }

  set host [lindex [split $uhost @] 1]
  if {($host == ${my-hostname}) || ($host == ${my-ip})} {
    set msg "it is me"
  } else {
     set msg "it is not me"
  }

  # send msg to channel
  putserv "privmsg $chan : welcome $nick $uhost :: $msg
                   
  return 1
}
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Mon Oct 05, 2009 9:31 am    Post subject: Reply with quote

As I indicated in my prior post, you can use the Eggdrop Tcl command 'isbotnick' to determine much more simply if it was the bot that triggered a join bind.

Code:

bind JOIN - * pJoinProc

proc pJoinProc {nick uhost hand chan} {
  if {[isbotnick $nick]} {
    # code here if it was the bot that triggered the join bind
  } else {
    # code here if it was not the bot that triggered the join bind
  }
  return 0
}

_________________
I must have had nothing to do
Back to top
View user's profile Send private message
krystal
Voice


Joined: 05 Oct 2009
Posts: 3
Location: Spain

PostPosted: Mon Oct 05, 2009 10:12 am    Post subject: Reply with quote

ah, they couldn't be the same nick without being the same user/bot.. doh

thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help 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