mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Update to new Knub 30 beta. Code clean-up.
This commit is contained in:
parent
5d579446c5
commit
2f470dc37a
299 changed files with 1075 additions and 1004 deletions
|
@ -1,4 +1,4 @@
|
|||
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { ConfigSchema, MuteOptions, MutesPluginType } from "./types";
|
||||
import { CasesPlugin } from "../Cases/CasesPlugin";
|
||||
import { GuildMutes } from "../../data/GuildMutes";
|
||||
|
@ -55,7 +55,7 @@ const EXPIRED_MUTE_CHECK_INTERVAL = 60 * 1000;
|
|||
let FIRST_CHECK_TIME = Date.now();
|
||||
const FIRST_CHECK_INCREMENT = 5 * 1000;
|
||||
|
||||
export const MutesPlugin = zeppelinPlugin<MutesPluginType>()("mutes", {
|
||||
export const MutesPlugin = zeppelinGuildPlugin<MutesPluginType>()("mutes", {
|
||||
showInDocs: true,
|
||||
info: {
|
||||
prettyName: "Mutes",
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { command } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
import { mutesCmd } from "../types";
|
||||
import { User } from "eris";
|
||||
import { sendSuccessMessage } from "../../../pluginUtils";
|
||||
|
||||
export const ClearBannedMutesCmd = command<MutesPluginType>()({
|
||||
export const ClearBannedMutesCmd = mutesCmd({
|
||||
trigger: "clear_banned_mutes",
|
||||
permission: "can_cleanup",
|
||||
description: "Clear dangling mutes for members who have been banned",
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { command } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
import { mutesCmd } from "../types";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
|
||||
export const ClearMutesCmd = command<MutesPluginType>()({
|
||||
export const ClearMutesCmd = mutesCmd({
|
||||
trigger: "clear_mutes",
|
||||
permission: "can_cleanup",
|
||||
description: "Clear dangling mute records from the bot. Be careful not to clear valid mutes.",
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import { command } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
import { mutesCmd } from "../types";
|
||||
import { sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { resolveMember } from "../../../utils";
|
||||
|
||||
export const ClearMutesWithoutRoleCmd = command<MutesPluginType>()({
|
||||
export const ClearMutesWithoutRoleCmd = mutesCmd({
|
||||
trigger: "clear_mutes_without_role",
|
||||
permission: "can_cleanup",
|
||||
description: "Clear dangling mutes for members whose mute role was removed by other means",
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import { command } from "knub";
|
||||
import { IMuteWithDetails, MutesPluginType } from "../types";
|
||||
import { IMuteWithDetails, mutesCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { DBDateFormat, isFullMessage, MINUTES, noop, resolveMember } from "../../../utils";
|
||||
import moment from "moment-timezone";
|
||||
import { humanizeDurationShort } from "../../../humanizeDurationShort";
|
||||
import { getBaseUrl } from "../../../pluginUtils";
|
||||
|
||||
export const MutesCmd = command<MutesPluginType>()({
|
||||
export const MutesCmd = mutesCmd({
|
||||
trigger: "mutes",
|
||||
permission: "can_view_list",
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
import { eventListener } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
import { mutesEvt } from "../types";
|
||||
|
||||
/**
|
||||
* Clear active mute from the member if the member is banned
|
||||
*/
|
||||
export const ClearActiveMuteOnMemberBanEvt = eventListener<MutesPluginType>()(
|
||||
"guildBanAdd",
|
||||
async ({ pluginData, args: { user } }) => {
|
||||
const mute = await pluginData.state.mutes.findExistingMuteForUserId(user.id);
|
||||
if (mute) {
|
||||
pluginData.state.mutes.clear(user.id);
|
||||
}
|
||||
},
|
||||
);
|
||||
export const ClearActiveMuteOnMemberBanEvt = mutesEvt("guildBanAdd", async ({ pluginData, args: { user } }) => {
|
||||
const mute = await pluginData.state.mutes.findExistingMuteForUserId(user.id);
|
||||
if (mute) {
|
||||
pluginData.state.mutes.clear(user.id);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import { eventListener } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
import { mutesEvt } from "../types";
|
||||
import { memberHasMutedRole } from "../functions/memberHasMutedRole";
|
||||
|
||||
/**
|
||||
* Clear active mute if the mute role is removed manually
|
||||
*/
|
||||
export const ClearActiveMuteOnRoleRemovalEvt = eventListener<MutesPluginType>()(
|
||||
export const ClearActiveMuteOnRoleRemovalEvt = mutesEvt(
|
||||
"guildMemberUpdate",
|
||||
async ({ pluginData, args: { member } }) => {
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
|
|
|
@ -1,25 +1,21 @@
|
|||
import { eventListener } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import { stripObjectToScalars } from "src/utils";
|
||||
import { mutesEvt } from "../types";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
|
||||
/**
|
||||
* Reapply active mutes on join
|
||||
*/
|
||||
export const ReapplyActiveMuteOnJoinEvt = eventListener<MutesPluginType>()(
|
||||
"guildMemberAdd",
|
||||
async ({ pluginData, args: { member } }) => {
|
||||
const mute = await pluginData.state.mutes.findExistingMuteForUserId(member.id);
|
||||
if (mute) {
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
export const ReapplyActiveMuteOnJoinEvt = mutesEvt("guildMemberAdd", async ({ pluginData, args: { member } }) => {
|
||||
const mute = await pluginData.state.mutes.findExistingMuteForUserId(member.id);
|
||||
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();
|
||||
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"]),
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_MUTE_REJOIN, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { resolveMember, stripObjectToScalars, UnknownUser } from "../../../utils";
|
||||
|
||||
export async function clearExpiredMutes(pluginData: PluginData<MutesPluginType>) {
|
||||
export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginType>) {
|
||||
const expiredMutes = await pluginData.state.mutes.getExpiredMutes();
|
||||
for (const mute of expiredMutes) {
|
||||
const member = await resolveMember(pluginData.client, pluginData.guild, mute.user_id);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Member } from "eris";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
|
||||
export function memberHasMutedRole(pluginData: PluginData<MutesPluginType>, member: Member) {
|
||||
export function memberHasMutedRole(pluginData: GuildPluginData<MutesPluginType>, member: Member) {
|
||||
return member.roles.includes(pluginData.config.get().mute_role);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { MuteOptions, MutesPluginType } from "../types";
|
||||
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
|
@ -15,10 +15,10 @@ import { TextChannel, User } from "eris";
|
|||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { Case } from "src/data/entities/Case";
|
||||
import { Case } from "../../../data/entities/Case";
|
||||
|
||||
export async function muteUser(
|
||||
pluginData: PluginData<MutesPluginType>,
|
||||
pluginData: GuildPluginData<MutesPluginType>,
|
||||
userId: string,
|
||||
muteTime: number = null,
|
||||
reason: string = null,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { MutesPluginType, UnmuteResult } from "../types";
|
||||
import { CaseArgs } from "../../Cases/types";
|
||||
import { resolveUser, stripObjectToScalars, resolveMember } from "../../../utils";
|
||||
|
@ -9,7 +9,7 @@ import { CaseTypes } from "../../../data/CaseTypes";
|
|||
import { LogType } from "../../../data/LogType";
|
||||
|
||||
export async function unmuteUser(
|
||||
pluginData: PluginData<MutesPluginType>,
|
||||
pluginData: GuildPluginData<MutesPluginType>,
|
||||
userId: string,
|
||||
unmuteTime: number = null,
|
||||
caseArgs: Partial<CaseArgs> = {},
|
||||
|
|
|
@ -3,7 +3,7 @@ import { tNullable, UserNotificationMethod, UserNotificationResult } from "../..
|
|||
import { Mute } from "../../data/entities/Mute";
|
||||
import { Member } from "eris";
|
||||
import { Case } from "../../data/entities/Case";
|
||||
import { BasePluginType } from "knub";
|
||||
import { BasePluginType, guildCommand, guildEventListener } from "knub";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { GuildCases } from "../../data/GuildCases";
|
||||
import { GuildArchives } from "../../data/GuildArchives";
|
||||
|
@ -60,3 +60,6 @@ export interface MuteOptions {
|
|||
caseArgs?: Partial<CaseArgs>;
|
||||
contactMethods?: UserNotificationMethod[];
|
||||
}
|
||||
|
||||
export const mutesCmd = guildCommand<MutesPluginType>();
|
||||
export const mutesEvt = guildEventListener<MutesPluginType>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue