| View previous topic :: View next topic |
| Author |
Message |
SL0RD Voice
Joined: 05 Oct 2008 Posts: 19
|
Posted: Tue May 18, 2010 9:40 pm Post subject: Info/command database |
|
|
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: | <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: | <user> !help
<bot> Simply ask your question and someone will be with you as soon as possible.
|
And for the list commands part
| Code: | <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 |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
|
| Back to top |
|
 |
SL0RD Voice
Joined: 05 Oct 2008 Posts: 19
|
Posted: Thu May 20, 2010 2:00 pm Post subject: |
|
|
| ok well thats kinda like what i want but if possible i don't want a space between the command and the trigger. |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Fri May 21, 2010 9:57 am Post subject: |
|
|
| Code: | # 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 |
|
| Back to top |
|
 |
SL0RD Voice
Joined: 05 Oct 2008 Posts: 19
|
Posted: Sun Oct 17, 2010 1:26 pm Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Sun Oct 17, 2010 4:45 pm Post subject: |
|
|
change:
| Code: | | set trigger_regexp {^\![a-z]+$} |
to:
| Code: | | 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 |
|
| Back to top |
|
 |
SL0RD Voice
Joined: 05 Oct 2008 Posts: 19
|
Posted: Sun Oct 17, 2010 4:51 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Sun Oct 17, 2010 4:54 pm Post subject: |
|
|
yap, cause the files on the disk are case sensitive,
try to change:
| Code: | | set trigger_name [lindex $input_data 1] |
to:
| Code: | | 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: | | 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.. |
|
| Back to top |
|
 |
SL0RD Voice
Joined: 05 Oct 2008 Posts: 19
|
Posted: Sun Oct 17, 2010 5:10 pm Post subject: |
|
|
| yea that worked, thanks a lot |
|
| Back to top |
|
 |
|