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 

Info/command database

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
SL0RD
Voice


Joined: 05 Oct 2008
Posts: 19

PostPosted: Tue May 18, 2010 9:40 pm    Post subject: Info/command database Reply with quote

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
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Thu May 20, 2010 1:56 pm    Post subject: Reply with quote

check TCL archive, i've made something smiliar
http://www.egghelp.org/cgi-bin/tcl_archive.tcl?mode=download&id=1333

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

try it
Back to top
View user's profile Send private message Visit poster's website
SL0RD
Voice


Joined: 05 Oct 2008
Posts: 19

PostPosted: Thu May 20, 2010 2:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Fri May 21, 2010 9:57 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SL0RD
Voice


Joined: 05 Oct 2008
Posts: 19

PostPosted: Sun Oct 17, 2010 1:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Sun Oct 17, 2010 4:45 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SL0RD
Voice


Joined: 05 Oct 2008
Posts: 19

PostPosted: Sun Oct 17, 2010 4:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Sun Oct 17, 2010 4:54 pm    Post subject: Reply with quote

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 Wink
[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
View user's profile Send private message Visit poster's website
SL0RD
Voice


Joined: 05 Oct 2008
Posts: 19

PostPosted: Sun Oct 17, 2010 5:10 pm    Post subject: Reply with quote

yea that worked, thanks a lot
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 -> Script Requests 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