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.

Spam Question Script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Spam Question Script

Post by ComputerTech »

So looking for a script that will make the bot generate a random letter/number then ask like this via PM to the user.

Generated code Kwq89fsef

Answer what above code says with !code <answer here>

So to answer in short, i need a script that generates a random letter/number code and asks the user via PM what the above code says and if the user answers the correct code then it passes and it not, it fails

Thanks in advanced :)
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

You have the random generator @ http://forum.egghelp.org/viewtopic.php?t=20848

just fill an array with it and wait for the answer:

Code: Select all

array set sentcode {}

bind pub o|o "!gencode" gencode
proc gencode {nick uhost handle chan text} {
   set args [split $text]
   if {[llength $args]!=1} {
      putserv "PRIVMSG $nick :usage is !gencode <victim>"
      return 1
   }
   set victim [join [lindex $args 0]]
   if {![onchan $victim]} {
      putserv "PRIVMSG $nick :Can't find $victim"
      return 1
   }
   set code [randString 8 8]
   set ::sentcode([string tolower $victim]) $code
   putserv "PRIVMSG $victim :your code is $code"
}

bind pub - "!code" getcode
proc getcode {nick uhost handle chan text} {
   set args [split $text]
   set victim [string tolower $nick]
   if {[llength $args]!=1} {
      putserv "PRIVMSG $nick :usage is !code <your code>"
      return 1
   }
   if {![info exists ::sentcode($victim)]} {
      putserv "PRIVMSG $nick :I'm not waiting a code from you"
      return 1
   }
   set code [join [lindex $args 0]]
   if {$::sentcode($victim) eq $code} {
      putserv "PRIVMSG $nick :Ok"
      unset ::sentcode($victim)
   } else {
      putserv "PRIVMSG $nick :Error with the code"
      return 1
   }
}

# usage : randString <min> <max>
proc randString { {min 1} {max 8} } {
   set chars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
   set size [expr {int(rand()*($max-$min+1)+$min)}]
   set range [string length $chars]
   set txt ""
   for {set i 0} {$i < $size} {incr i} {
      set pos [expr {int(rand()*$range)}]
      append txt [string index $chars $pos]
   }
   return $txt
}
Feel free to adapt that (not tested, some errors can occure)
s
simo
Revered One
Posts: 1079
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i would simply use nickserv for that and set channel to +R
User avatar
CrazyCat
Revered One
Posts: 1236
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

simo wrote:i would simply use nickserv for that and set channel to +R
ComputerTech never said it was to access a channel, he said the !code command must pass if codes match, and fail if not.
Nothing seems related to nickserv nor channel access.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Yeah, it was actually suppose to be a Spam Question security for a ZNC Request Eggdrop 8)

But thank you CrazyCat for that code, i will try it right away :wink:
ComputerTech
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

That worked brilliant CrazyCat, thank you :D
ComputerTech
Post Reply