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 

remote join and part

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


Joined: 16 Mar 2009
Posts: 10

PostPosted: Mon Mar 16, 2009 8:47 pm    Post subject: remote join and part Reply with quote

here is my first script
Code:
bind pub - "!join" join:proc
bind pub - "!part" part:proc

proc join:proc { chan text nick } {
  global join part
  if {[$nick == Dark_Aaron]} {
   putserv "JOIN :$text"
  }
}

proc part:proc { chan text nick } {
  global part join
  if {[$nick == Dark_Aaron]]} {
   putserv "PART $chan :$text"
  }
}


i am getting

Code:
[19:39] Tcl error [join:proc]: wrong # args: should be "join:proc chan text nick"


when i try to use it
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Mar 16, 2009 9:08 pm    Post subject: Reply with quote

You are using "pub" bindings, hence your procs ("functions") need to accept 5 arguments, corresponding to nickname, host, handle, channel, and text of the message that triggered the binding.

Next, this will fail utterly:
Code:
if {[$nick == Dark_aaron]} {

In fact, this will result in remote code exploits. [] are used for command substitutions. That is, take whatever is between the [], execute it as a separate command, and substitute the text (including the []) with whatever was returned by that command execution.
What you should do is this:
Code:
if {[string equal -nocase $nick "Dark_aaron"]} {

Here we execute the command "string" with the parameters "equal", "-nocase", the value of $nick, and "Dark_aaron". Checking the manpage for the string command, this tells us string will compare the two strings (equal) in a case-insensitive (-nocase) manner, and return true if they're the same, false otherwize.

Further,
You have this command-line:
Code:
global part join

The purpose of the global command, is to link local variables to their counterpart in the global namespace. Yet you do not make use either of those variables in either function. This will not cause an error, but it is bad practise, and may cause confusion as to which variables are actually in use. Also be aware of variable name collisions (such as two scripts using the same variable for different purposes).
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Dark_Aaron
Voice


Joined: 16 Mar 2009
Posts: 10

PostPosted: Mon Mar 16, 2009 9:26 pm    Post subject: Reply with quote

so it should look like

Code:
bind pub - "!join" join:proc
bind pub - "!part" part:proc

proc join:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   putserv "JOIN :$text"
  }
}

proc part:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   putserv "PART $chan :$text"
  }
}


???
Back to top
View user's profile Send private message
Dark_Aaron
Voice


Joined: 16 Mar 2009
Posts: 10

PostPosted: Mon Mar 16, 2009 9:32 pm    Post subject: Reply with quote

Dark_Aaron wrote:
so it should look like

Code:
bind pub - "!join" join:proc
bind pub - "!part" part:proc

proc join:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   putserv "JOIN :$text"
  }
}

proc part:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   putserv "PART $chan :$text"
  }
}


???


this works but...

here is logs from client and partyline

client:
[8:30:pm] <~Dark_Aaron> !join #q
[8:30:pm] * Eggy (Eggy@ServicesAdmin.TheBeagleClub.net) has joined #q
[8:30:pm] * Eggy (Eggy@ServicesAdmin.TheBeagleClub.net) has left #q

partyline:
[20:24] joined #q but didn't want to!
Back to top
View user's profile Send private message
arfer
Master


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

PostPosted: Mon Mar 16, 2009 10:07 pm    Post subject: Reply with quote

You have to use the commands

channel add $text

and

channel remove $text

to create/delete a dynamic channel record

Code:

bind pub - "!join" join:proc
bind pub - "!part" part:proc

proc join:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   channel add $text
  }
}

proc part:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   channel remove $text
  }
}


I would probably add some code to the join proc to check that the bot didn't already have a channel record for $text before adding it. Likewise I would test if the channel record existed and if it was dynamic before attempting to part it.
_________________
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 Mar 16, 2009 10:28 pm    Post subject: Reply with quote

Here's one I prepared earlier.

Responds to pub or msg commands.

Note that the binds are 'global owner' only. Always a good idea if you are doing stuff like this.

Code:

bind MSG n join prcJoinMsgJoin
bind PUB n !join prcJoinPubJoin
bind MSG n part prcPartMsgPart
bind PUB n !part prcPartPubPart

proc prcJoinMsgJoin {nick uhost hand txt} {
  global botnick
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {![validchan $tchan]} {
        channel add $tchan
        savechannels
        putserv "NOTICE $nick :created dynamic channel record $tchan"
      } else {putserv "NOTICE $nick :error - a channel record for $tchan already exists"}
    } else {putserv "NOTICE $nick :error - $tchan is not in the format of a valid channel name"}
  } else {putserv "NOTICE $nick :error - correct syntax is /msg $botnick join <#channel>"}
  return 0
}

proc prcJoinPubJoin {nick uhost hand channel txt} {
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {![validchan $tchan]} {
        channel add $tchan
        savechannels
        putserv "PRIVMSG $channel :created dynamic channel record $tchan"
      } else {putserv "PRIVMSG $channel :-error- ($nick) - a channel record for $tchan already exists"}
    } else {putserv "PRIVMSG $channel :-error- ($nick) - $tchan is not in the format of a valid channel name"}
  } else {putserv "PRIVMSG $channel :-error- ($nick) - correct syntax is !join <#channel>"}
  return 0
}

