ahoys / tunnelerjs

An anti-spam bot for Discord.
MIT License
14 stars 8 forks source link

Mute instead of banning people #2

Closed ZbonaL closed 7 years ago

ZbonaL commented 7 years ago

Hi I'm wondering how to change the ban file to mute people instead.

ahoys commented 7 years ago

Great idea. See the file util/module.inc.ban. I think you can just change target.ban(1); to target.setMute(1); (line 7) as a fast trick. Discord.js setMute documentation

If that doesn't work, try creating a new "muted users" role that has no writing permissions, then instead of target.ban, use target.setRole(["id of the just created role"]).

I'll try to implement a configurable ban/kick/mute switch to the next version of the bot.

ZbonaL commented 7 years ago

Ok cool, I will try that.

ZbonaL commented 7 years ago

I tried both ways couldnt get it to work: this is what i tried for the second part: `.module.exports = () => {

const module = {};

module.execute = (target) => {
    if (target.setRole("316601940068925440")) {
        // var muteRole = setRole("");
        const mute = target.addRole("316601940068925440");
        mute.then((value) => {
            console.log(`${target.user.username} was muted.`);
            return true;
        }).catch((reason) => {
            console.log(`mute of ${target.user.username} failed: ${reason}`);
            return false;
        })
    }
    return false;
};

return module;

}; `

ahoys commented 7 years ago

I tried the following code:

module.exports = () => {

    const module = {};

    module.execute = (target) => {
        const role = target.addRole('316668100361846796');
        role.then(() => {
            console.log(`${target.user.username} was muted.`);
            return true;
        }).catch((reason) => {
            console.log(`Mute of ${target.user.username} failed: ${reason}`);
            return false;
        });
    };

    return module;
};

And it worked for me.

ZbonaL commented 7 years ago

ok thanks for the help

ZbonaL commented 7 years ago

So I found another issue, The issue is that after being unmuted the bot will mute someone as soon as they start typing again.

ahoys commented 7 years ago

That is because the bot thinks the person should still be punished, as it reflects the previous messages of the users to the new message. Easy way to cancel the punishment is to reboot the bot as it has no long-term memory.

However, we can also clear the user log immediately after the punishment has occurred. Try this on tunneler.js, line ~108:

if (Ban.execute(target)) {
  // Ban successful.
  if (!settingsContainer['enable_quiet_mode']) {
    Message.channel.send(`${Strings.util.antispam.success_0}` +
      `${target.user.username}` +
      `${Strings.util.antispam.success_1}`);
    }
  AntiSpam.clearUserHistory(sourceId, Message.author.id);
}

Note the new AntiSpam.clearUserHistory line.

ZbonaL commented 7 years ago

I've tried it but it doesnt seem to be working

ahoys commented 7 years ago

Ok, I researched a bit and got it working.

First of all, there seems to be a bug that needs to be fixed. In module.inc.antispam line 130 module.isSpam = (uId, gId, messageObject, settingsContainer) => { should be: module.isSpam = (gId, uId, messageObject, settingsContainer) => {.

Second, you need to add return true; to module.inc.ban, line 14. Currently it can't reach the clearUserHistory line we added above as the Ban.execute(target) returns undefined/false.

Hope this helps.

ZbonaL commented 7 years ago

i see

ahoys commented 7 years ago

Hey,

I'm in a progress of creating a refreshed version (0.96) of the bot's first release (0.95). You can already download a working copy from here: https://github.com/ahoys/tunnelerjs/tree/alpha

The refreshed version includes all the features discussed above. See the readme for "Example: muting a user as a punishment".

Make sure to remove the old version of the bot before adding a new one so that there won't be any conflicts. Also, it is a good idea to backup auth.json and settings.json so you don't have to setup everything from the beginning (do not replace the new settings.json entirely as it holds new setting strings).

I'll release a new stable build after I've tested the new version for a few days. I'll inform you if there are any bug fixes / changes that require updating the bot.

ZbonaL commented 7 years ago

ok cool

ZbonaL commented 7 years ago

I know that this was closed but I was wondering if it was possible to make a timed mute. What I mean is when the mute roll is given the a timer starts and after it ends it removes the role. I did play around with setTimeout but it wouldnt work in the mute/ban file because of module.exports, do you know a way to handle that?

ahoys commented 7 years ago

Hey, I investigated and the following seems to do the trick:

const target = Message.member;
setTimeout(() => {
    if (Punish.execute(target, settingsContainer)) {
        // Punish successful.
        if (!settingsContainer['enable_quiet_mode']) {
            Message.channel.send(`${Strings.util.antispam.success_0}` +
                `${target.user.username}` +
                `${Strings.util.antispam.success_1}`);
        }
        AntiSpam.clearUserHistory(sourceId, Message.author.id);
    }
}, 5120);

This goes into tunneler.js.

ZbonaL commented 7 years ago

Thanks

ZbonaL commented 7 years ago

I tried it but it didnt seem to work. const target = Message.member; setTimeout(() => { if (Mute.execute(target)) { // Mute successful. if (!settingsContainer['enable_quiet_mode']) { Message.channel.send(${Strings.util.antispam.success_0}+ ${target.user.username}+ ${Strings.util.antispam.success_1}); } AntiSpam.clearUserHistory(sourceId, Message.author.id); } }, 1000);

ahoys commented 7 years ago

Make sure you have the latest version of the branch (0.9.6). Your code seems to be different from the one I pasted above.

The tweak may have some side-effects, like the bot may attempt to set the role multiple times as the 'to-be-muted' user keeps talking after the bot has decided about the punishment.