Paste2 Logo
  1. #cs
  2. Autore: Red Skull
  3. Mail: RedSkull[At]gmail[Dot]com
  4. Web: http://redskull92.wordpress.com
  5. Descrizione: Bot Irc in AutoIt By Red Skull
  6. Versione: 1.0
  7. #ce
  8.  
  9. #include <string.au3>
  10. #include <array.au3>
  11.  
  12. Global Const $server="server",$porta=6668,$nick="SkullBot",$canale="#canale",$version="1.0",$padrone="nick"
  13. Global $tizzi[1]
  14.  
  15. TCPStartup()
  16. Global $conn=TCPConnect(TCPNameToIP($server),$porta)
  17. TCPSend($conn,"NICK "&$nick&@CRLF)
  18. TCPSend($conn,"USER "&$nick&" 0 * :"&$nick&@CRLF)
  19. TCPSend($conn,"JOIN "&$canale&@CRLF)
  20.  
  21. ;Saluta appena entra
  22. Rispondi(0,"Salve")
  23.  
  24. While 1
  25.         $recv = TCPRecv($conn, 10000)
  26.         $split=StringSplit($recv,@CRLF)
  27.         For $i=0 To $split[0]
  28.                 $cerca=StringSplit($split[$i]," ")
  29.                 ;Risponde al PING
  30.                 If $cerca[1] = "PING" Then TCPSend($conn,"PONG "&$cerca[2]&@CRLF)
  31.                 If $cerca[1] = "" Then ContinueLoop
  32.                 If $cerca[0] <= 2 Then ContinueLoop
  33.                 Switch $cerca[2]                               
  34.                         Case "PRIVMSG"
  35.                                 ;Prende user e messaggio
  36.                         Global  $user=StringRegExp($cerca[1],":(.*?)!",3)
  37.                         Global  $mex=StringRegExp($split[$i],":(.+?):(.+)",3)
  38.                                 If StringCompare($cerca[3],$canale) <> 0 Then
  39.                                         ;Se riceve una query
  40.                                         Controlla(StringLower($mex[1]),$user[0],1)
  41.                                 Else
  42.                                         ;Se riceve un messaggio publico
  43.                                         Controlla(StringLower($mex[1]),$user[0],0)
  44.                                 EndIf
  45.                         Case "KICK"
  46.                                 ;In caso il bot viene kickato
  47.                                 Dim $text[7]=["Perchè ?","Fottiti","Fanculo","Muori","Fuck","GTFO"]
  48.                                 TCPSend($conn,"JOIN "&$canale&@CRLF)
  49.                                 $who=StringRegExp($cerca[1],":(.*?)!",3)
  50.                                 Rispondi(0,$text[Random(0,6,1)]&" "&$who[0])
  51.                         Case "QUIT"
  52.                                   $tizzio=StringRegExp($cerca[1],":(.*?)!",3)
  53.                                   _ArrayDelete($tizzi,$tizzio[0])
  54.                 EndSwitch
  55.         Next
  56.                                
  57.        
  58.  
  59. WEnd
  60.  
  61. Func Rispondi($priv=0,$msg="")
  62.         If $priv = 0 Then
  63.                 ;Public
  64.                 TCPSend($conn,"PRIVMSG "&$canale&" :"&$msg&@CRLF)
  65.         Else
  66.                 ;Query
  67.                 TCPSend($conn,"PRIVMSG "&$user[0]&" :"&$msg&@CRLF)
  68.         EndIf
  69. EndFunc
  70.  
  71. Func Controlla($mex="",$utente="",$query=0)
  72.                  ;Saluta 1 sola volta per utente, a meno chè non quitti.
  73.                  $find=StringRegExp($mex,"(ciao|we!eccomi|salve|hola|giorno|sera|notte)",3)
  74.                  If @error = 0 And _ArraySearch($tizzi,$utente) = -1 Then      
  75.                         Rispondi($query,"Ciao "&$utente&" ^^")
  76.                         _ArrayAdd($tizzi,$utente)
  77.                  EndIf
  78.                  ;Versione
  79.                  $find=StringRegExp($mex,"!!v",3)
  80.                  If @error = 0 Then Rispondi($query,"Versione SkullBot : "&$version)
  81.                  ;Uso
  82.                  $find=StringRegExp($mex,"!!usage",3)
  83.                  If @error = 0 Then
  84.                          If $utente = $padrone Then
  85.                                  Rispondi(0,"SkullBot By Red Skull")
  86.                                  Rispondi(0,"Versione:"&$version)
  87.                                  Rispondi(0,"!!v - Mostra la versione")
  88.                                  Rispondi(0,"!!author - Mostra l'autore")
  89.                                  Rispondi(0,"!!quit - Termina il bot")
  90.                                  Rispondi(0,"!!speak - Parla al posto tuo (Solo in query)")
  91.                                  Rispondi(0,"!!upper - Trasforma una stringa in MAIUSCOLO")
  92.                                  Rispondi(0,"!!reverse - Gira una stringa")
  93.                          Else
  94.                                  Rispondi(0,"Solo il mio padrone può vedere come usarmi !")
  95.                          EndIf
  96.                 EndIf
  97.                 ;Autore
  98.                 $find=StringRegExp($mex,"!!author",3)
  99.                  If @error = 0 Then
  100.                  Rispondi(0,"Autore: Red Skull")
  101.                  Rispondi(0,"Mail: RedSkull92@gmail.com")
  102.                  Rispondi(0,"Sito: http://redskull92.wordpress.com")           
  103.                  EndIf
  104.                 ;Uscita
  105.                 $find=StringRegExp($mex,"!!quit",3)
  106.                 If @error = 0 Then
  107.                         If $utente = $padrone Then
  108.                                 Rispondi($query,"Bye !!")
  109.                                 TCPSend($conn,"QUIT"&@CRLF)
  110.                                 TCPShutdown()
  111.                                 Exit
  112.                         Else
  113.                                 Rispondi($query,"Solo il mio padrone può terminarmi!")
  114.                         EndIf
  115.                 EndIf
  116.                 ;Parla come il bot
  117.                 $find=StringRegExp($mex,"!!speak (.+)",3)
  118.                 If @error = 0 And $query=1 Then
  119.                         If $utente = $padrone Then
  120.                                 Rispondi(0,$find[0])
  121.                         Else
  122.                                 Rispondi(0,"Solo il mio padrone può farmi parlare!")
  123.                         EndIf
  124.                 EndIf
  125.                 ;Trasforma una stringa in maiuscolo
  126.                 $find=StringRegExp($mex,"!!upper (.+)",3)
  127.                 If @error = 0 Then Rispondi($query,StringUpper($find[0]))
  128.                 ;Stampa la stringa al contrario
  129.                 $find=StringRegExp($mex,"!!reverse (.+)",3)
  130.                 If @error = 0 Then Rispondi($query,_StringReverse($find[0]))
  131.                        
  132. EndFunc
  133.        
  134. ;By
  135. ;Red Skull
  136.        

SkullBot

By Red Skull