mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-14 21:31:50 +00:00
Merge pull request #113 from DarkView/fr_compChanCategories
Allow companion_channels to take category ID
This commit is contained in:
commit
c9431bebcc
5 changed files with 24 additions and 19 deletions
|
@ -1,10 +1,11 @@
|
|||
import { eventListener } from "knub";
|
||||
import { CompanionChannelsPluginType } from "../types";
|
||||
import { handleCompanionPermissions } from "../functions/handleCompanionPermissions";
|
||||
import { stripObjectToScalars } from "src/utils";
|
||||
|
||||
export const VoiceChannelJoinEvt = eventListener<CompanionChannelsPluginType>()(
|
||||
"voiceChannelJoin",
|
||||
({ pluginData, args: { member, newChannel } }) => {
|
||||
handleCompanionPermissions(pluginData, member.id, newChannel.id);
|
||||
handleCompanionPermissions(pluginData, member.id, newChannel);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -5,6 +5,6 @@ import { handleCompanionPermissions } from "../functions/handleCompanionPermissi
|
|||
export const VoiceChannelLeaveEvt = eventListener<CompanionChannelsPluginType>()(
|
||||
"voiceChannelLeave",
|
||||
({ pluginData, args: { member, oldChannel } }) => {
|
||||
handleCompanionPermissions(pluginData, member.id, null, oldChannel.id);
|
||||
handleCompanionPermissions(pluginData, member.id, null, oldChannel);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -5,6 +5,6 @@ import { handleCompanionPermissions } from "../functions/handleCompanionPermissi
|
|||
export const VoiceChannelSwitchEvt = eventListener<CompanionChannelsPluginType>()(
|
||||
"voiceChannelSwitch",
|
||||
({ pluginData, args: { member, oldChannel, newChannel } }) => {
|
||||
handleCompanionPermissions(pluginData, member.id, newChannel.id, oldChannel.id);
|
||||
handleCompanionPermissions(pluginData, member.id, newChannel, oldChannel);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { VoiceChannel } from "eris";
|
||||
import { PluginData } from "knub";
|
||||
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
||||
|
||||
|
@ -8,10 +9,13 @@ const defaultCompanionChannelOpts: Partial<TCompanionChannelOpts> = {
|
|||
export function getCompanionChannelOptsForVoiceChannelId(
|
||||
pluginData: PluginData<CompanionChannelsPluginType>,
|
||||
userId: string,
|
||||
voiceChannelId: string,
|
||||
voiceChannel: VoiceChannel,
|
||||
): TCompanionChannelOpts[] {
|
||||
const config = pluginData.config.getMatchingConfig({ userId, channelId: voiceChannelId });
|
||||
const config = pluginData.config.getMatchingConfig({ userId, channelId: voiceChannel.id });
|
||||
return Object.values(config.entries)
|
||||
.filter(opts => opts.voice_channel_ids.includes(voiceChannelId))
|
||||
.filter(
|
||||
opts =>
|
||||
opts.voice_channel_ids.includes(voiceChannel.id) || opts.voice_channel_ids.includes(voiceChannel.parentID),
|
||||
)
|
||||
.map(opts => Object.assign({}, defaultCompanionChannelOpts, opts));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
||||
import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId";
|
||||
import { PluginData } from "knub";
|
||||
import { TextChannel } from "eris";
|
||||
import { TextChannel, VoiceChannel } from "eris";
|
||||
import { isDiscordRESTError, MINUTES } from "../../../utils";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
|
@ -12,20 +12,20 @@ const ERROR_COOLDOWN = 5 * MINUTES;
|
|||
export async function handleCompanionPermissions(
|
||||
pluginData: PluginData<CompanionChannelsPluginType>,
|
||||
userId: string,
|
||||
voiceChannelId: string,
|
||||
oldChannelId?: string,
|
||||
voiceChannel: VoiceChannel,
|
||||
oldChannel?: VoiceChannel,
|
||||
);
|
||||
export async function handleCompanionPermissions(
|
||||
pluginData: PluginData<CompanionChannelsPluginType>,
|
||||
userId: string,
|
||||
voiceChannelId: null,
|
||||
oldChannelId: string,
|
||||
voiceChannel: null,
|
||||
oldChannel: VoiceChannel,
|
||||
);
|
||||
export async function handleCompanionPermissions(
|
||||
pluginData: PluginData<CompanionChannelsPluginType>,
|
||||
userId: string,
|
||||
voiceChannelId?: string,
|
||||
oldChannelId?: string,
|
||||
voiceChannel?: VoiceChannel,
|
||||
oldChannel?: VoiceChannel,
|
||||
) {
|
||||
if (pluginData.state.errorCooldownManager.isOnCooldown(ERROR_COOLDOWN_KEY)) {
|
||||
return;
|
||||
|
@ -35,11 +35,11 @@ export async function handleCompanionPermissions(
|
|||
const oldPerms: Map<string, number> = new Map(); // channelId => permissions
|
||||
const permsToSet: Map<string, number> = new Map(); // channelId => permissions
|
||||
|
||||
const oldChannelOptsArr: TCompanionChannelOpts[] = oldChannelId
|
||||
? getCompanionChannelOptsForVoiceChannelId(pluginData, userId, oldChannelId)
|
||||
const oldChannelOptsArr: TCompanionChannelOpts[] = oldChannel
|
||||
? getCompanionChannelOptsForVoiceChannelId(pluginData, userId, oldChannel)
|
||||
: [];
|
||||
const newChannelOptsArr: TCompanionChannelOpts[] = voiceChannelId
|
||||
? getCompanionChannelOptsForVoiceChannelId(pluginData, userId, voiceChannelId)
|
||||
const newChannelOptsArr: TCompanionChannelOpts[] = voiceChannel
|
||||
? getCompanionChannelOptsForVoiceChannelId(pluginData, userId, voiceChannel)
|
||||
: [];
|
||||
|
||||
for (const oldChannelOpts of oldChannelOptsArr) {
|
||||
|
@ -65,7 +65,7 @@ export async function handleCompanionPermissions(
|
|||
for (const channelId of permsToDelete) {
|
||||
const channel = pluginData.guild.channels.get(channelId);
|
||||
if (!channel || !(channel instanceof TextChannel)) continue;
|
||||
await channel.deletePermission(userId, `Companion Channel for ${oldChannelId} | User Left`);
|
||||
await channel.deletePermission(userId, `Companion Channel for ${oldChannel.id} | User Left`);
|
||||
}
|
||||
|
||||
for (const [channelId, permissions] of permsToSet) {
|
||||
|
@ -76,7 +76,7 @@ export async function handleCompanionPermissions(
|
|||
permissions,
|
||||
0,
|
||||
"member",
|
||||
`Companion Channel for ${voiceChannelId} | User Joined`,
|
||||
`Companion Channel for ${voiceChannel.id} | User Joined`,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue