mIRC Home    About    Download    Register    News    Help

Print Thread
(Twitch-Bot) raffle script with subscriber-check #253097 25/05/15 02:18 PM
Joined: Mar 2015
Posts: 19
R
Ravelux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: Mar 2015
Posts: 19
Hey,

I am not a good scripter but I have scripted a addme-script where people can join into the raffle.

I have access to the list of subscribers (https://api.twitch.tv/kraken/channels/CHANNELNAME/subscriptions).

My goal is to add subscribers multiple times to the rafflelist (RSNs.txt) but I am not so experienced in mIRC scripting so I don't know a way how to do this.

I've tried it already via vbscript but this way isn't possible because of:
- too long way (execute script, read script, read file, cut line in file, etc)

So I need your help and I hope you have any idea for me how I can solve my problem.

Thank you !

Code:
on *:TEXT:!give *:#: {
  if ($nick == ravelux) {
    if ($2 == 1) {
      var %lines = $lines(RSNs.txt)
      set %user1 $read(RSNs.txt, n)
      while ($read(doublecheck.txt,w,%user1) != $null) {
        set %user1 $read(RSNs.txt, n) 
      }
      msg $chan The winner is: %user1
      write doublecheck.txt %user1
    } 
    elseif ($2 == 2) {
      var %lines = $lines(RSNS.txt)
      set %user1 $read(RSNS.txt, n)
      set %user2 $read(RSNS.txt, n)
      while ((%user1 == %user2) || ($read(doublecheck.txt,w,%user1) != $null) || ($read(doublecheck.txt,w,%user2) != $null)) {
        set %user1 $read(RSNS.txt, n)
        set %user2 $read(RSNS.txt, n) 
      }
      while ($read(doublecheck.txt,w,%user1) != $null) {
        set %user1 $read(RSNS.txt, n) 
      }
      while ($read(doublecheck.txt,w,%user2) != $null) {
        set %user2 $read(RSNS.txt, n) 
      }
      msg $chan The winners are: %user1 , %user2
      write doublecheck.txt %user1
      write doublecheck.txt %user2
    }
    elseif ($2 == 3) {
      var %lines = $lines(RSNS.txt)
      set %user1 $read(RSNS.txt, n)
      set %user2 $read(RSNS.txt, n)
      set %user3 $read(RSNS.txt, n)
      while ((%user1 == %user2) || (%user1 == %user3) || (%user2 == %user3) || ($read(doublecheck.txt,w,%user1) != $null) || ($read(doublecheck.txt,w,%user2) != $null) || ($read(doublecheck.txt,w,%user3) != $null)) {
        set %user1 $read(RSNS.txt, n)
        set %user2 $read(RSNS.txt, n)
        set %user3 $read(RSNS.txt, n) 
      }
      msg $chan The winners are: %user1 , %user2 , %user3
      write doublecheck.txt %user1
      write doublecheck.txt %user2
      write doublecheck.txt %user3
    }
    elseif ($2 == 4) {
      var %lines = $lines(RSNS.txt)
      set %user1 $read(RSNS.txt, n)
      set %user2 $read(RSNS.txt, n)
      set %user3 $read(RSNS.txt, n)
      set %user4 $read(RSNS.txt, n)
      while ((%user1 == %user2) || (%user1 == %user3) || (%user1 == %user4) || (%user2 == %user3) || (%user2 == %user4) || (%user3 == %user4) || ($read(doublecheck.txt,w,%user1) != $null) || ($read(doublecheck.txt,w,%user2) != $null) || ($read(doublecheck.txt,w,%user3) != $null) || ($read(doublecheck.txt,w,%user4) != $null)) {
        set %user1 $read(RSNS.txt, n)
        set %user2 $read(RSNS.txt, n)
        set %user3 $read(RSNS.txt, n) 
        set %user4 $read(RSNS.txt, n)
      }
      msg $chan The winners are: %user1 , %user2 , %user3 , %user4
      write doublecheck.txt %user1
      write doublecheck.txt %user2
      write doublecheck.txt %user3
      write doublecheck.txt %user4
    }
    elseif ($2 == 5) {
      var %lines = $lines(RSNS.txt)
      set %user1 $read(RSNS.txt, n)
      set %user2 $read(RSNS.txt, n)
      set %user3 $read(RSNS.txt, n)
      set %user4 $read(RSNS.txt, n)
      set %user5 $read(RSNS.txt, n)
      while ((%user1 == %user2) || (%user1 == %user3) || (%user1 == %user4) || (%user1 == %user5) || (%user2 == %user3) || (%user2 == %user4) || (%user2 == %user5) || (%user3 == %user4) || (%user3 == %user5) || (%user3 == %user6) || (%user4 == %user5) || ($read(doublecheck.txt,w,%user1) != $null) || ($read(doublecheck.txt,w,%user2) != $null) || ($read(doublecheck.txt,w,%user3) != $null) || ($read(doublecheck.txt,w,%user4) != $null) || ($read(doublecheck.txt,w,%user5) != $null)) {
        set %user1 $read(RSNS.txt, n)
        set %user2 $read(RSNS.txt, n)
        set %user3 $read(RSNS.txt, n) 
        set %user4 $read(RSNS.txt, n)
        set %user5 $read(RSNS.txt, n)
      }
      msg $chan The winners are: %user1 , %user2 , %user3 , %user4 , %user5
      write doublecheck.txt %user1
      write doublecheck.txt %user2
      write doublecheck.txt %user3
      write doublecheck.txt %user4
      write doublecheck.txt %user5
    }
    elseif ($2 == 6) {
      var %lines = $lines(RSNS.txt)
      set %user1 $read(RSNS.txt, n)
      set %user2 $read(RSNS.txt, n)
      set %user3 $read(RSNS.txt, n)
      set %user4 $read(RSNS.txt, n)
      set %user5 $read(RSNS.txt, n)
      set %user6 $read(RSNS.txt, n)
      while ((%user1 == %user2) || (%user1 == %user3) || (%user1 == %user4) || (%user1 == %user5) || (%user1 == %user6) || (%user2 == %user3) || (%user2 == %user4) || (%user2 == %user5) || (%user2 == %user6) || (%user3 == %user4) || (%user3 == %user5) || (%user3 == %user6) || (%user4 == %user5) || (%user4 == %user6) || (%user5 == %user6) || ($read(doublecheck.txt,w,%user1) != $null) || ($read(doublecheck.txt,w,%user2) != $null) || ($read(doublecheck.txt,w,%user3) != $null) || ($read(doublecheck.txt,w,%user4) != $null) || ($read(doublecheck.txt,w,%user5) != $null) || ($read(doublecheck.txt,w,%user6) != $null)) {
        set %user1 $read(RSNS.txt, n)
        set %user2 $read(RSNS.txt, n)
        set %user3 $read(RSNS.txt, n) 
        set %user4 $read(RSNS.txt, n)
        set %user5 $read(RSNS.txt, n)
        set %user6 $read(RSNS.txt, n)
      }
      msg $chan The winners are: %user1 , %user2 , %user3 , %user4 , %user5 , %user6
      write doublecheck.txt %user1
      write doublecheck.txt %user2
      write doublecheck.txt %user3
      write doublecheck.txt %user4
      write doublecheck.txt %user5
      write doublecheck.txt %user6
    }
    elseif ($2 == 7) {
      var %lines = $lines(RSNS.txt)
      set %user1 $read(RSNS.txt, n)
      set %user2 $read(RSNS.txt, n)
      set %user3 $read(RSNS.txt, n)
      set %user4 $read(RSNS.txt, n)
      set %user5 $read(RSNS.txt, n)
      set %user6 $read(RSNS.txt, n)
      set %user7 $read(RSNS.txt, n)
      while ((%user1 == %user2) || (%user1 == %user3) || (%user1 == %user4) || (%user1 == %user5) || (%user1 == %user6) || (%user1 == %user7) || (%user2 == %user3) || (%user2 == %user4) || (%user2 == %user5) || (%user2 == %user6) || (%user2 == %user7) || (%user3 == %user4) || (%user3 == %user5) || (%user3 == %user6) || (%user3 == %user7) || (%user4 == %user5) || (%user4 == %user6) || (%user4 == %user7) || (%user5 == %user6) || (%user5 == %user7) || (%user6 == %user7) ||  ($read(doublecheck.txt,w,%user1) != $null) || ($read(doublecheck.txt,w,%user2) != $null) || ($read(doublecheck.txt,w,%user3) != $null) || ($read(doublecheck.txt,w,%user4) != $null) || ($read(doublecheck.txt,w,%user5) != $null) || ($read(doublecheck.txt,w,%user6) != $null) || ($read(doublecheck.txt,w,%user7) != $null)) {
        set %user1 $read(RSNS.txt, n)
        set %user2 $read(RSNS.txt, n)
        set %user3 $read(RSNS.txt, n) 
        set %user4 $read(RSNS.txt, n)
        set %user5 $read(RSNS.txt, n)
        set %user6 $read(RSNS.txt, n)
        set %user7 $read(RSNS.txt, n)
      }
      msg $chan The winners are: %user1 , %user2 , %user3 , %user4 , %user5 , %user6 , %user7
      write doublecheck.txt %user1
      write doublecheck.txt %user2
      write doublecheck.txt %user3
      write doublecheck.txt %user4
      write doublecheck.txt %user5
      write doublecheck.txt %user6
      write doublecheck.txt %user7
    }
    elseif ($2 == 8) {
      var %lines = $lines(RSNS.txt)
      set %user1 $read(RSNS.txt, n)
      set %user2 $read(RSNS.txt, n)
      set %user3 $read(RSNS.txt, n)
      set %user4 $read(RSNS.txt, n)
      set %user5 $read(RSNS.txt, n)
      set %user6 $read(RSNS.txt, n)
      set %user7 $read(RSNS.txt, n)
      set %user8 $read(RSNS.txt, n)
      while ((%user1 == %user2) || (%user1 == %user3) || (%user1 == %user4) || (%user1 == %user5) || (%user1 == %user6) || (%user1 == %user7) || (%user1 == %user8) || (%user2 == %user3) || (%user2 == %user4) || (%user2 == %user5) || (%user2 == %user6) || (%user2 == %user7) || (%user2 == %user8) ||  (%user3 == %user4) || (%user3 == %user5) || (%user3 == %user6) || (%user3 == %user7) || (%user3 == %user8) || (%user4 == %user5) || (%user4 == %user6) || (%user4 == %user7) || (%user4 == %user8) || (%user5 == %user6) || (%user5 == %user7) || (%user5 == %user8) || (%user6 == %user7) || (%user6 == %user8) || (%user7 == %user8) ||  ($read(doublecheck.txt,w,%user1) != $null) || ($read(doublecheck.txt,w,%user2) != $null) || ($read(doublecheck.txt,w,%user3) != $null) || ($read(doublecheck.txt,w,%user4) != $null) || ($read(doublecheck.txt,w,%user5) != $null) || ($read(doublecheck.txt,w,%user6) != $null) || ($read(doublecheck.txt,w,%user7) != $null) || ($read(doublecheck.txt,w,%user8) != $null)) {
        set %user1 $read(RSNS.txt, n)
        set %user2 $read(RSNS.txt, n)
        set %user3 $read(RSNS.txt, n) 
        set %user4 $read(RSNS.txt, n)
        set %user5 $read(RSNS.txt, n)
        set %user6 $read(RSNS.txt, n)
        set %user7 $read(RSNS.txt, n) 
        set %user8 $read(RSNS.txt, n)
      }
      msg $chan The winners are: %user1 , %user2 , %user3 , %user4 , %user5 , %user6 , %user7 , %user8
      write doublecheck.txt %user1
      write doublecheck.txt %user2
      write doublecheck.txt %user3
      write doublecheck.txt %user4
      write doublecheck.txt %user5
      write doublecheck.txt %user6
      write doublecheck.txt %user7
      write doublecheck.txt %user8
    }
    elseif ($2 == 9) {
      var %lines = $lines(RSNS.txt)
      set %user1 $read(RSNS.txt, n)
      set %user2 $read(RSNS.txt, n)
      set %user3 $read(RSNS.txt, n)
      set %user4 $read(RSNS.txt, n)
      set %user5 $read(RSNS.txt, n)
      set %user6 $read(RSNS.txt, n)
      set %user7 $read(RSNS.txt, n)
      set %user8 $read(RSNS.txt, n)
      set %user9 $read(RSNS.txt, n)
      while ((%user1 == %user2) || (%user1 == %user3) || (%user1 == %user4) || (%user1 == %user5) || (%user1 == %user6) || (%user1 == %user7) || (%user1 == %user8) || (%user1 == %user9) || (%user2 == %user3) || (%user2 == %user4) || (%user2 == %user5) || (%user2 == %user6) || (%user2 == %user7) || (%user2 == %user8) || (%user2 == %user9) || (%user3 == %user4) || (%user3 == %user5) || (%user3 == %user6) || (%user3 == %user7) || (%user3 == %user8) || (%user3 == %user9) || (%user4 == %user5) || (%user4 == %user6) || (%user4 == %user7) || (%user4 == %user8) || (%user4 == %user9) || (%user5 == %user6) || (%user5 == %user7) || (%user5 == %user8) || (%user5 == %user9) || (%user6 == %user7) || (%user6 == %user8) || (%user6 == %user9) || (%user7 == %user8) || (%user7 == %user9) || (%user8 == %user9) || ($read(doublecheck.txt,w,%user1) != $null) || ($read(doublecheck.txt,w,%user2) != $null) || ($read(doublecheck.txt,w,%user3) != $null) || ($read(doublecheck.txt,w,%user4) != $null) || ($read(doublecheck.txt,w,%user5) != $null) || ($read(doublecheck.txt,w,%user6) != $null) || ($read(doublecheck.txt,w,%user7) != $null) || ($read(doublecheck.txt,w,%user8) != $null) || ($read(doublecheck.txt,w,%user9) != $null)) {
        set %user1 $read(RSNS.txt, n)
        set %user2 $read(RSNS.txt, n)
        set %user3 $read(RSNS.txt, n) 
        set %user4 $read(RSNS.txt, n)
        set %user5 $read(RSNS.txt, n)
        set %user6 $read(RSNS.txt, n)
        set %user7 $read(RSNS.txt, n) 
        set %user8 $read(RSNS.txt, n)
        set %user9 $read(RSNS.txt, n)
      }
      msg $chan The winners are: %user1 , %user2 , %user3 , %user4 , %user5 , %user6 , %user7 , %user8 , %user9
      write doublecheck.txt %user1
      write doublecheck.txt %user2
      write doublecheck.txt %user3
      write doublecheck.txt %user4
      write doublecheck.txt %user5
      write doublecheck.txt %user6
      write doublecheck.txt %user7
      write doublecheck.txt %user8
      write doublecheck.txt %user9
    }
    else {
      msg $chan This number is not scripted
    }
  }
  else {
  msg $nick Sorry, you are not allowed to use this command }
}