proc prcPartMsgPart {nick uhost hand txt} {
  global botnick
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {[validchan $tchan]} {
        if {[isdynamic $tchan]} {
          channel remove $tchan
          savechannels
          putserv "NOTICE $nick :deleted dynamic channel record $tchan"
        } else {putserv "NOTICE $nick :error - only dynamic channels can be parted"}
      } else {putserv "NOTICE $nick :error - a channel record for $tchan does not exist"}
    } else {putserv "NOTICE $nick :error - $tchan is not in the format of a valid channel name"}
  } else {putserv "NOTICE $nick :error - correct syntax is /msg $botnick part <#channel>"}
  return 0
}

proc prcPartPubPart {nick uhost hand channel txt} {
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {[validchan $tchan]} {
        if {[isdynamic $tchan]} {
          channel remove $tchan
          savechannels
          if {![string equal -nocase $tchan $channel]} {
            putserv "PRIVMSG $channel :deleted dynamic channel record $tchan"
          }
        } else {putserv "PRIVMSG $channel :-error- ($nick) - only dynamic channels can be parted"}
      } else {putserv "PRIVMSG $channel :-error- ($nick) - a channel record for $tchan does not exist"}
    } else {putserv "PRIVMSG $channel :-error- ($nick) - $tchan is not in the format of a valid channel name"}
  } else {putserv "PRIVMSG $channel :-error- ($nick) - correct syntax is !part <#channel>"}
  return 0
}

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


Joined: 16 Mar 2009
Posts: 10

PostPosted: Mon Mar 16, 2009 10:47 pm    Post subject: Reply with quote

arfer wrote:
Here's one I prepared earlier.

Responds to pub or msg commands.

Note that the binds are 'global owner' only. Always a good idea if you are doing stuff like this.

Code:

bind MSG n join prcJoinMsgJoin
bind PUB n !join prcJoinPubJoin
bind MSG n part prcPartMsgPart
bind PUB n !part prcPartPubPart

proc prcJoinMsgJoin {nick uhost hand txt} {
  global botnick
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {![validchan $tchan]} {
        channel add $tchan
        savechannels
        putserv "NOTICE $nick :created dynamic channel record $tchan"
      } else {putserv "NOTICE $nick :error - a channel record for $tchan already exists"}
    } else {putserv "NOTICE $nick :error - $tchan is not in the format of a valid channel name"}
  } else {putserv "NOTICE $nick :error - correct syntax is /msg $botnick join <#channel>"}
  return 0
}

proc prcJoinPubJoin {nick uhost hand channel txt} {
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {![validchan $tchan]} {
        channel add $tchan
        savechannels
        putserv "PRIVMSG $channel :created dynamic channel record $tchan"
      } else {putserv "PRIVMSG $channel :-error- ($nick) - a channel record for $tchan already exists"}
    } else {putserv "PRIVMSG $channel :-error- ($nick) - $tchan is not in the format of a valid channel name"}
  } else {putserv "PRIVMSG $channel :-error- ($nick) - correct syntax is !join <#channel>"}
  return 0
}

proc prcPartMsgPart {nick uhost hand txt} {
  global botnick
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {[validchan $tchan]} {
        if {[isdynamic $tchan]} {
          channel remove $tchan
          savechannels
          putserv "NOTICE $nick :deleted dynamic channel record $tchan"
        } else {putserv "NOTICE $nick :error - only dynamic channels can be parted"}
      } else {putserv "NOTICE $nick :error - a channel record for $tchan does not exist"}
    } else {putserv "NOTICE $nick :error - $tchan is not in the format of a valid channel name"}
  } else {putserv "NOTICE $nick :error - correct syntax is /msg $botnick part <#channel>"}
  return 0
}

proc prcPartPubPart {nick uhost hand channel txt} {
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {[validchan $tchan]} {
        if {[isdynamic $tchan]} {
          channel remove $tchan
          savechannels
          if {![string equal -nocase $tchan $channel]} {
            putserv "PRIVMSG $channel :deleted dynamic channel record $tchan"
          }
        } else {putserv "PRIVMSG $channel :-error- ($nick) - only dynamic channels can be parted"}
      } else {putserv "PRIVMSG $channel :-error- ($nick) - a channel record for $tchan does not exist"}
    } else {putserv "PRIVMSG $channel :-error- ($nick) - $tchan is not in the format of a valid channel name"}
  } else {putserv "PRIVMSG $channel :-error- ($nick) - correct syntax is !part <#channel>"}
  return 0
}


how do i add some1 to global owner list
Back to top
View user's profile Send private message
arfer
Master


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

PostPosted: Tue Mar 17, 2009 3:23 am    Post subject: Reply with quote

You read the docs that those kind folk at Eggheads sent with the bot.
_________________
I must have had nothing to do
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