mIRC Home    About    Download    Register    News    Help

Print Thread
Seperate commands for different channels in txt #247023 19/07/14 01:48 AM
Joined: Jun 2014
Posts: 14
J
jbgrw Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Jun 2014
Posts: 14
So I found this script on the forums but it bunches in all commands into one big mess on the txt file without separating them into the channel they work on.
Code:
on $4:text:/^!add !?(\S+)/iS:#:{
  writeini commands.ini # $regml(1) $$3-
  msg # $nick - The command $$2 has been added.
  var %text $read(command.txt,1)
  if %text == $null {
    var %line current commands:  $+ , ! $+ $regml(1)
  }
  else {
    var %line %text ! $+ $regml(1)
  }

  write -l1 command.txt %line
}


Code:
on 4:TEXT:!commands:#: {
msg # Commands are: $read(commands.txt)
}

I could not figure out how to separate them because I'm terrible.
I need it so that when you do !commands it only shows the commands that were made on that channel.

Last edited by jbgrw; 19/07/14 01:55 AM.
Re: Seperate commands for different channels in txt [Re: jbgrw] #247025 19/07/14 07:43 AM
Joined: Jul 2014
Posts: 48
A
AeonPsych Offline
Ameglian cow
Offline
Ameglian cow
A
Joined: Jul 2014
Posts: 48
I'm a noob at mirc combined with twitch chat bot scripting, but I am going to take a shot at helping you out, since I used to do basic software programming a few years ago.


However you store the commands, you want to store them per channel. For example, I am trying to get my chat bot operable in multiple channels, and so far, I am able to have a working bot in my channel and have very basic useability in a test channel I created. What I can do in the test channel is use all of the static commands/variables I have coded into the script/bot, and also some dynamic text only commands. Long story short, I can add a new command in the test channel as long as it is a command that only responds with text. (does no functions, etc.)
It is currently setup that it stores the newly created command into a text file that it also reads the command from. In this text file, the commands are organized by channel names as follow:
[#originalchannelname]
command1=(text to respond with)
command2=(text to respond with)

[#testchannelname]
command1=(text to respond with)
command2=(text to respond with)


etc.

When reading from the file, depending on where the command was accessed (original channel, or test), it will pull that respective command.


If you already have the commands being stored this way, then you just need to read from the text file for the commands only listed for the channel calling them.





If I'm not mistaken, if you already have it working where commands are already unique to a channel, reading the text file in the same way you access the commands should only return the channel specific commands.
If not, maybe I helped by giving you some stuff to think about. I would try and help more, but again, I am a noob to this mirc/irc/twitch/bot/script stuff, and am trying to learn how to do virtually the same you are trying to do atm.

Last edited by AeonPsych; 19/07/14 07:44 AM.
Re: Seperate commands for different channels in txt [Re: AeonPsych] #247049 20/07/14 12:04 AM
Joined: Jun 2014
Posts: 14
J
jbgrw Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Jun 2014
Posts: 14
I've tried replacing
Code:
var %line current commands: $+ , ! $+ $regml(1)

with
Code:
 var %line # $+ , ! $+ $regml(1)

But that doesn't work

Re: Seperate commands for different channels in txt [Re: jbgrw] #247051 20/07/14 01:16 AM
Joined: Jul 2014
Posts: 48
A
AeonPsych Offline
Ameglian cow
Offline
Ameglian cow
A
Joined: Jul 2014
Posts: 48
well, this part of your code should be storing the commands per channel:
Code:
writeini commands.ini # $regml(1) $$3-


I'm not sure what else you have going on in the on add command, as when I have my script write new commands to text file, I have the on trigger, a check for isop, and then the write ini code. The write ini code is exactly the same as you have. That is all I have in my on add code block.
Have you verified that the commands are being stored per channel?


I haven't quite figured out what everything stands for in mirc script language, but if I'm not mistaken, when writing the new command, the # designates the specific channel it is being added from/to, the $regml(1) designates the name of the command, and $ss3- designates the text for the command?

if so, when reading back from the text file, you will want to designate that you are reading from channel #, and then also the name of the command $regml(1).




So far I have not yet gotten into coding iterating over all commands for channel to return everything stored for that channel, but if you are simply just looking for a !commands command where it will just return the commands per your channel, store a commandname in the text that returns the commands for your channel. Then, when you add a new command, make sure you either manually add the new command to the list, or code into your addcomm command that the command name is also written to the end of your commandname command in the text.

At least this is how I would do it until figuring out a way to iterate through the text successfully, but honestly, that seems like a lot more code would be required then the benefits. Maybe I'm just thinking about the logic wrong, but we will see.




The code you have to read the file:
Code:
on 4:TEXT:!commands:#: {
msg # Commands are: $read(commands.txt)
}

Looks like it returns everything in the commands.text file? Even the channel names, command names, and command text, right?
If so, it is because you are only simply reading the text file, not designating a channel to read from.

Last edited by AeonPsych; 20/07/14 01:19 AM.
Re: Seperate commands for different channels in txt [Re: AeonPsych] #247054 20/07/14 02:39 AM
Joined: Jun 2014
Posts: 14
J
jbgrw Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Jun 2014
Posts: 14
ok so when I add commands doing
Code:
  write command2.txt # $regml(1)

It lists like
#channel test1
#channel test2

And I don't know how to make it so it reads just the command names and not everything

Re: Seperate commands for different channels in txt [Re: jbgrw] #247055 20/07/14 03:46 AM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Code:
on $4:text:/^!add !?(\S+)/iS:#:{
  writeini commands.ini # $regml(1) $$3-
  msg # $nick - The command $$2 has been added.
}

on 4:TEXT:!commands:#: {
  var %i 1 | while $ini(commands.ini,#,%i) {
    var %commands %commands $v1
    inc %i
  }
  msg # $iif(%commands,Commands are: %commands,No commands available)
}

Untested.

Re: Seperate commands for different channels in txt [Re: blessing] #247056 20/07/14 03:53 AM
Joined: Jul 2014
Posts: 48
A
AeonPsych Offline
Ameglian cow
Offline
Ameglian cow
A
Joined: Jul 2014
Posts: 48
that looks like it would iterate through the text file for what you were looking for. Not sure if it would just return the command names or not, though.


For that, like I said. Without iterating through the file, juts store the commands into a command.
#channel commands=These are the commands for my channel: !command1, !command2, !command3, etc.

when you call !commands the bot would reply:
bot:These are the commands for my channel: !command1, !command2, !command3, etc.


That's assuming your write command, and read command code is good.

Re: Seperate commands for different channels in txt [Re: blessing] #247057 20/07/14 03:59 AM
Joined: Jun 2014
Posts: 14
J
jbgrw Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Jun 2014
Posts: 14
Many thanks! Very appreciated!
works perfectly