mIRC Homepage
Posted By: GamingTom Command to add on text commands. - 26/06/13 01:34 PM
I'm needing some help with a script I'm working on. What I want is when someone types in, for example,
Code:
!add [test] [this is a test command]

with the brackets, it will add a new remote so when they now type in !test it will reply 'this is a test command'. I would also like the new command they added to only be available on that channel.
Any help would be appreciated.
Posted By: Loki12583 Re: Command to add on text commands. - 26/06/13 02:10 PM
Taking in input in this way can be dangerous, make sure to always use the 'n' switch with $readini and do not pass unknown text into a timer.

Code:
alias addcommand {
  var %chan = $1, %command = $2, %reply = $$3-
  writeini commands.ini %chan %command %reply
}

on *:text:*:#:{
  if ($regex($1-,/!add \[(\S+)\] \[(.+)\]/Si)) {
    addcommand # $+(!,$regml(1)) $regml(2)
  }
  elseif ($readini(commands.ini,n,#,$1)) {
    msg # $v1
  }
}
Posted By: GamingTom Re: Command to add on text commands. - 26/06/13 02:18 PM
Thanks so much for the help! laugh
Now that I've added the commands, is there an easier way to delete them instead of going into the .ini file and deleting them manually? So I would do
Code:
!remove [test]
and it deletes the command from the .ini file.
Thanks anyway for the help.
Posted By: Loki12583 Re: Command to add on text commands. - 26/06/13 10:15 PM
Code:
alias addcommand {
  var %chan = $1, %command = $2, %reply = $$3-
  writeini commands.ini %chan %command %reply
}

alias remcommand {
  var %chan = $1, %command = $2
  remini commands.ini %chan %command
}

on *:text:*:#:{
  if ($regex($1-,/!add \[(\S+)\] \[(.+)\]/Si)) {
    addcommand # $+(!,$regml(1)) $regml(2)
  }
  elseif ($regex($1-,/!remove \[(\S+)\]/Si)) {
    remcommand # $+(!,$regml(1))
  }
  elseif ($readini(commands.ini,n,#,$1)) {
    msg # $v1
  }
}
Posted By: GamingTom Re: Command to add on text commands. - 27/06/13 02:19 PM
Thanks you so much for your help! However, I have something else I need help with if you don't mind. At the moment I have

Code:
!add [<command>] [<message>]


but I was wondering if it would be possible to do something like this so that it makes people on of a certain user level use it:

Code:
!add [<user level>] [<command>] [<message>]


And one other thing, how would I go about adding custom timers, for example:

Code:
!addtimer [<delay>] [<name>] [<message>]


and it would be activated by doing:

Code:
!activatetimer [<name>]


Would I use the same sort of format for the !add command?
Anyway, once again, thanks for your help.
Posted By: Andy84 Re: Command to add on text commands. - 30/04/14 07:17 PM
mh, i need this too but its not working for me
what am i doing wrong?

i need to !addcom !command testforcommand
and a !delcom !command

to just add/remove commands to my bot which will give out some text/informations

i tried it with the script from loki, even if i edited some things for me like userlvls it dont work

can someone help me on that?
Posted By: Bramzee Re: Command to add on text commands. - 30/04/14 09:27 PM
Code:
on $*:text:/^!addcom !?(\S+)/iS:#:{
  if ($nick !isop #) return
  writeini commands.ini commands $regml(1) $$3-
}
 
on $*:text:/^!delcom !?(\S+)/iS:#:{
  if ($nick !isop #) return
  remini commands.ini commands $regml(1)
}
 
on $*:text:/^!(\S+)/:#:{
  if ($nick !isop #) return
  if ($readini(commands.ini,n,commands,$regml(1))) msg # $v1
}




To add: "!addcom !test this is a test command"
To del: "!delcom !test"
To use: "!test" Bot -> this is a test command"

To edit, just redo the !addcom !test and add whatever you want the new message to be.
Posted By: Andy84 Re: Command to add on text commands. - 01/05/14 02:42 AM
nice, ty very much, that works
i'll try to edit some things to get it as i want
(floot/msg/etc)
hope it will work then too

otherwise can i message you?
would be great

