mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +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 { eventListener } from "knub";
|
||||||
import { CompanionChannelsPluginType } from "../types";
|
import { CompanionChannelsPluginType } from "../types";
|
||||||
import { handleCompanionPermissions } from "../functions/handleCompanionPermissions";
|
import { handleCompanionPermissions } from "../functions/handleCompanionPermissions";
|
||||||
|
import { stripObjectToScalars } from "src/utils";
|
||||||
|
|
||||||
export const VoiceChannelJoinEvt = eventListener<CompanionChannelsPluginType>()(
|
export const VoiceChannelJoinEvt = eventListener<CompanionChannelsPluginType>()(
|
||||||
"voiceChannelJoin",
|
"voiceChannelJoin",
|
||||||
({ pluginData, args: { member, newChannel } }) => {
|
({ 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>()(
|
export const VoiceChannelLeaveEvt = eventListener<CompanionChannelsPluginType>()(
|
||||||
"voiceChannelLeave",
|
"voiceChannelLeave",
|
||||||
({ pluginData, args: { member, oldChannel } }) => {
|
({ 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>()(
|
export const VoiceChannelSwitchEvt = eventListener<CompanionChannelsPluginType>()(
|
||||||
"voiceChannelSwitch",
|
"voiceChannelSwitch",
|
||||||
({ pluginData, args: { member, oldChannel, newChannel } }) => {
|
({ 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 { PluginData } from "knub";
|
||||||
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
||||||
|
|
||||||
|
@ -8,10 +9,13 @@ const defaultCompanionChannelOpts: Partial<TCompanionChannelOpts> = {
|
||||||
export function getCompanionChannelOptsForVoiceChannelId(
|
export function getCompanionChannelOptsForVoiceChannelId(
|
||||||
pluginData: PluginData<CompanionChannelsPluginType>,
|
pluginData: PluginData<CompanionChannelsPluginType>,
|
||||||
userId: string,
|
userId: string,
|
||||||
voiceChannelId: string,
|
voiceChannel: VoiceChannel,
|
||||||
): TCompanionChannelOpts[] {
|
): TCompanionChannelOpts[] {
|
||||||
const config = pluginData.config.getMatchingConfig({ userId, channelId: voiceChannelId });
|
const config = pluginData.config.getMatchingConfig({ userId, channelId: voiceChannel.id });
|
||||||
return Object.values(config.entries)
|
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));
|
.map(opts => Object.assign({}, defaultCompanionChannelOpts, opts));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
||||||
import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId";
|
import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId";
|
||||||
import { PluginData } from "knub";
|
import { PluginData } from "knub";
|
||||||
import { TextChannel } from "eris";
|
import { TextChannel, VoiceChannel } from "eris";
|
||||||
import { isDiscordRESTError, MINUTES } from "../../../utils";
|
import { isDiscordRESTError, MINUTES } from "../../../utils";
|
||||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
|
@ -12,20 +12,20 @@ const ERROR_COOLDOWN = 5 * MINUTES;
|
||||||
export async function handleCompanionPermissions(
|
export async function handleCompanionPermissions(
|
||||||
pluginData: PluginData<CompanionChannelsPluginType>,
|
pluginData: PluginData<CompanionChannelsPluginType>,
|
||||||
userId: string,
|
userId: string,
|
||||||
voiceChannelId: string,
|
voiceChannel: VoiceChannel,
|
||||||
oldChannelId?: string,
|
oldChannel?: VoiceChannel,
|
||||||
);
|
);
|
||||||
export async function handleCompanionPermissions(
|
export async function handleCompanionPermissions(
|
||||||
pluginData: PluginData<CompanionChannelsPluginType>,
|
pluginData: PluginData<CompanionChannelsPluginType>,
|
||||||
userId: string,
|
userId: string,
|
||||||
voiceChannelId: null,
|
voiceChannel: null,
|
||||||
oldChannelId: string,
|
oldChannel: VoiceChannel,
|
||||||
);
|
);
|
||||||
export async function handleCompanionPermissions(
|
export async function handleCompanionPermissions(
|
||||||
pluginData: PluginData<CompanionChannelsPluginType>,
|
pluginData: PluginData<CompanionChannelsPluginType>,
|
||||||
userId: string,
|
userId: string,
|
||||||
voiceChannelId?: string,
|
voiceChannel?: VoiceChannel,
|
||||||
oldChannelId?: string,
|
oldChannel?: VoiceChannel,
|
||||||
) {
|
) {
|
||||||
if (pluginData.state.errorCooldownManager.isOnCooldown(ERROR_COOLDOWN_KEY)) {
|
if (pluginData.state.errorCooldownManager.isOnCooldown(ERROR_COOLDOWN_KEY)) {
|
||||||
return;
|
return;
|
||||||
|
@ -35,11 +35,11 @@ export async function handleCompanionPermissions(
|
||||||
const oldPerms: Map<string, number> = new Map(); // channelId => permissions
|
const oldPerms: Map<string, number> = new Map(); // channelId => permissions
|
||||||
const permsToSet: Map<string, number> = new Map(); // channelId => permissions
|
const permsToSet: Map<string, number> = new Map(); // channelId => permissions
|
||||||
|
|
||||||
const oldChannelOptsArr: TCompanionChannelOpts[] = oldChannelId
|
const oldChannelOptsArr: TCompanionChannelOpts[] = oldChannel
|
||||||
? getCompanionChannelOptsForVoiceChannelId(pluginData, userId, oldChannelId)
|
? getCompanionChannelOptsForVoiceChannelId(pluginData, userId, oldChannel)
|
||||||
: [];
|
: [];
|
||||||
const newChannelOptsArr: TCompanionChannelOpts[] = voiceChannelId
|
const newChannelOptsArr: TCompanionChannelOpts[] = voiceChannel
|
||||||
? getCompanionChannelOptsForVoiceChannelId(pluginData, userId, voiceChannelId)
|
? getCompanionChannelOptsForVoiceChannelId(pluginData, userId, voiceChannel)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
for (const oldChannelOpts of oldChannelOptsArr) {
|
for (const oldChannelOpts of oldChannelOptsArr) {
|
||||||
|
@ -65,7 +65,7 @@ export async function handleCompanionPermissions(
|
||||||
for (const channelId of permsToDelete) {
|
for (const channelId of permsToDelete) {
|
||||||
const channel = pluginData.guild.channels.get(channelId);
|
const channel = pluginData.guild.channels.get(channelId);
|
||||||
if (!channel || !(channel instanceof TextChannel)) continue;
|
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) {
|
for (const [channelId, permissions] of permsToSet) {
|
||||||
|
@ -76,7 +76,7 @@ export async function handleCompanionPermissions(
|
||||||
permissions,
|
permissions,
|
||||||
0,
|
0,
|
||||||
"member",
|
"member",
|
||||||
`Companion Channel for ${voiceChannelId} | User Joined`,
|
`Companion Channel for ${voiceChannel.id} | User Joined`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue