Jump to content

Chrome UDF|twitch.tv|chat monitoring


Go to solution Solved by dragan,

Recommended Posts

Hey there guys. I've got a problem, can somebody tell me how to check if someone said a predefined command on Twitch.tv chat? I am trying to make a info bot for my friend. 

Example:

stream is online as well as the info-bot is running

random viewer says "!playlist" and my bot respons with something like "playlist link: blah blah blah"

of course, there will be anti-flood protection and so on

I just need this one thing, the rest I can guess/find myself :-)

Link to comment
Share on other sites

  • Moderators

suckinsyn,

Post split into new thread. In future please do not hijack completely unrelated threads. :naughty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hey there guys, I don't know if my post has to be accepted or is it deleted, but I've asked same question in the Chrome UDF thread and it did not show up. Anyway, asking again here :)

How can I monitor twitch.tv chat if there's a predefined command sent by random viewer? I am trying to write a info-bot for my friend. He's streaming, I am managing the stream - adverting, answering viewers questions and so on.

If allowed to, I will provide link to his stream, but all chats are the same I guess. I will only need tips on how to make my script look for predefined commands.

Thanks in advance :-)

Link to comment
Share on other sites

  • Moderators

suckinsyn,

As you can see above, I had moved it - they are now merged. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

<div id="ember598" class="ember-view chat-line">
  <div class="indicator"></div>
   <span class="timestamp">5:10</span> 
   <span class="badges"></span>&nbsp;
   <span class="from" style="color:#008000">Pan_brodaty</span>
   <span class="colon">:</span> 
   <span class="message" style="undefined">test</span>
</div>

This is how the chat msg looks.

5:10 BanTimeout  Pan_brodaty: test

From the left, timestamp -> badges (moderator icon and so on) -> from as nick -> colon, well, colon -> and the msg itself

I've played a bit with it today too, but can't get nowhere yet. Any help?

edit: ban and timeout are the moderator tools

Edited by suckinsyn
Link to comment
Share on other sites

  • Solution

I feel generous today...

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>
#include <GuiMenu.au3>
#include <IE.au3>

Global const $twitchURL = "http://www.twitch.tv/"
Global $twitch_ID = "snejkipl";
Global $isVisible = 1;
Global $fullUrl = $twitchURL & $twitch_ID
Global $LastMessage = ""

Global $width = 800, $height = 600
Global $Form1 = GUICreate("Twitch Chat details for: " & $twitch_ID, $width, $height)
Global $hRichEdit = _GUICtrlRichEdit_Create($Form1, "", 0, 0, $width, $height, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
GUISetState(@SW_SHOW)

AppedSystemMessage("Please wait while I start IE..." & @CRLF)
Global $oIE = _IECreate("about:blank", 0, $isVisible);

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_LINK)
_GUICtrlRichEdit_AutoDetectURL($hRichEdit, True)

AppedSystemMessage("Please wait while I load up: " & $fullUrl & @CRLF)
_IENavigate($oIE, $fullUrl);
AppedSystemMessage("Please wait while the chat loads up..."  & @CRLF)

While 1
    Sleep(100)
    _CheckForMessages()
WEnd

Func _CheckForMessages()
    If NOT IsObj($oIE) Then Return
    $chatObject = _IEGetObjById($oIE, "chat")
    If NOT IsObj($chatObject) Then Return
    $divsInChat = _IETagNameGetCollection($chatObject, "div")
    if IsObj($divsInChat) Then
        $addMessages = False
        for $oneDivInChat in $divsInChat
            if StringInStr($oneDivInChat.classname, "ember-view chat-line") Then
                $allSpans = _IETagNameGetCollection($oneDivInChat, "span")
                if IsObj($allSpans) Then
                    $curMessage = "";
                    $stringColor = "0x00000000";
                    for $oneSpan in $allSpans
                        Switch $oneSpan.classname
                            case "timestamp"
                                $curMessage &= "<" & $oneSpan.innertext & "> "
                            case "from"
                                if ($oneSpan.innertext = "jtv") Then
                                    $stringColor = "0x00C3C3C3"
                                Else
                                    $curMessage &= $oneSpan.innertext & ": "
                                    $pulledColor = StringReplace(StringReplace($oneSpan.style.getAttribute('color'), "rgb(", ""), ")", "");
                                    $splitCol = StringSplit($pulledColor, ',')
                                    if ($splitCol[0] >= 3) Then $stringColor = "0x00" & Hex(Number(StringStripWS($splitCol[3], 3)), 2) & Hex(Number(StringStripWS($splitCol[2], 3)), 2) & Hex(Number(StringStripWS($splitCol[1], 3)), 2)
                                EndIf
                            case "message"
                                if (StringLen(StringStripWS($oneSpan.innertext, 3)) > 0) AND (String($oneSpan.innertext) <> "0") Then $curMessage &= $oneSpan.innertext
                                $allSpans2 = _IETagNameGetCollection($oneSpan, "span")
                                if IsObj($allSpans2) Then
                                    for $oneSpan2 in $allSpans2
                                        if StringInStr($oneSpan2.classname, "emoticon") Then $curMessage &= "[" & StringReplace($oneSpan2.classname, "emoticon ", "") & "]"
                                    Next
                                EndIf
                        EndSwitch
                    Next
                    if (StringLen($LastMessage) = 0 OR $addMessages) Then
                        AppendUserMessage($curMessage  & @CRLF, $stringColor)
                        $LastMessage = $curMessage
                    Else
                        if $LastMessage = $curMessage then $addMessages = True
                    EndIf
                EndIf
            EndIf
        Next
    EndIf
EndFunc

func AppendUserMessage($sText, $iColor)
    _GUICtrlRichEdit_AppendTextColor($hRichEdit, $sText, $iColor)
EndFunc

Func AppedSystemMessage($sText)
    _GUICtrlRichEdit_AppendTextColor($hRichEdit, $sText, 0x00C3C3C3)
EndFunc

Func _GUICtrlRichEdit_AppendTextColor($hWnd, $sText, $iColor)
    Local $iLength = _GUICtrlRichEdit_GetTextLength($hWnd, True, True)
    Local $iCp = _GUICtrlRichEdit_GetCharPosOfNextWord($hWnd, $iLength)
    _GUICtrlRichEdit_AppendText($hWnd, $sText)
    _GUICtrlRichEdit_SetSel($hWnd, $iCp-1, $iLength + StringLen($sText))
    _GUICtrlRichEdit_SetCharColor($hWnd, $iColor)
    _GuiCtrlRichEdit_Deselect($hWnd)
EndFunc

Func WM_SYSCOMMAND($hWnd, $iMsg, $WParam, $LParam)
    Switch $hWnd
        Case $Form1
            Switch $WParam
                Case $SC_CLOSE
                    _GUICtrlRichEdit_Destroy($hRichEdit)
                    _IEQuit($oIE)
                    Exit
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
    #forceref $hWnd, $iMsg, $iWparam
    Local $hWndFrom, $iCode, $tNMHDR, $tEnLink, $cpMin, $cpMax, $tMsgFilter
    $tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hRichEdit
            Select
                Case $iCode = $EN_LINK
                    $tMsgFilter = DllStructCreate($tagMSGFILTER, $iLparam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then
                        $tEnLink = DllStructCreate($tagENLINK, $iLparam)
                        $cpMin = DllStructGetData($tEnLink, "cpMin")
                        $cpMax = DllStructGetData($tEnLink, "cpMax")
                        ShellExecute(_GUICtrlRichEdit_GetTextInRange($hRichEdit, $cpMin, $cpMax));
                    EndIf
            EndSelect
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

EDIT :

I just realized, that twitch chat is powered by IRC. And there are plenty of IRC scripts in here. You just need to get the correct parameters (server, port, channel...).
You can also build a chat bot with mIRC:

Edited by dragan
Link to comment
Share on other sites

  • 7 months later...

Sorry to bring up such an old thread, but I was searching for something similar and found this instead:

 You agree that you will abide by these Terms of Service and
will not: [..]
15. use any robot, spider, scraper, crawler or other automated
means to access the Twitch Service for any purpose or bypass
any measures Twitch may use to prevent or restrict access to
the Twitch Service;

 

I mean the chat is part of the Twitch Service right?

A little worried that other people might use this script here and face consequences.

This ToS does not apply for the TwitchAPI though (which I am trying to use).

Edit: Couldn't find report button

Edited by draien
Link to comment
Share on other sites

  • 1 month later...

I feel generous today...

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiRichEdit.au3>
#include <GuiMenu.au3>
#include <IE.au3>

Global const $twitchURL = "http://www.twitch.tv/"
Global $twitch_ID = "snejkipl";
Global $isVisible = 1;
Global $fullUrl = $twitchURL & $twitch_ID
Global $LastMessage = ""

Global $width = 800, $height = 600
Global $Form1 = GUICreate("Twitch Chat details for: " & $twitch_ID, $width, $height)
Global $hRichEdit = _GUICtrlRichEdit_Create($Form1, "", 0, 0, $width, $height, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
GUISetState(@SW_SHOW)

AppedSystemMessage("Please wait while I start IE..." & @CRLF)
Global $oIE = _IECreate("about:blank", 0, $isVisible);

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_LINK)
_GUICtrlRichEdit_AutoDetectURL($hRichEdit, True)

AppedSystemMessage("Please wait while I load up: " & $fullUrl & @CRLF)
_IENavigate($oIE, $fullUrl);
AppedSystemMessage("Please wait while the chat loads up..."  & @CRLF)

While 1
    Sleep(100)
    _CheckForMessages()
WEnd

Func _CheckForMessages()
    If NOT IsObj($oIE) Then Return
    $chatObject = _IEGetObjById($oIE, "chat")
    If NOT IsObj($chatObject) Then Return
    $divsInChat = _IETagNameGetCollection($chatObject, "div")
    if IsObj($divsInChat) Then
        $addMessages = False
        for $oneDivInChat in $divsInChat
            if StringInStr($oneDivInChat.classname, "ember-view chat-line") Then
                $allSpans = _IETagNameGetCollection($oneDivInChat, "span")
                if IsObj($allSpans) Then
                    $curMessage = "";
                    $stringColor = "0x00000000";
                    for $oneSpan in $allSpans
                        Switch $oneSpan.classname
                            case "timestamp"
                                $curMessage &= "<" & $oneSpan.innertext & "> "
                            case "from"
                                if ($oneSpan.innertext = "jtv") Then
                                    $stringColor = "0x00C3C3C3"
                                Else
                                    $curMessage &= $oneSpan.innertext & ": "
                                    $pulledColor = StringReplace(StringReplace($oneSpan.style.getAttribute('color'), "rgb(", ""), ")", "");
                                    $splitCol = StringSplit($pulledColor, ',')
                                    if ($splitCol[0] >= 3) Then $stringColor = "0x00" & Hex(Number(StringStripWS($splitCol[3], 3)), 2) & Hex(Number(StringStripWS($splitCol[2], 3)), 2) & Hex(Number(StringStripWS($splitCol[1], 3)), 2)
                                EndIf
                            case "message"
                                if (StringLen(StringStripWS($oneSpan.innertext, 3)) > 0) AND (String($oneSpan.innertext) <> "0") Then $curMessage &= $oneSpan.innertext
                                $allSpans2 = _IETagNameGetCollection($oneSpan, "span")
                                if IsObj($allSpans2) Then
                                    for $oneSpan2 in $allSpans2
                                        if StringInStr($oneSpan2.classname, "emoticon") Then $curMessage &= "[" & StringReplace($oneSpan2.classname, "emoticon ", "") & "]"
                                    Next
                                EndIf
                        EndSwitch
                    Next
                    if (StringLen($LastMessage) = 0 OR $addMessages) Then
                        AppendUserMessage($curMessage  & @CRLF, $stringColor)
                        $LastMessage = $curMessage
                    Else
                        if $LastMessage = $curMessage then $addMessages = True
                    EndIf
                EndIf
            EndIf
        Next
    EndIf
EndFunc

func AppendUserMessage($sText, $iColor)
    _GUICtrlRichEdit_AppendTextColor($hRichEdit, $sText, $iColor)
EndFunc

Func AppedSystemMessage($sText)
    _GUICtrlRichEdit_AppendTextColor($hRichEdit, $sText, 0x00C3C3C3)
EndFunc

Func _GUICtrlRichEdit_AppendTextColor($hWnd, $sText, $iColor)
    Local $iLength = _GUICtrlRichEdit_GetTextLength($hWnd, True, True)
    Local $iCp = _GUICtrlRichEdit_GetCharPosOfNextWord($hWnd, $iLength)
    _GUICtrlRichEdit_AppendText($hWnd, $sText)
    _GUICtrlRichEdit_SetSel($hWnd, $iCp-1, $iLength + StringLen($sText))
    _GUICtrlRichEdit_SetCharColor($hWnd, $iColor)
    _GuiCtrlRichEdit_Deselect($hWnd)
EndFunc

Func WM_SYSCOMMAND($hWnd, $iMsg, $WParam, $LParam)
    Switch $hWnd
        Case $Form1
            Switch $WParam
                Case $SC_CLOSE
                    _GUICtrlRichEdit_Destroy($hRichEdit)
                    _IEQuit($oIE)
                    Exit
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iWparam, $iLparam)
    #forceref $hWnd, $iMsg, $iWparam
    Local $hWndFrom, $iCode, $tNMHDR, $tEnLink, $cpMin, $cpMax, $tMsgFilter
    $tNMHDR = DllStructCreate($tagNMHDR, $iLparam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hRichEdit
            Select
                Case $iCode = $EN_LINK
                    $tMsgFilter = DllStructCreate($tagMSGFILTER, $iLparam)
                    If DllStructGetData($tMsgFilter, "msg") = $WM_LBUTTONUP Then
                        $tEnLink = DllStructCreate($tagENLINK, $iLparam)
                        $cpMin = DllStructGetData($tEnLink, "cpMin")
                        $cpMax = DllStructGetData($tEnLink, "cpMax")
                        ShellExecute(_GUICtrlRichEdit_GetTextInRange($hRichEdit, $cpMin, $cpMax));
                    EndIf
            EndSelect
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

EDIT :

I just realized, that twitch chat is powered by IRC. And there are plenty of IRC scripts in here. You just need to get the correct parameters (server, port, channel...).

You can also build a chat bot with mIRC:

'>

and

'>
Console Browse: Navigate on the WEB in a textual consoleMultiPing!: Show computer on the lan and/or show the local/remote task, ALL animated!KillaWin: Event executingCryptPage: Crypt your webpage and show only with key
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...