Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OpenConsole()
- ConsoleTitle("IRC bot by kaiser_czar")
- ConsoleColor(14,1)
- *membuff=AllocateMemory(2048*4)
- rejoin:
- ClearConsole()
- Result = InitNetwork()
- If Result=0
- Goto endofprog
- EndIf
- Print("Server: ")
- servername$=Input()
- If servername$="synirc"
- servername$="fjord.no.eu.synirc.net"
- ElseIf servername$="esper"
- servername$="irc.esper.net"
- ElseIf servername$="slashnet"
- servername$="irc.slashnet.org"
- EndIf
- PrintN("")
- portname.l=6667
- Print("Username: ")
- username$=Input()
- PrintN("")
- Print("Password: ")
- password$=""
- Repeat
- letter$=Inkey()
- If RawKey()=13
- ElseIf RawKey()=8
- If Len(password$)>0
- password$=Left(password$, Len(password$)-1)
- EndIf
- ElseIf RawKey()<>0
- Print("*")
- password$=password$+letter$
- EndIf
- Until RawKey()=13
- PrintN(Chr(13))
- PrintN(Chr(13))
- ClearConsole()
- PrintN("Connecting...")
- Global Connection
- Connection = OpenNetworkConnection(servername$, portname)
- Procedure chat(chatmsg$,medium$)
- SendNetworkString(Connection, "PRIVMSG "+medium$+" "+chatmsg$+#CRLF$)
- EndProcedure
- If Connection
- PrintN("Connected!"+Chr(13))
- PrintN(Chr(13))
- Print("Channel: ")
- channel$=Input()
- PrintN(Chr(13))
- SendNetworkString(Connection, "PASS "+password$+#CRLF$)
- SendNetworkString(Connection, "NICK "+username$+#CRLF$)
- SendNetworkString(Connection, "USER "+username$+" 0 * :DaBot"+#CRLF$)
- SendNetworkString(Connection, "JOIN "+channel$+#CRLF$)
- SendNetworkString(Connection, "MODE " + username$ + " +B"+#CRLF$)
- SendNetworkString(Connection, "MODE " + username$ + " -R"+#CRLF$)
- SendNetworkString(Connection, "MODE " + username$ + " -G"+#CRLF$)
- quit=0
- Repeat
- Inkey()
- If RawKey()=27
- Goto quit
- EndIf
- Event = NetworkClientEvent(Connection)
- Select Event
- Case #PB_NetworkEvent_Data
- FreeMemory(*membuff)
- *membuff=AllocateMemory(2048*4)
- recievedData=ReceiveNetworkData(Connection,*membuff,2048*4)
- incomingData$=PeekS(*membuff)
- Debug incomingData$
- lnbrInd=FindString(incomingData$,Chr(32),0)
- If RawKey()=27
- Goto quit
- EndIf
- ;Ping to stay alive.
- If Left(incomingData$, 4) = "PING"
- serverPingOriginate$=Mid(incomingData$,FindString(incomingData$, ":",0) + 1,lnbrInd-1)
- PrintN("Staying alive: PING from "+serverPingOriginate$)
- SendNetworkString(Connection, "PONG "+serverPingOriginate$)
- PrintN("PONG returned. 21 to win.")
- PrintN(Chr(10))
- ; Autojoin after kick if Golden starts being a dick again.
- ElseIf Mid(incomingData$, FindString(incomingData$, " ",2)-4)="KICK"
- Goto rejoin
- ElseIf Mid(incomingData$,lnbrInd+1, 7) = "PRIVMSG" ; Recieve text from the channel
- message$=Mid(incomingData$,lnbrInd+9)
- msgSender$=StringField(incomingData$,1,"!")
- msgSender$=Trim(msgSender$,":")
- Global medium$
- medium$=Left(message$, FindString(message$," ", 0)-1)
- message$=Right(message$, Len(message$)-FindString(message$,":",0))
- message$=Trim(message$)
- ; Prints the text to console, differently if PM or in channel.
- If medium$=channel$
- PrintN(msgSender$+" said:")
- ConsoleColor(12,1)
- PrintN(message$)
- ConsoleColor(14,1)
- ElseIf medium$=username$
- PrintN("Private message from "+msgSender$+":")
- ConsoleColor(11,1)
- PrintN(message$)
- ConsoleColor(14,1)
- EndIf
- If RawKey()=27
- Goto quit
- EndIf
- ; Test for commands from me.
- If medium$=username$
- medium$=msgSender$
- EndIf
- If Left(message$, 1)="." And msgSender$="kaiser_czar"
- ; Count command.
- If Left(message$, 6)=".count"
- countlen.l=Val(Trim(Mid(message$,FindString(message$," ",1),FindString(message$," ",1+FindString(message$," ",1))-FindString(message$," ",1))))
- saymsg$=Trim(Right(message$,Len(message$)-Len(Left(message$,FindString(message$," ",1+FindString(message$," ",1))))))
- For curcount.l = countlen To 1 Step -1
- chat(Str(curcount),medium$)
- Delay(800)
- Next
- chat(saymsg$,medium$)
- ; Quit command.
- ElseIf Left(message$, 5)=".quit"
- Goto quit
- ; Commands command.
- ElseIf Left(message$, 9)=".commands"
- chat("Commands: .commands, .count, .say, .quit",medium$)
- ; Say command
- ElseIf Left(message$, 4)=".say"
- message$=Right(message$, Len(message$)-5)
- chat(message$, medium$)
- ; Bad command given.
- Else
- chat("Error: That is not a command currently installed. Perhaps you should add it?",medium$)
- EndIf
- EndIf
- If RawKey()=27
- Goto quit
- EndIf
- ElseIf Right(incomingData$,20)="ERROR :Closing Link:"
- PrintN("Disconnected by Server.")
- quit=1
- EndIf
- EndSelect
- If RawKey()=27
- Goto quit
- EndIf
- Until quit=1
- quit:
- chat("Quitting BAI",medium$)
- Delay(20)
- CloseNetworkConnection(Connection)
- Else
- PrintN("Connection failed.")
- EndIf
- endofprog:
- CloseConsole()
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement