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.

Create Trigger Script

Support & discussion of released scripts, and announcements of new releases.
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Create Trigger Script

Post by Madalin »

For any ideas for improving the code
For any bugs or questions please post here

Code: Select all

#### ++++ Author: MadaliN <madalinmen28@yahoo.com>
### +++ Website: www.Ascenture.ro
## +++ TCL Name: Trigger
# +++ Version: 2.0
## ++++
# Commands:
#   !trigger activate                (local or global owner)
#   !trigger deactivate             (local or global owner)
#   !trigger url www.ascenture.ro      (any user)
#   !trigger -list                (local or global owner)
#   !trigger -del url                (local or global owner)
#

####
# +++ This script can have the same commands saved on two different channels with different information (this means every channel has its own database)
####
# +++ Created: 5/19/2013
####

bind PUBM - * trigger:main

## ++ Set here what triggers you want the script to work with
set ascenture(trigger) {! . ` ?}

## ++ Set here the flag (local) for the activate/deactivate script (n = owner/m = master/o = operator)
set ascenture(flag-ad) "n"

## ++ Set here the flag (local) to use add/delete/list commands (n = owner/m = master/o = operator)
set ascenture(flag-adl) "n"

## ++ Set here the flag (local) to use the command like '!cmd NICKNAME' (n = owner/m = master/o = operator)
set ascenture(flag-cm) "n"

setudef flag trigger

proc trigger:main {nick uhost hand chan arg} {
	global trigger ascenture

	if {[string index $arg 0] in $ascenture(trigger)} {

		### +++ Checking for triggers
		if {[channel get $chan trigger]} {
			foreach n [array names trigger $chan,*] {
				set newvar [string map [list [string index $arg 0] ""] [lindex [split $arg] 0]]
				if {[string match -nocase $newvar [lindex [split $n ","] 1]]} {
					if {[llength [lindex [split $arg] 1]] && [matchattr $hand $ascenture(flag-cm)] || [matchattr $hand |$ascenture(flag-cm) $chan]} {
						foreach n [split $trigger($n) "|"] { if {[llength $n]} { putserv "PRIVMSG $chan :[lindex [split $arg] 1]: \002$newvar\002 - $n" } }
					} else {
						set nr 0
						foreach n [split $trigger($n) "|"] {
							if {[llength $n]} {
								incr nr
								if {$nr == 1} {
									putserv "PRIVMSG $chan :$nick: \002$newvar\002 - $n"
								} else {
									putserv "PRIVMSG $chan :$nick: $n"
								}
							}
						}
					}
				}
			}
		}

		set temp(cmd) [string range $arg 1 end]
		set temp(cmd) [lindex [split $temp(cmd)] 0]
		set arg [join [lrange [split $arg] 1 end]]
	} elseif {[isbotnick [lindex [split $arg] 0]]} {
		set temp(cmd) [lindex [split $arg] 1]
		set arg [join [lrange [split $arg] 2 end]]
	} else { return 0 }

	if {[info commands triggercmd:$temp(cmd)] != ""} { triggercmd:$temp(cmd) $nick $uhost $hand $chan $arg }
}

proc triggercmd:trigger {nick uhost hand chan arg} {
	global trigger ascenture

	switch -exact -- [lindex [split $arg] 0] {
		activate {
			if {[matchattr $hand $ascenture(flag-ad)] || [matchattr $hand |$ascenture(flag-ad) $chan]} {
				channel set $chan +trigger

				putserv "PRIVMSG $chan :\002$nick\002 - TRIGGER script \00312activated\003 succesfully"
			}
		}
		deactivate {
			if {[matchattr $hand $ascenture(flag-ad)] || [matchattr $hand |$ascenture(flag-ad) $chan]} {
				channel set $chan -trigger

				putserv "PRIVMSG $chan :\002$nick\002 - TRIGGER script \00312deactivated\003 succesfully"
			}
		}
		list -
		-list {
			if {[matchattr $hand $ascenture(flag-adl)] || [matchattr $hand |$ascenture(flag-adl) $chan]} {

				set l ""
				foreach a [array names trigger $chan,*] {
					lappend l "\00303[lindex [split $a ","] 1]\003"
				}

				if {$l == ""} {
					putserv "PRIVMSG $chan :\002$nick\002 - There are no trigger commands for this channel"
					return
				} else {
					putserv "PRIVMSG $chan :\002$nick\002 - Trigger command list: [join $l "\002,\002 "]"
				}
			}
		}
		del -
		-del {
			if {[matchattr $hand $ascenture(flag-adl)] || [matchattr $hand |$ascenture(flag-adl) $chan]} {
				if {![info exists trigger($chan,[lindex [split $arg] 1])]} {
					putserv "PRIVMSG $chan :\002$nick\002 - There is no command \00312[lindex [split $arg] 1]\003 in my database"
				} else {
					unset -nocomplain trigger($chan,[lindex [split $arg] 1])
					trigger:save

					putserv "PRIVMSG $chan :\002$nick\002 - Command \00312[lindex [split $arg] 1]\003 erased succesfully"
				}
			}
		}
		default {
			if {[matchattr $hand $ascenture(flag-adl)] || [matchattr $hand |$ascenture(flag-adl) $chan]} {
				if {[lindex [split $arg] 1] == ""} { putserv "PRIVMSG $chan :\002$nick\002 - You did not provide ARGS for \00304[lindex [split $arg] 0]\003 command"; return }
				if {![info exists trigger($chan,[lindex [split $arg] 0])]} {
					set trigger($chan,[lindex [split $arg] 0]) "[join [lrange $arg 1 end]]"
					trigger:save

					putserv "PRIVMSG $chan :\002$nick\002 - You succesfully added trigger \00312[lindex [split $arg] 0]"
				} else {
					putserv "PRIVMSG $chan :\002$nick\002 - Command \00312[lindex [split $arg] 0]\003 already exists"
				}
			}
		}
	}
}

proc trigger:save {} {
	global trigger

	set ofile [open trigger w]
	puts $ofile "array set trigger [list [array get trigger]]"
	close $ofile
}

catch {source trigger}

putlog "+++ Succesfully loaded: \00312Trigger TCL Script"
Last edited by Madalin on Sat Aug 03, 2013 4:28 am, edited 1 time in total.
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Version 2.0 now you can define the access level for every command
It now can support lines for the command
s
sekai
Voice
Posts: 7
Joined: Sat Feb 25, 2012 6:09 am
Location: Brazil - SP

Post by sekai »

error for me.

!trigger active
Tcl error [trigger:main]: syntax error in expression "[string index $arg 0] in $ascenture(trigger)": extra tokens at end of expression
:(
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

I modifyed some things and i tested every command and it worked. Ive tested the script on 2 systems one with FREEBSD one with CENTOS both with tcl version 8.5.9 and eggdrop v1.6.20

If you still encounter problems with the script please provide informations about the system/tcl/eggdrop version
s
sekai
Voice
Posts: 7
Joined: Sat Feb 25, 2012 6:09 am
Location: Brazil - SP

Post by sekai »

Thanks for reply, my error is my eggdrop, using eggdrop1.8 the tcl work fine, thank you Madalin :) .
u
user18765
Voice
Posts: 9
Joined: Sun Apr 15, 2012 6:14 am

Improvement

Post by user18765 »

Hi, I tried your TCL and I think it is very nice! I wanted to leave my feedback, and also push for a little improvement of its features!

There's just one feature I consider missing (I do some examples, too):

1) Management of new variables (e.g. $sender and $user)
  • !trigger irctutorial $user, this is a simple irc tutorial for newbies http://etc.

Code: Select all

<normaluser> Hey! Can you tell me how to use IRC?
<owner> !irctutorial | normaluser
<bot> normaluser, this is a simple irc tutorial for newbies http://etc.
  • !trigger irctutorial $user, $sender told me to give you this: http://etc.

Code: Select all

<normaluser> Hey! Can you tell me how to use IRC?
<owner> !irctutorial | normaluser
<bot> normaluser, owner told me to give you this: http://etc
I would try to manage even 3rd party users, not only sender and addressee

2) I would enable multiple input (and output) modes, to make everything more human
  • !trigger irctutorial Hi! $user, I think that this one could be good for you: http://etc.

Code: Select all

<normaluser> Hello! Can you tell me how to use IRC?
<owner> Hey bot, give normaluser a good !irctutorial
<bot> Hi! normaluser, I think that this one could be good for you: http://etc
Commands must be more flexible , and not require boring fixed patterns.
Also, the owner could give a list of possible answers from which the bot can randomly choose. And for "input modes", I would employ a "keywords" technique. Keywords such as GIVE. Without any special symbol like ! . , at the beginning. Just language.

That's (almost eheh) all. I reserve the other ones for the next release XD
Bye.
Anonymous
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Thanks for your ideas
The problem was that noone complained about the script atleast about the commands and what things needed improved. The idea was that if i knew exactly what the script would need i would have made it exactly like that :) but i didnt. This is exactly the script i used it a long time ago and decided to make it public and share it with others and since then noone said we need this we need that :) so trust me as soon as i will this script will be used i will improve its code/command to be more flexible and easy to use

Ideas noted and in the next version i will consider what you suggested of course :D
u
user18765
Voice
Posts: 9
Joined: Sun Apr 15, 2012 6:14 am

Post by user18765 »

I'm having a problem with your script.
Eggdrop version ===> 1.6.21
Tcl Version ===> 8.5.13

I (the owner of the bot) don't have any problem. BUT other users do.
I wanted some users to be able to add/del triggers. So I changed the flags at the beginning of your script setting them all as "o" (operators). I then added those users to the operators group (from the party channel) with the command .adduser username operator
The user-adding process went fine, successfully. I then restarted the bot, but still the users weren't able to use any feature.
What do you think?

(bmn user) Thank you, bye :)
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Check the users if they really have that flag (local/global) and see in botnet chat if you have any error. Copy paste the script on http://paste.tclhelp.net if you know you have edited other things maybe you have an error or something (that website will tell you)
a
anotheregglover
Voice
Posts: 38
Joined: Thu Jan 13, 2005 12:01 am
Contact:

Post by anotheregglover »

thx for this script.

i am encountering a problem. i think everytime i restart or rehash the bot the added trigger commands are lost.

where does the script save the added trigger cmds?

Btw. egghelp.org archive still refers to version 1.0
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Well yes ive send the new version to be uploaded instead of the old version but that didnt happened so i posted the script here. Use this version here on the forum and see if the problem still persists. I know there is no problem with this version
J
Jagg
Halfop
Posts: 53
Joined: Sat Jan 24, 2004 11:32 am

Post by Jagg »

...are there " allowed as/in descriptions?! When I use " in desr the trigger isn't saved here.
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

Give me the exact usage you are using
J
Jagg
Halfop
Posts: 53
Joined: Sat Jan 24, 2004 11:32 am

Post by Jagg »

Hmmm, can't reproduce it again. Now everything looks good, even

Code: Select all

!trigger that's: ("a test"), another test (-!user blubb 12-2): https://www.etestasfsdf.com next: test
worked.

Sorry :? 8)

...and thanks for this script!
u
user18765
Voice
Posts: 9
Joined: Sun Apr 15, 2012 6:14 am

Madalin trigger.tcl script Modified

Post by user18765 »

Hi. I modified Madalin's trigger script with a couple of minor changes.
He didn't think of the feature !cmd NICKNAME used by everybody, even users which aren't known by the bot. But I needed that feature. And I did the same for the !trigger -list command. I simply distinguished the ADD/DEL needed flag with the LIST needed flag. And, for these two, added the value "-" that means "All Users". Here's the source:

Code: Select all

#### ++++ Author: MadaliN <madalinmen28@yahoo.com>
### +++ Website: www.Ascenture.ro
## +++ TCL Name: Trigger
# +++ Version: 2.0.1
## ++++
# Commands:
#   !trigger activate                (local or global owner)
#   !trigger deactivate             (local or global owner)
#   !trigger url www.ascenture.ro      (any user)
#   !trigger -list                (local or global owner)
#   !trigger -del url                (local or global owner)
#

####
# +++ This script can have the same commands saved on two different channels with different information (this means every channel has its own database)
####
# +++ Created: 5/19/2013
####

bind PUBM - * trigger:main

## ++ Set here what triggers you want the script to work with
set ascenture(trigger) {! . ` ?}

## ++ Set here the flag (local) for the enable/disable the script (n = owner/m = master/o = operator)
set ascenture(flag-ed) "n"

## ++ Set here the flag (local) to use add/delete commands (n = owner/m = master/o = operator)
set ascenture(flag-ad) "n"

## ++ Set here the flag (local) to use list command (n = owner/m = master/o = operator/ "-" = everybody)
set ascenture(flag-l) "o"

## ++ Set here the flag (local) to use the command like '!cmd NICKNAME' (n = owner/m = master/o = operator/ "-" = everybody)
set ascenture(flag-cm) "-"

setudef flag trigger

proc trigger:main {nick uhost hand chan arg} {
   global trigger ascenture

   if {[string index $arg 0] in $ascenture(trigger)} {

      ### +++ Checking for triggers
      if {[channel get $chan trigger]} {
         foreach n [array names trigger $chan,*] {
            set newvar [string map [list [string index $arg 0] ""] [lindex [split $arg] 0]]
            if {[string match -nocase $newvar [lindex [split $n ","] 1]]} {
               if {[llength [lindex [split $arg] 1]] && [matchattr $hand $ascenture(flag-cm)] || [matchattr $hand |$ascenture(flag-cm) $chan] || $ascenture(flag-cm) eq "-"} {
                  foreach n [split $trigger($n) "|"] { if {[llength $n]} { putserv "PRIVMSG $chan :[lindex [split $arg] 1]: \002$newvar\002 - $n" } }
               } else {
                  set nr 0
                  foreach n [split $trigger($n) "|"] {
                     if {[llength $n]} {
                        incr nr
                        if {$nr == 1} {
                           putserv "PRIVMSG $chan :$nick: \002$newvar\002 - $n"
                        } else {
                           putserv "PRIVMSG $chan :$nick: $n"
                        }
                     }
                  }
               }
            }
         }
      }

      set temp(cmd) [string range $arg 1 end]
      set temp(cmd) [lindex [split $temp(cmd)] 0]
      set arg [join [lrange [split $arg] 1 end]]
   } elseif {[isbotnick [lindex [split $arg] 0]]} {
      set temp(cmd) [lindex [split $arg] 1]
      set arg [join [lrange [split $arg] 2 end]]
   } else { return 0 }

   if {[info commands triggercmd:$temp(cmd)] != ""} { triggercmd:$temp(cmd) $nick $uhost $hand $chan $arg }
}

