vdeville / twitch-bot

Framework/Library to create Twitch bot using PHP and module system. Easily create your own module with your own features
https://mythevalentinus.github.io/twitch-bot-docs/en/
GNU General Public License v3.0
7 stars 0 forks source link

Commands Module Delay Issue #11

Open mahony0 opened 5 years ago

mahony0 commented 5 years ago

https://github.com/MyTheValentinus/twitch-bot/blob/6063287cae29ab3e1f00bc1c220ebe10487b6722/modules/commands/Commands.php#L95

on this line, $this->lastCommands[$cmd] is not returning any result because it needs to be indexed with $command->getCommand() keys, not $cmd.

If you can approve this is a bug, I can send PR.

vdeville commented 5 years ago

Do you see this line https://github.com/MyTheValentinus/twitch-bot/blob/6063287cae29ab3e1f00bc1c220ebe10487b6722/modules/commands/Commands.php#L121 ? I think is what you mention ?

vdeville commented 5 years ago

And this https://github.com/MyTheValentinus/twitch-bot/blob/6063287cae29ab3e1f00bc1c220ebe10487b6722/modules/commands/Commands.php#L93

mahony0 commented 5 years ago

Yes, this line gives $command->getCommand() as key: https://github.com/MyTheValentinus/twitch-bot/blob/6063287cae29ab3e1f00bc1c220ebe10487b6722/modules/commands/Commands.php#L121

but this line checks $this->getRealCommand($command->getCommand()) as key: https://github.com/MyTheValentinus/twitch-bot/blob/6063287cae29ab3e1f00bc1c220ebe10487b6722/modules/commands/Commands.php#L95

so, as getCommand() and getRealCommand($command->getCommand()) not returning same results, delaying is not working as intended. We tested and there's no delay on sending commands for viewers. All viewers can send command without delay with current code.

vdeville commented 5 years ago

Hmmm stange, this module work on my channel, the only possible bug is line 121 i think, need to get real command not only get command, in case of alias command, the user can spam an alias. I need to debug, is old code ^^

mahony0 commented 5 years ago

Sure, I made it work by applying these changes:

/*
 * line: 93
 */
$cmd = $command->getCommand();

if (isset($this->lastCommands[$cmd])) {
    $lastUsedTime = $this->lastCommands[$cmd];
} else {
    $lastUsedTime = time() - $this->delay;
}

// .....

/*
 * line: 121
 */
$this->lastCommands[$cmd] = time();