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.

script request

Old posts that have not been replied to for several years.
Locked
d
dragoneye
Voice
Posts: 9
Joined: Tue Apr 19, 2005 4:21 pm

script request

Post by dragoneye »

hello guys again =) im currently working on a matchfindbot-script but i cannot figure how to make a spam protection to it, i also need somekinda timer to delete 1 line from the database.
script works like this when u type !cw 3 now on the bot will
msg [ RQ3 CW ] #channel is looking for 3vs3 @ now - Server on
and save it to database.txt, when u type !cwlist the bot will read the database.txt and passes the text to the channel. i need somekinda timer to delete the msg from the database when 15min have passed, but i dont wanna delete all messages from there only that 1 line wich you typed 15mins ago. so here is the script. that !remove is only a temporally until i can get that timerthing to work

Code: Select all

# (c) Dragoneye & babou
set chanlist [channels]
set vs "vs"

bind pub - !cw ewa_cw
bind pub - !help ewa_help
bind msg m|m spam ewa_spam
bind pub - !ctb ewa_pcw
bind pub - !cwlist ewa_cwlist
bind pub - !remove ewa_remove

proc ewa_spam { nick uhost handle arg } {
  global chanlist
  for { set index 0 } { $index<[llength $chanlist] } { incr index } {
            puthelp "PRIVMSG [lindex $chanlist $index] :$arg"
  }
}            
  

proc ewa_help { nick uhost handle channel arg } {
  puthelp "NOTICE $nick : *******Matchfind*******"
  puthelp "NOTICE $nick : !cw <number of players> <time> <on/off>"
  puthelp "NOTICE $nick : You can do '!CTB' with same use to ask for a Capture the briefcase cw."
  puthelp "NOTICE $nick : for example: !cw 4 9pm on"
  puthelp "NOTICE $nick : <on/off> is the status of a server. If you can have one do 'on', if not do 'off'."
  puthelp "NOTICE $nick : You need to be OP to ask for a cw. If ReactionBot is not on your channel ask it to Dragoneye @ #clan.sup or mail dragon@netikka.fi."
    puthelp "NOTICE $nick : *******Teh End**********"
}


proc ewa_cw { nick uhost handle channel arg } {
  global chanlist vs
set file datafile.txt
  if {![file exists $file]} {close [open $file w]}
  set io [open $file w]
    if { [isop $nick $channel] } {
    set ewa_playernumber [string tolower [lindex $arg 0]]
    set ewa_time [lindex $arg 1]
    set ewa_server [string tolower [lindex $arg 2]]
    if { ( $ewa_playernumber != "" ) && ( $ewa_time !="" ) && ( $ewa_server !="" ) } {
      if { $ewa_playernumber == "1" || $ewa_playernumber == "2" || $ewa_playernumber == "3" || $ewa_playernumber == "4" || $ewa_playernumber == "5" || $ewa_playernumber == "6" || $ewa_playernumber == "7" || $ewa_playernumber == "8" } {
        if { ( $ewa_server == "on" ) || ( $ewa_server == "off" ) } {
          set ewa_status $ewa_server
          for { set index 0 } { $index<[llength $chanlist] } { incr index } {
            putserv "PRIVMSG [lindex $chanlist $index] :\\[ RQ3 CW \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
           # putserv "PRIVMSG reactionbot3 :spam \[ RQ3 CW \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
           # putserv "PRIVMSG reactionbot2 :spam \[ RQ3 CW \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
    }
puts $io "\[ RQ3 CW ]\ $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
  close $io
        } else {
          puthelp "NOTICE $nick : $ewa_server is a bad server status, it must be 'on' or 'off'. Try '!help' for more info."
        } 
      } else {
        puthelp "NOTICE $nick : $ewa_playernumber is bad, it's the number of players you want in the cw. It must be set between 1 and 8. Try '!help' for more info."
      }
    } else {
      puthelp "NOTICE $nick : Uh?? What are you trying to say? Do '!help' for more info."
    }  
  } else {
    puthelp "NOTICE $nick : You need to be OP to ask for a cw. You need to be OP to ask for a cw. If ReactionBot is not on your channel ask it to Dragoneye @ #clan.sup or mail dragon@netikka.fi."
  }
}

