mrflibblehat Posted March 20, 2014 Posted March 20, 2014 (edited) Hi All, I am developing an IRC Bot and have come across a small problem. Everything works fine until the ConnectToIRC function is called. This is when a while Loop is in play, I assume this is because the while loop is hogging the program and blocking other commands. so my question, Is there a way around this or a way I could do this differently so that I can receive data when it comes in and also use controls on the gui? If I remove the while loop inside the ConnectToIRC function, Other gui buttons work correctly (Close Button for example) Thanks for any help or insight you may provide. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GUIEdit.au3> #Include <ScrollBarConstants.au3> #include <ComboConstants.au3> #Include <Array.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("AutoIT IRCBot", 537, 339, 192, 124) $Edit1 = GUICtrlCreateEdit("", 8, 8, 521, 257, $ES_AUTOVSCROLL + $WS_VSCROLL) $btnSend = GUICtrlCreateButton("Send", 456, 304, 73, 25) $inIRCServ = GUICtrlCreateInput("irc.freenode.net", 8, 272, 97, 21) $inPort = GUICtrlCreateInput("6667", 112, 272, 65, 21) $inChat = GUICtrlCreateInput("", 288, 304, 161, 21) $btnCon = GUICtrlCreateButton("Connect", 184, 272, 73, 25) $Combo1 = GUICtrlCreateCombo("Channel", 288, 272, 161, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseBot") GUICtrlSetOnEvent($btnCon, "ConnectToIRC") GUICtrlSetOnEvent($btnSend, "IRCSend") GUISetState(@SW_SHOW) TCPStartup() ;~ Read INI Values Global $vIRCNick = IniRead("ircbot.ini", "information", "Nick", "AutoITIRCBot") Global $vIRCAltNick = IniRead("ircbot.ini", "information", "AltNick", "AutoITIRCBot_") Global $vIRCRealName = IniRead("ircbot.ini", "information", "RealName", "AutoITIRCBot") Global $vIRCChannels = IniRead("ircbot.ini", "information", "Channels", "#AutoITIRCBot") $vChanArr = StringSplit($vIRCChannels, "|") While 1 Sleep(100) WEnd Func ConnectToIRC() GUICtrlSetState($btnCon, $GUI_DISABLE) GUICtrlSetState($inIRCServ, $GUI_DISABLE) GUICtrlSetState($inPort, $GUI_DISABLE) $vIRCServer = TCPNameToIP(GuiCtrlRead($inIRCServ)) $vIRCPort = GuiCtrlRead($inPort) $vConnect = TCPConnect($vIRCServer, $vIRCPort) TCPSend($vConnect, "USER " & $vIRCNick & " 0 0 :" & $vIRCRealName & @CRLF) TCPSend($vConnect, "NICK " & $vIRCNick & @CRLF) For $i = 1 to Ubound($vChanArr) -1 TCPSend($vConnect, "JOIN " & $vChanArr[$i] & @CRLF) GUICtrlSetData($Combo1, $vChanArr[$i], $vChanArr[$i]) Next While 1 $vRecv = TCPRecv($vConnect, 4096) If $vRecv <> "" Then GuiCtrlSetData($Edit1, $vRecv, 1) EndIf Wend EndFunc Func CloseBot() Exit EndFunc Ini File [information] Nick=UKTestBot AltNick=UKTestBot_ RealName=UKTestBOT Channels=#test333|#test222 Edited March 20, 2014 by mrflibblehat [font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]
Moderators Solution Melba23 Posted March 20, 2014 Moderators Solution Posted March 20, 2014 mrflibblehat, I assume this is because the while loop is hogging the program and blocking other commandsCorrect, AutoIt will queue any other commands until you return to the main idle loop. I suggest you move the contents of that While..WEnd loop inside your main idle loop and use a flag to tell it when to operate - something like this (untested):; Add this at the start Global $fJoin = False ; [other code] While 1 Sleep(100) ; Look for joins if needed If $fJoin Then $vRecv = TCPRecv($vConnect, 4096) If $vRecv <> "" Then GuiCtrlSetData($Edit1, $vRecv, 1) EndIf EndIf WEnd Func ConnectToIRC() ; [other code] For $i = 1 to Ubound($vChanArr) -1 TCPSend($vConnect, "JOIN " & $vChanArr[$i] & @CRLF) GUICtrlSetData($Combo1, $vChanArr[$i], $vChanArr[$i]) Next ; Set the flag $fJoin = True EndFuncYou might also think of clearing the flag at some point by looking to see if you have received the correct number of responses so that you only fire the check when necessary. M23 mrflibblehat 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mrflibblehat Posted March 20, 2014 Author Posted March 20, 2014 Thank you Melba23, That has worked perfectly [font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now