thank u
Posted By: Bramzee Re: Command to add on text commands. - 01/05/14 05:05 AM
Code:
on $*:text:/^!(\S+)/:#:{
  if ((%floodcom) || ($($+(%,floodcom.,$2),2))) { return }
  set -u10 %floodcom On
  set -u30 %floodom. $+ $nick On
  if ($readini(commands.ini,n,commands,$regml(1))) msg # $v1
}


This should be the only thing you'll need floodprotection on. If people are spamming the !addcom and !delcom you can just basically copy/paste this and change "floodcom" to "floodadd" and "flooddel"

Also, yeah you can message me. I'm semi-new to all of this but I'm learning fast and willing to help if I can man smile
Posted By: Devin Re: Command to add on text commands. - 07/05/14 11:53 PM
Towards Bram, ( I forgot to quote you :P )


I know a basic understanding on the way to program simple stuff, but is there a way I could make it also say for example "Command "(command) has been created" ?

Oh, I'm a noob. Haha, brain farted badly, but anyways, thanks for the code dude, thats really a nice addition for me! laugh

Uhm, is there a way to change the preface it uses, I've tried and it just doesn't work.

But about that feature where I can select a user level?
Posted By: Bramzee Re: Command to add on text commands. - 08/05/14 02:44 AM
Not sure I know what you mean, could be the lack of sleep ha. Explain a little more in detail?
Posted By: Devin Re: Command to add on text commands. - 08/05/14 03:35 AM
You know how it defaults to a "!" for commands and when you add them it defaults to that? Well my bot has a ~ instead, and I tried to do !addcom ~test test and that just made me type !~test xD, I just wanted to know how to change it, since I broke it while trying to :P
Posted By: Bramzee Re: Command to add on text commands. - 08/05/14 06:10 AM
Is there a reason it has to have the "~" ?? If not, I'd suggest using just the ! but this will work if you don't care about the length or anything like that...

Ex:

You-> !addcom ~test THIS IS A TEST!
Bot-> Successfully created ~test!
You-> !~test
Bot-> THIS IS A TEST!

Code:
on $*:text:/^!~(\S+)/:#:{
  if ((%floodcom) || ($($+(%,floodcom.,$2),2))) { return }
  set -u10 %floodcom On
  set -u30 %floodom. $+ $nick On
  if ($readini(commands.ini,n,commands,$regml(1))) msg # $v1
}


That's my fix with no sleep in me. If it's not acceptable I'll be around tomorrow to help you smile Between the two of us, we should be able to get it lol.
Posted By: blessing Re: Command to add on text commands. - 08/05/14 07:21 AM
replace all (!) in script with (~) except (!isop)
Posted By: Bramzee Re: Command to add on text commands. - 08/05/14 02:19 PM
Already tested it that way, I couldn't get it working. It will add the command to the file, but won't read it. That's why I just used !~command for now.
Posted By: Devin Re: Command to add on text commands. - 09/05/14 04:17 AM
The only reason I would need the preface ~ would be because the channel my bot is in has servers in it that relay chat and they use ! as prefaces. but thanks for the effort :P
Posted By: blessing Re: Command to add on text commands. - 09/05/14 04:29 AM
Try if this works.

~addcom ~test this is a test
~test
~delcom ~test

Code:
on $*:text:/^~addcom ~?(\S+)/iS:#:{
  if ($nick !isop #) return
  writeini commands.ini commands $regml(1) $$3-
}
 
on $*:text:/^~delcom ~?(\S+)/iS:#:{
  if ($nick !isop #) return
  remini commands.ini commands $regml(1)
}

on $*:text:/^~(\S+)/:#:{
  if ((%floodcom) || ($($+(%,floodcom.,$2),2))) { return }
  set -u10 %floodcom On
  set -u30 %floodom. $+ $nick On
  if ($readini(commands.ini,n,commands,$regml(1))) msg # $v1
}
Posted By: Devin Re: Command to add on text commands. - 09/05/14 05:03 AM
Actually, replacing the two "!"'s with "~"s on the first lines of addcom and delcom it made the preface work.. Anyways, thanks alot for that code dude laugh
Posted By: Bramzee Re: Command to add on text commands. - 09/05/14 10:36 AM
yeah... didn't try that ha. Good call man smile
Posted By: OneAngryDuck Re: Command to add on text commands. - 11/05/14 11:48 AM
Hey Everyone,

