mIRC Home    About    Download    Register    News    Help

Print Thread
#258634 04/08/16 10:30 PM
Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
I'm making a chat bot for a site that has a set limit on the amount of messages you can send.
The limit is 100 message per 30 seconds.

I want the bot to store additional messages sent in a buffer and write them out,
so it does not exceed 100 messages within 30 seconds.

What would be the best way to do that?

Thanks
Toast


Life is potato.
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Code:
alias addbuf {
  window -h @buffer
  aline @buffer $1-
  if (!$timer(buffer)) flushbuffer
}

alias flushbuffer {
  if ($line(@buffer,1)) {
    $v1
    dline @buffer 1
    .timerbuffer -m 1 310 flushbuffer
  }
  else window -c @buffer
}

All you need to do is to add "addbuf" in front of the commands you way to add to the buffer. It will automatically spam the first line instantly, and rest with 350 ms delay (100 = 35 seconds, just to be safe) after that.

It adds all of them to the same buffer, no matter what the target channel/whatever is. It wouldn't be hard to create a buffer for each channel.

Here's an example:
Code:
on *:text:!test:#: {
  var %x = 20
  while (%x) {
    addbuf msg # TEST: line %x
    dec %x
  }
}


Just to note: it has no limits on what commands it'll execute, so you don't want to let random people add anything to it. You can get around that by making sure the command always starts with "msg #" or something.

Dazuz #258636 05/08/16 01:48 AM
Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
Thank you so much for your time and effort, I'm pretty new to the mIRC scripting language and I don't really understand much of the code you provided me with. So I just wanna make sure that I understand the system.

So if let's say the bot is connected to 100+ channels, and every channel requests 10 messages per 10 seconds, this system wouldn't have a problem with that? Like it would output the commands to the right channels and so on

Also does it just add the commands to a queue and output the next command in queue once every 350ms? (which would result in later commands to get a huge delay, but im fine with that)

Again thank you so much

- Toast

Last edited by TillableToast; 05/08/16 02:15 AM.

Life is potato.
Dazuz #258637 05/08/16 02:06 AM
Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
I just tested the system by making the bot spam multiple channels with the code you gave me. Resulted in a chat ban so not sure if the delay is high enough.

Code:
.timerbuffer -m 1 310 flushbuffer


Is 310 the amount of miliseconds in between messages?


Life is potato.
Dazuz #258638 05/08/16 02:11 AM
Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
Further testing shows that the code you provided skips some commands. Like the buffer doesn't store the messages properly.


Life is potato.
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Thought I changed the delay to 350, but apparently it's 310. Try changing it to 350. I recommend you look at the timer help section (/help /timer), but -m indicates that the delay is in milliseconds.

Is the 100 messages in 30 seconds limit channel specific or shared between all channels?

The /addbuf command adds whatever commands you give it to the end of the buffer, and then it spams them one by one with 310 ms interval.

There is absolutely nothing in the code that would make it skip commands. Well, other than lines that only contain "0" or "$false", in which case the script would stop completely. There is a tiny chance that the window buffer is full, but even the minimum window buffer is 500 lines, so I doubt it's that. If you want to be sure, you can replace "window -h @buffer" with "window -hj5000 @buffer".

The way it works is that it looks at the line #1 in the window, executes it and removes it, which means that #2 becomes #1 and so on. If there are any lines in the list, it will execute them.

Last edited by Dazuz; 05/08/16 02:23 AM.
Dazuz #258640 05/08/16 02:26 AM
Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
Thank you for the fast reply!
Im gonna have to wait till the ban is lifted to try it out. I do now a bit about timers, just wanted to make sure laugh

The message limit is per connection (IP address)
So a more permanent solution would be to change VPS servers on reached message limit, though I do not think you would wanna spend the time helping me with that system wink

Thank you
- Toast

Last edited by TillableToast; 05/08/16 02:28 AM.

Life is potato.
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Since it's per connection, the way the script works is perfect for it.

Technically if you wanted to make it more complex, you could allow it to spam commands faster when it was nowhere near the limit. The problem with that is that you have no way to know how the limit exactly works. At what point the server resets the count or decreases it, or at what # the server is at.

Since you got banned while using 310 ms delay, try increasing it. 100x310 is 31 seconds, so it's quite close to the limit.


EDIT: you can test out the buffer with echo commands.
Code:
//addbuf echo -a line | addbuf echo -a line another line | addbuf echo -a line third line | addbuf echo -a line and so on

Last edited by Dazuz; 05/08/16 02:34 AM.
Dazuz #258642 05/08/16 02:35 AM
Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
Quote:
Technically if you wanted to make it more complex, you could allow it to spam commands faster when it was nowhere near the limit. The problem with that is that you have no way to know how the limit exactly works. At what point the server resets the count or decreases it, or at what # the server is at.


That is true, though as I said I would have to come up with a system that would automatically change the connection when it reaches the limit to work around the limit.

Though this comes with a lot of difficulties like how to store data etc.

This would be to prevent any delay at all

Last edited by TillableToast; 05/08/16 02:37 AM.

Life is potato.
Dazuz #258643 05/08/16 02:42 AM
Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
Also does this buffer store the channels it has to send the commands to properly?


Life is potato.
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
It stores the command you give it. It only queues the commands you'd normally send the server straight away. It doesn't change the commands at all. If you give it "msg #mychannel ohai!" command, it'll execute exactly that command. The only difference between this and the normal way you'd send messages, is that you add "addbuf" in front of the commands.


It wouldn't be hard to make it alternate between two or more connections.
Code:
alias flushbuffer {
  if ($line(@buffer,1)) {
    inc %flushbuffer
    if (!$scon(%flushbuffer)) %flushbuffer = 1
    scid %flushbuffer $v1
    dline @buffer 1
    .timerbuffer -m 1 $round($calc(350 /$scon(0)),0) flushbuffer
  }
  else window -c @buffer
}

That would alternate between all of the connections in specific order from 1 to whatever. It will also divide the 350 ms between the number of connections. It doesn't check for anything though, if you're connected to some other network, it would still try to send a command there too. If disconnected, it would still try to send a command.

It wouldn't be too hard to make it check for those things, but I'm lazy. You can use $scon(<number>).status to check if it's connected, and $scon(<number>).network to what network it's connected.

Dazuz #258645 05/08/16 03:14 AM
Joined: May 2016
Posts: 50
T
Babel fish
OP Offline
Babel fish
T
Joined: May 2016
Posts: 50
Wait so how does the $scon work? As I said it's per IP address so it would have to change the IP address as well.


Life is potato.
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
/help $scon

You can use it to list all of the connections to IRC servers the mIRC you use it in has, and information about them.

$scon(0) returns the number of connections, $scon(1) returns the connection ID of the first connection and $scon(1).status returns $status of the first connection.


Link Copied to Clipboard