Jump to content

IRC UDF - Updated Version of Chips' IRC UDF - Release: V1.22 - 09/06/2016 - Technical Writer Needed!


rcmaehl
 Share

Recommended Posts

Hey guys,

Thought I would share this, it's an example on how to use IRC and this UDF to connect to a twitch channel's chat and send a message using a hotkey :)

Thank you @rcmaehl for sharing :)

#include <IRC.au3>
#include <Misc.au3>

; Allow some TCP lag
Opt("TCPTimeout", 500)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Twitch chat hotkey", 381, 436, 192, 124)
GUISetFont(10, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Twitch chat hotkey", 128, 8, 153, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Twitch username:", 16, 88, 144, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 176, 88, 185, 24)
$Label3 = GUICtrlCreateLabel("OAuth password:", 16, 128, 141, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("oauth:", 176, 128, 185, 24)
$Button1 = GUICtrlCreateButton("Get OAuth password", 88, 176, 201, 41)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Twitch channel:", 16, 240, 128, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("kolento", 160, 240, 201, 24)
$Label5 = GUICtrlCreateLabel("Message:", 16, 288, 81, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input4 = GUICtrlCreateInput("Kappa hello guys Kappa", 112, 288, 249, 24)
$Button2 = GUICtrlCreateButton("Connect", 104, 376, 193, 41)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("Status: disconnected", 136, 336, 128, 20)
GUICtrlSetColor(-1, 0xFF0000)
$Label7 = GUICtrlCreateLabel("Press F10 once connected to send the message", 56, 48, 291, 20)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;restore previous values if the software has already been used

if RegRead("HKCU\Software\TwitchChatHotkey", "username") <> "" Then

    GUICtrlSetData($Input1, RegRead("HKCU\Software\TwitchChatHotkey", "username"))
    GUICtrlSetData($Input2, RegRead("HKCU\Software\TwitchChatHotkey", "password"))
    GUICtrlSetData($Input3, RegRead("HKCU\Software\TwitchChatHotkey", "channel"))
    GUICtrlSetData($Input4, RegRead("HKCU\Software\TwitchChatHotkey", "message"))

EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ShellExecute("http://twitchapps.com/tmi/")
        Case $Button2
            GUICtrlSetState($Button2, $GUI_DISABLE)
            connect()
    EndSwitch
WEnd

Func connect()

    GUICtrlSetData($Label6, "Status: connecting...")
    GUICtrlSetColor($Label6, $COLOR_BLUE)

    $username = GUICtrlRead($Input1)
    $password = GUICtrlRead($Input2)
    $channel = StringLower(GUICtrlRead($Input3))
    $message = GUICtrlRead($Input4)

    ;backup info for future usage

    Regwrite("HKCU\Software\TwitchChatHotkey", "username", "REG_SZ", $username)
    Regwrite("HKCU\Software\TwitchChatHotkey", "password", "REG_SZ", $password)
    Regwrite("HKCU\Software\TwitchChatHotkey", "channel", "REG_SZ", $channel)
    Regwrite("HKCU\Software\TwitchChatHotkey", "message", "REG_SZ", $message)

    ;Start Up Networking
    TCPStartup()

    ; Connect to IRC. Send Password, if any. Declare User Identity.
    Local $Sock = _IRCConnect("irc.chat.twitch.tv", 6667, $username, 0, $username, $password)

    ; Prepare to Receive Data
    Local $sRecv = ""

    ; Start Loop
    While 1

        ; Receive Data
        $sRecv = _IRCGetMsg($Sock)
        ConsoleWrite($sRecv)

        ; Split Data into Commands and Parameters for Processing
        Local $sTemp = StringSplit($sRecv, " ")

        ; If Not Usable, then Skip this Data
        If $sTemp[0] <= 2 Then ContinueLoop

        ; Decide What To Do Based on Received Data
        Switch $sTemp[2]

            ; On Server Welcome
            Case $RPL_WELCOME

                ; Join channel
                _IRCChannelJoin($Sock, "#" & $channel)

                GUICtrlSetData($Label6, "Status: connected")
                GUICtrlSetColor($Label6, $COLOR_GREEN)

                While 1

                    If _IsPressed(79) Then

                        $message = GUICtrlRead($Input4)

                        _IRCRaw($Sock, "PRIVMSG #" & $channel & " :" & $message)

                        while _IsPressed(79)

                            ;do nothing when the key is kept pressed to avoid chat flood, so the message is only sent once

                        WEnd

                    endif

                    $nMsg = GUIGetMsg()

                    If $nMsg = $GUI_EVENT_CLOSE Then

                        ; Disconnect
                        _IRCDisconnect($Sock)

                        ; Shutdown Networking
                        TCPShutdown()

                        Exit

                    EndIf

                WEnd

        EndSwitch

    WEnd

EndFunc   ;==>connect

You can find a compiled version here:  Twitch chat message hotkey.exe

Edited by Neutro
Link to comment
Share on other sites

  • 1 month later...

Hi,

I found a bug in _IRCMultiSendMsg() function.

Between #475 and #481 lines of the IRC.au3 file there is code that not allow continue to case else of select statment, thus the function cannot work never. 

The select statment contains two expressions that are mutually exclusive, then either is always true, then never execute case else branch, then TCPSend() never execute which is the heart of _IRCMultiSendMsg()

Case $_sTarget = ""
            $_sReturn = SetError(2, 1, 0)
        Case Not $_sTarget = ""
            Switch AscW(StringLeft($_sTarget, 1))
                Case 0 To 32, 34, 36, 37, 39 To 42, 44 To 47, 58 To 64, 91 To 96, 123 To 1114111 ; AKA Not 33,35,38,43,48 To 57,65 To 90,97 To 122
                    $_sReturn = SetError(2, 2, 0)
            EndSwitch

Tested with current version of Autoit (3.3.14.2) and current version of IRC UDF (September 6, 2016)

Please, fixit

Link to comment
Share on other sites

  • 2 weeks later...

EDIT: Holy...

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

  • 2 months later...

Holy Moly he's right... just not for the reason specified. The example file returns 4-2 due to a poor implementation of IsBinary

Working on a fix now

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Latest Update:

.
  GUI.au3            Added   : Listview for connected Servers
  _IRCChannelInvite  Updated : Better channel error checking
  _IRCChannelJoin    Updated : Better channel error checking
  _IRCChannelKick    Added   : Ability to Kick users from Multiple Channels
  _IRCChannelPart    Updated : Better channel error checking
  _IRCChannelTopic   Updated : Better channel error checking
  _IRCMultiSendMsg   Fixed   : Flag implimentation

 

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...