This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Ircop eggdrop bot with SACommands

Help for those learning Tcl or writing their own scripts.
V
Valentin
Voice
Posts: 14
Joined: Sun Sep 04, 2022 12:54 am
Location: London
Contact:

Ircop eggdrop bot with SACommands

Post by Valentin »

Hello guys. I need a little bit help about this script. Something is wrong. Is it possiable someone help me with it?

Code: Select all

bind msg n op msg:op

proc msg:op {nick uhost handle txt}  {
  if {$txt == ""} {
    putserv "samode $chan +o $nick"
    return 0
  }

  if {![onchan $txt $chan]} {
    putserv "notice $nick :$txt is not on $chan"
    return 0
  }
  putserv "samode $chan +o $txt"
  putserv "PRIVMAG #admins :$txt get OP in $chan"
}
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Give the error message, use .set errorInfo to have more datas about the error.
But...
- $chan is never setted
- PRIVMAG ?
V
Valentin
Voice
Posts: 14
Joined: Sun Sep 04, 2022 12:54 am
Location: London
Contact:

Post by Valentin »

CrazyCat wrote:Give the error message, use .set errorInfo to have more datas about the error.
But...
- $chan is never setted
- PRIVMAG ?

Hey, CrazyCat. This is the error:
[08:42:39] Tcl error [msg:op]: can't read "chan": no such variable
if there's a will, there's a way.
w
willyw
Revered One
Posts: 1204
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

...
This is the error:
[08:42:39] Tcl error [msg:op]: can't read "chan": no such variable
CrazyCat pointed that out,with:
- $chan is never setted
See here:

Code: Select all

