mIRC Home    About    Download    Register    News    Help

Print Thread
Run scripts from a different file #239582 09/11/12 07:47 AM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
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.

Re: Run scripts from a different file [Re: Judgebot] #239584 09/11/12 11:15 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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
Re: Run scripts from a different file [Re: Riamus2] #239585 09/11/12 03:06 PM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
Posts: 18
So what would the code be like?

$read C:\file.text ?

Re: Run scripts from a different file [Re: Judgebot] #239590 09/11/12 06:07 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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.

Last edited by Riamus2; 09/11/12 06:22 PM.

Invision Support
#Invision on irc.irchighway.net
Re: Run scripts from a different file [Re: Riamus2] #239593 09/11/12 06:59 PM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
Posts: 18
OK I will test this now.

Re: Run scripts from a different file [Re: Judgebot] #239602 09/11/12 09:04 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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.

Re: Run scripts from a different file [Re: Horstl] #239605 10/11/12 12:29 AM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
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?

Re: Run scripts from a different file [Re: Judgebot] #239611 10/11/12 11:42 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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).

Re: Run scripts from a different file [Re: Horstl] #239612 10/11/12 12:33 PM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
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?

Re: Run scripts from a different file [Re: Judgebot] #239639 12/11/12 04:13 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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?

Re: Run scripts from a different file [Re: Horstl] #239647 12/11/12 03:59 PM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
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.

Last edited by Judgebot; 12/11/12 04:02 PM.
Re: Run scripts from a different file [Re: Judgebot] #239654 12/11/12 11:24 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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
Re: Run scripts from a different file [Re: Riamus2] #239674 13/11/12 12:49 PM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
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
 }

Re: Run scripts from a different file [Re: Judgebot] #239683 13/11/12 11:05 PM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
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.

Re: Run scripts from a different file [Re: hixxy] #239693 14/11/12 03:48 PM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
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

Re: Run scripts from a different file [Re: Judgebot] #239694 14/11/12 06:07 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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.

Last edited by sparta; 14/11/12 06:08 PM.

if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: Run scripts from a different file [Re: sparta] #239698 14/11/12 11:57 PM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
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

Re: Run scripts from a different file [Re: Judgebot] #239707 15/11/12 11:19 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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
Re: Run scripts from a different file [Re: Riamus2] #239708 15/11/12 08:25 PM
Joined: Nov 2012
Posts: 18
J
Judgebot Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Nov 2012
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.