mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
More rework progress, mostly done up to ModActions
This commit is contained in:
parent
52839cc9f3
commit
57893e7f76
38 changed files with 199 additions and 241 deletions
|
@ -1,11 +1,9 @@
|
|||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { CompanionChannelsPluginType, ConfigSchema, TCompanionChannelOpts } from "./types";
|
||||
import { VoiceChannelJoinEvt } from "./events/VoiceChannelJoinEvt";
|
||||
import { VoiceChannelSwitchEvt } from "./events/VoiceChannelSwitchEvt";
|
||||
import { VoiceChannelLeaveEvt } from "./events/VoiceChannelLeaveEvt";
|
||||
import { CompanionChannelsPluginType, ConfigSchema } from "./types";
|
||||
import { trimPluginDescription } from "../../utils";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||
import { CooldownManager } from "knub";
|
||||
import { VoiceStateUpdateEvt } from "./events/VoiceStateUpdateEvt";
|
||||
|
||||
const defaultOptions = {
|
||||
config: {
|
||||
|
@ -29,7 +27,7 @@ export const CompanionChannelsPlugin = zeppelinGuildPlugin<CompanionChannelsPlug
|
|||
configSchema: ConfigSchema,
|
||||
defaultOptions,
|
||||
|
||||
events: [VoiceChannelJoinEvt, VoiceChannelSwitchEvt, VoiceChannelLeaveEvt],
|
||||
events: [VoiceStateUpdateEvt],
|
||||
|
||||
beforeLoad(pluginData) {
|
||||
pluginData.state.errorCooldownManager = new CooldownManager();
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
import { companionChannelsEvt } from "../types";
|
||||
import { handleCompanionPermissions } from "../functions/handleCompanionPermissions";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
|
||||
export const VoiceChannelJoinEvt = companionChannelsEvt({
|
||||
event: "voiceChannelJoin",
|
||||
listener({ pluginData, args: { member, newChannel } }) {
|
||||
handleCompanionPermissions(pluginData, member.id, newChannel);
|
||||
},
|
||||
});
|
|
@ -1,9 +0,0 @@
|
|||
import { companionChannelsEvt } from "../types";
|
||||
import { handleCompanionPermissions } from "../functions/handleCompanionPermissions";
|
||||
|
||||
export const VoiceChannelLeaveEvt = companionChannelsEvt({
|
||||
event: "voiceChannelLeave",
|
||||
listener({ pluginData, args: { member, oldChannel } }) {
|
||||
handleCompanionPermissions(pluginData, member.id, null, oldChannel);
|
||||
},
|
||||
});
|
|
@ -1,9 +0,0 @@
|
|||
import { companionChannelsEvt } from "../types";
|
||||
import { handleCompanionPermissions } from "../functions/handleCompanionPermissions";
|
||||
|
||||
export const VoiceChannelSwitchEvt = companionChannelsEvt({
|
||||
event: "voiceChannelSwitch",
|
||||
listener({ pluginData, args: { member, oldChannel, newChannel } }) {
|
||||
handleCompanionPermissions(pluginData, member.id, newChannel, oldChannel);
|
||||
},
|
||||
});
|
|
@ -0,0 +1,12 @@
|
|||
import { companionChannelsEvt } from "../types";
|
||||
import { handleCompanionPermissions } from "../functions/handleCompanionPermissions";
|
||||
|
||||
export const VoiceStateUpdateEvt = companionChannelsEvt({
|
||||
event: "voiceStateUpdate",
|
||||
listener({ pluginData, args: { oldState, newState } }) {
|
||||
const oldChannel = oldState.channel;
|
||||
const newChannel = newState.channel;
|
||||
const memberId = newState.member ? newState.member.id : oldState.member!.id;
|
||||
handleCompanionPermissions(pluginData, memberId, newChannel, oldChannel);
|
||||
},
|
||||
});
|
|
@ -1,3 +1,4 @@
|
|||
import { StageChannel, VoiceChannel } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
||||
|
||||
|
@ -8,7 +9,7 @@ const defaultCompanionChannelOpts: Partial<TCompanionChannelOpts> = {
|
|||
export async function getCompanionChannelOptsForVoiceChannelId(
|
||||
pluginData: GuildPluginData<CompanionChannelsPluginType>,
|
||||
userId: string,
|
||||
voiceChannel: VoiceChannel,
|
||||
voiceChannel: VoiceChannel | StageChannel,
|
||||
): Promise<TCompanionChannelOpts[]> {
|
||||
const config = await pluginData.config.getMatchingConfig({ userId, channelId: voiceChannel.id });
|
||||
return Object.values(config.entries)
|
||||
|
|
|
@ -5,6 +5,7 @@ import { GuildPluginData } from "knub";
|
|||
import { isDiscordRESTError, MINUTES } from "../../../utils";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { VoiceChannel, TextChannel, Permissions, StageChannel } from "discord.js";
|
||||
|
||||
const ERROR_COOLDOWN_KEY = "errorCooldown";
|
||||
const ERROR_COOLDOWN = 5 * MINUTES;
|
||||
|
@ -12,20 +13,8 @@ const ERROR_COOLDOWN = 5 * MINUTES;
|
|||
export async function handleCompanionPermissions(
|
||||
pluginData: GuildPluginData<CompanionChannelsPluginType>,
|
||||
userId: string,
|
||||
voiceChannel: VoiceChannel,
|
||||
oldChannel?: VoiceChannel,
|
||||
);
|
||||
export async function handleCompanionPermissions(
|
||||
pluginData: GuildPluginData<CompanionChannelsPluginType>,
|
||||
userId: string,
|
||||
voiceChannel: null,
|
||||
oldChannel: VoiceChannel,
|
||||
);
|
||||
export async function handleCompanionPermissions(
|
||||
pluginData: GuildPluginData<CompanionChannelsPluginType>,
|
||||
userId: string,
|
||||
voiceChannel: VoiceChannel | null,
|
||||
oldChannel?: VoiceChannel,
|
||||
voiceChannel: VoiceChannel | StageChannel | null,
|
||||
oldChannel?: VoiceChannel | StageChannel | null,
|
||||
) {
|
||||
if (pluginData.state.errorCooldownManager.isOnCooldown(ERROR_COOLDOWN_KEY)) {
|
||||
return;
|
||||
|
@ -65,18 +54,16 @@ export async function handleCompanionPermissions(
|
|||
for (const channelId of permsToDelete) {
|
||||
const channel = pluginData.guild.channels.cache.get(channelId);
|
||||
if (!channel || !(channel instanceof TextChannel)) continue;
|
||||
await channel.deletePermission(userId, `Companion Channel for ${oldChannel!.id} | User Left`);
|
||||
await channel.permissionOverwrites.get(userId)?.delete(`Companion Channel for ${oldChannel!.id} | User Left`);
|
||||
}
|
||||
|
||||
for (const [channelId, permissions] of permsToSet) {
|
||||
const channel = pluginData.guild.channels.cache.get(channelId);
|
||||
if (!channel || !(channel instanceof TextChannel)) continue;
|
||||
await channel.editPermission(
|
||||
await channel.updateOverwrite(
|
||||
userId,
|
||||
permissions,
|
||||
0,
|
||||
"member",
|
||||
`Companion Channel for ${voiceChannel!.id} | User Joined`,
|
||||
new Permissions(BigInt(permissions)).serialize(),
|
||||
{reason: `Companion Channel for ${voiceChannel!.id} | User Joined`},
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue