Your Ad Here
#cs
Autore: Red Skull
Mail: RedSkull[At]gmail[Dot]com
Web: http://redskull92.wordpress.com
Descrizione: Bot Irc in AutoIt By Red Skull
Versione: 1.0
#ce

#include <string.au3>
#include <array.au3>

Global Const $server="server",$porta=6668,$nick="SkullBot",$canale="#canale",$version="1.0",$padrone="nick"
Global $tizzi[1]

TCPStartup()
Global $conn=TCPConnect(TCPNameToIP($server),$porta)
TCPSend($conn,"NICK "&$nick&@CRLF)
TCPSend($conn,"USER "&$nick&" 0 * :"&$nick&@CRLF)
TCPSend($conn,"JOIN "&$canale&@CRLF)

;Saluta appena entra
Rispondi(0,"Salve")

While 1
	$recv = TCPRecv($conn, 10000)
	$split=StringSplit($recv,@CRLF)
	For $i=0 To $split[0]
		$cerca=StringSplit($split[$i]," ")
		;Risponde al PING
		If $cerca[1] = "PING" Then TCPSend($conn,"PONG "&$cerca[2]&@CRLF)
		If $cerca[1] = "" Then ContinueLoop
		If $cerca[0] <= 2 Then ContinueLoop
		Switch $cerca[2]				
			Case "PRIVMSG"
				;Prende user e messaggio
			Global	$user=StringRegExp($cerca[1],":(.*?)!",3)
			Global	$mex=StringRegExp($split[$i],":(.+?):(.+)",3)
				If StringCompare($cerca[3],$canale) <> 0 Then
					;Se riceve una query
					Controlla(StringLower($mex[1]),$user[0],1)
				Else
					;Se riceve un messaggio publico
					Controlla(StringLower($mex[1]),$user[0],0)
				EndIf
			Case "KICK"
				;In caso il bot viene kickato
				Dim $text[7]=["Perchè ?","Fottiti","Fanculo","Muori","Fuck","GTFO"] 
				TCPSend($conn,"JOIN "&$canale&@CRLF)
				$who=StringRegExp($cerca[1],":(.*?)!",3)
				Rispondi(0,$text[Random(0,6,1)]&" "&$who[0])
			Case "QUIT"
				  $tizzio=StringRegExp($cerca[1],":(.*?)!",3)
				  _ArrayDelete($tizzi,$tizzio[0])
		EndSwitch
	Next
				
	

WEnd

Func Rispondi($priv=0,$msg="")
	If $priv = 0 Then
		;Public
		TCPSend($conn,"PRIVMSG "&$canale&" :"&$msg&@CRLF)
	Else
		;Query
		TCPSend($conn,"PRIVMSG "&$user[0]&" :"&$msg&@CRLF)
	EndIf
EndFunc

Func Controlla($mex="",$utente="",$query=0)
		 ;Saluta 1 sola volta per utente, a meno chè non quitti.
		 $find=StringRegExp($mex,"(ciao|we!eccomi|salve|hola|giorno|sera|notte)",3) 
		 If @error = 0 And _ArraySearch($tizzi,$utente) = -1 Then	
			Rispondi($query,"Ciao "&$utente&" ^^") 
			_ArrayAdd($tizzi,$utente)
		 EndIf
		 ;Versione
		 $find=StringRegExp($mex,"!!v",3)
		 If @error = 0 Then Rispondi($query,"Versione SkullBot : "&$version)
		 ;Uso
		 $find=StringRegExp($mex,"!!usage",3)
		 If @error = 0 Then 
			 If $utente = $padrone Then
				 Rispondi(0,"SkullBot By Red Skull")
				 Rispondi(0,"Versione:"&$version)
				 Rispondi(0,"!!v - Mostra la versione")
				 Rispondi(0,"!!author - Mostra l'autore")
				 Rispondi(0,"!!quit - Termina il bot")
				 Rispondi(0,"!!speak - Parla al posto tuo (Solo in query)")
				 Rispondi(0,"!!upper - Trasforma una stringa in MAIUSCOLO")
				 Rispondi(0,"!!reverse - Gira una stringa")
			 Else
				 Rispondi(0,"Solo il mio padrone può vedere come usarmi !")
			 EndIf
		EndIf
		;Autore	
		$find=StringRegExp($mex,"!!author",3)
		 If @error = 0 Then 
		 Rispondi(0,"Autore: Red Skull")
		 Rispondi(0,"Mail: RedSkull92@gmail.com")
		 Rispondi(0,"Sito: http://redskull92.wordpress.com")		
		 EndIf
		;Uscita
		$find=StringRegExp($mex,"!!quit",3)
		If @error = 0 Then
			If $utente = $padrone Then
				Rispondi($query,"Bye !!")
				TCPSend($conn,"QUIT"&@CRLF)
				TCPShutdown()
				Exit
			Else
				Rispondi($query,"Solo il mio padrone può terminarmi!")
			EndIf
		EndIf
		;Parla come il bot
		$find=StringRegExp($mex,"!!speak (.+)",3)
		If @error = 0 And $query=1 Then 
			If $utente = $padrone Then
				Rispondi(0,$find[0])
			Else
				Rispondi(0,"Solo il mio padrone può farmi parlare!")
			EndIf
		EndIf
		;Trasforma una stringa in maiuscolo
		$find=StringRegExp($mex,"!!upper (.+)",3)
		If @error = 0 Then Rispondi($query,StringUpper($find[0]))
		;Stampa la stringa al contrario
		$find=StringRegExp($mex,"!!reverse (.+)",3)
		If @error = 0 Then Rispondi($query,_StringReverse($find[0]))
			
EndFunc
	
;By
;Red Skull

SkullBot

By Red Skull