mIRC Home    About    Download    Register    News    Help

Print Thread
#254586 18/08/15 10:09 AM
Joined: Jul 2015
Posts: 7
I
iJordi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jul 2015
Posts: 7
I am making a twitch bot for a friend and one of the things we would like to have is a quote system. We are both noobs at mIRC, I am able to do some basic commands, but I'm having troubles with reading and changing files. I am currently using the script from here to add and display the quotes.

Code:
ON !*:TEXT:!*:#: {
  tokenize 32 $strip($1-,burci)
  if ($1 == !quote) {
    if (!$2) { quote random }
    elseif ($2) { quote $2- }
  }
}

alias quote {
  if ($1 == add) { 
    if ($nick !isop #) { return }
    var %n $ini(quotes.ini,#,0)
    inc %n 
    writeini quotes.ini # %n $2-
    msg # Quote $chr(35) $+ %n added. Use !quote $chr(35) $+ %n $+ .
  }
  else {
    var %1 $iif($left($1,1) == $chr(35),$mid($1,2-),$1)
    if (%1 !isnum) { 
      if (%1 == random) {
        var %n $ini(quotes.ini,#,0)
        var %rng $rand(1,%n)
        msg # Quote $chr(35) $+ %rng $+ : $readini(quotes.ini,n,#,%rng)
      }
      else { 
        var %n $ini(quotes.ini,#,0)
        var %i 1
        while (%i <= %n) {
          var %read $readini(quotes.ini,n,#,%i)
          if ($1- isin %read) msg # Quote $chr(35) $+ %i $+ : $v2
          inc %i
        }
      }
    }
    elseif (%1 isnum) { msg # Quote $chr(35) $+ %1 $+ : $readini(quotes.ini,n,#,%1) }
  }
}


Now I'm trying to add some code to this to be able to edit/delete quotes by using commands, but I can't seem to figure it out.
So far I have just changed the quotes.ini file manually

Can someone help me to get this done?

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
To remove sections or items from an ini you can use /remini.
It follows the same structure as writeini. Use /help /remini to guide yourself.

What you know from the script is that it will only ever function in an on text event as some of the parameters like $nick and # will only follow assuming it's from that event.
Thus, the first step you need to do is all the quote alias. Now, as the original author I already know that it calls the alias everytime !quote is called. Typing !quote [random text] will call the quote alias with any random text as well, filling $1-.

So, with this knowledge we can script some basic stuff.

If you look at the alias, you can see that we have an if statement asking for if ($1 == add) { }
Considering that this works like !quote add ... you can make something similar like elseif ($1 == rem) { }

Inside these brackets you would have to check for a number or a string. Let's make the simplest one, a number.
Let's assume that the script will use $2 as the number. So it would look like this in the alias; $1 == rem, $2 == nr. and like this in the text event !quote rem nr.
Code:
elseif ($1 == rem) { 
if ($nick !isop #) { return } 
var %2 $remove($2,$chr(35)) 
;Above makes sure to remove any chr(35) which is # from the string.
if (%2 isnum) { 
;%2 is a number, we know that now. Let's remove it
remini quotes.ini # %2
}
else { 
;Here you try to search if %2 is a string that matches something in the file
}
}
Now, this code is not really designed that well. Let's say you have 50 quotes and remove #33. #32,#34,#50 would still be all the same, only #33 would be gone. The next time a quote is added, it would take the number of items in the ini and add +1, which would be 49 + 1 = 50 and overwrite that. Now the workaround would be not to actually use remini but overwrite the #33 instead. Let's say you use
Code:
writeini quotes.ini # %2 DELETED
instead. This would work for the future. But definitely looks bad if someone wants to use that quote, or it's on random.

My recommendation? Use the script you have for reference, make your own version and scratch that one.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Jul 2015
Posts: 7
I
iJordi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jul 2015
Posts: 7
Thanks for the reply and for the explanation, but as I said, I only know some basic mIRC stuff, so I need to bother you with some more questions eek

Considering what you said about the numbering when deleting quotes, I am just gonna make a command for editing existing commands instead of deleting them.

I tried altering the code you posted to be able to do that, but i couldn't figure out how.
Code:
elseif ($1 == edit) {
if ($nick isop #) { return }
var %2 $remove($2,$chr(35)
if (%2 isnum) {
writeini quotes.ini # %2 $3- 


I thought the command could look something like this:
!quote edit 1 updated quote here


I feel like doing something stupid and obviously wrong, but I just can't figure it out :c

What do I need to change to make it work? And where should I put it in the original code I have at the start of this thread?

Joined: Aug 2015
Posts: 16
A
Pikka bird
Offline
Pikka bird
A
Joined: Aug 2015
Posts: 16
Your problem is that $1 would be referring to !quote. You need to be testing $2. So here's your updated code. It should work just fine.


Code:
elseif ($2 == edit) {
if ($nick isop #) { return }
var %2 $remove($2,$chr(35)
if (%2 isnum) {
writeini quotes.ini # %2 $3- 

Last edited by acpixel; 19/08/15 03:18 PM.
Joined: Jul 2015
Posts: 7
I
iJordi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jul 2015
Posts: 7
Thanks for trying to help me smile
So, now I got this, but it still doesn't work. Have I forgotten something or maybe misplaced some code?

Code:
ON !*:TEXT:!*:#: {
  tokenize 32 $strip($1-,burci)
  if ($1 == !quote) {
    if (!$2) { quote random }
    elseif ($2) { quote $2- }
  }
}
alias quote {
  if ($1 == add) { 
    if ($nick isop #) { return }
    var %n $ini(quotes.ini,#,0)
    inc %n 
    writeini quotes.ini # %n $2-
    msg # Quote $chr(35) $+ %n added. Use !quote $chr(35) $+ %n $+ .
  }
  elseif ($1 == edit) {
    if ($nick isop #) { return }
    var %2 $remove($2,$chr(35)
    if (%2 isnum) {
      writeini quotes.ini # %2 $3-  
      msg # Quote $chr(35) %2 updated.
    }
    else {
      if (!%comwait) {
       set -u60 %comwait 1
       var %1 $iif($left($1,1) == $chr(35),$mid($1,2-),$1)
       if (%1 !isnum) { 
        if (%1 == random) {
          var %n $ini(quotes.ini,#,0)
          var %rng $rand(1,%n)
          msg # $chr(35) $+ %rng $+ : $readini(quotes.ini,n,#,%rng)
        }
        else { 
          var %n $ini(quotes.ini,#,0)
          var %i 1
          while (%i <= %n) {
            var %read $readini(quotes.ini,n,#,%i)
            if ($1- isin %read) msg # $chr(35) $+ %i $+ : $v2
            inc %i
          }
        }
      }
      elseif (%1 isnum) { msg # $chr(35) $+ %1 $+ : $readini(quotes.ini,n,#,%1) }
    }
  }


Last edited by iJordi; 19/08/15 05:42 PM. Reason: Typo
Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
@acpixel $1 is correct, this is an alias and not an on text event. The things passed from the text event to the alias will be parsed as $1-. Since we're passing from $2- to the alias, $1- will be the same as $2- in the text event. It's important to know the difference.

The script is broken cause of 3 reasons.
1. You're checking if user is an op, if so return. You want to check if user is NOT an op. !isop.
2. You didn't close your bracket on the $remove
3. You didn't close your squiggly bracket on the elseif.

Fix these and it should be fine.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Jul 2015
Posts: 7
I
iJordi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jul 2015
Posts: 7
Thank you so much for the help smile
The script is working now.

Last edited by iJordi; 20/08/15 03:04 PM.
Joined: Jul 2015
Posts: 7
I
iJordi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jul 2015
Posts: 7
Just one last question...
If I want to add a cooldown on the commands for displaying the quotes, how should I code that in?

This is the code I have now
Code:
ON !*:TEXT:!*:#: {
  tokenize 32 $strip($1-,burci)
  if ($1 == !quote) {
    if (!$2) { quote random }
    elseif ($2) { quote $2- }
  }
}
alias quote {
  if ($1 == add) { 
    if ($nick !isop #) { return }
    var %n $ini(quotes.ini,#,0)
    inc %n 
    writeini quotes.ini # %n $2-
    msg # Quote $chr(35) $+ %n added. Use !quote $chr(35) $+ %n $+ .
  }
  elseif ($1 == edit) {
    if ($nick !isop #) { return }
    var %2 $remove($2,$chr(35))
    if (%2 isnum) {
      writeini quotes.ini # %2 $3-  
      msg # Quote $chr(35) %2 updated.
    }
  }
  else {   
    var %1 $iif($left($1,1) == $chr(35),$mid($1,2-),$1)
    if (%1 !isnum) { 
      if (%1 == random) {
        var %n $ini(quotes.ini,#,0)
        var %rng $rand(1,%n)
        msg # $chr(35) $+ %rng $+ : $readini(quotes.ini,n,#,%rng)
      }
      else { 
        var %n $ini(quotes.ini,#,0)
        var %i 1
        while (%i <= %n) {
          var %read $readini(quotes.ini,n,#,%i)
          if ($1- isin %read) 
        }
      }
    }
    elseif (%1 isnum) { msg # $chr(35) $+ %1 $+ : $readini(quotes.ini,n,#,%1) }
  }
}


I tried putting this piece of code
Code:
if (!%comwait) {
    set -u6 %comwait 1

}

on different places in the code, but everytime it just broke the whole script.
Where should I place it? Is it even the right code to use?

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Code:
  else {   
if (%comwait) return
else set -u6 %comwait 1
    var %1 $remove($1,$chr(35))
    if (%1 !isnum) { 
      if (%1 == random) {
        var %n $ini(quotes.ini,#,0)
        var %rng $rand(1,%n)
        msg # $chr(35) $+ %rng $+ : $readini(quotes.ini,n,#,%rng)
      }
      else { 
        var %n $ini(quotes.ini,#,0)
        var %i 1
        while (%i <= %n) {
          var %read $readini(quotes.ini,n,#,%i)
          if ($1- isin %read) 
        }
      }
    }
    elseif (%1 isnum) { msg # $chr(35) $+ %1 $+ : $readini(quotes.ini,n,#,%1) }
  }
The code in that else condition is where it will message a channel. Whether it be specified number, specified string or random. So you'd put it right before that.

Edit: I can tell you made some changes that can break the code when checking for strings in the text. At the end of the code you have a while loop that no longer gets incremented.
Code:
        while (%i <= %n) {
          var %read $readini(quotes.ini,n,#,%i)
          if ($1- isin %read) 
        }
You might wanna fix that with the earlier code.

Last edited by Nillen; 20/08/15 09:22 PM.

Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Jul 2015
Posts: 7
I
iJordi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jul 2015
Posts: 7
I fixed that last part.
But I can't get the cooldwon to work
When I delete this part of the code
Code:
if (%comwait) return
else set -u6 %comwait 1

everything works fine, but when it's in the script all the code after it just doesn't work.


Code:
ON !*:TEXT:!*:#: {
  tokenize 32 $strip($1-,burci)
  if ($1 == !quote) {
    if (!$2) { quote random }
    elseif ($2) { quote $2- }
  }
}
alias quote {
  if ($1 == add) { 
    if ($nick !isop #) { return }
    var %n $ini(quotes.ini,#,0)
    inc %n 
    writeini quotes.ini # %n $2-
    msg # Quote $chr(35) $+ %n added. Use !quote $chr(35) $+ %n $+ .
  }
  elseif ($1 == edit) {
    if ($nick !isop #) { return }
    var %2 $remove($2,$chr(35))
    if (%2 isnum) {
      writeini quotes.ini # %2 $3-  
      msg # Quote $chr(35) %2 updated.
    }
  }
  else {   
    if (%comwait) { return }
    else {
      set -u6 %comwait 1
      var %1 $remove($1,$chr(35))
      if (%1 !isnum) { 
        if (%1 == random) {
          var %n $ini(quotes.ini,#,0)
          var %rng $rand(1,%n)
          msg # $chr(35) $+ %rng $+ : $readini(quotes.ini,n,#,%rng)
        }
        else { 
          if ($nick !isop #) { return } 
          var %n $ini(quotes.ini,#,0)
          var %i 1
          while (%i <= %n) {
            var %read $readini(quotes.ini,n,#,%i)
            if ($1- isin %read) msg # $chr(35) $+ %i $+ : $v2
            inc %i
          }
        }
      }
      elseif (%1 isnum) { msg # $chr(35) $+ %1 $+ : $readini(quotes.ini,n,#,%1) }
    }
  }
}


Did I miss something?

Joined: Jul 2015
Posts: 7
I
iJordi Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
I
Joined: Jul 2015
Posts: 7
Fixed the script laugh

Thanks you so much for the help


Link Copied to Clipboard