Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. OpenConsole()
  2. ConsoleTitle("IRC bot by kaiser_czar")
  3. ConsoleColor(14,1)
  4. Global *membuff
  5. *membuff=AllocateMemory(2048*4)
  6. rejoin:
  7. ClearConsole()
  8. Result = InitNetwork()
  9. If Result=0
  10.   Goto endofprog
  11. EndIf
  12.  
  13. Print("Server: ")
  14. Global servername$
  15. servername$=Input()
  16. If servername$="synirc"
  17.   servername$="fjord.no.eu.synirc.net"
  18. ElseIf servername$="esper"
  19.   servername$="irc.esper.net"
  20. ElseIf servername$="slashnet"
  21.   servername$="irc.slashnet.org"  
  22. EndIf
  23. PrintN("")
  24. Global portname
  25. portname=6667
  26. Print("Username: ")
  27. Global username$
  28. username$=Input()
  29. PrintN("")
  30. Print("Password: ")
  31. Global password$
  32. password$=""
  33. Repeat
  34.   letter$=Inkey()
  35.   If RawKey()=13
  36.   ElseIf RawKey()=8
  37.     If Len(password$)>0
  38.       password$=Left(password$, Len(password$)-1)
  39.     EndIf
  40.   ElseIf RawKey()<>0
  41.     Print("*")
  42.     password$=password$+letter$
  43.   EndIf
  44. Until RawKey()=13
  45. PrintN(Chr(13))
  46. PrintN(Chr(13))
  47. ClearConsole()
  48. PrintN("Connecting...")
  49.  
  50. Global Connection
  51. Connection = OpenNetworkConnection(servername$, portname)
  52.  
  53.  
  54. Procedure chat(chatmsg$,medium$)
  55.   SendNetworkString(Connection, "PRIVMSG "+medium$+" "+chatmsg$+#CRLF$)
  56. EndProcedure
  57.  
  58.  
  59. Procedure TypingThread(hello)
  60.   Repeat
  61.     keypressed$=Inkey()
  62.     If RawKey()=27
  63.       Global quit
  64.       quit=1
  65.     ElseIf keypressed$="t"
  66.       #window_0=0
  67.       #string_0=0
  68.       If OpenWindow(#Window_0, 220, 0, 611, 42, "Enter Text:",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
  69.         StringGadget(#String_0, 20, 10, 570, 20, "")
  70.       EndIf
  71.       Repeat
  72.       Until RawKey()=13
  73.       sendtochan$=GetGadgetText(#string_0)
  74.       SendNetworkString(Connection, "PRIVMSG "+channel$+" "+sendtochan$+#CRLF$)
  75.       SetGadgetText(#string_0,"")
  76.       CloseWindow(#window_0)
  77.     EndIf
  78.   Until WaitWindowEvent() = #PB_Event_CloseWindow
  79. EndProcedure
  80.  
  81.  
  82.   Procedure EverythingElse(hellotwo)
  83.     Repeat
  84.      
  85.       Event = NetworkClientEvent(Connection)
  86.       Select Event
  87.         Case #PB_NetworkEvent_Data
  88.           FreeMemory(*membuff)
  89.           *membuff=AllocateMemory(2048*4)
  90.           Global incomingData$
  91.           recievedData=ReceiveNetworkData(Connection,*membuff,2048*4)
  92.           incomingData$=PeekS(*membuff)
  93.           lnbrInd=FindString(incomingData$,Chr(32),0)
  94.           If RawKey()=27
  95.             Goto quit
  96.           EndIf
  97.          
  98.          
  99.           ;Ping to stay alive.
  100.           If Left(incomingData$, 4) = "PING"
  101.             serverPingOriginate$=Mid(incomingData$,FindString(incomingData$, ":",0) + 1,lnbrInd-1)
  102.             PrintN("Staying alive: PING from "+serverPingOriginate$)
  103.             SendNetworkString(Connection, "PONG "+serverPingOriginate$)
  104.             PrintN("PONG returned. 21 to win.")
  105.             PrintN(Chr(10))
  106.            
  107.            
  108.             ; Autojoin after kick if Golden starts being a dick again.
  109.           ElseIf Mid(incomingData$, FindString(incomingData$, " ",2)-4)="KICK"
  110.             Goto rejoin
  111.            
  112.            
  113.           ElseIf Mid(incomingData$,lnbrInd+1, 7) = "PRIVMSG" ; Recieve text from the channel
  114.             Global message$
  115.             Global msgSender$
  116.             Global medium$
  117.             message$=Mid(incomingData$,lnbrInd+9)
  118.             msgSender$=StringField(incomingData$,1,"!")
  119.             msgSender$=Trim(msgSender$,":")
  120.             medium$=Left(message$, FindString(message$," ", 0)-1)
  121.             message$=Right(message$, Len(message$)-FindString(message$,":",0))
  122.             message$=Trim(message$)
  123.            
  124.             ; Prints the text to console, differently if PM or in channel.
  125.             If medium$=channel$
  126.               PrintN(msgSender$+" said:")
  127.               ConsoleColor(12,1)
  128.               PrintN(message$)
  129.               ConsoleColor(14,1)
  130.             ElseIf medium$=username$
  131.               PrintN("Private message from "+msgSender$+":")
  132.               ConsoleColor(11,1)
  133.               PrintN(message$)
  134.               ConsoleColor(14,1)
  135.             EndIf
  136.             If RawKey()=27
  137.               Goto quit
  138.             EndIf
  139.            
  140.            
  141.             ; Test for commands from me.
  142.             If medium$=username$
  143.               medium$=msgSender$
  144.             EndIf
  145.             If Left(message$, 1)="." And msgSender$="kaiser_czar"
  146.              
  147.               ; Count command.
  148.               If Left(message$, 6)=".count"
  149.                 countlen.l=Val(Trim(Mid(message$,FindString(message$," ",1),FindString(message$," ",1+FindString(message$," ",1))-FindString(message$," ",1))))
  150.                 saymsg$=Trim(Right(message$,Len(message$)-Len(Left(message$,FindString(message$," ",1+FindString(message$," ",1))))))
  151.                 For curcount.l = countlen To 1 Step -1
  152.                   chat(Str(curcount),channel$)
  153.                   Delay(800)
  154.                 Next
  155.                 chat(saymsg$,channel$)
  156.                 PrintN("Counted from "+Str(countlen)+" to 1, and then said '"+saymsg$+"'.")
  157.                 PrintN(Chr(13))
  158.                
  159.                 ; Quit command.
  160.               ElseIf Left(message$, 5)=".quit"
  161.                 PrintN("Quitting.")
  162.                 Goto quit
  163.                
  164.                 ; Commands command.
  165.               ElseIf Left(message$, 9)=".commands"
  166.                 chat("Commands: .commands, .count, .say, .quit",channel$)
  167.                 PrintN("Printed a list of commands to "+medium$+".")
  168.                 PrintN(Chr(13))
  169.                
  170.                 ; Say command
  171.               ElseIf Left(message$, 4)=".say"
  172.                 message$=Right(message$, Len(message$)-5)
  173.                 chat(message$, channel$)
  174.                 PrintN("Said the message '"+message$+"'.")
  175.                
  176.                 ; Bad command given.
  177.               Else
  178.                 chat("Error: That is not a command currently installed. Perhaps you should add it?",channel$)
  179.               EndIf
  180.             EndIf
  181.            
  182.            
  183.           ElseIf Right(incomingData$,20)="ERROR :Closing Link:"
  184.             PrintN("Disconnected by Server.")
  185.             quit=1
  186.           EndIf
  187.          
  188.       EndSelect
  189.     Until quit=1
  190.   EndProcedure
  191.  
  192.  
  193. If Connection
  194.   PrintN("Connected!"+Chr(13))
  195.   PrintN(Chr(13))
  196.   Print("Channel: ")
  197.   Global channel$
  198.   channel$=Input()
  199.   PrintN(Chr(13))
  200.   SendNetworkString(Connection, "PASS "+password$+#CRLF$)
  201.   SendNetworkString(Connection, "NICK "+username$+#CRLF$)
  202.   SendNetworkString(Connection, "USER "+username$+" 0 * :DaBot"+#CRLF$)
  203.   SendNetworkString(Connection, "JOIN "+channel$+#CRLF$)
  204.   SendNetworkString(Connection, "MODE " + username$ + " +B"+#CRLF$)
  205.   SendNetworkString(Connection, "MODE " + username$ + " -R"+#CRLF$)
  206.   SendNetworkString(Connection, "MODE " + username$ + " -G"+#CRLF$)
  207.   quit=0
  208.   CreateThread(@TypingThread(),2)
  209.  
  210.   CreateThread(@EverythingElse(),1)
  211.   Repeat
  212.   Until quit=1
  213.  
  214.   quit:
  215.   chat("Quitting BAI",channel$)
  216.   Delay(20)
  217.   CloseNetworkConnection(Connection)
  218. Else
  219.   PrintN("Connection failed.")
  220. EndIf
  221.  
  222.  
  223. endofprog:
  224. CloseConsole()
  225. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement