mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Turn on strict TS compilation. Fix up and tweak types accordingly.
This commit is contained in:
parent
690955a399
commit
629002b8d9
172 changed files with 720 additions and 534 deletions
|
@ -17,6 +17,7 @@ import { CaseArgs } from "../Cases/types";
|
|||
import { Member } from "eris";
|
||||
import { ClearActiveMuteOnMemberBanEvt } from "./events/ClearActiveMuteOnMemberBanEvt";
|
||||
import { ReapplyActiveMuteOnJoinEvt } from "./events/ReapplyActiveMuteOnJoinEvt";
|
||||
import { mapToPublicFn } from "../../pluginUtils";
|
||||
|
||||
const defaultOptions = {
|
||||
config: {
|
||||
|
@ -82,19 +83,12 @@ export const MutesPlugin = zeppelinGuildPlugin<MutesPluginType>()("mutes", {
|
|||
],
|
||||
|
||||
public: {
|
||||
muteUser(pluginData) {
|
||||
return (userId: string, muteTime: number = null, reason: string = null, muteOptions: MuteOptions = {}) => {
|
||||
return muteUser(pluginData, userId, muteTime, reason, muteOptions);
|
||||
};
|
||||
},
|
||||
unmuteUser(pluginData) {
|
||||
return (userId: string, unmuteTime: number = null, args: Partial<CaseArgs>) => {
|
||||
return unmuteUser(pluginData, userId, unmuteTime, args);
|
||||
};
|
||||
},
|
||||
muteUser: mapToPublicFn(muteUser),
|
||||
unmuteUser: mapToPublicFn(unmuteUser),
|
||||
hasMutedRole(pluginData) {
|
||||
return (member: Member) => {
|
||||
return member.roles.includes(pluginData.config.get().mute_role);
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
return muteRole ? member.roles.includes(muteRole) : false;
|
||||
};
|
||||
},
|
||||
},
|
||||
|
|
|
@ -12,7 +12,7 @@ export const ClearMutesCmd = mutesCmd({
|
|||
},
|
||||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
const failed = [];
|
||||
const failed: string[] = [];
|
||||
for (const id of args.userIds) {
|
||||
const mute = await pluginData.state.mutes.findExistingMuteForUserId(id);
|
||||
if (!mute) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import { DBDateFormat, isFullMessage, MINUTES, noop, resolveMember } from "../..
|
|||
import moment from "moment-timezone";
|
||||
import { humanizeDurationShort } from "../../../humanizeDurationShort";
|
||||
import { getBaseUrl } from "../../../pluginUtils";
|
||||
import { Member } from "eris";
|
||||
|
||||
export const MutesCmd = mutesCmd({
|
||||
trigger: "mutes",
|
||||
|
@ -31,7 +32,7 @@ export const MutesCmd = mutesCmd({
|
|||
let clearReactionsTimeout;
|
||||
const clearReactionsDebounce = 5 * MINUTES;
|
||||
|
||||
let lines = [];
|
||||
let lines: string[] = [];
|
||||
|
||||
// Active, logged mutes
|
||||
const activeMutes = await pluginData.state.mutes.getActiveMutes();
|
||||
|
@ -41,13 +42,13 @@ export const MutesCmd = mutesCmd({
|
|||
if (a.expires_at == null && b.expires_at == null) {
|
||||
return a.created_at > b.created_at ? -1 : 1;
|
||||
}
|
||||
return a.expires_at > b.expires_at ? 1 : -1;
|
||||
return a.expires_at! > b.expires_at! ? 1 : -1;
|
||||
});
|
||||
|
||||
if (args.manual) {
|
||||
// Show only manual mutes (i.e. "Muted" role added without a logged mute)
|
||||
const muteUserIds = new Set(activeMutes.map(m => m.user_id));
|
||||
const manuallyMutedMembers = [];
|
||||
const manuallyMutedMembers: Member[] = [];
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
|
||||
if (muteRole) {
|
||||
|
@ -65,7 +66,7 @@ export const MutesCmd = mutesCmd({
|
|||
} else {
|
||||
// Show filtered active mutes (but not manual mutes)
|
||||
let filteredMutes: IMuteWithDetails[] = activeMutes;
|
||||
let bannedIds: string[] = null;
|
||||
let bannedIds: string[] | null = null;
|
||||
|
||||
// Filter: mute age
|
||||
if (args.age) {
|
||||
|
|
|
@ -10,9 +10,11 @@ export const ReapplyActiveMuteOnJoinEvt = mutesEvt("guildMemberAdd", async ({ pl
|
|||
if (mute) {
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
|
||||
const memberRolesLock = await pluginData.locks.acquire(`member-roles-${member.id}`);
|
||||
await member.addRole(muteRole);
|
||||
memberRolesLock.unlock();
|
||||
if (muteRole) {
|
||||
const memberRolesLock = await pluginData.locks.acquire(`member-roles-${member.id}`);
|
||||
await member.addRole(muteRole);
|
||||
memberRolesLock.unlock();
|
||||
}
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_MUTE_REJOIN, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
|
|
|
@ -10,7 +10,10 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
|
|||
|
||||
if (member) {
|
||||
try {
|
||||
await member.removeRole(pluginData.config.get().mute_role);
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
if (muteRole) {
|
||||
await member.removeRole(muteRole);
|
||||
}
|
||||
} catch (e) {
|
||||
pluginData.state.serverLogs.log(LogType.BOT_ALERT, {
|
||||
body: `Failed to remove mute role from {userMention(member)}`,
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Member } from "eris";
|
|||
import { GuildPluginData } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
|
||||
export function memberHasMutedRole(pluginData: GuildPluginData<MutesPluginType>, member: Member) {
|
||||
return member.roles.includes(pluginData.config.get().mute_role);
|
||||
export function memberHasMutedRole(pluginData: GuildPluginData<MutesPluginType>, member: Member): boolean {
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
return muteRole ? member.roles.includes(muteRole) : false;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
ucfirst,
|
||||
UserNotificationResult,
|
||||
resolveMember,
|
||||
UserNotificationMethod,
|
||||
} from "../../../utils";
|
||||
import { renderTemplate } from "../../../templateFormatter";
|
||||
import { TextChannel, User } from "eris";
|
||||
|
@ -20,8 +21,8 @@ import { Case } from "../../../data/entities/Case";
|
|||
export async function muteUser(
|
||||
pluginData: GuildPluginData<MutesPluginType>,
|
||||
userId: string,
|
||||
muteTime: number = null,
|
||||
reason: string = null,
|
||||
muteTime?: number,
|
||||
reason?: string,
|
||||
muteOptions: MuteOptions = {},
|
||||
) {
|
||||
const lock = await pluginData.locks.acquire(`mute-${userId}`);
|
||||
|
@ -90,7 +91,7 @@ export async function muteUser(
|
|||
}));
|
||||
|
||||
if (muteMessage && user instanceof User) {
|
||||
let contactMethods = [];
|
||||
let contactMethods: UserNotificationMethod[] = [];
|
||||
|
||||
if (muteOptions?.contactMethods) {
|
||||
contactMethods = muteOptions.contactMethods;
|
||||
|
@ -112,18 +113,21 @@ export async function muteUser(
|
|||
|
||||
// Create/update a case
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
let theCase: Case;
|
||||
let theCase: Case | undefined =
|
||||
existingMute && existingMute.case_id ? await pluginData.state.cases.find(existingMute.case_id) : undefined;
|
||||
|
||||
if (existingMute && existingMute.case_id) {
|
||||
if (theCase) {
|
||||
// Update old case
|
||||
// Since mutes can often have multiple notes (extraNotes), we won't post each case note individually,
|
||||
// but instead we'll post the entire case afterwards
|
||||
theCase = await pluginData.state.cases.find(existingMute.case_id);
|
||||
const noteDetails = [`Mute updated to ${muteTime ? timeUntilUnmute : "indefinite"}`];
|
||||
const reasons = [reason, ...(muteOptions.caseArgs?.extraNotes || [])];
|
||||
const reasons = reason ? [reason] : [];
|
||||
if (muteOptions.caseArgs?.extraNotes) {
|
||||
reasons.push(...muteOptions.caseArgs.extraNotes);
|
||||
}
|
||||
for (const noteReason of reasons) {
|
||||
await casesPlugin.createCaseNote({
|
||||
caseId: existingMute.case_id,
|
||||
caseId: existingMute!.case_id,
|
||||
modId: muteOptions.caseArgs?.modId,
|
||||
body: noteReason,
|
||||
noteDetails,
|
||||
|
@ -132,7 +136,7 @@ export async function muteUser(
|
|||
}
|
||||
|
||||
if (muteOptions.caseArgs?.postInCaseLogOverride !== false) {
|
||||
casesPlugin.postCaseToCaseLogChannel(existingMute.case_id);
|
||||
casesPlugin.postCaseToCaseLogChannel(existingMute!.case_id);
|
||||
}
|
||||
} else {
|
||||
// Create new case
|
||||
|
|
|
@ -7,18 +7,20 @@ import humanizeDuration from "humanize-duration";
|
|||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { WithRequiredProps } from "../../../utils/typeUtils";
|
||||
|
||||
export async function unmuteUser(
|
||||
pluginData: GuildPluginData<MutesPluginType>,
|
||||
userId: string,
|
||||
unmuteTime: number = null,
|
||||
unmuteTime?: number,
|
||||
caseArgs: Partial<CaseArgs> = {},
|
||||
): Promise<UnmuteResult> {
|
||||
): Promise<UnmuteResult | null> {
|
||||
const existingMute = await pluginData.state.mutes.findExistingMuteForUserId(userId);
|
||||
const user = await resolveUser(pluginData.client, userId);
|
||||
const member = await resolveMember(pluginData.client, pluginData.guild, userId); // Grab the fresh member so we don't have stale role info
|
||||
const modId = caseArgs.modId || pluginData.client.user.id;
|
||||
|
||||
if (!existingMute && !memberHasMutedRole(pluginData, member)) return;
|
||||
if (!existingMute && member && !memberHasMutedRole(pluginData, member)) return null;
|
||||
|
||||
if (unmuteTime) {
|
||||
// Schedule timed unmute (= just set the mute's duration)
|
||||
|
@ -31,7 +33,7 @@ export async function unmuteUser(
|
|||
// Unmute immediately
|
||||
if (member) {
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
if (member.roles.includes(muteRole)) {
|
||||
if (muteRole && member.roles.includes(muteRole)) {
|
||||
await member.removeRole(muteRole);
|
||||
}
|
||||
} else {
|
||||
|
@ -47,7 +49,7 @@ export async function unmuteUser(
|
|||
const timeUntilUnmute = unmuteTime && humanizeDuration(unmuteTime);
|
||||
|
||||
// Create a case
|
||||
const noteDetails = [];
|
||||
const noteDetails: string[] = [];
|
||||
if (unmuteTime) {
|
||||
noteDetails.push(`Scheduled unmute in ${timeUntilUnmute}`);
|
||||
} else {
|
||||
|
@ -61,13 +63,13 @@ export async function unmuteUser(
|
|||
const createdCase = await casesPlugin.createCase({
|
||||
...caseArgs,
|
||||
userId,
|
||||
modId: caseArgs.modId,
|
||||
modId,
|
||||
type: CaseTypes.Unmute,
|
||||
noteDetails,
|
||||
});
|
||||
|
||||
// Log the action
|
||||
const mod = pluginData.client.users.get(caseArgs.modId);
|
||||
const mod = pluginData.client.users.get(modId);
|
||||
if (unmuteTime) {
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_TIMED_UNMUTE, {
|
||||
mod: stripObjectToScalars(mod),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue