Mirc top points command

By Trahanqc on Jan 21, 2015

Hi guys, I'm using a points system for my twitch channel and I wanted to create a command that can show viewers who have the most points. So I created a command called !toppoints and it's working fine. However, I really really don't like how I coded it and I would like to know how I can improve the code so I can specify a number to the command. Ex: !toppoints 5 (Will display the 5 viewers who have the most points)

Goals:

  • Cleanup the code
  • Add a number parameter so the code can be more flexible

Thanks for any of your help! :)

; Display the 5 users with the most points
on *:text:!toppoints*:#: {
  if ($0 == 1) {
    var %j = 1
    var %channelLength = $calc($calc($len(#) + 1) * -1)
    var %max5 = 0
    var %max4 = 0
    var %max3 = 0
    var %max2 = 0
    var %max1 = 0
    var %name5 = Unknown
    var %name4 = Unknown
    var %name3 = Unknown
    var %name2 = Unknown
    var %name1 = Unknown
    var %done = 0

    while (%j <= $ini(Points.ini,0)) {
      var %section $ini(Points.ini,%j)
      var %points = $readini(Points.ini,%section,Points)
      var %fullname = $right(%section, %channelLength)

      ; I don't want to see these name
      if ($count(%fullname, nightbot) == 0 && $count(%fullname, xanbot) == 0 && $count(%fullname, twitchranks) == 0 && $count(%fullname, moobot) == 0) {
        if (%points > %max5) { 
          %max1 = %max2
          %max2 = %max3
          %max3 = %max4
          %max4 = %max5
          %max5 = %points

          %name1 = %name2
          %name2 = %name3
          %name3 = %name4
          %name4 = %name5
          %name5 = %fullname

          %done = 1
        }

        if (%points > %max4 && %done == 0) {
          %max1 = %max2
          %max2 = %max3
          %max3 = %max4
          %max4 = %points

          %name1 = %name2
          %name2 = %name3
          %name3 = %name4
          %name4 = %fullname

          %done = 1
        }

        if (%points > %max3 && %done == 0) {
          %max1 = %max2
          %max2 = %max3
          %max3 = %points

          %name1 = %name2
          %name2 = %name3
          %name3 = %fullname

          %done = 1
        }

        if (%points > %max2 && %done == 0) {
          %max1 = %max2
          %max2 = %points

          %name1 = %name2
          %name2 = %fullname

          %done = 1
        }

        if (%points > %max1 && %done == 0) {      
          %max1 = %points

          %name1 = %fullname
        }
      }

      %done = 0
      inc %j
    }

    msg $chan Top 5 points : 1. %name5 %max5 pts 2. %name4 %max4 pts 3. %name3 %max3 pts 4. %name2 %max2 pts 5. %name1 %max1 pts

  }
  else {
    msg $chan Wrong parameters. Use !toppoints
  }
}

Comments

Sign in to comment.
Trahanqc   -  Jan 21, 2015

Here's the output this code generates (5 differents viewers)

Top 5 points : 1. trahanqc 13456 pts 2. trahanqc2 13044 pts 3. trahanqc3 3199 pts 4. trahanqc4 3132 pts 5. trahanqc5 1926 pts

Trahanqc  -  Jan 23, 2015

I found a way to do it. Code is available here : https://github.com/Trahanqc/TwitchBot/blob/master/toppoints.ini

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.