mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Fixed ban command
This commit is contained in:
parent
2874a0cf83
commit
a49bb81ce1
1 changed files with 63 additions and 63 deletions
|
@ -60,77 +60,77 @@ export async function actualBanCmd(
|
||||||
} else {
|
} else {
|
||||||
forceban = true;
|
forceban = true;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
// Abort if trying to ban user indefinitely if they are already banned indefinitely
|
||||||
|
if (!existingTempban && !time) {
|
||||||
|
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `User is already banned indefinitely.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Abort if trying to ban user indefinitely if they are already banned indefinitely
|
// Ask the mod if we should update the existing ban
|
||||||
if (!existingTempban && !time) {
|
const reply = await waitForButtonConfirm(
|
||||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(context, `User is already banned indefinitely.`);
|
context,
|
||||||
return;
|
{ content: "Failed to message the user. Log the warning anyway?" },
|
||||||
}
|
{ confirmText: "Yes", cancelText: "No", restrictToId: author.id },
|
||||||
|
);
|
||||||
|
|
||||||
// Ask the mod if we should update the existing ban
|
if (!reply) {
|
||||||
const reply = await waitForButtonConfirm(
|
pluginData
|
||||||
context,
|
.getPlugin(CommonPlugin)
|
||||||
{ content: "Failed to message the user. Log the warning anyway?" },
|
.sendErrorMessage(context, "User already banned, update cancelled by moderator");
|
||||||
{ confirmText: "Yes", cancelText: "No", restrictToId: author.id },
|
lock.unlock();
|
||||||
);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update or add new tempban / remove old tempban
|
||||||
|
if (time && time > 0) {
|
||||||
|
if (existingTempban) {
|
||||||
|
await pluginData.state.tempbans.updateExpiryTime(user.id, time, mod.id);
|
||||||
|
} else {
|
||||||
|
await pluginData.state.tempbans.addTempban(user.id, time, mod.id);
|
||||||
|
}
|
||||||
|
const tempban = (await pluginData.state.tempbans.findExistingTempbanForUserId(user.id))!;
|
||||||
|
registerExpiringTempban(tempban);
|
||||||
|
} else if (existingTempban) {
|
||||||
|
clearExpiringTempban(existingTempban);
|
||||||
|
pluginData.state.tempbans.clear(user.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new case for the updated ban since we never stored the old case id and log the action
|
||||||
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||||
|
const createdCase = await casesPlugin.createCase({
|
||||||
|
modId: mod.id,
|
||||||
|
type: CaseTypes.Ban,
|
||||||
|
userId: user.id,
|
||||||
|
reason: formattedReason,
|
||||||
|
noteDetails: [`Ban updated to ${time ? humanizeDuration(time) : "indefinite"}`],
|
||||||
|
});
|
||||||
|
if (time) {
|
||||||
|
pluginData.getPlugin(LogsPlugin).logMemberTimedBan({
|
||||||
|
mod: mod.user,
|
||||||
|
user,
|
||||||
|
caseNumber: createdCase.case_number,
|
||||||
|
reason: formattedReason,
|
||||||
|
banTime: humanizeDuration(time),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
pluginData.getPlugin(LogsPlugin).logMemberBan({
|
||||||
|
mod: mod.user,
|
||||||
|
user,
|
||||||
|
caseNumber: createdCase.case_number,
|
||||||
|
reason: formattedReason,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!reply) {
|
|
||||||
pluginData
|
pluginData
|
||||||
.getPlugin(CommonPlugin)
|
.getPlugin(CommonPlugin)
|
||||||
.sendErrorMessage(context, "User already banned, update cancelled by moderator");
|
.sendSuccessMessage(
|
||||||
|
context,
|
||||||
|
`Ban updated to ${time ? "expire in " + humanizeDuration(time) + " from now" : "indefinite"}`,
|
||||||
|
);
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update or add new tempban / remove old tempban
|
|
||||||
if (time && time > 0) {
|
|
||||||
if (existingTempban) {
|
|
||||||
await pluginData.state.tempbans.updateExpiryTime(user.id, time, mod.id);
|
|
||||||
} else {
|
|
||||||
await pluginData.state.tempbans.addTempban(user.id, time, mod.id);
|
|
||||||
}
|
|
||||||
const tempban = (await pluginData.state.tempbans.findExistingTempbanForUserId(user.id))!;
|
|
||||||
registerExpiringTempban(tempban);
|
|
||||||
} else if (existingTempban) {
|
|
||||||
clearExpiringTempban(existingTempban);
|
|
||||||
pluginData.state.tempbans.clear(user.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new case for the updated ban since we never stored the old case id and log the action
|
|
||||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
|
||||||
const createdCase = await casesPlugin.createCase({
|
|
||||||
modId: mod.id,
|
|
||||||
type: CaseTypes.Ban,
|
|
||||||
userId: user.id,
|
|
||||||
reason: formattedReason,
|
|
||||||
noteDetails: [`Ban updated to ${time ? humanizeDuration(time) : "indefinite"}`],
|
|
||||||
});
|
|
||||||
if (time) {
|
|
||||||
pluginData.getPlugin(LogsPlugin).logMemberTimedBan({
|
|
||||||
mod: mod.user,
|
|
||||||
user,
|
|
||||||
caseNumber: createdCase.case_number,
|
|
||||||
reason: formattedReason,
|
|
||||||
banTime: humanizeDuration(time),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
pluginData.getPlugin(LogsPlugin).logMemberBan({
|
|
||||||
mod: mod.user,
|
|
||||||
user,
|
|
||||||
caseNumber: createdCase.case_number,
|
|
||||||
reason: formattedReason,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pluginData
|
|
||||||
.getPlugin(CommonPlugin)
|
|
||||||
.sendSuccessMessage(
|
|
||||||
context,
|
|
||||||
`Ban updated to ${time ? "expire in " + humanizeDuration(time) + " from now" : "indefinite"}`,
|
|
||||||
);
|
|
||||||
lock.unlock();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we're allowed to ban this member if they are on the server
|
// Make sure we're allowed to ban this member if they are on the server
|
||||||
|
|
Loading…
Add table
Reference in a new issue