mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2013
Posts: 61
E
Babel fish
OP Offline
Babel fish
E
Joined: Sep 2013
Posts: 61
Hey Chaps, this will probably be an easy one for most of you, but either I don't fully understand it, or I'm getting the syntax wrong.

What I'm trying to do (which has been successful), is create a way to allow users to create their own commands in the bot (This works, and has been tested, see below code), as well as a way for me to completely add commands to the bot using my twitch channel (I've since got a slave machine (Wyse 3030 with Windows 10) to run the bot 24/7). Due to having the bot on another machine, I've been attempting to code a way to be able to add / remove commands remotely without needing to remote onto the machine.

Code
on *:TEXT:!addcommand *:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # ! Adding new command. Please Wait...
  write C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt on *:TEXT:! [ $+ [ $2 ] ] [ $+ [ $chr(58) ] ] [ $+ [ $chan ] ] [ $+ [ $chr(58) ] ] [ $+ [ $chr(32) ] ] [ $+ [ $chr(123) ] ] [ $+ [ $chr(32) ] ] .msg # [ $+ [ $chr(32) ] ] [ $+ [ $3- $chr(32) ] ] [ $+ [ $chr(125) ] ]
  .timer 1 2 .msg # ! The bot is reloading the command list, please wait...
  .timer 1 3 /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Command List Refreshed. Command ! [ $+ [ $2 ] ]  is now active.
}

on *:TEXT:!addcommandfull *:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # ! Adding new command. Please Wait...
  write C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt $2-
  .timer 1 2 .msg # The bot is reloading the command list, please wait...
  .timer 1 3 /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Command List Refreshed. Command is now active.
}

on *:TEXT:!removecommand *:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # ! Removing command: ! $+ $$2 $+ . Please Wait...
  $read(C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt,w,*[ $+ [ $2 ] ]*)
  .msg # $readn
  write -dl $+ $readn C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 2 .msg # The bot is reloading the command list, please wait...
  .timer 1 3 /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Command List Refreshed. Command: [ $+ [ $chr(32) $2 ] ] has been removed.
}

on *:TEXT:!reload:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # Reloading commands. Please Wait
  /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Commands Reloaded Manually.
}


The issue I'm having, is the !removecommand. I'm aiming to find $2 within the file, choose that line, and remove it / write over the line (ideally), stating "; Command $$2 Removed", so I can see when commands have been deleted.

On checking $readn, it comes back with the integer of 0, meaning it's not finding it within the file.

I guess my syntax is wrong, but can someone take a look and correct, or point me in the right direction how to fix it? I've looked at mIRC and the wiki, and I've tried multiple different attempts, all of which have failed.

Thanks
Egg


Twitch Live-Streamer:
Synth Riders
Beat Saber
www.twitch.tv/eggfriedcheese
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
The whole concept of what you're doing is dangerous, because someone could use this to embed very nasty commands into your bot. You should NEVER evaluate a string created by someone who's not trusted. That includes putting it inside square braces, using $read without the n switch, putting it into a timer command, etc.

$read(additionalcommands.txt,w,*[ $+ [ $2 ] ]*) .msg # $readn

This shows you what you're trying to do:

//tokenize 32 a foobar | echo -a *[ $+ [ $2 ] ]*

result: *[foobar ]*

Since your diskfile doesn't contain any literal square braces, there's no match

If your intent is to do something like this:

//tokenize 32 a foobar | echo -a * [ $+ [ $2 ] ] *

result: *foobar *

... you might get a false match where trying to delete the FOO command could incorrectly match xyzfoo if that's encountered first.

You might want instead the s switch's scan, which scans a line where the 1st word is a case-insensitive match for $2, and it returns the remainder of the line excluding your match:

var %a $read(additionalcommands.txt,s,$2)
if (%a != $null) write -dl $+ $readn additionalcommands.txt

