Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OpenConsole()
- ConsoleTitle("IRC bot by kaiser_czar")
- ConsoleColor(14,1)
- Global *membuff
- *membuff=AllocateMemory(2048*4)
- rejoin:
- ClearConsole()
- Result = InitNetwork()
- If Result=0
- Goto endofprog
- EndIf
- Print("Server: ")
- Global servername$
- 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("")
- Global portname
- portname=6667
- Print("Username: ")
- Global username$
- username$=Input()
- PrintN("")
- Print("Password: ")
- Global 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
- Procedure TypingThread(hello)
- Repeat
- keypressed$=Inkey()
- If RawKey()=27
- Global quit
- quit=1
- ElseIf keypressed$="t"
- #window_0=0
- #string_0=0
- If OpenWindow(#Window_0, 220, 0, 611, 42, "Enter Text:", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
- StringGadget(#String_0, 20, 10, 570, 20, "")
- EndIf
- Repeat
- Until RawKey()=13
- sendtochan$=GetGadgetText(#string_0)
- SendNetworkString(Connection, "PRIVMSG "+channel$+" "+sendtochan$+#CRLF$)
- SetGadgetText(#string_0,"")
- CloseWindow(#window_0)
- EndIf
- Until WaitWindowEvent() = #PB_Event_CloseWindow
- EndProcedure
- Procedure EverythingElse(hellotwo)
- Repeat
- Event = NetworkClientEvent(Connection)
- Select Event
- Case #PB_NetworkEvent_Data
- FreeMemory(*membuff)
- *membuff=AllocateMemory(2048*4)
- Global incomingData$
- recievedData=ReceiveNetworkData(Connection,*membuff,2048*4)
- incomingData$=PeekS(*membuff)
- 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
- Global message$
- Global msgSender$
- Global medium$
- message$=Mid(incomingData$,lnbrInd+9)
- msgSender$=StringField(incomingData$,1,"!")
- msgSender$=Trim(msgSender$,":")
- 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),channel$)
- Delay(800)
- Next
- chat(saymsg$,channel$)
- PrintN("Counted from "+Str(countlen)+" to 1, and then said '"+saymsg$+"'.")
- PrintN(Chr(13))
- ; Quit command.
- ElseIf Left(message$, 5)=".quit"
- PrintN("Quitting.")
- Goto quit
- ; Commands command.
- ElseIf Left(message$, 9)=".commands"
- chat("Commands: .commands, .count, .say, .quit",channel$)
- PrintN("Printed a list of commands to "+medium$+".")
- PrintN(Chr(13))
- ; Say command
- ElseIf Left(message$, 4)=".say"
- message$=Right(message$, Len(message$)-5)
- chat(message$, channel$)
- PrintN("Said the message '"+message$+"'.")
- ; Bad command given.
- Else
- chat("Error: That is not a command currently installed. Perhaps you should add it?",channel$)
- EndIf
- EndIf
- ElseIf Right(incomingData$,20)="ERROR :Closing Link:"
- PrintN("Disconnected by Server.")
- quit=1
- EndIf
- EndSelect
- Until quit=1
- EndProcedure
- If Connection
- PrintN("Connected!"+Chr(13))
- PrintN(Chr(13))
- Print("Channel: ")
- Global 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
- CreateThread(@TypingThread(),2)
- CreateThread(@EverythingElse(),1)
- Repeat
- Until quit=1
- quit:
- chat("Quitting BAI",channel$)
- Delay(20)
- CloseNetworkConnection(Connection)
- Else
- PrintN("Connection failed.")
- EndIf
- endofprog:
- CloseConsole()
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement