Fix rejoin mutes not working
This commit is contained in:
parent
94870ef85d
commit
59ef2e6fec
3 changed files with 41 additions and 0 deletions
|
@ -15,6 +15,8 @@ import { muteUser } from "./functions/muteUser";
|
|||
import { unmuteUser } from "./functions/unmuteUser";
|
||||
import { CaseArgs } from "../Cases/types";
|
||||
import { Member } from "eris";
|
||||
import { ClearActiveMuteOnMemberBanEvt } from "./events/ClearActiveMuteOnMemberBanEvt";
|
||||
import { ReapplyActiveMuteOnJoinEvt } from "./events/ReapplyActiveMuteOnJoinEvt";
|
||||
|
||||
const defaultOptions = {
|
||||
config: {
|
||||
|
@ -70,6 +72,8 @@ export const MutesPlugin = zeppelinPlugin<MutesPluginType>()("mutes", {
|
|||
// prettier-ignore
|
||||
events: [
|
||||
ClearActiveMuteOnRoleRemovalEvt,
|
||||
ClearActiveMuteOnMemberBanEvt,
|
||||
ReapplyActiveMuteOnJoinEvt,
|
||||
],
|
||||
|
||||
public: {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { eventListener } from "knub";
|
||||
import { MutesPluginType } 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);
|
||||
}
|
||||
},
|
||||
);
|
|
@ -0,0 +1,22 @@
|
|||
import { eventListener } from "knub";
|
||||
import { MutesPluginType } from "../types";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import { stripObjectToScalars } from "src/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;
|
||||
await member.addRole(muteRole);
|
||||
|
||||
pluginData.state.serverLogs.log(LogType.MEMBER_MUTE_REJOIN, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
Loading…
Add table
Reference in a new issue