If your .txt is being kept in the same folder as the mirc.ini, you don't need to include the path, because by default that's the folder looked into when not using a path. To avoid nasty exploits, here's some other examples of things to avoid:

https://en.wikichip.org/wiki/mirc/msl_injection

Joined: Sep 2013
Posts: 61
E
Babel fish
OP Offline
Babel fish
E
Joined: Sep 2013
Posts: 61
The !addcommandfull is only usable by me. That just saves me logging into the thin client to add the command manually

The !addcommand command is there to "$$2 = command" and "$$3- being the text to be added to the command".

I've edited the !addcommand, to remove all the following: | { } [ ]

Code
  write C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt on *:TEXT:! [ $+ [ $2 ] ] [ $+ [ $chr(58) ] ] [ $+ [ $chan ] ] [ $+ [ $chr(58) ] ] [ $+ [ $chr(32) ] ] [ $+ [ $chr(123) ] ] [ $+ [ $chr(32) ] ] .msg # [ $+ [ $chr(32) ] ] [ $+ [ $remove($3,$chr(124),$chr(123),$chr(125),$chr(91),$chr(93)) $chr(32) ] ] [ $+ [ $chr(125) ] ]


This is now removing everything in a command from | - Which will stop the bot breaking at least. With the command forcing a .msg #channel, it'll only post it in their channel anyway.

If I'm checking for a command then, would I be able to do something like this?

Code
on *:TEXT:!removecommand *:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # ! Removing command: ! $+ $$2 $+ . Please Wait...
  var %a $read(additionalcommands.txt,s,$2)
  if (%a != $null) write -dl $+ $readn additionalcommands.txt
  .timer 1 2 .msg # The bot is reloading the command list, please wait...
  .timer 1 3 /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Command List Refreshed. Command: [ $+ [ $chr(32) $2 ] ] has been removed.
}


This is what gets added to the file, which is the correct format:

Code
on *:TEXT:!command1:#amiretroyet: { .msg #amiretroyet test }
on *:TEXT:!testbar:#amiretroyet: { .msg #amiretroyet test }


However, on testing, this did not work.

Last edited by EggFriedCheese; 02/06/22 12:33 PM.

Twitch Live-Streamer:
Synth Riders
Beat Saber
www.twitch.tv/eggfriedcheese
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
When trying to make things work, it helps to include debug messages, such as using the -s switch with the /var command so you can see exactly what is/isnt being filled into the variable, or using an echo to see the contents of the parameters used for writing/reading disk.

It looks like you're using !addcommand to add 1-line aliases to the bot, but then you're writing to a file which is being loaded into remote script. That means either $2- needs to begin with the alias keyword, or you need to specifically write alias to the beginning of each line, which then affects how you search for an existing command to kill it, or else you should load it with -ra into the aliases tab.

When you say it doesn't work, is it just the finding that doesn't work, or the writing, or the executing?

Joined: Sep 2013
Posts: 61
E
Babel fish
OP Offline
Babel fish
E
Joined: Sep 2013
Posts: 61
Looks like it's still not finding the command correctly.

Ideally, I'd want to be searching for the following:

! <Then the command from $2>:# <The $chan from twitch> :

i.e.

Code
 !testing:#eggfriedcheese: 


So that it's looking for that command in their channel, and then once that's found, it deletes.


Twitch Live-Streamer:
Synth Riders
Beat Saber
www.twitch.tv/eggfriedcheese
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
I thought I'd posted this earlier, but I don't see it now.

!testing:#eggfriedcheese:

var %match $+(!,$2,:,$chan,:)
var %match $read(additionalcommands.txt,nts,%match)
if (%match != $null) write -dl $+ $readn additionalcommands.txt


Note that, as I mentioned earlier, you should use the 'n' switch if you need to avoid a command containing $word_beginning_with_dollar being evaluated as an identifier. On the other hand, if you want to have a command containing $me or $nick then having those evaluated as identifiers, then avoid the 'n' switch.