proc triggercmd:trigger {nick uhost hand chan arg} {
   global trigger ascenture

   switch -exact -- [lindex [split $arg] 0] {
      activate {
         if {[matchattr $hand $ascenture(flag-ed)] || [matchattr $hand |$ascenture(flag-ed) $chan]} {
            channel set $chan +trigger

            putserv "PRIVMSG $chan :\002$nick\002 - TRIGGER script \00312activated\003 succesfully"
         }
      }
      deactivate {
         if {[matchattr $hand $ascenture(flag-ed)] || [matchattr $hand |$ascenture(flag-ed) $chan]} {
            channel set $chan -trigger

            putserv "PRIVMSG $chan :\002$nick\002 - TRIGGER script \00312deactivated\003 succesfully"
         }
      }
      list -
      -list {
         if {[matchattr $hand $ascenture(flag-ad)] || [matchattr $hand |$ascenture(flag-ad) $chan] || $ascenture(flag-l) eq "-"} {

            set l ""
            foreach a [array names trigger $chan,*] {
               lappend l "\00303[lindex [split $a ","] 1]\003"
            }

            if {$l == ""} {
               putserv "PRIVMSG $chan :\002$nick\002 - There are no trigger commands for this channel"
               return
            } else {
               putserv "PRIVMSG $chan :\002$nick\002 - Trigger command list: [join $l "\002,\002 "]"
            }
         }
      }
      del -
      -del {
         if {[matchattr $hand $ascenture(flag-ad)] || [matchattr $hand |$ascenture(flag-ad) $chan]} {
            if {![info exists trigger($chan,[lindex [split $arg] 1])]} {
               putserv "PRIVMSG $chan :\002$nick\002 - There is no command \00312[lindex [split $arg] 1]\003 in my database"
            } else {
               unset -nocomplain trigger($chan,[lindex [split $arg] 1])
               trigger:save

               putserv "PRIVMSG $chan :\002$nick\002 - Command \00312[lindex [split $arg] 1]\003 erased succesfully"
            }
         }
      }
      default {
         if {[matchattr $hand $ascenture(flag-ad)] || [matchattr $hand |$ascenture(flag-ad) $chan]} {
            if {[lindex [split $arg] 1] == ""} { putserv "PRIVMSG $chan :\002$nick\002 - You did not provide ARGS for \00304[lindex [split $arg] 0]\003 command"; return }
            if {![info exists trigger($chan,[lindex [split $arg] 0])]} {
               set trigger($chan,[lindex [split $arg] 0]) "[join [lrange $arg 1 end]]"
               trigger:save

               putserv "PRIVMSG $chan :\002$nick\002 - You succesfully added trigger \00312[lindex [split $arg] 0]"
            } else {
               putserv "PRIVMSG $chan :\002$nick\002 - Command \00312[lindex [split $arg] 0]\003 already exists"
            }
         }
      }
   }
}

proc trigger:save {} {
   global trigger

   set ofile [open trigger w]
   puts $ofile "array set trigger [list [array get trigger]]"
   close $ofile
}

catch {source trigger}

putlog "+++ Succesfully loaded: \00312Trigger TCL Script" 

Post Reply