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.

help on faq.tcl

Old posts that have not been replied to for several years.
Locked
d
draftmann
Voice
Posts: 3
Joined: Fri Aug 12, 2005 9:15 am

help on faq.tcl

Post by draftmann »

please help me with this tcl, i want this code bind pub - "[string trim $faq(cmdchar)]faq" faq:tell_fact only for user's with cmode(+o, +h and +v). if user without cmode(+o, +h and +v) use this command(??faq nick keyword) to notice himself/herself if he use bind pub - "[string trim $faq(cmdchar)]faq" faq:tell_fact command. Sorry for my bad english :)
Here's an Example how the bot show and how i want the bot to show.
<@nick1> ??faq Guest url
<@bot> Guest: (url) www.somesite.com
<@nick1> ?? url
<@bot> (url) www.somesite.com
<Guest> ?? nick1 url
<@bot> Guest3: (url) www.somesite.com
<Guest> ??faq nick1 url
<@bot> Guest5: (url) www.somesite.com
this it how the script works, it also shows when normal users(not op, halfop or voice) use the public command. I want to for use by op halfop and voice only. Means this command is for any user, but i want it for op/halfop/voice only.

And this is how i want the bot to show(some code needed to change for this) when cmode without(+o,+h and +v) uses this command
<Guest> ??faq nick1 url
-Notice(bot)- u dont have permission for this command.(something like that!)
<Guest> ?? url
-Notice(bot)- www.somesite.com
to notice nick2 non (op, halfop or voice).
i tried my best to explain it how i want the script/tcl to be, may be u can get me. :)
Here is the script.

Code: Select all

bind pub - "[string trim $faq(cmdchar)]" faq:explain_fact
bind pub - "[string trim $faq(cmdchar)]faq" faq:tell_fact
bind pub - "[string trim $faq(cmdchar)]addword" faq:add_fact
bind pub - "[string trim $faq(cmdchar)]delword" faq:delete_fact
bind pub - "[string trim $faq(cmdchar)]modify" faq:modify_fact
bind pub - "[string trim $faq(cmdchar)]close-faq" faq:close-faqdb
bind pub - "[string trim $faq(cmdchar)]open-faq" faq:open-faqdb
bind pub - "[string trim $faq(cmdchar)]faq-help" faq:faq_howto

proc faq:close-faqdb {nick idx handle channel args} {
 global faq
 if { [lsearch -exact [split [string tolower $faq(channels)]] [string tolower $channel]] < 0 } { 
  return 0
 }
 if {![matchattr $handle [string trim $faq(glob_flag)]|[string trim $faq(chan_flag)] $channel]} {
  putnotc $nick "You can't change the faq-database status."
  return 0
 }
 if {$faq(status)==0} {
  set faq(status) 1
  putnotc $nick "The faq-database was \002closed correctly\002."
  putnotc $nick "Now anybody cant use the command '[string trim $faq(cmdchar)] keyword'."
  putnotc $nick "To open the faq-database again use the command '[string trim $faq(cmdchar)]open-faq'."
  return 0
 }
 if {$faq(status)==1} {
  putnotc $nick "The faq-database is \002already closed\002."
  return 0
 }
}

proc faq:open-faqdb {nick idx handle channel args} {
 global faq
 if { [lsearch -exact [split [string tolower $faq(channels)]] [string tolower $channel]] < 0 } {
  return 0
 }
 if {![matchattr $handle [string trim $faq(glob_flag)]|[string trim $faq(chan_flag)] $channel]} {
  putnotc $nick "You can't change the faq-database status."
  return 0
 }
 if {$faq(status)==1} {
  set faq(status) 0
  putnotc $nick "The faq-database was \002opened correctly\002."
  putnotc $nick "Now anybody can use the command '[string trim $faq(cmdchar)] \002keyword\002'."
  putnotc $nick "To close the faq-database again just use the command '[string trim $faq(cmdchar)]close-faq'."
  return 0
 }
 if {$faq(status)==0} {
  putnotc $nick "The faq-database is \002already open\002."
  return 0
 }
}