The 't' switch only comes into play when line#1 in its entirety is a number, in which case mIRC sees that number as if it's the number of lines in the text file when searching for a random line, but it apparently doesn't have an effect on the 's' switch.

Joined: Sep 2013
Posts: 61
E
Babel fish
OP Offline
Babel fish
E
Joined: Sep 2013
Posts: 61
So I've put this into the bot, and the bot still isn't removing the line. It doesn't break out of the command though
Code
on *:TEXT:!removecommand *:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # ! Removing command: $+ $chr(32) $+ $$2 $+ . Please Wait...
  var %match $+(!,$2,:,$chan,:)
  var %match $read(additionalcommands.txt,nts,%match)
  if (%match != $null) write -dl $+ $readn additionalcommands.txt
  if (%match = $null) .msg # Match Not Found
  .timer 1 2 .msg # The bot is reloading the command list, please wait...
  .timer 1 3 /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Command List Refreshed. Command: [ $+ [ $chr(32) $2 ] ] has been removed.
}


Is posting the following in the chat:

EggFriedCheese: !removecommand !egg1
EggBot_V1: ! Removing command: !egg1. Please Wait...
EggBot_V1: Match Not Found
EggBot_V1: The bot is reloading the command list, please wait...
EggBot_V1: Command List Refreshed. Command: !egg1 has been removed.

Last edited by EggFriedCheese; 03/06/22 04:06 PM.

Twitch Live-Streamer:
Synth Riders
Beat Saber
www.twitch.tv/eggfriedcheese
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
You need to clarify what you're searching for. Your earlier post said you wanted:

"Ideally, I'd want to be searching for the following:

! <Then the command from $2>:# <The $chan from twitch> :"

which means to me that your syntax for removing the command would be to exclude the ! from $2 because your example here showed the ! as being something to attach to a $2 which doesn't contain the !

If you want to have the $2 begin with the ! then you want to change from
var %match $+(!,$2,:,$chan,:)
to
var %match $+($2,:,$chan,:)

I still don't know what you're wanting your disk file to look like, or how you want to execute your installed commands, because a line beginning like !testing:##maroon: isn't going to be executed without some scripting.

Also, unless you're trying to create alias commands that the bot will execute, why are you loading this into the remote tab of scripts editor? You obviously don't have 'monitor file changes' enabled in the script editor, because otherwise each time you write to a loaded script file it's triggering the 'are you sure' prompt

Edit: since you don't need the path when writing to the file, if you still think you need to /load the file, then you don't need the path there either. Also, the period trailing the ending curly brace shouldn't be there, because nothing should be touching that { } pair except possibly having the event's colon preceding the opening {
You can tell the period causes a problem, since it causes Ctrl+H to report a mismatched bracket


Last edited by maroon; 03/06/22 03:39 PM.
Joined: Sep 2013
Posts: 61
E
Babel fish
OP Offline
Babel fish
E
Joined: Sep 2013
Posts: 61
Okay, yeah, I was being an idiot, I forgot we coded it like that laugh

It's working now smile


Twitch Live-Streamer:
Synth Riders
Beat Saber
www.twitch.tv/eggfriedcheese
Joined: Sep 2013
Posts: 61
E
Babel fish
OP Offline
Babel fish
E
Joined: Sep 2013
Posts: 61
Also, the file is a "temporary hold" for additional commands. The bot is being used in other channels, so giving them the flexibility to create basic chat commands that will respond is the idea here. Removing commands is just there for the user to remove, if they've made a mistake or something.

As I'll still be having control over the commands, I can move them into the main remote.ini file after the fact. The reason I have the .txt loaded, is if I don't load the file, and /reload after every edit, the command doesn't work in the chat. It's just a workaround, as I'm not giving people access to write to remote.ini (Which I don't think you can anyway).

