3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 20:35:02 +00:00

Migrate Slowmode to new Plugin structure

This commit is contained in:
Dark 2020-07-23 00:25:40 +02:00
parent ebcb28261b
commit b4b8680431
14 changed files with 538 additions and 0 deletions

View file

@ -0,0 +1,28 @@
import { GuildChannel, TextChannel } from "eris";
import { PluginData } from "knub";
import { SlowmodePluginType } from "../types";
import { clearBotSlowmodeFromUserId } from "./clearBotSlowmodeFromUserId";
export async function disableBotSlowmodeForChannel(
pluginData: PluginData<SlowmodePluginType>,
channel: GuildChannel & TextChannel,
) {
// Disable channel slowmode
await pluginData.state.slowmodes.deleteChannelSlowmode(channel.id);
// Remove currently applied slowmodes
const users = await pluginData.state.slowmodes.getChannelSlowmodeUsers(channel.id);
const failedUsers = [];
for (const slowmodeUser of users) {
try {
await clearBotSlowmodeFromUserId(pluginData, channel, slowmodeUser.user_id);
} catch (e) {
// Removing the slowmode failed. Record this so the permissions can be changed manually, and remove the database entry.
failedUsers.push(slowmodeUser.user_id);
await pluginData.state.slowmodes.clearSlowmodeUser(channel.id, slowmodeUser.user_id);
}
}
return { failedUsers };
}