Advertisement
Guest User

Untitled

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