mIRC Home    About    Download    Register    News    Help

Print Thread
#249743 13/12/14 05:53 PM
Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
I've been working on getting my chatbot to recognize colored text with its commands, but as of yet, I haven't worked out how to do so.

Probably the most basic command I have, !time, is listed here as an example:

Code:
on 1:text:*time:#: { .msg $chan 5It is $time EST right now. }


It works perfectly fine with anyone who doesn't have colored text, of course, but if it sees the colored text character before the !, it won't respond. Any suggestions on what I could change to get it working would be appreciated.

Joined: Jul 2006
Posts: 4,151
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,151
You must strip the color before matching using $strip:

Code:
on *:text:*:#:{
  if ($strip($1) == !time) {

  }
}

Last edited by Wims; 13/12/14 06:06 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Gotcha, thanks much! smile

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
...I don't gotcha, apparently. Exactly where and how do I use this? As mentioned, !time is the most basic command I have, it is far from the /only/ command I have. The bot has somewhere in the range of 100 different !command words.

Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Code:
on *:text:*:#: {
  if ($strip($1) == !word1) { do stuff }
  if ($strip($1) == !word2) { do stuff }
  if ($strip($1) == !word3) { do stuff }
  if ($strip($1) == !word4) { do stuff }
}

Last edited by Belhifet; 13/12/14 07:25 PM.
Joined: Aug 2014
Posts: 42
K
Ameglian cow
Offline
Ameglian cow
K
Joined: Aug 2014
Posts: 42
Originally Posted By: Belhifet
Code:
on *:text:*:#: {
  if ($strip($1) == !word1) { do stuff }
  if ($strip($1) == !word2) { do stuff }
  if ($strip($1) == !word3) { do stuff }
  if ($strip($1) == !word4) { do stuff }
}


That is pretty, how can i put in a flood control (different for each !command) in that script?

Joined: Nov 2014
Posts: 149
J
Vogon poet
Offline
Vogon poet
J
Joined: Nov 2014
Posts: 149
Originally Posted By: Krawalli

That is pretty, how can i put in a flood control (different for each !command) in that script?

The same flood control for all commands

Code:
on *:text:*:#: {
  if ($strip($1) == !word1) || ($strip($1) == !word2) || ($strip($1) == !word3) || ($strip($1) == !word4) {
    if ($timer(AntiFlood [ $+ [ $nick ] ]) == $null) { set %lessnums [ $+ [ $nick ] ] 10 | .timerAntiFlood [ $+ [ $nick ] ] 10 1 dec %lessnums [ $+ [ $nick ] ] }
    else { msg # $nick Command is ready to use in %lessnums [ $+ [ $nick ] ] seconds | return }
  }
  if (%lessnums [ $+ [ $nick ] ] != 0) {
    if ($strip($1) == !word1) { do stuff }
    if ($strip($1) == !word2) { do stuff }
    if ($strip($1) == !word3) { do stuff }
    if ($strip($1) == !word4) { do stuff }
  }
}


Time antiflood is set in 10 seconds, to change this, you must modify the numbers in red color.
Quote:
if ($timer(AntiFlood [ $+ [ $nick ] ]) == $null) { set %lessnums [ $+ [ $nick ] ] 10 | .timerAntiFlood [ $+ [ $nick ] ] 10 1 dec %lessnums [ $+ [ $nick ] ]


Flood control (different time for each !command), occurred to me quickly this code, which could be shortened in less lines.
Code:
on *:text:*:#: {
  if ($strip($1) == !word1) { 
    if ($timer(AntiFlood1 [ $+ [ $nick ] ]) == $null) { set %lessnums1 [ $+ [ $nick ] ] 10 | .timerAntiFlood1 [ $+ [ $nick ] ] 10 1 dec %lessnums1 [ $+ [ $nick ] ] }
    else { msg # $nick Command $qt(!word1) is ready to use in %lessnums1 [ $+ [ $nick ] ] seconds | return }
  }    

  if ($strip($1) == !word2) { 
    if ($timer(AntiFlood2 [ $+ [ $nick ] ]) == $null) { set %lessnums2 [ $+ [ $nick ] ] 20 | .timerAntiFlood2 [ $+ [ $nick ] ] 20 1 dec %lessnums2 [ $+ [ $nick ] ] }
    else { msg # $nick Command $qt(!word2) is ready to use in %lessnums2 [ $+ [ $nick ] ] seconds | return }
  }    

  if ($strip($1) == !word3) { 
    if ($timer(AntiFlood3 [ $+ [ $nick ] ]) == $null) { set %lessnums3 [ $+ [ $nick ] ] 30 | .timerAntiFlood3 [ $+ [ $nick ] ] 30 1 dec %lessnums3 [ $+ [ $nick ] ] }
    else { msg # $nick Command $qt(!word3) is ready to use in %lessnums3 [ $+ [ $nick ] ] seconds | return }
  }    

  if ($strip($1) == !word4) { 
    if ($timer(AntiFlood4 [ $+ [ $nick ] ]) == $null) { set %lessnums4 [ $+ [ $nick ] ] 40 | .timerAntiFlood4 [ $+ [ $nick ] ] 40 1 dec %lessnums4 [ $+ [ $nick ] ] }
    else { msg # $nick Command $qt(!word4) is ready to use in %lessnums4 [ $+ [ $nick ] ] seconds | return }
  }    

  if (%lessnums1 [ $+ [ $nick ] ] != 0) {
    if ($strip($1) == !word1) { do stuff }
  }
  if (%lessnums2 [ $+ [ $nick ] ] != 0) {
    if ($strip($1) == !word2) { do stuff }
  }  
  if (%lessnums3 [ $+ [ $nick ] ] != 0) {

    if ($strip($1) == !word3) { do stuff }
  }
  if (%lessnums4 [ $+ [ $nick ] ] != 0) {

    if ($strip($1) == !word4) { do stuff }
  }
}


Time antiflood is set in 10,20,30 and 40 seconds for each different command, to change this, you must modify this numbers in two places timers and variables, corresponding to each command.



Last edited by JuanAm; 14/12/14 09:51 AM.
Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Ok so, This isn't finished...and I'm sure there are coding mistakes cause I wrote it. But I was thinking about what would be a good way to do hundreds of responses. If for some reason you wanted to.

Code:
on *:text:!*:#: {
  if ($hfind($+(responses.,$chan), $1)) { 
    var %chan $chan
    messages $1 $hfind($+(responses.,$chan), $1) 
  }
}
on *:join:#: {
  if ($nick == $me) {
    hmake $+(responses.,$chan)
    hload $+(responses.,$chan) responses.ini
    .timer.messagequeue 0 1 messages2 $chan
  }
}
;example response !command cooldown .msg %chan message
alias messages {
  if (!$hget($+(messages.,%chan))) { hmake $+(messages.,%chan) }
  if ($3 == msg || $3 == .msg) {
    if ($($+(%,sentmessage.,%chan,$1),2) > 0) {          
      if ($hfind($+(messages.,%chan), $1)) { return failresponse $1 }
      else { 
        hadd $+(messages.,%chan) $3- 
        set $+(%,cooldowns.,%chan) $addtok($+(%,cooldowns.,%chan), $1, 32)
      }
    }
    else { 
      .msg $2- 
      inc $sentmessage. $+ %chan $+ $1 $2
    }
  }
}
alias messagesqueue {
  if ($hget($+(messages.,$1), 0) > 0) {
    var %t $numtok($+(%,cooldowns.,$1), 32)
    var %i 1
    while (%i < %t) {
      if ($($+(%,sentmessage.,$1,$gettok($+(%,cooldowns.,$1),%i,32)),2) > 0) {
        dec $sentmessage. $+ $2 $+ $gettok($+(%,cooldowns.,$1),%i,32)
      }
      else {
        var %chan $1
        tokenize $hget($+(messages.,$1), 1)
        .msg $4- 
        set $+(%,cooldowns.,%chan) $deltok($+(%,cooldowns.,%chan),%i,32)
        return
      }
    }
  }
}


So my idea was just make an ini and format it like
!command1 cooldown msg %chan message
and now that I think about it it seems like you could go back and cut out a chunk of that and simply
!command1 cooldown message

But I wrote the above snippet with the first format in mind. I think what I wrote would work right up until the failed response part..thats where I got bored. I might work on this some more later but I thought I'd post it just as an idea. Its also possible this is a dumb idea smile

Last edited by Belhifet; 14/12/14 04:49 PM.
Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
okdokie finished it up..I think
Code:
on *:text:!*:#: {
  if ($hfind($+(responses.,$chan), $1)) { 
    var %chan $chan
    messages $1 $hfind($+(responses.,$chan), $1) 
  }
}
on *:join:#: {
  if ($nick == $me) {
    .timer.messagequeue 0 1 messages2 $chan
    if (!$hget($+(responses.,$chan))) { hmake $+(responses.,$chan) }
    hload -i $+(responses.,$chan) responses.ini
  }
}
;example response !command cooldown message
alias messages {
  if (!$hget($+(messages.,%chan))) { hmake $+(messages.,%chan) }
  if ($($+(%,sentmessage.,%chan,$1),2) > 0) {          
    if ($hfind($+(messages.,%chan), $1)) { return failresponse $1 %chan }
    else { 
      hadd $+(messages.,%chan) $3- 
      set $+(%,cooldowns.,%chan) $addtok($+(%,cooldowns.,%chan), $1, 32)
    }
  }
  else { 
    .msg %chan $3- 
    inc %sentmessage. $+ %chan $+ $1 $2

  }
}
alias messagesqueue {
  if ($hget($+(messages.,$1), 0) > 0) {
    var %t $numtok($+(%,cooldowns.,$1), 32)
    var %i 1
    while (%i < %t) {
      if ($($+(%,sentmessage.,$1,$gettok($+(%,cooldowns.,$1),%i,32)),2) > 0) {
        dec %sentmessage. $+ $1 $+ $gettok($+(%,cooldowns.,$1),%i,32)
      }
      else {
        var %chan $1
        tokenize $hget($+(messages.,$1), 1)
        .msg $4- 
        set $+(%,cooldowns.,%chan) $deltok($+(%,cooldowns.,%chan),%i,32)
        hdel $+(messages.,%chan) $hget($+(messages.,%chan), %i).item
        return
      }
    }
  }
}
;example failresponse from responses ini fail !cooldown message
alias failresponse {
  var %chan $2,%r = $1,%t = $hfind($+(responses.,%chan),fail,0),var %i = 1
  while (%i > %t) {
    tokenize $hfind($+(responses.,%chan),fail,%i)
    if ($1 == %r) { .msg %chan $2- }
    else { inc % i }
  }
}


So the ini file would look like

Code:
!command1 cooldown message
fail !command1 message
!command2 cooldown message
fail !command2 message
!command3 cooldown message
fail !command3 message
!command4 cooldown message
fail !command4 message


I didn't test anything, and I think I completely missed the point of the original question..and the question that came up after that. Basically I'm saying this post is probably worthless. Enjoy!

Edit..ok so not the first edit, I actually tested this..and even the hash table doesnt load up the way I thought it would. This will take some time to get right..MMMybad.


Ok rather than keep reposting I'll just post the slowmotion fixes..It now will work once, but the part that deals with failed messages and the time until next message doesnt work smile

Code:
on *:text:!*:#: {
  if ($hfind($+(responses.,$chan), $1)) { 
    set %chan $chan
    messages $1 $hget($+(responses.,$chan), $1) 
  }
}
on *:join:#: {
  if ($nick == $me) {
    .timer.messagequeue. $+ $chan 0 1 messagesqueue $chan
    if (!$hget($+(responses.,$chan))) { hmake $+(responses.,$chan) }
    hload -i $+(responses.,$chan) responses.ini
  }
}
;example response !command cooldown message
alias messages {
echo chan %chan 
  if (!$hget($+(messages.,%chan))) { hmake $+(messages.,%chan) }
  if ($($+(%,sentmessage.,%chan,$1),2) > 0) {          
    if ($hfind($+(messages.,%chan), $1)) {
    echo 1 $1 chan %chan  
    failresponse $1 %chan 
    return 
    }
    else { 
      hadd $+(messages.,%chan) $3- 
      set $addtok($+(%,cooldowns.,%chan), $1, 32)
    }
  }
  else { 
    .msg %chan $3- 
    inc %sentmessage. $+ %chan $+ $1 $2

  }
}
alias messagesqueue {
  if ($hget($+(messages.,$1), 0) > 0) {
    var %t $numtok($+(%,cooldowns.,$1), 32)
    var %i 1
    while (%i < %t) {
      if ($($+(%,sentmessage.,$1,$gettok($($+(%,cooldowns.,$1),2),%i,32)),2) > 0) {
        dec %sentmessage. $+ $1 $+ $gettok($+(%,cooldowns.,$1),%i,32)
      }
      else {
        var %chan $1
        tokenize $hget($+(messages.,$1), 1)
        .msg $4- 
        set $+(%,cooldowns.,%chan) $deltok($+(%,cooldowns.,%chan),%i,32)
        hdel $+(messages.,%chan) $hget($+(messages.,%chan), %i).item
        return
      }
    }
  }
}
;example failresponse from responses ini fail !cooldown message
alias failresponse {
  var %chan $2,%r = $1,%t = $hfind($+(responses.,%chan),fail,0),var %i = 1
  while (%i > %t) {
    tokenize $hget($+(responses.,%chan),fail,%i)
    if ($1 == %r) { .msg %chan $2- }
    else { inc % i }
  }
}

Last edited by Belhifet; 14/12/14 08:23 PM.

Link Copied to Clipboard