proc faq:explain_fact {nick idx handle channel args} {
 global faq
 if { [lsearch -exact [split [string tolower $faq(channels)]] [string tolower $channel]] < 0 } {
  return 0
 }
 if {$faq(status) == 1} { 
  putnotc $nick "The faq-database is \002closed\002."
  return 0 
 }
 if {![file exist $faq(database)]} { 
  set database [open $faq(database) w]
  puts -nonewline $database ""
  close $database
 }
 set fact [ string trim [ string tolower [ join $args ] ] ]
 if {$fact == ""} {
#  putmsg $nick "Syntax: [string trim $faq(cmdchar)] \002keyword\002"
  return 0
 }
 set database [open $faq(database) r]
 set dbline ""
 while {![eof $database]} {
  gets $database dbline
  set dbfact [ string tolower [ lindex [split $dbline [string trim $faq(splitchar)]] 0 ]] 
  set dbdefinition [string range $dbline [expr [string length $fact]+1] end]
  if {$dbfact==$fact} {
    if {[string match -nocase "*$faq(newline)*" $dbdefinition]} {
      set out1 [lindex [split $dbdefinition $faq(newline)] 0]
      set out2 [string range $dbdefinition [expr [string length $out1]+2] end]
      putmsg $channel "\002$fact\002: $out1"
      putmsg $channel "\002$fact\002: $out2"
   } else { 
     putmsg $channel "\002$fact\002: $dbdefinition"
   }
   close $database
   return 0
  }
 }
 close $database
 putnotc $nick "I don't know about \002$fact\002."
 if {[matchattr $handle [string trim $faq(glob_flag)]|[string trim $faq(chan_flag)] $channel]} {
  putnotc $nick "You could add \002$fact\002 by using [string trim $faq(cmdchar)]addword \002$fact\002[string trim $faq(splitchar)]Definition goes here."
 } else {
#  putnotc $nick "If you're looking for a TCL-Script try http://www.egghelp.org/cgi-bin/tcl_archive.tcl?strings=$fact"
 }
 return 0
}

proc faq:tell_fact {nick idx handle channel args} {
 global faq
 if { [lsearch -exact [split [string tolower $faq(channels)]] [string tolower $channel]] < 0 } {
  return 0
 }
 if {$faq(status)==1} { 
  putnotc $nick "The faq-database is \002closed\002."
  return 0 
 }
 if {![file exist $faq(database)]} { 
  set database [open $faq(database) w]
  puts -nonewline $database ""
  close $database
 }
 set tellnick [ lindex [split [join $args]] 0 ] 
 set fact [ string trim [ string tolower [ join [ lrange [split [join $args]] 1 end ] ] ] ]
 if {$tellnick == ""} { 
  putnotc $nick "Syntax: [string trim $faq(cmdchar)]faq \002nick\002 keyword"
  return 0 
 }
 if {$fact == ""} { 
  putnotc $nick "Syntax: [string trim $faq(cmdchar)]faq nick \002keyword\002"
  return 0
 }
 set database [open $faq(database) r]
 set dbline ""
 while {![eof $database]} {
  gets $database dbline
  set dbfact [ string tolower [ lindex [split $dbline [string trim $faq(splitchar)]] 0 ] ]
  set dbdefinition [string range $dbline [expr [string length $fact]+1] end]
  if {$dbfact==$fact} {
    if {[string match -nocase "*$faq(newline)*" $dbdefinition]} {
      set out1 [lindex [split $dbdefinition "$faq(newline)"] 0]
      set out2 [string range $dbdefinition [expr [string length $out1]+2] end]
      putmsg $channel "\002$tellnick\002: ($dbfact) $out1"
      putmsg $channel "\002$tellnick\002: ($dbfact) $out2"
    } else {
      putmsg $channel "\002$tellnick\002: ($dbfact) $dbdefinition"
    }
    putlog "FAQ: Send keyword \"\002$fact\002\" to $tellnick by $nick ($idx)"
    close $database
    return 0
  }
 }
 close $database
 putnotc $nick "I don't have the keyword \002$fact\002 in my database."
 if {[matchattr $handle [string trim $faq(glob_flag)]|[string trim $faq(chan_flag)] $channel]} {
  putnotc $nick "You could add \002$fact\002 by using [string trim $faq(cmdchar)]addword \002$fact\002[string trim $faq(splitchar)]Definition goes here."
 } else {
#  putnotc $nick "If you're looking for a TCL-Script try http://www.egghelp.org/cgi-bin/tcl_archive.tcl?strings=$fact"
 }
 return 0
}

