Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
- *membuff=AllocateMemory(2048*4)
- ;- Window Constants
- ;
- Enumeration
- #Window_0
- EndEnumeration
- disptext$=""
- ;- Gadget Constants
- ;
- Enumeration
- #ScrollArea_0
- #String_0
- #Text_0
- EndEnumeration
- #EnterKeyPressed=4
- #MenuBar_0=0
- Global Connection
- Procedure kcConnect()
- If Connection
- Else
- disptext$=disptext$+#CRLF$+#CRLF$+" Please type the server:"+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- Repeat
- conWinEvent=WaitWindowEvent()
- Until EventMenu()=4
- Global server$=GetGadgetText(#String_0)
- SetGadgetText(#String_0,"")
- Global port=6667
- disptext$=disptext$+server$+#CRLF$+#CRLF$+" Please type your username:"+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- Repeat
- conWinEvent=WaitWindowEvent()
- Until EventMenu()=4
- Global username$=GetGadgetText(#String_0)
- SetGadgetText(#String_0,"")
- disptext$=disptext$+username$+#CRLF$+#CRLF$+" Please type your password:"+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- Repeat
- conWinEvent=WaitWindowEvent()
- Until EventMenu()=4
- Global password$=GetGadgetText(#String_0)
- SetGadgetText(#String_0,"")
- For x=1 To Len(password$)
- disptext$=disptext$+"*"
- Next
- disptext$=disptext$+#CRLF$+#CRLF$+" Please type the channel:"+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- Repeat
- conWinEvent=WaitWindowEvent()
- Until EventMenu()=4
- Global channel$=GetGadgetText(#String_0)
- SetGadgetText(#String_0,"")
- disptext$=disptext$+channel$+#CRLF$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- InitNetwork()
- connection = OpenNetworkConnection(server$,port)
- If connection
- disptext$=disptext$+"Connected!"+#CRLF$+#CRLF$
- 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$)
- Else
- disptext$=disptext$+"Connection failed."+#CRLF$+#CRLF$
- EndIf
- SetGadgetText(#Text_0,disptext$)
- EndIf
- EndProcedure
- Procedure chat(chatmsg$,medium$)
- SendNetworkString(Connection, "PRIVMSG "+medium$+" "+chatmsg$+#CRLF$)
- EndProcedure
- Procedure Open_Window_0()
- If OpenWindow(#Window_0, 278, 0, 638, 556, "IRC bot (windowed) by kaiser_czar", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
- If CreateMenu(#MenuBar_0, WindowID(#Window_0))
- MenuTitle("File")
- MenuItem(1,"Connect")
- MenuItem(2,"Disconnect")
- MenuItem(3,"Quit")
- EndIf
- StringGadget(#String_0, 20, 505, 600, 20, "")
- AddKeyboardShortcut(#Window_0,#PB_Shortcut_Return,#EnterKeyPressed)
- ;-
- ScrollAreaGadget(#ScrollArea_0, 10, 10, 610, 480, 610, 10000, 10)
- TextGadget(#Text_0, 13, 11,580,9990,disptext$)
- CloseGadgetList()
- SetActiveGadget(#String_0)
- EndIf
- EndProcedure
- netEvent=0
- Open_Window_0()
- homescreen:
- exit=#False
- Repeat
- winEvent = WindowEvent()
- If Connection
- netEvent = NetworkClientEvent(Connection)
- EndIf
- Select winEvent
- Case #PB_Event_Menu
- Select EventMenu()
- Case 1 ;CONNECT
- kcConnect()
- Case 2 ;DISCONNECT
- If Connection
- CloseNetworkConnection(Connection)
- EndIf
- Case 3 ; QUIT
- exit=#True
- Case 4 ; enter was pressed
- Global typed$=GetGadgetText(#String_0)
- SetGadgetText(#String_0,"")
- disptext$=disptext$+" You said:"+#CRLF$+" "+typed$+#CRLF$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- chat(typed$,channel$)
- EndSelect
- Case #PB_Event_CloseWindow
- exit=#True
- EndSelect
- Select netEvent
- 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 Left(incomingData$, 4) = "PING" ; Ping returner
- serverPingOriginate$=Mid(incomingData$,FindString(incomingData$, ":",0) + 1,lnbrInd-1)
- disptext$=disptext$+"Staying alive: PING from "+serverPingOriginate$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- SendNetworkString(Connection, "PONG "+serverPingOriginate$)
- disptext$=disptext$+"PONG returned. 21 to win."+#CRLF$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- ElseIf Mid(incomingData$, FindString(incomingData$, " ",2)-4)="KICK" ; Autojoin after kick.
- CloseNetworkConnection(Connection)
- disptext$=disptext$+"You were kicked. Rejoining..."
- connection = OpenNetworkConnection(server$,port)
- If connection
- disptext$=disptext$+"Connected!"+#CRLF$+#CRLF$
- 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$)
- Else
- disptext$=disptext$+"Connection failed."+#CRLF$+#CRLF$
- EndIf
- SetGadgetText(#Text_0,disptext$)
- ElseIf Mid(incomingData$,lnbrInd+1, 7) = "PRIVMSG" ; Recieve text from the channel
- 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$)
- If medium$=channel$ ; If text was said, print it. Different for PM's and channel messages.
- disptext$=disptext$+" "+msgSender$+" said:"+#CRLF$+message$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- ElseIf medium$=username$
- disptext$=disptext$+" Private message from "+msgSender$+":"+#CRLF$+message$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- EndIf
- If medium$=username$
- medium$=msgSender$
- EndIf
- If Left(message$, 1)="."
- If msgSender$="kaiser_czar"
- If Left(message$, 6)=".count" ; Count command
- 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$)
- disptext$=disptext$+" You counted to "+Str(countlen)+" and then said '"+saymsg$+"'."+#CRLF$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- ElseIf Left(message$, 5)=".quit" ;Quit command
- chat("Quitting, g'day people.",channel$)
- disptext$=disptext$+" Disconnected by user."+#CRLF$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- Delay(20)
- CloseNetworkConnection(Connection)
- ElseIf Left(message$, 9)=".commands" ;Lists commands.
- chat("Commands: .commands, .count, .say, .quit",channel$)
- disptext$=disptext$+" Printed a list of commands to channel."+#CRLF$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- ElseIf Left(message$, 4)=".say"
- message$=Right(message$, Len(message$)-5)
- chat(message$, channel$)
- disptext$=disptext$+" Said the message '"+message$+"' to channel."+#CRLF$+#CRLF$
- SetGadgetText(#Text_0,disptext$)
- EndIf
- Else
- chat("You are not allowed to command me!",msgSender$)
- EndIf
- EndIf
- EndIf
- EndSelect
- Until exit=#True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement