mIRC Home    About    Download    Register    News    Help

Topic Options
#254586 - 18/08/15 11:09 AM [Twitch] Edit/delete quotes
iJordi Offline
Nutrimatic drinks dispenser

Registered: 09/07/15
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?

Top
#254587 - 18/08/15 12:43 PM Re: [Twitch] Edit/delete quotes [Re: iJordi]
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
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

Top
#254602 - 19/08/15 02:06 PM Re: [Twitch] Edit/delete quotes [Re: Nillen]
iJordi Offline
Nutrimatic drinks dispenser

Registered: 09/07/15
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?

Top
#254607 - 19/08/15 04:16 PM Re: [Twitch] Edit/delete quotes [Re: iJordi]
acpixel Offline
Pikka bird

Registered: 19/08/15
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- 


Edited by acpixel (19/08/15 04:18 PM)

Top
#254617 - 19/08/15 06:38 PM Re: [Twitch] Edit/delete quotes [Re: acpixel]
iJordi Offline
Nutrimatic drinks dispenser

Registered: 09/07/15
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) }
    }
  }



Edited by iJordi (19/08/15 06:42 PM)
Edit Reason: Typo

Top
#254621 - 19/08/15 09:03 PM Re: [Twitch] Edit/delete quotes [Re: iJordi]
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
@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

Top
#254630 - 20/08/15 04:04 PM Re: [Twitch] Edit/delete quotes [Re: Nillen]
iJordi Offline
Nutrimatic drinks dispenser

Registered: 09/07/15
Posts: 7
Thank you so much for the help smile
The script is working now.


Edited by iJordi (20/08/15 04:04 PM)

Top
#254633 - 20/08/15 09:59 PM Re: [Twitch] Edit/delete quotes [Re: Nillen]
iJordi Offline
Nutrimatic drinks dispenser

Registered: 09/07/15
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?

Top
#254634 - 20/08/15 10:20 PM Re: [Twitch] Edit/delete quotes [Re: iJordi]
Nillen Offline
Hoopy frood

Registered: 24/12/13
Posts: 779
Loc: Sweden
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.


Edited by Nillen (20/08/15 10:22 PM)
_________________________
Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Top
#254640 - 21/08/15 11:30 AM Re: [Twitch] Edit/delete quotes [Re: Nillen]
iJordi Offline
Nutrimatic drinks dispenser

Registered: 09/07/15
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?

Top
#254656 - 22/08/15 12:56 PM Re: [Twitch] Edit/delete quotes [Re: iJordi]
iJordi Offline
Nutrimatic drinks dispenser

Registered: 09/07/15
Posts: 7
Fixed the script laugh

Thanks you so much for the help

Top