Re: (Twitch-Bot) raffle script with subscriber-check [Re: Ravelux] #253098 25/05/15 04:18 PM
Joined: Jan 2004
Posts: 1,323
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,323
Once you have all the nicks in a file use something like this instead of repeating so much code:

Code:
alias pickn {
  var %list, %choose = $$1, %file = somefile.txt, %limit = $lines(%file)
  if (!$exists(%file)) return
  if (%choose > %limit) return
  
  while ($numtok(%list,32) < %choose) {
    var %pick = $read(%file,$rand(1,%limit))
    if ($istok(%list,%pick,32)) { continue }
    %list = $addtok(%list,%pick,32)
  }

  echo -ag %list
}

Re: (Twitch-Bot) raffle script with subscriber-check [Re: Loki12583] #253099 25/05/15 04:39 PM
Joined: Mar 2015
Posts: 19
R
Ravelux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: Mar 2015
Posts: 19
Thank you. My code is working so I dont really want to change something. My problem is that this link is the only way I have the subscribers. So this list is 1 line with more than 40k characters and I need to check if $2 is in content of this website. I don't know a way how to do that.

(Twitch-Bot) raffle script with subscriber-check [Re: Ravelux] #253126 27/05/15 05:16 AM
Joined: Mar 2015
Posts: 19
R
Ravelux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: Mar 2015
Posts: 19
Can no one help me in this case? frown

