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.

Info/command database

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
S
SL0RD
Voice
Posts: 19
Joined: Sun Oct 05, 2008 11:44 am

Info/command database

Post by SL0RD »

I have searched for hours to try and find a script to do what i want, but nothing works correctly or does the tings that i want. I also attempted to write a script myself but i became lost and couldn't figure things out very early on.

Basically what I want to do is have database that keeps a list of triggers and their responses that i can add to, delete from and modify. so it would need to have a command to add and delete triggers, as well as a command to list all the available triggers in the database. so something like,

Code: Select all

<Admin> !add !help Simply ask your question and someone will be with you as soon as possible.
<Bot> Command created successfully
Then any user can use that command, so..

Code: Select all

<user> !help
<bot> Simply ask your question and someone will be with you as soon as possible.
And for the list commands part

Code: Select all

<Admin> !triggers
<Bot> the available commands are: !help, !site
i think that covers everything, i have been trying for months to create/find something like this, any help will be muchly appreciated
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

check TCL archive, i've made something smiliar
http://www.egghelp.org/cgi-bin/tcl_arch ... ad&id=1333

if you want it for all users, change rights at 'bind',

try it
S
SL0RD
Voice
Posts: 19
Joined: Sun Oct 05, 2008 11:44 am

Post by SL0RD »

ok well thats kinda like what i want but if possible i don't want a space between the command and the trigger.
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

Code: Select all

# Author: tomekk
# e-mail:  tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html

# if you want to use this script on your chan, type in eggdrop console (via telnet or DCC chat)
# .chanset #channel_name +triggers
# and later .save

# trigger name regexp (default: !<chars>)
set trigger_regexp {^\![a-z]+$}

# 'database' file
set dbase "triggers.db"

################################################################################################
bind pubm - "*" catch_fct

setudef flag triggers

if {[file exists $dbase] == 0} {
	set new_f [open $dbase w]
	close $new_f
}

proc readdb { } {
	global dbase

	set get_data [open $dbase r]
	set entries [split [read $get_data] "\n"]
	close $get_data

	return $entries
}

proc check_if_exists { cmd } {
	set yeah_got_it 0

	foreach each_line [readdb] {
		if {$each_line != ""} {
			set the_cmd_name [lindex [split $each_line ":"] 0]

			if {$the_cmd_name == $cmd} {
				set yeah_got_it 1
				break
			}
		}
	}

	return $yeah_got_it
}

proc get_trigger_data { cmd } {
	set proc_output ""

	foreach db_line [readdb] {
		if {$db_line != ""} {
			set db_line_data [split $db_line ":"]
			set db_cmd [lindex $db_line_data 0]
			set db_data [join [lrange $db_line_data 1 end] ":"]

			if {$db_cmd == $cmd} {
				set proc_output $db_data
				break
			}
		}
	}

	return $proc_output
}

proc catch_fct { nick uhost hand chan arg } {
	global dbase trigger_regexp

	if {![channel get $chan triggers]} {
		return                  
	}

	set input_data [split $arg]
	set cmd_name [string tolower [lindex $input_data 0]]
	set trigger_name [lindex $input_data 1]
	set trigger_data [join [lrange $input_data 2 end]]

	switch -- $cmd_name {
		"!add" {
			if {($trigger_name != "") && ($trigger_data != "")} {
				if {[regexp $trigger_regexp $trigger_name]} {
					if {[check_if_exists $trigger_name] == 0} {
						set new_entry [open $dbase a]
						puts $new_entry "$trigger_name:$trigger_data"
						close $new_entry
					} {
						putquick "PRIVMSG $chan :trigger with this name already exists"
					}
				} {
					putquick "PRIVMSG $chan :wrong trigger name"
				}
			} {
				putquick "PRIVMSG $chan :use: !add <trigger_name> <trigger_data>"
			}
		}

		"!del" {
			if {$trigger_name != ""} {
				if {[regexp $trigger_regexp $trigger_name]} {
					if {[check_if_exists $trigger_name] == 1} {
						set old_db [readdb]

						set new_db [open $dbase w]

						foreach new_db_line $old_db {
							if {$new_db_line != ""} {
								set old_trigger_name [lindex [split $new_db_line ":"] 0]
								if {$old_trigger_name != $trigger_name} {
									puts $new_db $new_db_line
								}
							}
						}

						close $new_db
					} {
						putquick "PRIVMSG $chan :trigger doesn't exists"
					}
				} {
					putquick "PRIVMSG $chan :wrong trigger name"
				}
			} {
				putquick "PRIVMSG $chan :use: !del <trigger_name>"
			}
		}

		"!mod" {
			 if {($trigger_name != "") && ($trigger_data != "")} {
			 	if {[regexp $trigger_regexp $trigger_name]} {
					 if {[check_if_exists $trigger_name] == 1} {
					 	set old_m_db [readdb]

						set new_m_db [open $dbase w]

						foreach new_m_db_line $old_m_db {
							if {$new_m_db_line != ""} {
								set old_m_trigger_name [lindex [split $new_m_db_line ":"] 0]
								if {$old_m_trigger_name == $trigger_name} {
									puts $new_m_db "$trigger_name:$trigger_data"
								} {
									puts $new_m_db $new_m_db_line
								}
							}
						}

						close $new_m_db
					 } {
					 	putquick "PRIVMSG $chan :trigger doesn't exists"
					 }
				} {
					putquick "PRIVMSG $chan :wrong trigger name"
				}
			 } {
			 	putquick "PRIVMSG $chan :use: !mod <trigger_name> <trigger_data>"
			 }
		}

		"!triggers" {
			set triggers_list [list]

			foreach trigger_cmd [readdb] {
				if {$trigger_cmd != ""} {
					set tr_name [lindex [split $trigger_cmd ":"] 0]
					lappend triggers_list $tr_name
				}
			}
			
			if {[llength $triggers_list] > 0} {
				putquick "PRIVMSG $chan :the available triggers are: [join $triggers_list ", "]"
			} {
				putquick "PRIVMSG $chan :database is empty"
			}
		}

		default {
			if {[regexp $trigger_regexp $cmd_name]} {
				set trigger_db_data [get_trigger_data $cmd_name]

				if {$trigger_db_data != ""} {
					putquick "PRIVMSG $chan :$trigger_db_data"
				} {
					putquick "PRIVMSG $chan :trigger doesn't exists"
				}
			}
		}
	}
}

putlog "triggers.tcl ver 0.1 by tomekk loaded"
try this one,
commands: !add, !del, !mod, !triggers are reserved

try it
S
SL0RD
Voice
Posts: 19
Joined: Sun Oct 05, 2008 11:44 am

Post by SL0RD »

Thanks a lot, that works great BUT I have one more request, is it possible to have commands with numbers and capital letters in them?
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

change:

Code: Select all

set trigger_regexp {^\![a-z]+$}
to:

Code: Select all

set trigger_regexp {^\![a-zA-Z0-9]+$}
it this case, commands will be case sensitive,
if you want to make !TEST same as !test you have to tweak some code inside this script
S
SL0RD
Voice
Posts: 19
Joined: Sun Oct 05, 2008 11:44 am

Post by SL0RD »

ok, well i tried that and the commands wouldnt work. I even tried changing it to just A-Z and command in all caps wouldn't work.
When i had it as [a-zA-Z0-9] only lowercase commands would work, it would allow me to add, del, and modify them. but they just wouldn't work
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

yap, cause the files on the disk are case sensitive,

try to change:

Code: Select all

set trigger_name [lindex $input_data 1]
to:

Code: Select all

set trigger_name [string tolower [lindex $input_data 1]]
lemme know about it, if this will not work then i will check it on some egg.

//
anyway, thanks for info - this is a bug ;)
[a-zA-Z] will not work with:

Code: Select all

set cmd_name [string tolower [lindex $input_data 0]]
because command name will be always 'tolower'

this should be fixed but i'm kinda lazy ass..
S
SL0RD
Voice
Posts: 19
Joined: Sun Oct 05, 2008 11:44 am

Post by SL0RD »

yea that worked, thanks a lot
Post Reply