proc faq:add_fact {nick idx handle channel args} {
 global faq
 if { [lsearch -exact [split [string tolower $faq(channels)]] [string tolower $channel]] < 0 } {
  return 0
 }
 if {$faq(status)==1} {
  putnotc $nick "The faq-database is \002closed\002."
  return 0
 }
 if {![matchattr $handle [string trim $faq(glob_flag)]|[string trim $faq(chan_flag)] $channel]} {
	putnotc $nick "You can't add keywords into my dababase."
  return 0
 }
 if {![file exist $faq(database)]} {
  set database [open $faq(database) w]
  puts -nonewline $database ""
  close $database
 }
 set fact [ string tolower [ lindex [split [join $args] [string trim $faq(splitchar)]] 0 ] ]
 set definition [string range [join $args] [expr [string length $fact]+1] end]  
 set database [open $faq(database) r]
 if {($fact=="")} {
  putnotc $nick "Left parameters."
  putnotc $nick "use: [string trim $faq(cmdchar)]addword \002keyword\002[string trim $faq(splitchar)]definition"
  return 0
 } elseif {($definition=="")} {
  putnotc $nick "Left parameters."
  putnotc $nick "use: [string trim $faq(cmdchar)]addword keyword[string trim $faq(splitchar)]\002definition\002"
  return 0
 }
 while {![eof $database]} {
  gets $database dbline
  set add_fact [ string tolower [ lindex [split $dbline [string trim $faq(splitchar)]] 0 ] ]
  if {$add_fact==$fact} {
   putnotc $nick "This keyword is already in my database:"
   putnotc $nick "Is: \002$fact\002 - $definition"
   putnotc $nick "If you want to modify it just use '[string trim $faq(cmdchar)]modify $fact[string trim $faq(splitchar)]\002definition\002'"
   close $database
   return 0
  }
 }
 close $database
 set database [open $faq(database) a]
 puts $database "$fact[string trim $faq(splitchar)]$definition"
 close $database
 putnotc $nick "The keyword \002$fact\002 was added correctly to my database."
 putnotc $nick "Now: \002$fact\002 - $definition"
}

proc faq:delete_fact {nick idx handle channel args} {
 global faq
 if { [lsearch -exact [split [string tolower $faq(channels)]] [string tolower $channel]] < 0 } {
  return 0
 }
 if {$faq(status)==1} {
  putnotc $nick "The faq-database is \002closed\002."
  return 0
 }
 if {![matchattr $handle [string trim $faq(glob_flag)]|[string trim $faq(chan_flag)] $channel]} {
  putnotc $nick "You can't delete keywords from my database."
  return 0
 }
 if {![file exist $faq(database)]} { 
  set database [open $faq(database) w]
  puts -nonewline $database ""
  close $database
 }
 set fact [string tolower [join $args]]
 if {($fact=="")} {
  putnotc $nick "Left parameters."
  putnotc $nick "use: [string trim $faq(cmdchar)]delword \002keyword\002"
  return 0
 }
 set database [open $faq(database) r]
 set dbline ""
 set found 0
 while {![eof $database]} {
  gets $database dbline
  set dbfact [ string tolower [ lindex [split $dbline [string trim $faq(splitchar)]] 0 ] ]
  set dbdefinition [string range $dbline [expr [string length $fact]+1] end]
  if {$dbfact!=$fact} {
   lappend datalist $dbline
  } else {
   putnotc $nick "The keyword \002$fact\002 was deleted correctly from my database."
   putnotc $nick "Was: \002$dbfact\002 - $dbdefinition"
   set found 1
  }
 }
 close $database
 set databaseout [open $faq(database) w]
 foreach line $datalist {
  if {$line!=""} {puts $databaseout $line}
 }
 close $databaseout
 if {$found != 1} {putnotc $nick "\002$fact\002 not found in my database."}
}