This has been a great help, I do have one question. Did anyone know out how to add the user level commands.

So right now I only have two options which is edit the script to have

This allowing anyone to use it

on $*:text:/^!(\S+)/:#:{
if ($readini(commands.ini,n,#,$regml(1))) msg # $v1
}


Or this allowing only ops

on $*:text:/^!(\S+)/:#:{
if ($nick !isop #) return
if ($readini(commands.ini,n,#,$regml(1))) msg # $v1
}

Is there a way when the op creates the command to say who can use it?
Posted By: judge2020 Re: Command to add on text commands. - 12/05/14 02:51 PM
an easy way to do it is make the command addcomMOD or something and make it add to a mod command list, then have 2 commands to find !* and one is ($nick !isop #) return
Code:
on $*:text:/^!addcommod !?(\S+)/iS:#:{
  if ($nick !isop #) return
    msg $chan added $2 to moderator commands!
    writeini modcommands.ini commands $regml(1) $3-
}

Code:
on $*:text:/^!(\S+)/:#:{
if ($nick !isop #) return
if ($readini(modcommands.ini,n,#,$regml(1))) msg # $v1
}
Posted By: OneAngryDuck Re: Command to add on text commands. - 12/05/14 09:35 PM
Ahh,

Simplest solution, looking me right in the face.

Thanks
Posted By: Bramzee Re: Command to add on text commands. - 21/05/14 05:44 PM
is there a way to do this, so that the command will read a text file itself? For instance, say I have a recent donator's list and want the command !recent to be in my commands.ini file but read from that list (so it updates automatically, after a donation is made) I know I can do:

Code:
on *:text:!recent:#: {
  msg # $read(donatorList.txt)
}


And, if it helps this is my !repeat script:

Code:
on *:text:!repeat *:#:{
  if $nick !isop # { msg # $nick You are not allowed to do that | return }
  if !$3 { msg # Usage: !repeat !<command name> <time in minute/off> | return }
  if ($3 !isnum || $3 < 1) && $3 != off { msg # <time> must be number greater than 0 or off | return }
  var %t $+(#,.,$2), %text $readini(commands.ini,n,commands,$right($2,-1))
  if !%text { msg # $2 does not exists. | return }
  if $timer($+(repeat.,%t)) {
    if $3 == off { 
      $+(.timerrepeat.,%t) off 
      msg # $2 repetition is now off.
    }
    else { msg # $2 is already repeating. }   
  } 
  else { 
    if $3 == off { msg # $2 has not been started yet. }
    else { 
      $+(.timerrepeat.,%t) 0 $calc($3 * 60) msg # $replace(%text,|,-,$,-,%,-) 
      msg # $2 is now repeating every $3 min $+ $iif($3 > 1,s) $+ . 
    }
  } 
}


But I'd also like to incorporate that into my existing !repeat command so I don't have to do it manually... If it's not possible, no big deal. Just like keeping my remote's as clean as possible :P
Posted By: blessing Re: Command to add on text commands. - 22/05/14 03:08 AM
make it as an alias.
Code:
alias recent return $read(donatorList.txt)

check if command is an alias or plain text.
Code:
on *:text:!repeat *:#:{
  ...
      ; check if command is an alias or just plain text

      if ($numtok(%text,32) == 1) && ($isalias(%text)) { var %cmd msg # $($+($,!,%text),2) }
      else { var %cmd msg # $replace(%text,|,-,$,-,%,-) }

      $+(.timerrepeat.,%t) 0 $calc($3 * 60) %cmd 
      msg # $2 is now repeating every $3 min $+ $iif($3 > 1,s) $+ .
  ...
}
Posted By: Devin editcom help, as long with some user levels? - 26/05/14 07:29 AM
So if anyone could also help out with here, I would like a ~editcom command but I tried and it hasn't worked for me, I figured it would work, but I'm really tired. Also, the easiest way, as someone mentioned, would be to just do a ~addcommod or have it check to see if the word mod is there possibly?

Code:
on $*:text:/^~addcom ~?(\S+)/iS:#:{
  writeini commands.ini commands $regml(1) $$3-
  { msg $chan $nick -> Command $2 has been created. }
}
on $*:text:/^~delcom ~?(\S+)/iS:#:{
  remini commands.ini commands $regml(1)
  { msg $chan $nick -> $2 has been removed from the command database. }
}

on $*:text:/^~(\S+)/:#:{
  if (!%comwait) {
    set -u6 %comwait 1
    if ($readini(commands.ini,n,commands,$regml(1))) msg # $v1
  }
  else { msg $chan $nick -> Command is on cool-down }
}
on $*:text:/^~editcom ~?(\S+)/iS:#:{
  writeini commands.ini commands $regml(1) $$3-
  { msg $chan $nick -> Command $2 has been updated. }
}
Originally Posted By: Devin
So if anyone could also help out with here, I would like a ~editcom command but I tried and it hasn't worked for me, I figured it would work, but I'm really tired. Also, the easiest way, as someone mentioned, would be to just do a ~addcommod or have it check to see if the word mod is there possibly?

Code:
on $*:text:/^~addcom ~?(\S+)/iS:#:{
  writeini commands.ini commands $regml(1) $$3-
  { msg $chan $nick -> Command $2 has been created. }
}
on $*:text:/^~delcom ~?(\S+)/iS:#:{
  remini commands.ini commands $regml(1)
  { msg $chan $nick -> $2 has been removed from the command database. }
}

on $*:text:/^~(\S+)/:#:{
  if (!%comwait) {
    set -u6 %comwait 1
    if ($readini(commands.ini,n,commands,$regml(1))) msg # $v1
  }
  else { msg $chan $nick -> Command is on cool-down }
}
on $*:text:/^~editcom ~?(\S+)/iS:#:{
  writeini commands.ini commands $regml(1) $$3-
  { msg $chan $nick -> Command $2 has been updated. }
}

You already that in the !* script
Code:
if ($readini(commands.ini,n,commands,$regml(1)))
so
Code:
on $*:text:/^~editcom ~?(\S+)/iS:#:{
if ($readini(commands.ini,n,commands,$regml(1)))  {
  writeini commands.ini commands $regml(1) $$3-
  msg $chan $nick -> Command $2 has been updated.
}
Else msg # sorry! that command is not already there. Consider adding it!
}
}
also you might want to add in some operator checks so randoms don't change all your commands.

Same can be done for !delcom
You have to change the order of the code. mIRC will not process next event if it is already matched.
~editcom is matched to this event
Code:
on $*:text:/^~(\S+)/:#:{
  ...
}

thus next event will be ignored.
Try move the code quoted above to the bottom of the script.
Is anyone else having a problem with adding commands that have links in them? For some reason the bot isn't liking it or something. I have a link protection script, but even after I remove that and try, I still have to add the command manually... Which wouldn't be a huge deal, but a few people are using my bot (and yes, this was not working even before they started using it). Any ideas on how to fix or what might be the problem?
Originally Posted By: Bramzee
Is anyone else having a problem with adding commands that have links in them? For some reason the bot isn't liking it or something. I have a link protection script, but even after I remove that and try, I still have to add the command manually... Which wouldn't be a huge deal, but a few people are using my bot (and yes, this was not working even before they started using it). Any ideas on how to fix or what might be the problem?


I don't have any issues, so it may be your code. Mine is custom, so it is a lot different than that of the sources here. Can you post the code that adds the commands you are typing in chat? It is quite difficult to tell what the issue is if I have nothing to go off of.
Sorry, a little tired. Meant to add that in...


Code:
on $*:text:/^!addcom !?(\S+)/iS:#:{
  if ($nick !isop #) { msg # Sorry $nick - You don't have permission to do that. } return
  writeini commands.ini # $regml(1) $$3-
  msg # $nick - The command $$2 has been added.
}

on $*:text:/^!delcom !?(\S+)/iS:#:{
  if ($nick !isop #) { msg # Sorry $nick - You don't have permission to do that. } return
  remini commands.ini # $regml(1)
  msg # $nick - The command $$2 has been removed.
}

