mIRC Home    About    Download    Register    News    Help

Topic Options
#261174 - 11/08/17 02:29 PM Help with "on PARSELINE:in:"
KubosKube Offline
Ameglian cow

Registered: 31/01/17
Posts: 39
Loc: Central US
So I'm using SReject's following code to catch Twitch whispers.

Code:
;; Converts incoming twitch whispers to private queries
;; Use on TEXT(/help on TEXT) or on OPEN(/help on OPEN) events to handle the event
on $*:PARSELINE:in:/^((@\S+ )?)(\x3A[^!@ ]+![^@ ]+@\S+) WHISPER (\S+) (\x3A.*)/i:{
  var %Count  = $regml(0)
  var %Tags   = $regml($calc(%Count -3))
  var %User   = $regml($calc(%Count -2))
  var %Target = $regml($calc(%Count -1))
  var %Msg    = $regml(%Count)
  if ($regex($server, /^(tmi|irc)\.(chat\.)?twitch\.tv$/i) && $me == %target) {
    .parseline -it
    .parseline -itqp %Tags %User PRIVMSG $me %Msg
  }
}


I also added in a small debug command to see what I was getting.

Code:
The code I added:
echo -a Count: %Count --- Tags: %Tags --- User: %User --- Target: %Target --- Msg: %Msg

Input:
@badges=;color=#1E90FF;display-name=KubosKube;emotes=;message-id=1126;thread-id=85000852_106951528;turbo=0;user-id=85000852;user-type= kuboskube kuboskubot Foo Bar

Output:
Count: 5 --- Tags: @badges=;color=#1E90FF;display-name=KubosKube;emotes=;message-id=1126;thread-id=85000852_106951528;turbo=0;user-id=85000852;user-type= --- User: kuboskube --- Target: kuboskubot --- Msg: Foo Bar


The part I need help with is how to get the user-id from the %Tags variable. One of the biggest issues here is the varying size of the raw data. If the user sends emotes over Twitch whispers, it makes the raw data significantly longer.

I'm also extremely interested in this regex stuff. I just don't know what "/^((@\S+ )?)(\x3A[^!@ ]+![^@ ]+@\S+) WHISPER (\S+) (\x3A.*)/i" means. I see a few recurring things, such as @/S+ and x3A , but I don't see the connection.

Top
#261181 - 12/08/17 03:34 PM Re: Help with "on PARSELINE:in:" [Re: KubosKube]
KubosKube Offline
Ameglian cow

Registered: 31/01/17
Posts: 39
Loc: Central US
If I replace the semicolons in %Tags with $chr(32), which is space, then I can just use "//StripUserID %Tags" several times to get the number I need.

Code:
alias StripUserID {
    if (user-id isin $1) {
      echo -a Found User ID: $remove($1,user-id=)
    }
    else {
      set %TagsTemp $remove(%TagsTemp,$1)
    }
}


So, although this solved my primary problem, I am still very curious as to how regex works. If anyone has any information on it, I'd appreciate hearing about it.

Top
#261182 - 12/08/17 07:13 PM Re: Help with "on PARSELINE:in:" [Re: KubosKube]
FroggieDaFrog Offline
Hoopy frood

Registered: 16/04/10
Posts: 828
Loc: USA
Originally Posted By: KubosKube
So I'm using SReject's following code to catch Twitch whispers.
The part I need help with is how to get the user-id from the %Tags variable. One of the biggest issues here is the varying size of the raw data. If the user sends emotes over Twitch whispers, it makes the raw data significantly longer.


Assuming you are using mTwitch.Core.mrc -- as that's where the snippet above comes from -- you can make use of the provided $mTwitch.MsgTags() alias:
Code:
  $mTwitch.MsgTags(%Tags, user-id)


Originally Posted By: KubosKube
I'm also extremely interested in this regex stuff. I just don't know what "/^((@\S+ )?)(\x3A[^!@ ]+![^@ ]+@\S+) WHISPER (\S+) (\x3A.*)/i" means. I see a few recurring things, such as @/S+ and x3A , but I don't see the connection.


The regex matches as follows:
  • Attempt to match at the start of the line: '^'
  • match @ followed by 1 or more Non-whitespace characters followed by a space: '@\S+ '
  • The above part may or may not exist, so the regex engine shouldn't require this part to match before attempting the next part; denoted with: '?'
  • Create a back reference for the above match; this is done via (): '((@\S+ )?)'
  • Match ':'(indicated by '\x3A') followed by one or more characters that AREN'T(indicated by the '^') '!' or '@' or space: '[^!@ ]+'
  • Then Match '!' followed by one or more characters that AREN'T '@' or space: '![^@ ]+'
  • Then Match '@' followed by one or more non-whitespace characters: '@\S+'
  • Then match the literal text: ' WHISPER '
  • Then match one or more whitespace characters, creating a back reference: '(\S+)'
  • Then match a space followed by ':'(indicated by '\x3A') followed by zero or more characters: ' (\x3A.*)'
  • The entire matching process should be case insensitive: '/[...]/i'

In summery it matches @tags(optional) :UserName!ident@host WHISPER target :message

--

As an aside:
For questions related specifically to mTwitch and/or its usage, feel free to open an issue ticket. Non-bug reports that are scripting-related questions involving mTwitch are allowed.

I also run a twitch channel specifically for mirc: #mirchelp. Feel free to drop in and ask questions for realtime support. I can't say I'm always active, but I am always idle, so as soon as I see your question(s) I'll provide assistant


Edited by FroggieDaFrog (12/08/17 07:31 PM)
_________________________
I am SReject
My Stuff

Top
#261184 - 13/08/17 04:46 AM Re: Help with "on PARSELINE:in:" [Re: FroggieDaFrog]
KubosKube Offline
Ameglian cow

Registered: 31/01/17
Posts: 39
Loc: Central US
Originally Posted By: FroggieDaFrog
(Insert Pure Awesomeness here)


I don't know if I can accurately summarize how amazing you are.
Many thanks!

I think I'm gonna bookmark this page. smile

Top