antibot script

Release your script here.
State:
- Author
- What it does
- Perhaps a little guide.
- Also, if the snippet is of any use to the community, it has a chance of getting posted on the main page, so don't hesitate to submit/ask!

antibot script

Postby Cristian » Thu Aug 12, 2010 3:54 pm

Uhh shabby topic

To enable the script:
    telnet your bot, .chanset #channel +question to enable the script.


What does it do:
    if a user joins the channel s/he will be queryed with a calculation question, if s/he answers wrong or dont answer at all, s/he will be banned for 24hours.
    s/he needs to answer with '.answer <answer>'

Please change:
    please change #channel to the channel you wish to use it on.
    please change kickreason if needed


Errors or feedback:
    works with eggdrop 1.6.19
    if anything dont work or it gives errors please post them here


Code: Select all
setudef flag question
namespace eval question {

   bind join - *             [namespace current]::onjoin
   bind msgm - ".answer *"      [namespace current]::answer
   
   
   namespace eval variable {
      variable bantime 1440
      variable tag "Banned:"
      variable kickreason "Possible bot"
      variable channel "#channel"
   }

   proc onjoin {nickname hostname handle channel} {
      global botnick timers answer
      
      if {[channel get $channel question] == 1} {
         if {![isbotnick $nickname] && ![info exists timers($hostname)]} {
            set num1 [rand 9]
            set num2 [rand 9]
            set q [expr $num1 + $num2]
            
            set answer($hostname) $q
            set timers($hostname) [timer 2 [list ::question::noanswer $hostname]]         

            putserv "PRIVMSG $nickname :I have a question, I want you to answer with '.answer <your-answer>'."
            putserv "PRIVMSG $nickname :What is $num1 + $num2"
            
         }
      }
   }
   
   
   
   
   
   proc noanswer {hostname} {
      global botnick timers answer
      if {[info exists timers($hostname)]} {
         set channel $::question::variable::channel
         set bantime $::question::variable::bantime
         
         foreach user [chanlist $channel] {
            if {[string match "$hostname" "[string trim [getchanhost $user $channel] "~"]"]} {
               set victim [string tolower $user]
            }
         }   
         if {[info exists victim]} {
            if {[botisop $channel]} {      
               putserv "mode $channel +b *!*[string trim $hostname "~"]"
               putserv "kick $channel $victim :$::question::variable::tag $::question::variable::kickreason"
               putserv "PRIVMSG $victim :you didn't answer my question."
            }
            newchanban $channel *!*[string trim $hostname "~"] question "$::question::variable::kickreason" $bantime
         }
         unset timers($hostname)
         unset answer($hostname)
      }
   }
   
   
   
   
   
   
   proc answer {nickname hostname handle arguments} {
      global botnick timers answer
      if {[info exists timers($hostname)]} {
      
         set channel $::question::variable::channel
         set bantime $::question::variable::bantime
         set correctanswer [lindex $arguments 1]   
      
         if {[string match $correctanswer $answer($hostname)] != 1} {
            if {[botisop $channel]} {
               putserv "mode $channel +b *!*[string trim $hostname "~"]"
               putserv "kick $channel $nickname :$::question::variable::tag $::question::variable::kickreason"
            }
            killtimer $timers($hostname)
            newchanban $channel *!*[string trim $hostname "~"] question "$::question::variable::kickreason" $bantime
            putserv "PRIVMSG $nickname :incorrect answer."
         } else {
            killtimer $timers($hostname)
            putserv "PRIVMSG $nickname :correct answer."
         }
         unset timers($hostname)
         unset answer($hostname)
      }
   }
}
putlog "\00304[string range [info script] 0 end]\00304 \002loaded...\002"
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar

Re: antibot script

Postby r0t3n » Fri Aug 13, 2010 1:05 pm

You could optimize that code alot better, firstly pubm is not required, use pub without the wildcard, secondly you can kill that timer on answer as for every user who answers your question, your running two procedures which is a waste of resources, and eggdrop is old and slow as is.

Thirdly, anyone with basic scripting knowledge can code a bot to bypass that check, a simple calculation question is nothing to a script kiddie with 10 minutes on their hands to write a script to shoot the answer back to the bot.

Also, in your noanswer proc, you do a foreach loop to grab the users nickname, this will fail if there is more than one user with the same hostname, you could end up kicking the wrong user, a user who could of already passed the check(s), you also dont break your foreach loop on the first match, so your victim variable will get overwritten on new matches until loop end, your banmask is also *!*ident@host.tld and the use of newchanban could ban all users matching that banmask, both verified and/or non-verified users, i'd recommend not using newchanban and just deploy a utimer to unset the ban, also i wouldn't use timer in eggdrop as its buggy, i'd recommend using utimer, which is deployed using seconds rather than minutes, so its more accurate.

Just thought i'd give my feedback =)
r0t3n
 

Re: antibot script

Postby Cristian » Fri Aug 13, 2010 4:33 pm

thanks for your lovely feedback ;)

1) true, I'll change that right away (I'm embarrassed)
2) could you explain that in more details, because I thought I killed the timer in the proc.
3) true true, but that wasn't the job ;)
4) If users have the same ident and hostname, they are kinda asking for it, if one of them screws things up, and yeah I agree with you, my foreach is very poor built.



please keep those replys coming (I saw you on irc).
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar


Return to TCL Scripting Release

Who is online

Users browsing this forum: No registered users and 3 guests

cron