Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;===============================================================================
- ;I've stopped developing for the night. Please check back in ~8-12 hours - Currently: 1AM GMT-5
- ;===============================================================================
- ;IRC BOT Coding
- ;No Rights Reserved
- ;No Copyright
- ;Requires Windows XP SP3+, AutoIt (If compiling from source).
- ;Estimated Compile Size: 3MB
- ;Please give mention to me (rcmaehl) though :D
- ; Changes since last version:
- ; Fixed missing '
- ; Todo
- ;Detect if PRIVMSG is coming from player or channel
- ;Add in support for disabling buttons
- ;Setup config file making/parsing for (Keys, Window Name to Send Keys to, IRC Server, IRC Channel, IRC Nick, IRC Port, Start Command Throttle)
- ;Add in parsing for other IRC error messages
- ;Add in democracy mode
- ; Compatibility:
- ; GB - Yes
- ; GBC - Yes
- ; GBA - Yes
- ; DS - Missing X/Y button Support
- TCPStartup()
- ;IRC Config
- Global $server = "irc.systemnet.info"
- Global $Port = 6667
- Global $channel = "#bulbagarden"
- Global $Nick = "IRC2EMU"
- Global $Sock ;This will hold the socket
- ;EMU config
- Global $Throttle = 2 ; 1 in $Throttle Chance of Start Button actually going through
- Global $Window = "Untitled" ; Temporarily Send Commands to Notepad
- Global $A = 'a'
- Global $B = 'b'
- Global $L = 'l'
- Global $R = 'r'
- Global $UP = '8'
- Global $DOWN = '2'
- Global $LEFT = '4'
- Global $RIGHT = '6'
- Global $START = '5'
- Global $SELECT = '0'
- $Sock = _IRCConnect($server, $Port, $Nick)
- While 1
- $Recv = TCPRecv($Sock, 8192)
- If Not $Recv Then ContinueLoop ;Nothing useful, check buffer again
- $sData = StringSplit($Recv, @CRLF, 1) ;If the buffer has more than one packet in it, split the packets into an array so they can all be processed in the order they were recieved
- For $i = 1 To $sData[0] ;Check through all packets if any were buffered
- $sTemp = StringSplit($sData[$i], " ")
- If $sTemp[1] = "PING" Then TCPSend($Sock, "PONG " & $sTemp[2] & @CRLF) ;Respond to PING requests from the server
- If $sTemp[0] < 3 Then ContinueLoop ;Error handling
- Switch $sTemp[2]
- Case "PRIVMSG" ;Main message opcode
- $User = StringMid($sTemp[1], 2, StringInStr($sTemp[1], "!") - 2) ;Parse the sender's username
- $Message = StringMid($sData[$i], StringInStr($sData[$i], ":", 0, 2) + 1) ;Parse the sender's full message
- ConsoleWrite($User & " - " & $Message & @CRLF)
- Switch StringLower($Message) ;Message parsing test
- Case "a"
- WinActivate($Window)
- Send($A)
- Case "b"
- WinActivate($Window)
- Send($B)
- Case "l"
- WinActivate($Window)
- Send($L)
- Case "r"
- WinActivate($Window)
- Send($R)
- Case "up"
- WinActivate($Window)
- Send($UP)
- Case "down"
- WinActivate($Window)
- Send($DOWN)
- Case "left"
- WinActivate($Window)
- Send($LEFT)
- Case "right"
- WinActivate($Window)
- Send($RIGHT)
- Case "start"
- If Random(1, $Throttle, 1) = 1 Then
- WinActivate($Window)
- Send($START)
- EndIf
- Case "select"
- If Random(1, $Throttle, 1) = 1 Then
- WinActivate($Window)
- Send($SELECT)
- EndIf
- EndSwitch
- Case "004"
- _IRCJoinChannel($Sock, $channel)
- _IRCChangeMode($Sock, "+i", $Nick)
- Case "443"
- MsgBox(1, "irc.au3", "IRC username in use")
- Case Else
- ConsoleWrite($sTemp[2] & " - " & $sData[$i] & @CRLF) ;Write all unhandled packets to STDOUT
- EndSwitch
- Next
- WEnd
- ;===============================================================================
- ;
- ; Description: Connects you to a IRC Server, and gives your chosen Nick
- ; Parameter(s): $server - IRC Server you wish to connect to
- ; $port - Port to connect to (Usually 6667)
- ; $nick - Nick you choose to use (You can change later)
- ; Requirement(s): TCPStartup () to be run
- ; Return Value(s): On Success - Socket identifer
- ; On Failure - It will exit on error
- ; Author(s): Chip
- ; Note(s): English only
- ;
- ;===============================================================================
- Func _IRCConnect($server, $port, $nick)
- Local $i = TCPConnect(TCPNameToIP($server), $port)
- If $i = -1 Then Exit MsgBox(1, "irc.au3 Error", "Server " & $server & " is not responding.")
- TCPSend($i, "NICK " & $nick & @CRLF)
- TCPSend($i, "USER " & $nick & " 0 0 " & $nick & @CRLF)
- Return $i
- EndFunc ;==>_IRCConnect
- ;===============================================================================
- ;
- ; Description: Joins an IRC Channel
- ; Parameter(s): $irc - Socket Identifer from _IRCConnect ()
- ; $chan - Channel you wish to join
- ; Requirement(s): _IRCConnect () to be run
- ; Return Value(s): On Success - 1
- ; On Failure - -1 = Server disconnected.
- ; Author(s): Chip
- ; Note(s): English only
- ;
- ;===============================================================================
- Func _IRCJoinChannel($irc, $chan)
- If $irc = -1 Then Return 0
- TCPSend($irc, "JOIN " & $chan & @CRLF)
- If @error Then
- MsgBox(1, "irc.au3", "Server has disconnected.")
- Return -1
- EndIf
- Return 1
- EndFunc ;==>_IRCJoinChannel
- ;===============================================================================
- ;
- ; Description: Sends a message using IRC
- ; Parameter(s): $irc - Socket Identifer from _IRCConnect ()
- ; $msg - Message you want to send
- ; $chan - Channel/Nick you wish to send to
- ; Requirement(s): _IRCConnect () to be run
- ; Return Value(s): On Success - 1
- ; On Failure - -1 = Server disconnected.
- ; Author(s): Chip
- ; Note(s): English only
- ;
- ;===============================================================================
- Func _IRCSendMessage($irc, $msg, $chan = "")
- If $irc = -1 Then Return 0
- If $chan = "" Then
- TCPSend($irc, $msg & @CRLF)
- If @error Then
- MsgBox(1, "irc.au3", "Server has disconnected.")
- Return -1
- EndIf
- Return 1
- EndIf
- TCPSend($irc, "PRIVMSG " & $chan & " :" & $msg & @CRLF)
- If @error Then
- MsgBox(1, "irc.au3", "Server has disconnected.")
- Return -1
- EndIf
- Return 1
- EndFunc ;==>_IRCSendMessage
- ;===============================================================================
- ;
- ; Description: Changes a MODE on IRC
- ; Parameter(s): $irc - Socket Identifer from _IRCConnect ()
- ; $mode - Mode you wish to change
- ; $chan - Channel/Nick you wish to send to
- ; Requirement(s): _IRCConnect () to be run
- ; Return Value(s): On Success - 1
- ; On Failure - -1 = Server disconnected.
- ; Author(s): Chip
- ; Note(s): English only
- ;
- ;===============================================================================
- Func _IRCChangeMode($irc, $mode, $chan = "")
- If $irc = -1 Then Return 0
- If $chan = "" Then
- TCPSend($irc, "MODE " & $mode & @CRLF)
- If @error Then
- MsgBox(1, "irc.au3", "Server has disconnected.")
- Return -1
- EndIf
- Return 1
- EndIf
- TCPSend($irc, "MODE " & $chan & " " & $mode & @CRLF)
- If @error Then
- MsgBox(1, "irc.au3", "Server has disconnected.")
- Return -1
- EndIf
- Return 1
- EndFunc ;==>_IRCChangeMode
- ;===============================================================================
- ;
- ; Description: Returns a PING to Server
- ; Parameter(s): $irc - Socket Identifer from _IRCConnect ()
- ; $ret - The end of the PING to return
- ; Requirement(s): _IRCConnect () to be run
- ; Return Value(s): On Success - 1
- ; On Failure - -1 = Server disconnected.
- ; Author(s): Chip
- ; Note(s): English only
- ;
- ;===============================================================================
- Func _IRCPing($irc, $ret)
- If $irc = -1 Then Return 0
- If $ret = "" Then Return -1
- TCPSend($irc, "PONG " & $ret & @CRLF)
- If @error Then
- MsgBox(1, "irc.au3", "Server has disconnected.")
- Return -1
- EndIf
- Return 1
- EndFunc ;==>_IRCPing
Advertisement
Add Comment
Please, Sign In to add comment