proc faq:modify_fact {nick idx handle channel args} {
 global faq
 if { [lsearch -exact [split [string tolower $faq(channels)]] [string tolower $channel]] < 0 } {
  return 0
 }
 if {$faq(status)==1} {
  putnotc $nick "The faq-database is \002closed\002."
  return 0
 }
 if {![matchattr $handle [string trim $faq(glob_flag)]|[string trim $faq(chan_flag)] $channel]} {
  putnotc $nick "You can't modify keywords in my database."
  return 0
 }
 if {![file exist $faq(database)]} { 
  set database [open $faq(database) w]
  puts -nonewline $database ""
  close $database
 }
 set fact [ string tolower [ lindex [split [join $args] [string trim $faq(splitchar)]] 0 ] ]
 set definition [string range [join $args] [expr [string length $fact]+1] end]
 set database [open $faq(database) r]
 if {($fact=="")} {
  putnotc $nick "Left parameters."
  putnotc $nick "use: [string trim $faq(cmdchar)]modify \002keyword\002[string trim $faq(splitchar)]definition"
  return 0
 }
 if {($definition=="")} {
  putnotc $nick "Left parameters."
  putnotc $nick "use: [string trim $faq(cmdchar)]modify keyword[string trim $faq(splitchar)]\002definition\002"
  return 0
 }
 set database [open $faq(database) r]
 set dbline ""
 set found 0
 while {![eof $database]} {
  gets $database dbline
  set dbfact [ string tolower [ lindex [split $dbline [string trim $faq(splitchar)]] 0 ] ]
  set dbdefinition [string range $dbline [expr [string length $fact]+1] end]
  if {$dbfact!=$fact} {
   lappend datalist $dbline
  } else {
   if {$dbdefinition!=$definition} {
    lappend datalist "$fact[string trim $faq(splitchar)]$definition"
    putnotc $nick "The keyword \002$fact\002 was modified correctly in my database."
    putnotc $nick "Is now: \002$fact\002 - $definition"
    putnotc $nick "Was: $dbfact - $dbdefinition"
    set found 1
   } else {
    lappend datalist $dbline
    putnotc $nick "I already had it that way. \002$fact\002 was not modified."
    putnotc $nick "Is: \002$fact\002 - $definition"
    set found 1
   }
  }
 }
 close $database
 set databaseout [open $faq(database) w]
 foreach line $datalist {
  if {$line!=""} {puts $databaseout $line}
 }
 close $databaseout
 if {$found != 1} {
  putnotc $nick "\002$fact\002 not found in my database"
  putnotc $nick "If you want to add the fact to the database use: [string trim $faq(cmdchar)]addword $fact[string trim $faq(splitchar)]\002description\002"
 }
}

proc faq:faq_howto {nick idx handle channel args} {
 global faq
 if { [lsearch -exact [split [string tolower $faq(channels)]] [string tolower $channel]] < 0 } {
  return 0
 }
 putnotc $nick "Help commands for FAQ Database $faq(version)"
 if {[matchattr $handle [string trim $faq(glob_flag)]|[string trim $faq(chan_flag)] $channel]} {
  if {$faq(status)==0} {
   putnotc $nick " - [string trim $faq(cmdchar)]close-faq"
   putnotc $nick " - [string trim $faq(cmdchar)]addword : [string trim $faq(cmdchar)]addword \002keyword\002[string trim $faq(splitchar)]your description goes here..."
   putnotc $nick " - [string trim $faq(cmdchar)]delword : [string trim $faq(cmdchar)]delword \002keyword\002"
   putnotc $nick " - [string trim $faq(cmdchar)]modify : [string trim $faq(cmdchar)]modify \002keyword\002[string trim $faq(splitchar)]your new description goes here..."
  }
  if {$faq(status)==1} {
   putnotc $nick " - [string trim $faq(cmdchar)]open-faq"
  }
 }
 if {$faq(status)==0} {
  putnotc $nick " - [string trim $faq(cmdchar)] \002keyword\002 : looks up keyword in the database"
  putnotc $nick " - To let the bot tell someone about something use [string trim $faq(cmdchar)]faq nick \002keyword\002"
 }
 if {$faq(status)==1} {
  putnotc $nick "The faq-database is \002closed\002."
 }
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Use the [isop], [ishalfop] and [isvoice] commands to check if the user has +o, +h or +v. Read tcl-commands.doc about these three commands.
d
draftmann
Voice
Posts: 3
Joined: Fri Aug 12, 2005 9:15 am

Post by draftmann »

thanks for ur reply Sir_Fz, can u please fixed this for me coz i dont know much about tcl and its command :(
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I'm not so interrested in fixing all that but if you help yourself then we'll defenitely help you.
d
draftmann
Voice
Posts: 3
Joined: Fri Aug 12, 2005 9:15 am

Post by draftmann »

Sir_Fz: i have no idea about scripting so can u please help me out.
Locked