mIRC Home    About    Download    Register    News    Help

Topic Options
#239582 - 09/11/12 07:47 AM Run scripts from a different file
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
What sample of code would I use to run set commands in a different file, even though I have a 'master' file with the main commands in it.

Top
#239584 - 09/11/12 11:15 AM Re: Run scripts from a different file [Re: Judgebot]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
Just $read the file. Without the n parameter in $read, it will evaluate anything that is read. Be very careful doing that if anyone has access to write something to the file besides you. Doing that sort of thing can be a significant security risk.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#239585 - 09/11/12 03:06 PM Re: Run scripts from a different file [Re: Riamus2]
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
So what would the code be like?

$read C:\file.text ?

Top
#239590 - 09/11/12 06:07 PM Re: Run scripts from a different file [Re: Judgebot]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
For syntax and examples: /help $read

Again, be aware that running commands this way leaves you open to security risks if you aren't careful. Never run a command from a file that people can write to.

Edit: I thought $read() was a little less secure. After I had a chance to test, simply using $read isn't quite enough, but here's one option:

Code:
alias command {
  noop $read(commands.txt,w,$1*)
}


commands.txt file:
Quote:

echo_hello | echo -a hello
echo_bye | echo -a bye


Use:
/command echo_hello
/command echo_bye

You can set the text file up with a command name to use followed by a pipe character and then followed by the command. The just specify the command name when using the command as shown and it will run the command in the text file that matches the command name you used.

You would of course have to adjust this to fit your needs. It's just a basic example.


Edited by Riamus2 (09/11/12 06:22 PM)
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#239593 - 09/11/12 06:59 PM Re: Run scripts from a different file [Re: Riamus2]
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
OK I will test this now.

Top
#239602 - 09/11/12 09:04 PM Re: Run scripts from a different file [Re: Judgebot]
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
Or use the /play command and the -c switch. With /play, you don't need that external alias and the other switches allow you to set further parameters, if required.

Top
#239605 - 10/11/12 12:29 AM Re: Run scripts from a different file [Re: Horstl]
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
Originally Posted By: Horstl
Or use the /play command and the -c switch. With /play, you don't need that external alias and the other switches allow you to set further parameters, if required.


Do you have an example/snippet of code that i could look at?

Top
#239611 - 10/11/12 11:42 AM Re: Run scripts from a different file [Re: Judgebot]
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
Create for instance a file "example.txt" and add a set of commands to it:
Code:
window -a "status window" | echo -st starting example
echo -s ...minimizing and restoring mIRC...
showmirc -n
showmirc -r
echo -st done!

Now within mIRC, if you use the following command:
Code:
/.play -spc "example.txt" 500
mIRC will execute all commands in that file.

Of course you can put the play command inside a custom alias like:
Code:
alias example { .play -spc "example.txt" 500 }
The -c switch tells mIRC to treat all the line in the file as commmands.
The -p switch tells mIRC to give priority to this play request (just in case there are other playbacks running at the moment).
Note that /play requires some target window, therefore I put the -s switch (in mIRC, there will always be a status window).
"500" specifies the per-line playback delay in milliseconds, i.e. the time offset between the different command lines of your file. Note that as the first line in example.txt has two commands on it, there will be no delay in-between the two. You can put "0" for delay to have mIRC execute all the commands without any line delay.

The play command syntax is documented in detail at "playing files" in your mIRC helpfile. For example, you could use an ini-file and have mIRC play a given topic (as the command register, with one or more command line associated to it).

Top
#239612 - 10/11/12 12:33 PM Re: Run scripts from a different file [Re: Horstl]
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
Originally Posted By: Horstl
Create for instance a file "example.txt" and add a set of commands to it:
Code:
window -a "status window" | echo -st starting example
echo -s ...minimizing and restoring mIRC...
showmirc -n
showmirc -r
echo -st done!

Now within mIRC, if you use the following command:
Code:
/.play -spc "example.txt" 500
mIRC will execute all commands in that file.

Of course you can put the play command inside a custom alias like:
Code:
alias example { .play -spc "example.txt" 500 }
The -c switch tells mIRC to treat all the line in the file as commmands.
The -p switch tells mIRC to give priority to this play request (just in case there are other playbacks running at the moment).
Note that /play requires some target window, therefore I put the -s switch (in mIRC, there will always be a status window).
"500" specifies the per-line playback delay in milliseconds, i.e. the time offset between the different command lines of your file. Note that as the first line in example.txt has two commands on it, there will be no delay in-between the two. You can put "0" for delay to have mIRC execute all the commands without any line delay.

The play command syntax is documented in detail at "playing files" in your mIRC helpfile. For example, you could use an ini-file and have mIRC play a given topic (as the command register, with one or more command line associated to it).


So there has to be a separate text file for every external command? you can't compile them into one external file?

Top
#239639 - 12/11/12 04:13 AM Re: Run scripts from a different file [Re: Judgebot]
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
Not if you use the .ini file structure. You could place every command (or set of commands) under a distinct [topic] header of a single .ini file.
What goal are you trying to attain by out-sourcing your commands, if I may ask?

Top
#239647 - 12/11/12 03:59 PM Re: Run scripts from a different file [Re: Horstl]
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
Originally Posted By: Horstl
Not if you use the .ini file structure. You could place every command (or set of commands) under a distinct [topic] header of a single .ini file.
What goal are you trying to attain by out-sourcing your commands, if I may ask?


Say i give someone access to a file called "user1.txt(/.ini)" then they have access to add command to that file.

But then i'd want the main file "remote.ini" to use the commands in that file for said channel.

Then it would go on to add more external files such as user2,3,4,5,6...


The main file structure would then be something like

