Timeouts: better validations (#438)
* better timeout validations Signed-off-by: GitHub <noreply@github.com> * almeida reviews Signed-off-by: GitHub <noreply@github.com> * better error handling Signed-off-by: GitHub <noreply@github.com> * add missing catch noops Signed-off-by: GitHub <noreply@github.com> --------- Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
parent
047ab872df
commit
8860d4fb22
5 changed files with 49 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
import moment from "moment-timezone";
|
||||
import { MuteTypes } from "../../../data/MuteTypes";
|
||||
import { noop } from "../../../utils.js";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin";
|
||||
import { getTimeoutExpiryTime } from "../functions/getTimeoutExpiryTime";
|
||||
|
@ -12,6 +13,7 @@ export const ReapplyActiveMuteOnJoinEvt = mutesEvt({
|
|||
event: "guildMemberAdd",
|
||||
async listener({ pluginData, args: { member } }) {
|
||||
const mute = await pluginData.state.mutes.findExistingMuteForUserId(member.id);
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
if (!mute) {
|
||||
return;
|
||||
}
|
||||
|
@ -25,11 +27,17 @@ export const ReapplyActiveMuteOnJoinEvt = mutesEvt({
|
|||
if (!member.isCommunicationDisabled()) {
|
||||
const expiresAt = mute.expires_at ? moment.utc(mute.expires_at).valueOf() : null;
|
||||
const timeoutExpiresAt = getTimeoutExpiryTime(expiresAt);
|
||||
await member.disableCommunicationUntil(timeoutExpiresAt);
|
||||
if (member.moderatable) {
|
||||
await member.disableCommunicationUntil(timeoutExpiresAt).catch(noop);
|
||||
} else {
|
||||
logs.logBotAlert({
|
||||
body: `Cannot mute user, specified user is not moderatable`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pluginData.getPlugin(LogsPlugin).logMemberMuteRejoin({
|
||||
logs.logMemberMuteRejoin({
|
||||
member,
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue