mIRC Homepage
Posted By: Sparkz Saving quotes - 26/08/14 02:09 PM
I want to have a script where a mod in chat can add quotes to. I currently have this (taken from a normal commands script)

on $*:text:/^!addquote !?(\S+)/iS:#:{
if ($nick !isop #) { return }
writeini quotes.ini # $regml(1) $2-
var %text $read(quotes.txt,1)
if %text == $null {
var %line Commands List: ! $+ $regml(1) $+ ,
}
else {
var %line %text ! $+ $regml(1)
}

write -l1 commandsresonse.txt %line
msg # $nick - A new quote has been added to the quotes file.
}

Problem I am having is that I want a mod to be able to put !quote into chat and have the bot auto pick a random quote from the file and put it in chat. If anyone could please help me with this. I have been trying but I can't get it to work.

Thanks!
Posted By: Nillen Re: Saving quotes - 26/08/14 02:43 PM
I have no idea how that works from just looking at it.

I made something real quick for you instead:
Code:
on *:text:!quote*:#: $mid($1-,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)
    }
  }
}
Tested and working. Not tested extensively however.

Syntax is:
!quote add Text of your choice > Adds quote
!quote random > Returns a random quote
!quote (#1|1) > Returns the first quote.
!quote Text of > Returns any matches.
Posted By: Sparkz Re: Saving quotes - 26/08/14 05:38 PM
Thank you so much. Just what I needed.
Posted By: paper0rplastic Re: Saving quotes - 16/09/14 07:05 PM
How would I change this to display "Quote N does not exist" when someone types in a quote number that hasn't been created yet?
Posted By: Nillen Re: Saving quotes - 17/09/14 03:28 AM
Code:
msg # Quote $chr(35) $+ %1 $+ : $readini(quotes.ini,n,#,%1)
You can make an if statement to check if it exists using only this line as your reference.
/help if then else
/help $iif
Posted By: paper0rplastic Re: Saving quotes - 17/09/14 06:33 AM
Got it. Thanks for the help!
Posted By: Blondemoscow Re: Saving quotes - 04/10/14 01:18 AM
I have a question. I'm still learning IRC, and this code is fantastic but I want to change it so I don't have to put in !quote random for a random quote. I would like to have it just be !quote. Problem is I have no idea where to make that change.
Posted By: westor Re: Saving quotes - 04/10/14 03:52 AM
Originally Posted By: Blondemoscow
I have a question. I'm still learning IRC, and this code is fantastic but I want to change it so I don't have to put in !quote random for a random quote. I would like to have it just be !quote. Problem is I have no idea where to make that change.


Try using this code (NOT TESTED):

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) }
  }
}
© mIRC Discussion Forums