proc ewa_pcw { nick uhost handle channel arg } {
   global chanlist vs
  if { [isop $nick $channel] } {
    set ewa_playernumber [string tolower [lindex $arg 0]]
    set ewa_time [lindex $arg 1]
    set ewa_server [string tolower [lindex $arg 2]]
    if { ( $ewa_playernumber != "" ) && ( $ewa_time !="" ) && ( $ewa_server !="" ) } {
      if { $ewa_playernumber == "1" || $ewa_playernumber == "2" || $ewa_playernumber == "3" || $ewa_playernumber == "4" || $ewa_playernumber == "5" || $ewa_playernumber == "6" || $ewa_playernumber == "7" || $ewa_playernumber == "8" } {
        if { ( $ewa_server == "on" ) || ( $ewa_server == "off" ) } {
          set ewa_status $ewa_server
          for { set index 0 } { $index<[llength $chanlist] } { incr index } {
            putserv "PRIVMSG [lindex $chanlist $index] :\\[ RQ3 CTB \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
         #   putserv "PRIVMSG reactionbot3 :spam \[ RQ3 CTB \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
         #   putserv "PRIVMSG reactionbot2 :spam \[ RQ3 CTB \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
		}
        } else {
          puthelp "NOTICE $nick : $ewa_server is a bad server status, it must be 'on' or 'off'. Try '!help' for more info."
        } 
      } else {
        puthelp "NOTICE $nick : $ewa_playernumber is bad, it's the number of players you want in the cw. It must be set between 1 and 8. Try '!help' for more info."
      }
    } else {
      puthelp "NOTICE $nick : Uh?? What are you trying to say? Do '!help' for more info."
    }  
  } else {
    puthelp "NOTICE $nick : You need to be OP to ask for a cw. You need to be OP to ask for a cw. If ReactionBot is not on your channel ask it to Dragoneye @ #clan.sup or mail dragon@netikka.fi."
  }
}

proc ewa_cwlist {nick uhost handle channel arg} {
  set file datafile.txt
  if {![file exists $file]} {close [open $file w]}
  set io [open $file r]
  set list ""
  while {![eof $io]} {
    gets $io line
    if {[string trim $line] == ""} {continue}
    lappend list $line
  }
  close $io
  set length [llength $list]
  set message "$length match[expr {($length == "1")?"":"es"}] found."
  putserv "PRIVMSG $channel :$message"
  foreach line $list {
    putserv "PRIVMSG $channel :$line"
  }
}


proc ewa_remove {nick uhost handle channel arg} {
  set file datafile.txt
  if {![file exists $file]} {close [open $file w]}
  set io [open $file r]
  set list ""
  while {![eof $io]} {
    gets $io line
    set line [string tolower $line]
    if {([string trim $line] == "") ||
        ($line == [string tolower $arg])} {continue}
    lappend list $line
  }
  close $io
  set io [open $file w]
  foreach line $list {puts $io $line}
  close $io
  putserv "PRIVMSG $channel :Removed. $arg"
}
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

flood:
place a "set cwflood 0" to the global init (like below set vs).

then append cwflood to "global chanlist vs", as far as I can see you need to do this in both procs.
now add this code below the global line:

Code: Select all

   if { $cwflood > 3 } {
      return 0
   }
   incr cwflood
   utimer 60 {incr cwflood -1}
replace the number '3' and '60' to whatever you like. The current setting would limit the usage to 3 per 60sec, meaning the 4th and more is ignored until 60sec of the 4th has passed.

delete:
add this line just below the puts and close where it will be saved:

timer 15 [list ewa_t_remove "\[ RQ3 CW ]\ $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"]

then add this proc:

Code: Select all

proc ewa_t_remove {text} {
   set file datafile.txt
   set io [open $file r]
      set list [split [read $io] \n]
   close $io
   if { [set line [lsearch $list $text]] != -1 } {
      set list [lreplace $list $line $line]
      set io [open $file w]
         puts -nonewline [join $line \n]
      close $io
   } else {
      putlog "error triing find line to delete in $file."
   }
}
I am not 100% sure if this lsearch will find it again this way, so i put in the putlog to catch this logical error, if it occurs :D.

PS: in the proc where you add the new entry via put you should rather use "set io [open $file a]" instead of "set io [open $file w]". opening with w will just overwrite the file, a will append at the end without reading the complete file.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

after some talk on IRC here the fixed total version

Code: Select all

set chanlist [channels]
set vs "vs"


bind pub - !cw ewa_cw
bind pub - !help ewa_help
bind msg m|m spam ewa_spam
bind pub - !ctb ewa_pcw
bind pub - !cwlist ewa_cwlist
bind pub - !remove ewa_remove

proc ewa_spam { nick uhost handle arg } {
  global chanlist
  for { set index 0 } { $index<[llength $chanlist] } { incr index } {
            puthelp "PRIVMSG [lindex $chanlist $index] :$arg"
  }
}            
  

proc ewa_help { nick uhost handle channel arg } {
  puthelp "NOTICE $nick : *******Matchfind*******"
  puthelp "NOTICE $nick : !cw <number of players> <time> <on/off>"
  puthelp "NOTICE $nick : You can do '!CTB' with same use to ask for a Capture the briefcase cw."
  puthelp "NOTICE $nick : for example: !cw 4 9pm on"
  puthelp "NOTICE $nick : <on/off> is the status of a server. If you can have one do 'on', if not do 'off'."
  puthelp "NOTICE $nick : You need to be OP to ask for a cw. If ReactionBot is not on your channel ask it to Dragoneye @ #clan.sup or mail dragon@netikka.fi."
    puthelp "NOTICE $nick : *******Teh End**********"
}


proc ewa_cw { nick uhost handle channel arg } {
  global chanlist vs cwflood 
  set arg [split $arg]
  if { ![info exists cwflood($channel)] } {
  	set cwflood($channel) 1
  } elseif { $cwflood($channel) > 2 } {
    puthelp "NOTICE $nick :Sorry dude, you have reached your limit, try again a few minutes later."
    return 0
  } else {
    incr cwflood($channel)
  }
  timer 10 [list incr cwflood($channel) -1]
  set file datafile.txt
  if {![file exists $file]} {close [open $file w]}
  set io [open $file a]
    if { [isop $nick $channel] } {
    set ewa_playernumber [string tolower [lindex $arg 0]]
    set ewa_time [lindex $arg 1]
    set ewa_server [string tolower [lindex $arg 2]]
    if { ( $ewa_playernumber != "" ) && ( $ewa_time !="" ) && ( $ewa_server !="" ) } {
      if { $ewa_playernumber == "1" || $ewa_playernumber == "2" || $ewa_playernumber == "3" || $ewa_playernumber == "4" || $ewa_playernumber == "5" || $ewa_playernumber == "6" || $ewa_playernumber == "7" || $ewa_playernumber == "8" } {
        if { ( $ewa_server == "on" ) || ( $ewa_server == "off" ) } {
          set ewa_status $ewa_server
          for { set index 0 } { $index<[llength $chanlist] } { incr index } {
            putserv "PRIVMSG [lindex $chanlist $index] :\\[ RQ3 CW \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
           # putserv "PRIVMSG reactionbot3 :spam \[ RQ3 CW \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
           # putserv "PRIVMSG reactionbot2 :spam \[ RQ3 CW \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
    }
    puts $io "\[ RQ3 CW ]\ $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
  close $io
  timer 15 [list ewa_t_remove "\[ RQ3 CW ]\ $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"] 

      } else {
          puthelp "NOTICE $nick : $ewa_server is a bad server status, it must be 'on' or 'off'. Try '!help' for more info."
        } 
      } else {
        puthelp "NOTICE $nick : $ewa_playernumber is bad, it's the number of players you want in the cw. It must be set between 1 and 8. Try '!help' for more info."
      }
    } else {
      puthelp "NOTICE $nick : Uh?? What are you trying to say? Do '!help' for more info."
    }  
  } else {
    puthelp "NOTICE $nick : You need to be OP to ask for a cw. You need to be OP to ask for a cw. If ReactionBot is not on your channel ask it to Dragoneye @ #clan.sup or mail dragon@netikka.fi."
  }
}

