mIRC Homepage
Posted By: iFort Autoreply TWITCH - 25/02/14 02:39 PM
Hey guys, I've been working on an autoreply function.
I assume you guys are slightly familiar with twitch atleast.
I have this function for commands:
Code:
on *:TEXT:!cmd*:#: {
  if ($nick isop $chan) {
    if ($left($3,1) == !) {
      if ($2 == add) {
        if (($($+(%,command.,$3),2))) { 
          /msg $chan command already exists. | return
        } 
        else { 
          set -n %command. $+ $3 $4- | /msg $chan Command $3 set to: $4- | return 
        }
      } 
      else if ($2 == remove) {
        if (($($+(%,command.,$3),2))) { 
          unset %command. $+ $3 | /msg $chan Command $3 removed. | return 
        } 
        else { 
          /msg $chan command does not exist. | return
        }
      }
      /msg $chan syntax: !cmd (add/remove) !<cmd> <text to type if add> | return
    }
    /msg $chan syntax: !cmd (add/remove) !<cmd> <text to type if add> | return
  }
}



as you can see I'm using variables and not a File.

well I wanted to do the same with Autoreply, as in
!autoreply add WORD woop woop
when someone says
lol lol word lol lol
it should say woop woop.


THIS WORKS because I'm using a while loop going over every word in the list
Code:
var %i = 1
while (%i <= $0) {
if ((($($+(%,autoreply.,$+($,%i)),2)) { msg $chan %autoreply. [ $+ [ $+($,%i)) ] ] }
INC %i
}


but this seems like WAY too much work. I think there's a better way to do this I just don't know how.

I also want it to work differently.
for example if I type:
!autoreply add *where*cookies* HERE THEY ARE

it should work on any sentence containing where and cookies in order, so multiple words in one sentence.
how can I make it so it recognizes the asterisk? ( as in, as if *where*cookies* was in an On *:text:*where*cookies*:#: )

thanks in advance!
Posted By: Loki12583 Re: Autoreply TWITCH - 25/02/14 03:39 PM
You can do this more easily with hash tables.

Code:
on *:start:{
  hmake autoreply
  hload -i autoreply autoreply.ini autoreply
}

on *:text:!autoreply & *:#:{
  var %method = $2, %match = $3, %reply = $4

  if ($nick !isop #) return

  if ($left(%match,1) != *) %match = * $+ %match
  if ($right(%match,1) != *) %match = %match $+ *

  if (%method == add) {
    if (!$hget(autoreply,%match)) {
      hadd -m autoreply %match %reply
      remini autoreply.ini autoreply
      hsave -i autoreply autoreply.ini autoreply
      msg # Reply added for %match
    }
  }
  elseif (%method == remove) {
    if ($hget(autoreply,%match)) {
      hdel autoreply %match
      remini autoreply.ini autoreply
      hsave -i autoreply autoreply.ini autoreply
      msg # Reply removed for %match
    }
  }
}

on *:text:*:#:{
  noop $hfind(autoreply, $1-, 0, W, msg # $hget(autoreply,$1-))
}
Posted By: iFort Re: Autoreply TWITCH - 25/02/14 09:16 PM
Thanks a lot!

I seem to understand how the code works smile
what does remini do after hadd though?
and also, how does the noop $hfind exactly work?, the (autoreply, $1-,O,W) part
Posted By: Loki12583 Re: Autoreply TWITCH - 25/02/14 10:19 PM
I used remini to remove the section in the ini file prior to saving it. This is because of a "bug" where items no longer present in the hash table are not removed from the ini file when saving. Looking at it again, you can remove the remini line from the "add" section.

You can look up $hfind in the help file, but briefly:
autoreply is the name of the table to search in. $1- is the input to match against, 0 (zero) signifies that it should perform on all matching values in the table (as opposed to the first or second it finds), W indicates that the item in the table is wildcard text. $hget(autoreply,$1-) is used to look up the data associated with that item.
© mIRC Discussion Forums