on $*:text:/^!(\S+)/:#:{
  if ((%floodcom) || ($($+(%,floodcom.,$2),2))) { return }
  set -u10 %floodcom On
  set -u30 %floodcom. $+ $nick On
  if ($readini(commands.ini,n,#,$regml(1))) msg # $v1
I notice this line is wrong
Code:
if ($nick !isop #) { msg # Sorry $nick - You don't have permission to do that. } return

should be
Code:
if ($nick !isop #) { msg # Sorry $nick - You don't have permission to do that. | return }
Adding links works for me using your code. What link are you trying to add if you don't mind me asking?
When I do anything with just text it works perfectly. But for a test, just to double check before asking for help, I tried "!addcom !test twitter is twitter.com" and got no response. I then checked my command.ini file to see if maybe it went in and just didn't repeat, but it wasn't there. I figured maybe it was a problem with the script.


EDIT: I fixed it. Sorry. I put it in it's own remote file. After thinking maybe it was one of my other scripts messing with it I decided I'd give that a shot. Thanks for trying to help anyway smile
Posted By: OneAngryDuck Re: Command to add on text commands. - 29/06/14 09:48 PM
Hey Everyone,

So been slowly plugging away at this and learning but this one maybe out of my league.

Is there a way to list what commands a channel has?
So like !ListCom

then msgs the channel with a list of the words.

I saw this Command List

Not sure if that would be the same logic

I tried the read command, but could not get it to format right. Then I got to thinking that will just post up the blob of text on the .ini. So then I was thinking that maybe with each !addcom I need to have it write something to a .txt that it could relay back.

I am not sure, has my head spinning any suggestions?
Posted By: judge2020 Re: Command to add on text commands. - 29/06/14 10:27 PM
https://forums.mirc.com/ubbthreads.php/ubb/showflat/Number/245756/Searchpage/1/Main/46310/Words/Awesome%21/Search/true/Re:_adding_commands_and_showin#Post245750

searched that so it has the search items in there :P

That script basically creates a .txt file named commandresonse.txt and every time someone adds it the new command will be added to the end, here is an example (i said ok since it didnt go through)
also
Code:
http://i.gyazo.com/a17c0750b371b29915d2b08b72d9ecb4.png

just is my list of names that can add commands, you should be able to edit your commands file and all that.

EDIT: almost forgot, here is the command i used to run this :P
Code:
on *:TEXT:!commands:#: { 
  if ((%floodcommands) || ($($+(%,floodcommands.,$nick),5))) { return }
  set -u15 %floodcommands On
  msg # $read(commandsresonse.txt)
}
Posted By: OneAngryDuck Re: Command to add on text commands. - 30/06/14 12:00 AM
Thanks,

Like always right in my face


Have another question about this, this is just for one channel if you have a few people that use it is there a way to do it like the .ini where it breaks down each command into each channel?
Posted By: judge2020 Re: Command to add on text commands. - 30/06/14 12:42 AM
change this
Code:
   writeini allcommands.ini commands $regml(1) $3-
to
Code:
   writeini allcommands.ini $chan $regml(1) $3-

changes [commands] to [#channel] in the .ini, so your !* command is
Code:
on $*:text:/^!(\S+)/:#:{ if ($readini(allcommands.ini,n,$chan,$regml(1))) msg # $v1 }
Posted By: OneAngryDuck Re: Command to add on text commands. - 30/06/14 12:57 AM
*SOLVED*
So just in case anyone want to do this too...

Code:
var %text $read(commandlist.txt,s,#)
  if %text != $null {
    var %line $remove(%text,! $+ $regml(1))
  }

  write -s $chan commandlist.txt # %line 
}





Sorry for the confusion I mean for the showing of the command list.

Right now when I used it if one channel will overwrite the text file.

So when I did the show command it was just showing the list of who ever added a command last.

I was trying to get it to make a new text file for each channel cause I only have 3 people using it, but I am not having much luck. Or have it break it down like the commands.ini does like it has the channel name then the command written under it.
Posted By: judge2020 Re: Command to add on text commands. - 30/06/14 03:42 AM
did you see my last post? it literally explained a way to break it into different channels
© mIRC Discussion Forums