Re: (Twitch-Bot) raffle script with subscriber-check [Re: Ravelux] #253127 27/05/15 06:30 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Are the names in a long line seperated by spaces? If so, you could do this to store them line by line in a .txt file, or better yet use a hash table http://en.wikichip.org/wiki/mirc/hash_tables
Code:
var %i 1
while ($gettok(%data,%i,32)) {
write subscribers.txt $gettok(%data,%i,32)
inc %i 
}

Last edited by Sakana; 27/05/15 06:32 AM.
Re: (Twitch-Bot) raffle script with subscriber-check [Re: Sakana] #253162 28/05/15 08:33 AM
Joined: Mar 2015
Posts: 19
R
Ravelux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: Mar 2015
Posts: 19
No, the problem is there is no space. Every nickname is placed between
Quote:
{"display_name":
and
Quote:
","_id"
.

Re: (Twitch-Bot) raffle script with subscriber-check [Re: Ravelux] #253164 28/05/15 10:05 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
You could isolate the nicks with this

Code:
var %a = $remove(%nicks,",:,$chr(44),_id,display_name,$chr(123))

Re: (Twitch-Bot) raffle script with subscriber-check [Re: Sakana] #253165 28/05/15 11:17 AM
Joined: Jan 2004
Posts: 1,323
L
Loki12583 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,323
Not if it's 4,000 characters he can't.

Use this JSON parser http://hawkee.com/snippet/10194/

Re: (Twitch-Bot) raffle script with subscriber-check [Re: Loki12583] #253200 30/05/15 11:44 AM
Joined: Mar 2015
Posts: 19
R
Ravelux Offline OP
Pikka bird
OP Offline
Pikka bird
R
Joined: Mar 2015
Posts: 19
So I need to use JSON parser for my problem?