mIRC Home    About    Download    Register    News    Help

Print Thread
#257285 27/03/16 07:07 AM
Joined: Mar 2016
Posts: 3
G
Self-satisified door
OP Offline
Self-satisified door
G
Joined: Mar 2016
Posts: 3
Okay, so i'm writing a relatively simple bot for my Twitch channel. Here is my code.

Code:
on *:text:!addcom *:#: {
  if ($nick == grandstaryoshi) {
    var %r = $read(commands.txt,ns,$2)
    if (%r) { .msg $chan /me Error! The command $qt($2) already exists in the database! | return }
    write commands.txt $2-
    msg $chan /me Command $2 has been added to the database!
  }
}

on *:text:!delcom *:#: {
  if ($nick == grandstaryoshi) {
    var %r = $read(commands.txt,ns,$2)
    if (!%r) { .msg $chan /me Error! The command $qt($2) does not exist in the database! | return }
    write -dl $+ $readn commands.txt
    msg $chan /me Command $2- has been deleted from the database!
  }
}

on *:text:!editcom & *:#: {
  if ($nick == grandstaryoshi) {
    var %r = $read(commands.txt,ns,$2)
    if (!%r) { .msg $chan /me Error! The command $qt($2) does not exist in the database! | return }
    write -l $+ $readn commands.txt $2-
    msg $chan /me Command $2 has been updated!
  }
}

on *:text:!addquote *:#: {
  if ($nick == grandstaryoshi) {
    var %r = $read(quotes.txt,ns,$2)
    if (%r) { .msg $chan /me Error! Quote $qt($2) already exists in the database! | return }
    write quotes.txt $2-
    msg $chan /me Quote $2 has been added to the database!
  }
}

on *:text:!delquote *:#: {
  if ($nick == grandstaryoshi) {
    var %r = $read(quotes.txt,ns,$2)
    if (!%r) { .msg $chan /me Error! Quote $qt($2) does not exist in the database! | return }
    write -dl $+ $readn quotes.txt
    msg $chan /me Quote $2- has been deleted from the database!
  }
}

on *:TEXT:*:#: {
  tokenize 32 $strip($1-,burci)
  if ($read(commands.txt, nts, $1)) {
    var %com = $v1
    var %com = $replace(%com,@user@,$iif($2,$2,?),@nick@,$nick,@target@,$target)
    if (-ul=mod == $gettok(%com,1,32)) && (!$mod($nick)) { halt }
    if (-ul=reg == $gettok(%com,1,32)) && (!$mod($nick)) && (!$regular($nick)) { halt }
    if (-ul=own == $gettok(%com,1,32)) && ($nick != %owner) { halt }
    if ($($+(%,flood,$1),2)) || ($($+(%,flood,$1,.,$nick),2)) { return }
    set -u5 $+(%,flood,$1) On
    set -u5 $+(%,flood,$1,.,$nick)
    if ($2 ison #) {
      msg $chan $2 $+ : $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
    else {
      msg $chan $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
  }
  elseif ($read(quotes.txt, nts, $1)) {
    var %com = $v1
    var %com = $replace(%com,@user@,$iif($2,$2,?),@nick@,$nick,@target@,$target)
    if (-ul=mod == $gettok(%com,1,32)) && (!$mod($nick)) { halt }
    if (-ul=reg == $gettok(%com,1,32)) && (!$mod($nick)) && (!$regular($nick)) { halt }
    if (-ul=own == $gettok(%com,1,32)) && ($nick != %owner) { halt }
    if ($($+(%,flood,$1),2)) || ($($+(%,flood,$1,.,$nick),2)) { return }
    set -u5 $+(%,flood,$1) On
    set -u5 $+(%,flood,$1,.,$nick)
    if ($2 ison #) {
      msg $chan $2 $+ : $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
    else {
      msg $chan $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
  }
}


At the moment, everything works. I can add/edit/delete commands, add/delete quotes, and call commands and quotes from text documents. The only issue i have is, since I number quotes, I can only call the quotes by typing the number in chat. For example, if I wanted to call quote 72, I would just type "72" in chat. I'd like to change this so that I can call quotes by typing !quote beforehand, for example "!quote 72". The specific part of the code that calls the quotes is this elseif statement:

Code:
  elseif ($read(quotes.txt, nts, $1)) {
    var %com = $v1
    var %com = $replace(%com,@user@,$iif($2,$2,?),@nick@,$nick,@target@,$target)
    if (-ul=mod == $gettok(%com,1,32)) && (!$mod($nick)) { halt }
    if (-ul=reg == $gettok(%com,1,32)) && (!$mod($nick)) && (!$regular($nick)) { halt }
    if (-ul=own == $gettok(%com,1,32)) && ($nick != %owner) { halt }
    if ($($+(%,flood,$1),2)) || ($($+(%,flood,$1,.,$nick),2)) { return }
    set -u5 $+(%,flood,$1) On
    set -u5 $+(%,flood,$1,.,$nick)
    if ($2 ison #) {
      msg $chan $2 $+ : $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
    else {
      msg $chan $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
  }


My question is simple. What would I have to add to that elseif statement in order to be able to call quotes by typing !quote before the number, rather than just the number? Any help is appreciated. Thanks!

Joined: Mar 2016
Posts: 3
G
Self-satisified door
OP Offline
Self-satisified door
G
Joined: Mar 2016
Posts: 3
Made small headway in realising that when I copied the block of code that deals with commands to have it deal with quotes separately, I could have just changed $1 to $2 to have it read the second word rather than the first when looking for quotes, which I've since done. However, I'm still having an issue making it such that it only activates when the first word in the command is !quote.

Joined: Mar 2016
Posts: 3
G
Self-satisified door
OP Offline
Self-satisified door
G
Joined: Mar 2016
Posts: 3
Did it, realised how stupid I was for not realising. Tired while coding don't mix. Finished code:

Code:
on *:text:!addcom *:#: {
  if ($nick == grandstaryoshi) {
    var %r = $read(commands.txt,ns,$2)
    if (%r) { .msg $chan /me Error! The command $qt($2) already exists in the database! | return }
    write commands.txt $2-
    msg $chan /me Command $2 has been added to the database!
  }
}

on *:text:!delcom *:#: {
  if ($nick == grandstaryoshi) {
    var %r = $read(commands.txt,ns,$2)
    if (!%r) { .msg $chan /me Error! The command $qt($2) does not exist in the database! | return }
    write -dl $+ $readn commands.txt
    msg $chan /me Command $2- has been deleted from the database!
  }
}

on *:text:!editcom & *:#: {
  if ($nick == grandstaryoshi) {
    var %r = $read(commands.txt,ns,$2)
    if (!%r) { .msg $chan /me Error! The command $qt($2) does not exist in the database! | return }
    write -l $+ $readn commands.txt $2-
    msg $chan /me Command $2 has been updated!
  }
}

on *:text:!addquote *:#: {
  var %r = $read(addquotes.txt,ns,$2)
  if (%r) { .msg $chan /me Error! Quote $qt($2) already exists in the database! | return }
  write addquotes.txt $2-
  msg $chan /me Quote processed and will be reviewed before being added to the database!
}

on *:text:!delquote *:#: {
  if ($nick == grandstaryoshi) {
    var %r = $read(quotes.txt,ns,$2)
    if (!%r) { .msg $chan /me Error! Quote $qt($2) does not exist in the database! | return }
    write -dl $+ $readn quotes.txt
    msg $chan /me Quote deleted from the database!
  }
}

on *:TEXT:*:#: {
  tokenize 32 $strip($1-,burci)
  if ($read(commands.txt, nts, $1)) {
    var %com = $v1
    var %com = $replace(%com,@user@,$iif($2,$2,?),@nick@,$nick,@target@,$target)
    if (-ul=mod == $gettok(%com,1,32)) && (!$mod($nick)) { halt }
    if (-ul=reg == $gettok(%com,1,32)) && (!$mod($nick)) && (!$regular($nick)) { halt }
    if (-ul=own == $gettok(%com,1,32)) && ($nick != %owner) { halt }
    if ($($+(%,flood,$1),2)) || ($($+(%,flood,$1,.,$nick),2)) { return }
    set -u5 $+(%,flood,$1) On
    set -u20 $+(%,flood,$1,.,$nick)
    if ($2 ison #) {
      msg $chan $2 $+ : $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
    else {
      msg $chan $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
  }
  elseif ($1 = !quote) && ($read(quotes.txt, nts, $2)) {
    var %com = $v1
    var %com = $replace(%com,@user@,$iif($2,$2,?),@nick@,$nick,@target@,$target)
    if (-ul=mod == $gettok(%com,1,32)) && (!$mod($nick)) { halt }
    if (-ul=reg == $gettok(%com,1,32)) && (!$mod($nick)) && (!$regular($nick)) { halt }
    if (-ul=own == $gettok(%com,1,32)) && ($nick != %owner) { halt }
    if ($($+(%,flood,$2),2)) || ($($+(%,flood,$2,.,$nick),2)) { return }
    set -u5 $+(%,flood,$2) On
    set -u5 $+(%,flood,$2,.,$nick)
    if ($2 ison #) {
      msg $chan $2 $+ : $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
    else {
      msg $chan $iif(-ul=mod == $gettok(%com,1,32) || -ul=reg == $gettok(%com,1,32) || -ul=own == $gettok(%com,1,32),$gettok(%com,2-,32),$gettok(%com,1-,32))
    }
  }
}

Last edited by GrandStarYoshi; 27/03/16 06:08 PM.

Link Copied to Clipboard