proc ewa_pcw { nick uhost handle channel arg } {
  global chanlist vs cwflood 
  set arg [split $arg]
  if { ![info exists cwflood($channel)] } {
  	set cwflood($channel) 1
  } elseif { $cwflood($channel) > 2 } {
    puthelp "NOTICE $nick :Sorry dude, you have reached your limit, try again a few minutes later."
    return 0
  } else {
    incr cwflood($channel)
  }
  timer 10 [list incr cwflood($channel) -1]
  if { [isop $nick $channel] } {
    set ewa_playernumber [string tolower [lindex $arg 0]]
    set ewa_time [lindex $arg 1]
    set ewa_server [string tolower [lindex $arg 2]]
    if { ( $ewa_playernumber != "" ) && ( $ewa_time !="" ) && ( $ewa_server !="" ) } {
      if { $ewa_playernumber == "1" || $ewa_playernumber == "2" || $ewa_playernumber == "3" || $ewa_playernumber == "4" || $ewa_playernumber == "5" || $ewa_playernumber == "6" || $ewa_playernumber == "7" || $ewa_playernumber == "8" } {
        if { ( $ewa_server == "on" ) || ( $ewa_server == "off" ) } {
          set ewa_status $ewa_server
          for { set index 0 } { $index<[llength $chanlist] } { incr index } {
            putserv "PRIVMSG [lindex $chanlist $index] :\\[ RQ3 CTB \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
         #   putserv "PRIVMSG reactionbot3 :spam \[ RQ3 CTB \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
         #   putserv "PRIVMSG reactionbot2 :spam \[ RQ3 CTB \] $channel is looking for $ewa_playernumber$vs$ewa_playernumber @ $ewa_time - Server $ewa_status"
		}
        } else {
          puthelp "NOTICE $nick : $ewa_server is a bad server status, it must be 'on' or 'off'. Try '!help' for more info."
        } 
      } else {
        puthelp "NOTICE $nick : $ewa_playernumber is bad, it's the number of players you want in the cw. It must be set between 1 and 8. Try '!help' for more info."
      }
    } else {
      puthelp "NOTICE $nick : Uh?? What are you trying to say? Do '!help' for more info."
    }  
  } else {
    puthelp "NOTICE $nick : You need to be OP to ask for a cw. You need to be OP to ask for a cw. If ReactionBot is not on your channel ask it to Dragoneye @ #clan.sup or mail dragon@netikka.fi."
  }
}

proc ewa_cwlist {nick uhost handle channel arg} {
  set file datafile.txt
  if {![file exists $file]} {close [open $file w]}
  set io [open $file r]
  set list ""
  while {![eof $io]} {
    gets $io line
    if {[string trim $line] == ""} {continue}
    lappend list $line
  }
  close $io
  set length [llength $list]
  set message "$length match[expr {($length == "1")?"":"es"}] found."
  putserv "PRIVMSG $channel :$message"
  foreach line $list {
    putserv "PRIVMSG $channel :$line"
  }
}

proc ewa_remove {nick uhost handle channel arg} {
  set file datafile.txt
  if {![file exists $file]} {close [open $file w]}
  set io [open $file r]
  set list ""
  while {![eof $io]} {
    gets $io line
    set line [string tolower $line]
    if {([string trim $line] == "") ||
        ($line == [string tolower $arg])} {continue}
    lappend list $line
  }
  close $io
  set io [open $file w]
  foreach line $list {puts $io $line}
  close $io
  putserv "PRIVMSG $channel :Removed. $arg"
}

proc ewa_t_remove {text} {
   set file datafile.txt
   set io [open $file r]
      set list [split [read $io] \n]
   close $io
   if { [set line [lsearch -exact $list $text]] != -1 } {
      set list [lreplace $list $line $line]
      set io [open $file w]
         puts -nonewline $io [join $list \n]
      close $io
   } else {
      putlog "error triing find line to delete in $file."
   }
}
PS: edited
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
d
dragoneye
Voice
Posts: 9
Joined: Tue Apr 19, 2005 4:21 pm

Post by dragoneye »

thx to allmighty De Kus the script works now =)
Locked