proc msg:op {nick uhost handle txt}  {
  if {$txt == ""} {
    putserv "samode $chan +o $nick"
...
When your script gets to that point, it is trying to use a variable named $chan, that does not exist. It's never been set in that procedure.

Is this script intended to be used in just one channel? If so, a simple solution would be to simply :

Code: Select all

set chan "#ChannelName"
at the top of the proc.

Also, don't forget that CrazyCat said:
- PRIVMAG ?
because once you get the $chan variable thing fixed, then that line with that typo in it, is going to error. ;)

I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
V
Valentin
Voice
Posts: 14
Joined: Sun Sep 04, 2022 12:54 am
Location: London
Contact:

Post by Valentin »

So, the point is to give me op at any channel where I want. The bot is IRCop. And must make notice at #admins for any get op. The bot will not be in the channel where I want to give me OP. Must be something like OperServ but eggdrop.
if there's a will, there's a way.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Try this code.
The command syntax is: op #somechannel
The bot will attempt to OP the +n flagged command user in #somechannel.
Important: This is Not a very secure method of getting op, as it is just protected by the flags on the bind!!!!
Be sure your bot owners only have very secure host masks!

Code: Select all

bind msg n op msg:op

proc msg:op {nick uhost handle txt}  {
  set chan [lindex [split [string trim $txt]] 0]

  if {![string match "#?*" $chan]} {
    putserv "PRIVMSG $nick :Command syntax: \002op #somechannel\002"
    return 0
  }

  putserv "samode $chan +o $nick"
  putserv "PRIVMSG #admins :$nick get OP in $chan"
}

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
V
Valentin
Voice
Posts: 14
Joined: Sun Sep 04, 2022 12:54 am
Location: London
Contact:

Post by Valentin »

Yeah, this work Spike^^ but is give OP only to the user use the command. I can`t give OP to another user. I can get of only to myself.
if there's a will, there's a way.
V
Valentin
Voice
Posts: 14
Joined: Sun Sep 04, 2022 12:54 am
Location: London
Contact:

Post by Valentin »

The bot now is give OP only to the user who use the command.
The false is my. I ment the bot must give OP to everyone named in the command.
The script must be work like this way: "op #somechannel somenick"
if there's a will, there's a way.
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Code: Select all

bind msg n op msg:op

proc msg:op {nick uhost handle txt}  {
  lassign [split [string trim $txt]] chan vict
  if {![string match "#?*" $chan]} {
    putserv "PRIVMSG $nick :Command syntax: \002op #somechannel \[user\]\002"
    return 0
  }
  if {$vict eq ""} { set vict $nick }
  putserv "samode $chan +o $vict"
  putserv "PRIVMSG #admins :$vict get OP in $chan"
}
This will allow !op #channel and !op #channel user
V
Valentin
Voice
Posts: 14
Joined: Sun Sep 04, 2022 12:54 am
Location: London
Contact:

Post by Valentin »

Thank you CrazyCat is working perfect!
if there's a will, there's a way.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

samop.tcl version 0.1

Post by SpiKe^^ »

Here's a more complete version of the script, with all the features you hinted about in your posts above...

This will allow !op #channel and !op #channel user
and !op #channel nick nick2 nick3

Code: Select all

# set one admin channel here for an added security check.
# both the bot and the command user will need to be in this channel.
# maybe set this channel password protected or invite only...
# ex. set samop(adminchan) "#admins"
# or set empty to not require command users to be in an admin channel.
# ex: set samop(adminchan) ""
set samop(adminchan) "#admins"

# set one report channel here for the bot to report mode changes to.
# ex. set samop(reportchan) "#admins"
# or set empty to not report modes.  ex: set samop(reportchan) ""
set samop(reportchan) "#admins"


bind msg n op msg:op

proc msg:op {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "PRIVMSG $nick :Command syntax: \002op #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "PRIVMSG $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "o" [llength $targets]] 
  putserv "samode $chan +$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :[join $targets] get OP in $chan"
  }
  return 0
}

putlog "samop.tcl version 0.1 loaded."

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
V
Valentin
Voice
Posts: 14
Joined: Sun Sep 04, 2022 12:54 am
Location: London
Contact:

Re: samop.tcl version 0.1

Post by Valentin »

Code: Select all

# set one admin channel here for an added security check.
# both the bot and the command user will need to be in this channel.
# maybe set this channel password protected or invite only...
# ex. set samop(adminchan) "#admins"
# or set empty to not require command users to be in an admin channel.
# ex: set samop(adminchan) ""
set samop(adminchan) "#admins"

# set one report channel here for the bot to report mode changes to.
# ex. set samop(reportchan) "#admins"
# or set empty to not report modes.  ex: set samop(reportchan) ""
set samop(reportchan) "#admins"


#################################
############# OWNER #############
#################################

bind msg n owner msg:qop

proc msg:qop {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002OWNER #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "q" [llength $targets]]
  putserv "samode $chan +$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used OWNER to make [join $targets] OWNER in $chan"
  }
  return 0
}


##################################
############ PROTECT #############
##################################

bind msg n protect msg:sop

proc msg:sop {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002PROTECT #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "a" [llength $targets]]
  putserv "samode $chan +$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used PROTECT to make [join $targets] PROTECT in $chan"
  }
  return 0
}


#################################
############## OP ###############
#################################

bind msg n op msg:op

proc msg:op {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002OP #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "o" [llength $targets]]
  putserv "samode $chan +$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used OP to make [join $targets] OP in $chan"
  }
  return 0
}


#################################
############# HALFOP ############
#################################

bind msg n halfop msg:hop

proc msg:hop {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002HALFOP #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "h" [llength $targets]]
  putserv "samode $chan +$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used HALFOP to make [join $targets] HALFOP in $chan"
  }
  return 0
}


#################################
############# VOICE #############
#################################

bind msg n voice msg:vop

proc msg:vop {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002VOICE #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "v" [llength $targets]]
  putserv "samode $chan +$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used VOICE to make [join $targets] VOICE in $chan"
  }
  return 0
}


#################################
############# OWNER #############
#################################

bind msg n deowner msg:deqop

proc msg:deqop {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002DEOWNER #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "q" [llength $targets]]
  putserv "samode $chan -$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used DEOWNER to make [join $targets] DEOWNER in $chan"
  }
  return 0
}


##################################
############ PROTECT #############
##################################

bind msg n deprotect msg:desop

proc msg:desop {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002DEPROTECT #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "a" [llength $targets]]
  putserv "samode $chan -$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used DEPROTECT to make [join $targets] DEPROTECT in $chan"
  }
  return 0
}


#################################
############## OP ###############
#################################

bind msg n deop msg:deop

proc msg:deop {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002DEOP #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "o" [llength $targets]]
  putserv "samode $chan -$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used DEOP to make [join $targets] DEOP in $chan"
  }
  return 0
}


#################################
############# HALFOP ############
#################################

bind msg n dehalfop msg:dehop

proc msg:dehop {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002DEHALFOP #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "h" [llength $targets]]
  putserv "samode $chan -$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used DEHALFOP to make [join $targets] DEHALFOP in $chan"
  }
  return 0
}


#################################
############ DEVOICE ############
#################################

bind msg n devoice msg:devop

proc msg:devop {nick uhost handle txt}  {   global samop
  set targets [lassign [split [string trim $txt]] chan]
  if {![string match "#?*" $chan]} {
    putserv "NOTICE $nick :Command syntax: \002DEVOICE #somechannel \[nick(s)\]\002"
    return 0
  }

  if {[string match "#?*" $samop(adminchan)]} {
    if {![botonchan $samop(adminchan)] || ![onchan $nick $samop(adminchan)]} {
      putserv "NOTICE $nick :Both you & the bot must be on $samop(adminchan)"
      return 0
    }
  }

  if {![llength $targets]} {  lappend targets $nick  }
  set mode [string repeat "v" [llength $targets]]
  putserv "samode $chan -$mode [join $targets]"
  if {[string match "#?*" $samop(reportchan)]} {
    putserv "PRIVMSG $samop(reportchan) :$nick used DEVOICE to make [join $targets] DEVOICE in $chan"
  }
  return 0
}


#################################
############# HELP ##############
#################################

bind msg n help msg:help
proc msg:help {nick uhost hand txt} {
  if {[llength $txt]<13} {
putserv "NOTICE $nick :=============== HELP ================"
putserv "NOTICE $nick :/msg AdminServ OWNER #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEOWNER #channel nick"
putserv "NOTICE $nick :/msg AdminServ PROTECT #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEPROTECT #channel nick"
putserv "NOTICE $nick :/msg AdminServ OP #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEOP #channel nick"
putserv "NOTICE $nick :/msg AdminServ HALFOP #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEHALFOP #channel nick"
putserv "NOTICE $nick :/msg AdminServ VOICE #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEVOICE #channel nick"
putserv "NOTICE $nick :/msg AdminServ HELP"
putserv "NOTICE $nick :================ END ================"
  }
}


putlog "samop.tcl version 0.1 loaded."

So, this is the scripts. Working perfect. I`m just added commands for +q +a +h +v -q -a -o -h -v and help.
Thank you, Spike^^ and CrazyCat
if there's a will, there's a way.
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Could do a shorter version using a routing proc:

Code: Select all

# set one admin channel here for an added security check.
# both the bot and the command user will need to be in this channel.
# maybe set this channel password protected or invite only...
# ex. set samop(adminchan) "#admins"
# or set empty to not require command users to be in an admin channel.
# ex: set samop(adminchan) ""
set samop(adminchan) "#admins"

# set one report channel here for the bot to report mode changes to.
# ex. set samop(reportchan) "#admins"
# or set empty to not report modes.  ex: set samop(reportchan) ""
set samop(reportchan) "#admins"


#################################
############# OWNER #############
#################################

bind msg n owner msg:qop
bind msg n protect msg:sop
bind msg n op msg:op
bind msg n halfop msg:hop
bind msg n voice msg:vop
bind msg n deowner msg:deqop
bind msg n deprotect msg:desop
bind msg n deop msg:deop
bind msg n dehalfop msg:dehop
bind msg n devoice msg:devop

proc msg:qop {nick uhost handle text}  { samode $nick + q OWNER $text }
proc msg:sop {nick uhost handle text}  { samode $nick + p PROTECT $text }
proc msg:op {nick uhost handle text}  { samode $nick + o OP $text }
proc msg:hop {nick uhost handle text}  { samode $nick + h HALFOP $text }
proc msg:vop {nick uhost handle text}  { samode $nick + v VOICE $text }
proc msg:deqop {nick uhost handle text}  { samode $nick - q DEOWNER $text }
proc msg:desop {nick uhost handle text}  { samode $nick - p DEPROTECT $text }
proc msg:deop {nick uhost handle text}  { samode $nick - o DEOP $text }
proc msg:dehop {nick uhost handle text}  { samode $nick - h DEHALFOP $text }
proc msg:devop {nick uhost handle text}  { samode $nick - v DEVOICE $text }

proc samode {nick to mode label text} {
   set targets [lassign [split [string trim $txt]] chan]
   if {![string match "#?*" $chan]} {
      putserv "NOTICE $nick :Command syntax: \002$label #somechannel \[nick(s)\]\002"
      return 0
   }
   if {[string match "#?*" $::samop(adminchan)]} {
      if {![botonchan $::samop(adminchan)] || ![onchan $nick $::samop(adminchan)]} {
         putserv "NOTICE $nick :Both you & the bot must be on $::samop(adminchan)"
         return 0
      }
   }
   if {![llength $targets]} {  lappend targets $nick  }
   set mode [string repeat $mode [llength $targets]]
   putserv "samode $chan $to$mode [join $targets]"
   if {[string match "#?*" $::samop(reportchan)]} {
      putserv "PRIVMSG $::samop(reportchan) :$nick used $label to make [join $targets] $label in $chan"
   }
   return 0
}

#################################
############# HELP ##############
#################################

bind msg n help msg:help
proc msg:help {nick uhost hand txt} {
  if {[llength $txt]<13} {
putserv "NOTICE $nick :=============== HELP ================"
putserv "NOTICE $nick :/msg AdminServ OWNER #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEOWNER #channel nick"
putserv "NOTICE $nick :/msg AdminServ PROTECT #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEPROTECT #channel nick"
putserv "NOTICE $nick :/msg AdminServ OP #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEOP #channel nick"
putserv "NOTICE $nick :/msg AdminServ HALFOP #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEHALFOP #channel nick"
putserv "NOTICE $nick :/msg AdminServ VOICE #channel nick"
putserv "NOTICE $nick :/msg AdminServ DEVOICE #channel nick"
putserv "NOTICE $nick :/msg AdminServ HELP"
putserv "NOTICE $nick :================ END ================"
  }
}


putlog "samop.tcl version 0.1 loaded." 
Could also be optimised with a variable containing modes and labels which can allow to generate help depending on its content
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

That looks nice CrazyCat:)
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Y
Yusif
Voice
Posts: 34
Joined: Fri Aug 18, 2023 11:08 am

Post by Yusif »

can you please do modify in this script for simple use?
need it work in #Chanops .. when the chanop need to op in any room by bot, he/she have to type:
!op #chan to get op in that room + confirm msg in #chanops he/she opped
!deop #chan to drop op + confirm msg in #chanops he/she deopped
!hop #chan to get halfop + confirm msg in #chanops he/she halfop
!dehop #chan to dehalfop + confirm msg in #chanops he/she dehop

thanks
Post Reply