I'll be honest, I'm probably going to re-code this into it's own API script in the future using c#, but that's a lot of work, and it's already coded quite well in mIRC, I'm not touching it for a while.

Code:

Code
on *:TEXT:!addcommand *:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # ! Adding new command. Please Wait...
  write C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt on *:TEXT:! [ $+ [ $remove($2,$chr(33)) ] ] [ $+ [ $chr(58) ] ] [ $+ [ $chan ] ] [ $+ [ $chr(58) ] ] [ $+ [ $chr(32) ] ] [ $+ [ $chr(123) ] ] [ $+ [ $chr(32) ] ] .msg # [ $+ [ $chr(32) ] ] [ $+ [ $remove($3-,$chr(124),$chr(123),$chr(125),$chr(91),$chr(93)) $chr(32) ] ] [ $+ [ $chr(125) ] ]
  .timer 1 2 .msg # ! The bot is reloading the command list, please wait...
  .timer 1 3 /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Command List Refreshed. Command ! [ $+ [ $remove($2,$chr(33)) ] ]  is now active.
}

on *:TEXT:!addcommandfull *:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # ! Adding new command. Please Wait...
  write C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt $2-
  .timer 1 2 .msg # The bot is reloading the command list, please wait...
  .timer 1 3 /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Command List Refreshed. Command is now active.
}

on *:TEXT:!removecommand *:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # ! Removing command: $+ $chr(32) $+ ! $+ $remove($2,$chr(33)) $+ . Please Wait...
  var %match $+(on,$chr(32),*,:,TEXT,:,!,$remove($2,$chr(33)),:,$chan,:)
  var %match $read(additionalcommands.txt,nts,%match)
  if (%match != $null) write -dl $+ $readn additionalcommands.txt
  if (%match = $null) { .msg # Command not found in the database. | return }
  .timer 1 2 .msg # The bot is reloading the command list, please wait...
  .timer 1 3 /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Command List Refreshed. Command: ! [ $+ [ $remove($2,$chr(33)) $chr(32) ] ] has been removed.
}

on *:TEXT:!reload:#: {
  if ($nick != eggfriedcheese) { return }
  .msg # Reloading commands. Please Wait
  /reload -rs C:\Users\danie\AppData\Roaming\mIRC\additionalcommands.txt
  .timer 1 5 .msg # Commands Reloaded Manually.
}

Last edited by EggFriedCheese; 03/06/22 04:05 PM.

Twitch Live-Streamer:
Synth Riders
Beat Saber
www.twitch.tv/eggfriedcheese
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
There's no practical difference between letting someone have write access to one remote script file vs a different one. The only difference between remote.ini and additionalcommands.txt is that the former is the default filename used when there are no user-custom scripts loaded, and the fact that loading a script with filetype .ini causes mirc to write nNUMBER= prefix for each line of the file, which would make it a little more complicated to scan for string matches. That's why many users rename remote.ini to remote.mrc, which identifies something as a scriptfile while keeping the file a little bit smaller due to eliminating all those line prefixes

Also, you're doing things a little harder to read. Equivalents:

var %match $+(on,$chr(32),*,:,TEXT,:,!,$remove($2,$chr(33)),:,$chan,:)
var %match $+(on *:TEXT:!,$remove($2,$chr(33)),:,$chan,:)

Joined: Sep 2013
Posts: 61
E
Babel fish
OP Offline
Babel fish
E
Joined: Sep 2013
Posts: 61
Oh, that makes sense. I've always just used remote.ini, I just thought loading a second file for "additional commands", to work in the bot, until I move them to the main code, was a good way to manage and moderate what's being added.

I've changed the below, I thought I needed to specify the spaces in the $+ using $chr, that's me learning something new today.

Thanks for your help btw smile

This bot is definitely coming along.


Twitch Live-Streamer:
Synth Riders
Beat Saber
www.twitch.tv/eggfriedcheese

Link Copied to Clipboard