mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
So, I've been trying to make this script be a bit more useful for me. I have been planning to use twitchemotes.com's API API to save all the data to a txt file, but then I found this https://twitchemotes.com/filters/global

I've got the list saved to a text file for now, and I am planning to have a !refreshemotes script to resave them), but I'm struggling to get the script to read from the file so that command will come later on.


Code:
ON @*:TEXT:*:#: {
  if ($nick !isop #) {
    if ( $regex($1-,/$read(emotes.txt)/g) >= 5 ) {
      msg # Stop spamming emotes, $nick $+ !
      msg # .timeout $nick 120
    }
  }
}


I thought simply reading from the file would scan the whole thing. Yeahh.. No....

Would someone mind showing me what I'm doing wrong? My main concern when I do get this working is that there are a LOT of emotes. This list only contains the global emotes. I will be saving a list of subemotes, not sure how to have it scan both files at the same time, or if it will crash.

Joined: May 2015
Posts: 249
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
$read(emotes.txt) - will read one random line from .txt.
To check for each line you need looping and $lines(.txt).


Dont give a fish - teach to fish!
Joined: Sep 2014
Posts: 259
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Try this. Save the emotes to a text file called emotes and then use /emotes

Code:
alias emotes { 
  var %len $lines(emotes.txt)
  var %i 0
  while (%i <= %len) {
    var %emote $read(emotes.txt,n,%i)
    if ($istok(%emotes,%emote,124) == $false) { set %emotes %emotes $+ %emote $+ $chr(124) }   
    inc %i 
  }
  set %emotes $left(%emotes,-1)
}

ON @*:TEXT:*:#: {
  if ($nick !isop #) {
    if ( $regex($1-,/\b $+ %emotes $+ \b/g) >= 5 ) {
      msg # Stop spamming emotes, $nick $+ !
      msg # .timeout $nick 120
    }
  }
}

Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
Running /emotes gives me this:

* /set: line too long (line 6, emotefilter.ini)

But it did create a variable with all the emotes separated by |
Running the script also timed someone out for just speaking, no emotes at all. The message was "ill call it a spamish test" O.o

Last edited by jimieo; 24/05/15 03:45 PM.
Joined: Sep 2014
Posts: 259
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Hmm, I dont get any errors. It's working correctly here

Code:
//echo -a $regex(ill call it a spamish test,/\b $+ %emotes $+ \b/g)
0

Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
I think I figured out what was causing my error.

I was saving the global emote list AND subscriber emote list into the emotes.txt file (29,000+ emotes). That line is HUGE. When I only saved the global list, it wasn't an issue.

I guess I should split them into two, or more variables or something? Hrmm.

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Setup:
Save both sets of emotes to a single file, each emote being on its own line
Format each line so its wrapped in *'s (*emote*)
Load the file into a hashtable: /hload -n table emotes.txt

Then use $hfind() to check for emote abuse:
Code:
ON @*:TEXT:*:#: {
  if ($nick !isop # && $hfind(table, $1-, 0, W) > 5) {
    msg # Stop spamming emotes, $nick $+ !
    msg # .timeout $nick 120
  }
}


After the inital setup/parsing of the emotes file this should be far faster than using $read() and able to handle huge lists that would surpass mIRC's line length limit


Last edited by FroggieDaFrog; 24/05/15 06:01 PM.

I am SReject
My Stuff
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
Thanks, to both of you. I altered the code provided by Sakana to add the *'s to the emotes.. my bot is chugging along. Will test it out as soon as I can.

Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
Alright, I've got the emotes all formatted to the *emote* and created a new hash table
"/hmake table" and followed with the
"/hload -n table emotes.txt" bit.

I couldn't tell if it had loaded any emotes. It didn't give me an error message, but failed to time someone out for spamming the first emote of that text file.

Last edited by jimieo; 24/05/15 10:51 PM.
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
assuming emotes.txt is in the same directory as mIRC
Code:
on *:START:{
  hmake twitchEmotes 2000
  hload -n twitchEmotes emotes.txt
}

ON @*:TEXT:*:#: {
  if ($nick !isop # && $hfind(twitchEmotes, $1-, 0, W) > 5) {
    msg # Stop spamming emotes, $nick $+ !
    msg # .timeout $nick 120
  }
}

Last edited by FroggieDaFrog; 24/05/15 10:57 PM.

I am SReject
My Stuff
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
The emote file is in AppData\Roaming\mIRC

Pasted the code you provided into it's own file, and it hasn't timed anyone out for emote spam yet.

Just in case I misunderstood you about the formatting for the emotes.. You meant like this, right?
Code:
*4Head*
*ANELE*
*ArsonNoSexy*
*AsianGlow*
*AtGL*
*AthenaPMS*
*AtIvy*
*AtWW*
*BabyRage*
*BatChest*
*BCWarrior*
*BibleThump*
*BigBrother*
*BionicBunion*
*BlargNaut*
*BloodTrail*
*BORT*



EDIT: I found this hash table viewer script which shows me that the emotes were added. Each appears as a number, with the text for the emote within.
http://hawkee.com/snippet/8895/

Last edited by jimieo; 25/05/15 03:28 AM.
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
So, I modified the script a little bit, to check for the first emote's line. If I type the emote, it doesn't work, however if I type "1" it yells at me about spam. This would only happen AFTER I loaded the hashtable using the viewer I showed in my previous post.

Code:
ON @*:TEXT:*:#: {
  if ($nick isop # && $hfind(table, $1-, 1) >= 1) {
    msg # Stop spamming emotes, $nick $+ !
    ;msg # .timeout $nick 120
  }
}


When I changed the script to this, it only timed someone out for saying 5, not the actual text of the emotes. And only one "5" would trigger, an instance of five "5" would not.
Code:
ON @*:TEXT:*:#: {
  if ($nick isop # && $hfind(table, $1-, 1) >= 5) {
    msg # Stop spamming emotes, $nick $+ !
    ;msg # .timeout $nick 120
  }
}

Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
I've changed the hload to...

Code:
hload -n twitchEmotes emotes.txt


... to stop the table from seeing the emotes as numbers. Now when I view it I see them as...
Code:
*Kappa*


If my understanding is correct, you suggested I format the emotes that way so the script checks before the emote and after for more instances of emotes?

Code:
ON @*:TEXT:*:#: {
  if ($nick isop # && $hfind(twitchEmotes, $1-, 0, w)) {
    INC %ecount
    if (%ecount >= 5) {
      msg # Stop spamming emotes, $nick $+ !
      ;msg # .timeout $nick 120
    }
  }
}

This was to test if it could read that way. Kappa would not trigger the warning, but *Kappa* did. A message of "*Kappa*" would increase the count, but "*Kappa* *Kappa* *Kappa* *Kappa*" would not increase the count.

Off to try more.

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Ok, I need some clarification:

Are emotes case sensitive?
Do emotes have to be surrounded by whitespace?

Assuming the answers to those questions are true:
Code:
; when mIRC starts
on *:START:{

  ; create a hashtable
  hmake twitchEmotes 200

  ; load twitch emotes into the hashtable using numbers as the keys
  ; and each line of the file as the values
  hload -n twitchemotes emotes.txt
}

; on text in a channel I am op in
on @*:TEXT:*:#:{

  ; check to make sure the user IS NOT an channel mod
  if ($nick !isop #) {
    ; store the input line
    set -eu0 %emoteCountLine $1-

    ; store the emote count, giving it a default value of 0
    set -eu0 %emoteCount 0

    ; search the hashtable's 'data' for any wildcard-matching items
    ; in the table that match text. For each found, call /countEmotes
    noop $hfind(twitchEmotes, $1-, 0, W, countEmotes $1-).data
    
    ; if the emotecount is equal-to or greater than 5, send message and timeout user
    if (%emoteCount >= 5) {
      msg # Stop spamming emotes, $nick $+ !
      msg # .timeout $nick 120
    }
    
    ; cleanup the variables
    unset %emoteCount, %emoteCountLine
  }
}

alias -l countEmotes {
  ; get the 'data' portion of the found match
  var %emote = $hget(TwitchEmotes, $1-)
  
  ; remove the surrounding *'s
  %emote = $left($right(%emote, -1), -1)

  ; turn the emote into a regex pattern
  %emote = /(?<=^| ) $+ $right($left($hget(twitchEmotes, $1-), -1),-1) $+ (?= |$)/g
  
  ; call the $regex and increase %emoteCount by the number of matches it finds
  inc %emoteCount $regex(%emoteCountLine, %emote)
}

Last edited by FroggieDaFrog; 26/05/15 01:25 PM.

I am SReject
My Stuff
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
You are correct, about the emotes being case sensitive, and the need of an empty space around them. That is one that I just found out. I wasn't aware twitch changed the way emotes were parsed.

Anywho, that script functions perfectly. Froggie, I do appreciate the time you've put in to help me achieve that goal.


Link Copied to Clipboard