mIRC Home    About    Download    Register    News    Help

Print Thread
Saving quotes #247785 26/08/14 02:09 PM
Joined: Aug 2014
Posts: 32
S
Sparkz Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Aug 2014
Posts: 32
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!

Re: Saving quotes [Re: Sparkz] #247786 26/08/14 02:43 PM
Joined: Dec 2013
Posts: 779
N
Nillen Offline
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
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.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Re: Saving quotes [Re: Nillen] #247793 26/08/14 05:38 PM
Joined: Aug 2014
Posts: 32
S
Sparkz Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Aug 2014
Posts: 32
Thank you so much. Just what I needed.

Re: Saving quotes [Re: Nillen] #248021 16/09/14 07:05 PM
Joined: Sep 2014
Posts: 52
paper0rplastic Offline
Babel fish
Offline
Babel fish
Joined: Sep 2014
Posts: 52
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?

Re: Saving quotes [Re: paper0rplastic] #248031 17/09/14 03:28 AM
Joined: Dec 2013
Posts: 779
N
Nillen Offline
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
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


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Re: Saving quotes [Re: Nillen] #248033 17/09/14 06:33 AM
Joined: Sep 2014
Posts: 52
paper0rplastic Offline
Babel fish
Offline
Babel fish
Joined: Sep 2014
Posts: 52
Got it. Thanks for the help!

Re: Saving quotes [Re: Nillen] #248331 04/10/14 01:18 AM
Joined: Oct 2014
Posts: 13
B
Blondemoscow Offline
Pikka bird
Offline
Pikka bird
B
Joined: Oct 2014
Posts: 13
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.

Re: Saving quotes [Re: Blondemoscow] #248335 04/10/14 03:52 AM
Joined: Dec 2008
Posts: 1,511
westor Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
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) }
  }
}