Code:
on *:text:*:#: {
  if ( $chan == #user1 ) {
    $read(user1.txt)
  }
}
on *:text:*:#: {
  if ( $chan == #user2 ) {
    $read(user2.txt)
  }
}


and so on, permissions and commands would be pulled from the different files.

I'd like the commands in each external file to look like:
Code:
on *:text:*!commandexample*:#: {
  msg $chan command example
}


this is a command example which it would look like in each file. So standard command format.


Edited by Judgebot (12/11/12 04:02 PM)

Top
#239654 - 12/11/12 11:24 PM Re: Run scripts from a different file [Re: Judgebot]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
You wouldn't be able to use event syntax like that. At least, not without considerable work, or unless you want to load the file and use it that way as just another script file.

As far as what you are attempting, you should absolutely never do this. Consider what happens if someone decides it would be "fun" to put in a command to delete things from your computer or grab your password file from your browser or other history and cookie information from you browser and download it? It would be VERY easy for someone to do basically anything they wanted to your computer. And with that kind of control, they could make it so you don't even notice... write the command to do what they want, then change it back to something innocuous until they are ready to do something bad again.

Never, never, never let someone create their own command on your computer and execute it. This is a really dangerous idea for a script. Unless you and only you have access to write commands, or you can absolutely trust those who have access (I wouldn't trust anyone besides very close family and perhaps very close real life friends). It would never be a good idea to give that kind of control to anyone you meet online no matter how good you think you know them.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#239674 - 13/11/12 12:49 PM Re: Run scripts from a different file [Re: Riamus2]
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
Originally Posted By: Riamus2
You wouldn't be able to use event syntax like that. At least, not without considerable work, or unless you want to load the file and use it that way as just another script file.

As far as what you are attempting, you should absolutely never do this. Consider what happens if someone decides it would be "fun" to put in a command to delete things from your computer or grab your password file from your browser or other history and cookie information from you browser and download it? It would be VERY easy for someone to do basically anything they wanted to your computer. And with that kind of control, they could make it so you don't even notice... write the command to do what they want, then change it back to something innocuous until they are ready to do something bad again.

Never, never, never let someone create their own command on your computer and execute it. This is a really dangerous idea for a script. Unless you and only you have access to write commands, or you can absolutely trust those who have access (I wouldn't trust anyone besides very close family and perhaps very close real life friends). It would never be a good idea to give that kind of control to anyone you meet online no matter how good you think you know them.


Ok, so is there a script snippet that does:

Code:
!addcommand isop !command command example

Code:
!addcommand public !command command example


!addcommand = the script
isop/public = the permissions
!command = the command you want adding (trigger)
command example = the text of the command (reply)

isop:
Code:
if ( $nick isop $chan )

public:
Code:
on *:text:*!command*:#:{ 
  msg $chan command example
 }

Top
#239683 - 13/11/12 11:05 PM Re: Run scripts from a different file [Re: Judgebot]
hixxy Offline
Hoopy frood

Registered: 06/09/05
Posts: 2876
Do you just want the script to be able to send messages or does it have to be able to execute other commands?

If the former, there's a much easier (and better) way of achieving what you want.

Top
#239693 - 14/11/12 03:48 PM Re: Run scripts from a different file [Re: hixxy]
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
Originally Posted By: hixxy
Do you just want the script to be able to send messages or does it have to be able to execute other commands?

If the former, there's a much easier (and better) way of achieving what you want.


I'd like a way of someone else adding commands to the bot, without them touching/giving me the command script to be added.

So any way of doing that (pretty much) I would be great full

Top
#239694 - 14/11/12 06:07 PM Re: Run scripts from a different file [Re: Judgebot]
sparta Offline
Planetary brain

Registered: 22/02/03
Posts: 3432
Loc: Sweden/Borlänge
You can yes, but it's a bad bad idea, i could format your whole computer (or worse) if you give that type of access so it's not a good idea.


Edited by sparta (14/11/12 06:08 PM)
_________________________
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }

Top
#239698 - 14/11/12 11:57 PM Re: Run scripts from a different file [Re: sparta]
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
Originally Posted By: sparta
You can yes, but it's a bad bad idea, i could format your whole computer (or worse) if you give that type of access so it's not a good idea.


I'd still like to see this script/code please.

the bot is running on a server and all of the programs are backup-ed away from the computer

Top
#239707 - 15/11/12 11:19 AM Re: Run scripts from a different file [Re: Judgebot]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
You know that the things people can do aren't limited to just that computer, right? If you're on a home network, they can gain access to other computers on the network. They can also easily get you banned from the IRC network and can send out viruses to people from your computer. They can also very easily set your computer up (outside of mIRC) to do things it shouldn't, such as passing on viruses or doing DDOS attacks on places. You are attempting to make it possible for someone to do anything they want from your computer as if they were sitting at the computer itself. This goes beyond whether you have a backup on that computer. It is just a really bad idea.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#239708 - 15/11/12 08:25 PM Re: Run scripts from a different file [Re: Riamus2]
Judgebot Offline
Pikka bird

Registered: 09/11/12
Posts: 18
Originally Posted By: Riamus2
You know that the things people can do aren't limited to just that computer, right? If you're on a home network, they can gain access to other computers on the network. They can also easily get you banned from the IRC network and can send out viruses to people from your computer. They can also very easily set your computer up (outside of mIRC) to do things it shouldn't, such as passing on viruses or doing DDOS attacks on places. You are attempting to make it possible for someone to do anything they want from your computer as if they were sitting at the computer itself. This goes beyond whether you have a backup on that computer. It is just a really bad idea.


The bot is used on TwitchTv, and I have spoken and know the twitch admins and they know me and the people who the bot will first be used for.

Top