Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
  2.  
  3. *membuff=AllocateMemory(2048*4)
  4.  
  5. ;- Window Constants
  6. ;
  7. Enumeration
  8.   #Window_0
  9. EndEnumeration
  10.  
  11. disptext$=""
  12.  
  13. ;- Gadget Constants
  14. ;
  15. Enumeration
  16.   #ScrollArea_0
  17.   #String_0
  18.   #Text_0
  19. EndEnumeration
  20. #EnterKeyPressed=4
  21.  
  22. #MenuBar_0=0
  23.  
  24. Global Connection
  25.  
  26. Procedure kcConnect()
  27.   If Connection
  28.   Else
  29.     disptext$=disptext$+#CRLF$+#CRLF$+"  Please type the server:"+#CRLF$
  30.     SetGadgetText(#Text_0,disptext$)
  31.     Repeat
  32.       conWinEvent=WaitWindowEvent()
  33.     Until EventMenu()=4
  34.     Global server$=GetGadgetText(#String_0)
  35.     SetGadgetText(#String_0,"")
  36.     Global port=6667
  37.     disptext$=disptext$+server$+#CRLF$+#CRLF$+"  Please type your username:"+#CRLF$
  38.     SetGadgetText(#Text_0,disptext$)
  39.     Repeat
  40.       conWinEvent=WaitWindowEvent()
  41.     Until EventMenu()=4
  42.     Global username$=GetGadgetText(#String_0)
  43.     SetGadgetText(#String_0,"")
  44.     disptext$=disptext$+username$+#CRLF$+#CRLF$+"  Please type your password:"+#CRLF$
  45.     SetGadgetText(#Text_0,disptext$)
  46.     Repeat
  47.       conWinEvent=WaitWindowEvent()
  48.     Until EventMenu()=4
  49.     Global password$=GetGadgetText(#String_0)
  50.     SetGadgetText(#String_0,"")
  51.     For x=1 To Len(password$)
  52.       disptext$=disptext$+"*"
  53.     Next
  54.     disptext$=disptext$+#CRLF$+#CRLF$+"  Please type the channel:"+#CRLF$
  55.     SetGadgetText(#Text_0,disptext$)
  56.     Repeat
  57.       conWinEvent=WaitWindowEvent()
  58.     Until EventMenu()=4
  59.     Global channel$=GetGadgetText(#String_0)
  60.     SetGadgetText(#String_0,"")
  61.     disptext$=disptext$+channel$+#CRLF$+#CRLF$
  62.     SetGadgetText(#Text_0,disptext$)
  63.     InitNetwork()
  64.     connection = OpenNetworkConnection(server$,port)
  65.     If connection
  66.       disptext$=disptext$+"Connected!"+#CRLF$+#CRLF$
  67.       SendNetworkString(Connection, "PASS "+password$+#CRLF$)
  68.       SendNetworkString(Connection, "NICK "+username$+#CRLF$)
  69.       SendNetworkString(Connection, "USER "+username$+" 0 * :DaBot"+#CRLF$)
  70.       SendNetworkString(Connection, "JOIN "+channel$+#CRLF$)
  71.       SendNetworkString(Connection, "MODE " + username$ + " +B"+#CRLF$)
  72.       SendNetworkString(Connection, "MODE " + username$ + " -R"+#CRLF$)
  73.       SendNetworkString(Connection, "MODE " + username$ + " -G"+#CRLF$)
  74.     Else
  75.       disptext$=disptext$+"Connection failed."+#CRLF$+#CRLF$
  76.     EndIf  
  77.     SetGadgetText(#Text_0,disptext$)
  78.   EndIf
  79. EndProcedure
  80.  
  81. Procedure chat(chatmsg$,medium$)
  82.   SendNetworkString(Connection, "PRIVMSG "+medium$+" "+chatmsg$+#CRLF$)
  83. EndProcedure
  84.  
  85. Procedure Open_Window_0()
  86.   If OpenWindow(#Window_0, 278, 0, 638, 556, "IRC bot (windowed) by kaiser_czar",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
  87.     If CreateMenu(#MenuBar_0, WindowID(#Window_0))
  88.       MenuTitle("File")
  89.       MenuItem(1,"Connect")
  90.       MenuItem(2,"Disconnect")
  91.       MenuItem(3,"Quit")
  92.     EndIf
  93.     StringGadget(#String_0, 20, 505, 600, 20, "")
  94.     AddKeyboardShortcut(#Window_0,#PB_Shortcut_Return,#EnterKeyPressed)
  95.    
  96.     ;-
  97.     ScrollAreaGadget(#ScrollArea_0, 10, 10, 610, 480, 610, 10000, 10)
  98.     TextGadget(#Text_0, 13, 11,580,9990,disptext$)
  99.     CloseGadgetList()
  100.     SetActiveGadget(#String_0)
  101.    
  102.   EndIf
  103. EndProcedure
  104.  
  105. netEvent=0
  106. Open_Window_0()
  107. homescreen:
  108.  
  109. exit=#False
  110. Repeat
  111.  
  112.   winEvent = WindowEvent()
  113.  
  114.   If Connection
  115.     netEvent = NetworkClientEvent(Connection)
  116.   EndIf
  117.  
  118.   Select winEvent
  119.     Case #PB_Event_Menu
  120.       Select EventMenu()
  121.          
  122.         Case 1 ;CONNECT
  123.           kcConnect()
  124.         Case 2 ;DISCONNECT
  125.           If Connection
  126.             CloseNetworkConnection(Connection)
  127.            
  128.           EndIf
  129.          
  130.         Case 3 ; QUIT
  131.           exit=#True
  132.          
  133.         Case 4 ; enter was pressed
  134.           Global typed$=GetGadgetText(#String_0)
  135.           SetGadgetText(#String_0,"")
  136.           disptext$=disptext$+"   You said:"+#CRLF$+" "+typed$+#CRLF$+#CRLF$
  137.           SetGadgetText(#Text_0,disptext$)
  138.           chat(typed$,channel$)
  139.          
  140.       EndSelect
  141.      
  142.      
  143.     Case #PB_Event_CloseWindow
  144.       exit=#True
  145.   EndSelect
  146.  
  147.   Select netEvent
  148.     Case #PB_NetworkEvent_Data
  149.       FreeMemory(*membuff)
  150.       *membuff=AllocateMemory(2048*4)
  151.       recievedData=ReceiveNetworkData(Connection,*membuff,2048*4)
  152.       incomingData$=PeekS(*membuff)
  153.       ;Debug incomingData$
  154.       lnbrInd=FindString(incomingData$,Chr(32),0)
  155.      
  156.       If Left(incomingData$, 4) = "PING"   ; Ping returner
  157.         serverPingOriginate$=Mid(incomingData$,FindString(incomingData$, ":",0) + 1,lnbrInd-1)
  158.         disptext$=disptext$+"Staying alive: PING from "+serverPingOriginate$+#CRLF$
  159.         SetGadgetText(#Text_0,disptext$)
  160.         SendNetworkString(Connection, "PONG "+serverPingOriginate$)
  161.         disptext$=disptext$+"PONG returned. 21 to win."+#CRLF$+#CRLF$
  162.         SetGadgetText(#Text_0,disptext$)
  163.        
  164.       ElseIf Mid(incomingData$, FindString(incomingData$, " ",2)-4)="KICK"    ; Autojoin after kick.
  165.         CloseNetworkConnection(Connection)
  166.         disptext$=disptext$+"You were kicked. Rejoining..."
  167.         connection = OpenNetworkConnection(server$,port)
  168.         If connection
  169.           disptext$=disptext$+"Connected!"+#CRLF$+#CRLF$
  170.           SendNetworkString(Connection, "PASS "+password$+#CRLF$)
  171.           SendNetworkString(Connection, "NICK "+username$+#CRLF$)
  172.           SendNetworkString(Connection, "USER "+username$+" 0 * :DaBot"+#CRLF$)
  173.           SendNetworkString(Connection, "JOIN "+channel$+#CRLF$)
  174.           SendNetworkString(Connection, "MODE " + username$ + " +B"+#CRLF$)
  175.           SendNetworkString(Connection, "MODE " + username$ + " -R"+#CRLF$)
  176.           SendNetworkString(Connection, "MODE " + username$ + " -G"+#CRLF$)
  177.         Else
  178.           disptext$=disptext$+"Connection failed."+#CRLF$+#CRLF$
  179.         EndIf  
  180.         SetGadgetText(#Text_0,disptext$)
  181.        
  182.         ElseIf Mid(incomingData$,lnbrInd+1, 7) = "PRIVMSG" ; Recieve text from the channel
  183.           message$=Mid(incomingData$,lnbrInd+9)
  184.           msgSender$=StringField(incomingData$,1,"!")
  185.           msgSender$=Trim(msgSender$,":")
  186.           medium$=Left(message$, FindString(message$," ", 0)-1)
  187.           message$=Right(message$, Len(message$)-FindString(message$,":",0))
  188.           message$=Trim(message$)
  189.          
  190.           If medium$=channel$  ; If text was said, print it. Different for PM's and channel messages.
  191.             disptext$=disptext$+"  "+msgSender$+" said:"+#CRLF$+message$+#CRLF$
  192.             SetGadgetText(#Text_0,disptext$)
  193.           ElseIf medium$=username$
  194.             disptext$=disptext$+"  Private message from "+msgSender$+":"+#CRLF$+message$+#CRLF$
  195.             SetGadgetText(#Text_0,disptext$)
  196.           EndIf
  197.          
  198.           If medium$=username$
  199.             medium$=msgSender$
  200.           EndIf
  201.          
  202.           If Left(message$, 1)="."
  203.             If msgSender$="kaiser_czar"
  204.              
  205.               If Left(message$, 6)=".count" ; Count command
  206.                 countlen.l=Val(Trim(Mid(message$,FindString(message$," ",1),FindString(message$," ",1+FindString(message$," ",1))-FindString(message$," ",1))))
  207.                 saymsg$=Trim(Right(message$,Len(message$)-Len(Left(message$,FindString(message$," ",1+FindString(message$," ",1))))))
  208.                 For curcount.l = countlen To 1 Step -1
  209.                   chat(Str(curcount),channel$)
  210.                   Delay(800)
  211.                 Next
  212.                 chat(saymsg$,channel$)
  213.                 disptext$=disptext$+"  You counted to "+Str(countlen)+" and then said '"+saymsg$+"'."+#CRLF$+#CRLF$
  214.                 SetGadgetText(#Text_0,disptext$)
  215.                
  216.               ElseIf Left(message$, 5)=".quit"  ;Quit command
  217.                 chat("Quitting, g'day people.",channel$)
  218.                 disptext$=disptext$+"  Disconnected by user."+#CRLF$+#CRLF$
  219.                 SetGadgetText(#Text_0,disptext$)
  220.                 Delay(20)
  221.                 CloseNetworkConnection(Connection)
  222.                
  223.               ElseIf Left(message$, 9)=".commands" ;Lists commands.
  224.                 chat("Commands: .commands, .count, .say, .quit",channel$)
  225.                 disptext$=disptext$+"  Printed a list of commands to channel."+#CRLF$+#CRLF$
  226.                 SetGadgetText(#Text_0,disptext$)
  227.                
  228.               ElseIf Left(message$, 4)=".say"
  229.                 message$=Right(message$, Len(message$)-5)
  230.                 chat(message$, channel$)
  231.                 disptext$=disptext$+"  Said the message '"+message$+"' to channel."+#CRLF$+#CRLF$
  232.                 SetGadgetText(#Text_0,disptext$)
  233.               EndIf
  234.              
  235.              
  236.             Else
  237.               chat("You are not allowed to command me!",msgSender$)
  238.             EndIf
  239.           EndIf
  240.          
  241.        
  242.       EndIf
  243.     EndSelect
  244.    
  245.   Until exit=#True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement