mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2017
Posts: 14
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2017
Posts: 14
Hey guys, I just have a quick question. I'm trying to make a script for a Twitch chat. I've had some fun with recording a ton of emotes being used, although there's 1 flaw to the entire thing. It seems like once a keyword has been found anywhere in the line, it won't do anything else other than what I told it to. Once. That means if you used 3 Kappa's, it only records 1 to the file.

Now I'm working on a system that awards people points for the bits they donate, although a common theme in this chat is that they like to spam 10 single bits in 1 message. To assign the correct amount of points, I need the script to NOT stop after the first found occurrence, but at the end of the message.

Any tips?

This is how my current script works for the MingLee emote.
Code:
on *:TEXT:*MingLee*:#: {
  writeini -n Emotes.ini $+(#,-,$date) MingLee $calc($readini(Emotes.ini,$+(#,-,$date),MingLee) + 1)
}

Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
There are a few ways.

$count(string,thing to count) would probably be the simplest solution.

example
$count(this is some hmm i don't hmm what the hmm,hmm)
that would give 3

on *:TEXT:*MingLee*:#: {
writeini -n Emotes.ini $+(#,-,$date) MingLee $calc($readini(Emotes.ini,$+(#,-,$date),MingLee) + $count($1-,MingLee))
}


http://scripting.pball.win
My personal site with some scripts I've released.
Joined: Apr 2017
Posts: 14
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2017
Posts: 14
Originally Posted By: pball
There are a few ways.

$count(string,thing to count) would probably be the simplest solution.

example
$count(this is some hmm i don't hmm what the hmm,hmm)
that would give 3

on *:TEXT:*MingLee*:#: {
writeini -n Emotes.ini $+(#,-,$date) MingLee $calc($readini(Emotes.ini,$+(#,-,$date),MingLee) + $count($1-,MingLee))
}


Is there a way to record different keywords aswell? The streamer recently implemented the BitBoss thing where people try to out-donate eachother to become the BitBoss, so they'd often donate 101 bits to defeat the current BitBoss, so I need it to recognize the 100 Bits, but also the single bit.

Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
You'll have to explain a bit more since I have zero idea about anything twitch. The best guess I have is there are multiple keywords worth different amounts?


http://scripting.pball.win
My personal site with some scripts I've released.
Joined: Apr 2017
Posts: 14
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2017
Posts: 14
Originally Posted By: pball
You'll have to explain a bit more since I have zero idea about anything twitch. The best guess I have is there are multiple keywords worth different amounts?


The general idea is that I've been asked to write a script that gives people points(I have set up my own Point system containing a Betting script and Russian Roulette to gain points) for their Bits. But people like spamming.
This works perfectly fine. It gets triggered by Cheer1 and counts 6x Cheer1
Quote:
cheer1 cheer1 cheer1 cheer1 cheer1 cheer1


This doesn't work. It gets triggered by Cheer100 and counts 4x Cheer100, but not the Cheer1
Quote:
cheer100 cheer100 cheer100 cheer100 cheer1


So I think your guess is partly correct. I want to be able to count every keyword(Preferrably in 1 piece of code, as right now I have the code of the OP repeated for every emote I have) in the string. Right now, it stops as soon as it finds the first keyword it matches.


This is how I currently have my keywords set up. It has a different piece of code for every keyword.
Code:
on *:TEXT:*Test1*:#: {
  writeini -n Emotes.ini $+(#,-,$date) Test1 $calc($readini(Emotes.ini,$+(#,-,$date),Test1) + $count($1-, Test1))
}

on *:TEXT:*Test2*:#: {
  writeini -n Emotes.ini $+(#,-,$date) Test2 $calc($readini(Emotes.ini,$+(#,-,$date),Test2) + $count($1-, Test2))
}

on *:TEXT:*Test3*:#: {
  writeini -n Emotes.ini $+(#,-,$date) Test3 $calc($readini(Emotes.ini,$+(#,-,$date),Test3) + $count($1-, Test3))
}


If I type
Quote:
Test2 Test2 Test3 Test3 Test3
it'll only count the Test2. If I swap it around to
Quote:
Test3 Test3 Test2
it'll only count Test3

Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
Well might not be the simplest way but this works and I'm pretty sure it'll do what you want.

All you have to do is add the keywords to the second line where cheer and test are. Then the script will count and add up all the numbers on those keywords.

Example:
cheer1 cheer3 cheer100 test20 test2 asdfa asdf asdf test5 asdfasd cheer4
That will count 108 for cheer and 27 for test

Code:
on *:text:*:#: {
  set -l %keywords cheer test
  set -l %num 1
  while ($gettok(%keywords,%num,32)) {
    set -l %kw $v1
    noop $regex($1-,/ $+ %kw $+ (\d+) $+ /iSg)
    set -l %num2 1
    while ($regml(%num2)) {
      set -l $+(%,%kw) $calc($($+(%,%kw),2) + $v1)
      inc %num2
    }
    writeini -n Emotes.ini $+(#,-,$date) %kw $calc($readini(Emotes.ini,$+(#,-,$date),%kw) + $($+(%,%kw),2))
    inc %num
  }
}


Let me know if this works out.

Last edited by pball; 21/05/17 06:26 PM. Reason: added case insensitive/strip control codes

http://scripting.pball.win
My personal site with some scripts I've released.
Joined: Apr 2017
Posts: 14
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2017
Posts: 14
Originally Posted By: pball
Well might not be the simplest way but this works and I'm pretty sure it'll do what you want.

All you have to do is add the keywords to the second line where cheer and test are. Then the script will count and add up all the numbers on those keywords.

Example:
cheer1 cheer3 cheer100 test20 test2 asdfa asdf asdf test5 asdfasd cheer4
That will count 108 for cheer and 27 for test

Code:
on *:text:*:#: {
  set -l %keywords cheer test
  set -l %num 1
  while ($gettok(%keywords,%num,32)) {
    set -l %kw $v1
    noop $regex($1-,/ $+ %kw $+ (\d+) $+ /g)
    set -l %num2 1
    while ($regml(%num2)) {
      set -l $+(%,%kw) $calc($($+(%,%kw),2) + $v1)
      inc %num2
    }
    writeini -n Emotes.ini $+(#,-,$date) %kw $calc($readini(Emotes.ini,$+(#,-,$date),%kw) + $($+(%,%kw),2))
    inc %num
  }
}


Let me know if this works out.


The idea does work, although there's 1 flaw to it. It's case-sensitive, so if someone types Cheer10 instead of my defined 'cheer' keyword, it won't register. Any way to fix that? I tried putting both 'Test' and 'test'in the keywords, but that just seems to double the input(So 2 cheers of 5 are 10, would become 20)

Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
whoops didn't think about that. I added i to the regex command so it's case insensitive and S to strip color codes and such.

code in previous post is updated


http://scripting.pball.win
My personal site with some scripts I've released.
Joined: Apr 2017
Posts: 14
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2017
Posts: 14
Originally Posted By: pball
whoops didn't think about that. I added i to the regex command so it's case insensitive and S to strip color codes and such.

code in previous post is updated


There's another problem that I didn't realise. Every word triggers the command now. It doesn't actually count, but still responds
https://gyazo.com/8e46861b9a0bbc1bd13ca7bfc46a14ac?token=1c6b5032cab2a0254d981769106128e5

I had to find out the hard way because people love to try and get me global banned as soon as they find a gap in the code, so I really need it to be idiot-proof

Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
what does your code look like now?


http://scripting.pball.win
My personal site with some scripts I've released.
Joined: Apr 2017
Posts: 14
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2017
Posts: 14
Originally Posted By: pball
what does your code look like now?


Currently the code looks like this
Code:
on *:text:*:#: {
  set -l %keywords test
  set -l %num 1
  while ($gettok(%keywords,%num,32)) {
    set -l %kw $v1
    noop $regex($1-,/ $+ %kw $+ (\d+) $+ /iSg)
    set -l %num2 1
    while ($regml(%num2)) {
      set -l $+(%,%kw) $calc($($+(%,%kw),2) + $v1)
      inc %num2
    }
    msg $chan thanks for the $calc($($+(%,%kw),2) + $v1) cheers!
    writeini -n Cheers.ini $+(#,-,$date) %kw $calc($readini(Cheers.ini,$+(#,-,$date),%kw) + $($+(%,%kw),2))
    inc %num
  }
}

Joined: Nov 2009
Posts: 295
P
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
It now checks if any cheers were counted before replying. If you add multiple keywords there will be a separate reply for each one, that can be fixed.

Code:
on *:text:*:#: {
  set -l %keywords test
  set -l %num 1
  while ($gettok(%keywords,%num,32)) {
    set -l %kw $v1
    noop $regex($1-,/ $+ %kw $+ (\d+) $+ /iSg)
    set -l %num2 1
    while ($regml(%num2)) {
      set -l $+(%,%kw) $calc($($+(%,%kw),2) + $v1)
      inc %num2
    }
    if ($($+(%,%kw),2) > 0) {
      msg $chan thanks for the $($+(%,%kw),2) cheers!
      writeini -n Cheers.ini $+(#,-,$date) %kw $calc($readini(Cheers.ini,$+(#,-,$date),%kw) + $($+(%,%kw),2))
    }
    inc %num
  }
}


http://scripting.pball.win
My personal site with some scripts I've released.
Joined: Oct 2015
Posts: 112
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
If I understand correctly, you are simply wanting to reward points based on the number of bits cheered, and the actual emote used to cheer is irrelevant? If that's the case, it seems like it would be much easier to just use message tags. Also, your current script can be easily exploited by anyone "faking cheers" by simply typing the cheer's in the chat even though they do not have any bits.

I'm not sure if you have message tags enabled already, if not, you will need to manually activate them. It doesn't hurt to enable "commands" and "membership" either while you're at it:

Code:
ON *:CONNECT: IF ($server == tmi.twitch.tv) CAP REQ :twitch.tv/commands twitch.tv/tags twitch.tv/membership


After making sure that you have message tags enabled, the script used would be as simple as the following:

Code:
ON *:TEXT:*:#: {
  IF ($msgtags(bits).key) {
    msg $chan thanks for the $msgtags(bits).key cheers!
    ;do other stuff here like writeini
  }
}

Joined: Apr 2017
Posts: 14
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2017
Posts: 14
Originally Posted By: Blas
If I understand correctly, you are simply wanting to reward points based on the number of bits cheered, and the actual emote used to cheer is irrelevant? If that's the case, it seems like it would be much easier to just use message tags. Also, your current script can be easily exploited by anyone "faking cheers" by simply typing the cheer's in the chat even though they do not have any bits.


I'm still open to completely new suggestions, if you have any because I would like to keep exploits to a minimum, obviously. The emotes being used are relevant aswell, as this is about adding points for every bit received, although I guess it works because Kappa1 is still a bit, just like Cheer1.


What I want the script to recognize:
Quote:

Cheers by using Emotes (Kappa[Amount], Kreygasm[Amount], SwiftRage[Amount])
Cheers with regular cheers (Cheer[Amount])
The amount of cheers entered (Kappa10 Cheer1 etc. etc.)
The complete total of the entire message with different emotes/cheers and amounts
The user cheering


Whenever someone sends bits in any way(In a chat message), I want my script to calculate the total worth of the message( For example; 1 + 10 + 1 + 100 + 1 = 113 bits) and write a 10% value of the bits to their points (= 11.3). I hope this is possible with MIRC.

Originally Posted By: Blas

I'm not sure if you have message tags enabled already, if not, you will need to manually activate them. It doesn't hurt to enable "commands" and "membership" either while you're at it:

Code:
ON *:CONNECT: IF ($server == tmi.twitch.tv) CAP REQ :twitch.tv/commands twitch.tv/tags twitch.tv/membership


After making sure that you have message tags enabled, the script used would be as simple as the following:

Code:
ON *:TEXT:*:#: {
  IF ($msgtags(bits).key) {
    msg $chan thanks for the $msgtags(bits).key cheers!
    ;do other stuff here like writeini
  }
}


Although I already had Membership, I'll add the other two aswell. If this more simple script works without exploits, I'll happily use it, although I do need it to be able to calculate the total of every message

Joined: Apr 2017
Posts: 14
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2017
Posts: 14
Originally Posted By: pball
It now checks if any cheers were counted before replying. If you add multiple keywords there will be a separate reply for each one, that can be fixed.

Code:
on *:text:*:#: {
  set -l %keywords test
  set -l %num 1
  while ($gettok(%keywords,%num,32)) {
    set -l %kw $v1
    noop $regex($1-,/ $+ %kw $+ (\d+) $+ /iSg)
    set -l %num2 1
    while ($regml(%num2)) {
      set -l $+(%,%kw) $calc($($+(%,%kw),2) + $v1)
      inc %num2
    }
    if ($($+(%,%kw),2) > 0) {
      msg $chan thanks for the $($+(%,%kw),2) cheers!
      writeini -n Cheers.ini $+(#,-,$date) %kw $calc($readini(Cheers.ini,$+(#,-,$date),%kw) + $($+(%,%kw),2))
    }
    inc %num
  }
}


If the single reply per keyword could be fixed, that would be great. Makes everything more simple. It does work good though!

Last edited by KevinSlice; 23/05/17 04:27 PM.
Joined: Apr 2017
Posts: 14
K
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2017
Posts: 14
So, I think I got it to work exactly the way I wanted it to. Thanks to you both I've managed to combine both the script that counts the total bits, as well as the functionality to check the authenticity of the bits.

Code:
on *:text:*:#: {
  set -l %keywords Cheer Kappa Kreygasm SwiftRage PogChamp 4Head
  set -l %num 1
  while ($gettok(%keywords,%num,32)) {
    set -l %kw $v1
    noop $regex($1-,/ $+ %kw $+ (\d+) $+ /iSg)
    set -l %num2 1
    while ($regml(%num2)) {
      set -l $+(%,%kw) $calc($($+(%,%kw),2) + $v1)
      inc %num2
    }
    if ($($+(%,%kw),2) > 0) {
      IF ($msgtags(bits).key) {
        /echo -a $msgtags(display-name).key donated $($+(%,%kw),2) %kw cheers!
        writeini -n Cheers.ini $+($msgtags(display-name).key) %kw $calc($readini(Cheers.ini,$+($msgtags(display-name).key),%kw) + $($+(%,%kw),2))
      }
      else {
        echo -a Attempted to cheat the system
        writeini -n CheersFailed.ini $+($nick) %kw $calc($readini(CheersFailed.ini,$+($nick), %kw) + $($+(%,%kw),2))
      }
    }
    inc %num
  }
}


I've added PogChamp and 4Head to the keywords so I had a way to test the system. They're being registered to CheersFailed.ini while actual bits(Kappa, Kreygasm, SwiftRage or Cheer) get registered to Cheers.ini. For the purpose of testing, I've made it send an Echo aswell to explain what happened and how. It currently says [Username] donated [Amount] [Keyword] cheers!
So if I'd type Kappa1, it'll say "KevinSlice donated 1 Kappa cheers!"


Link Copied to Clipboard