Update DJS
This commit is contained in:
parent
ac619ec00f
commit
5e73d380c5
23 changed files with 71 additions and 56 deletions
|
@ -263,8 +263,8 @@ connect().then(async () => {
|
|||
startUptimeCounter();
|
||||
});
|
||||
|
||||
bot.initialize();
|
||||
logger.info("Bot Initialized");
|
||||
logger.info("Logging in...");
|
||||
await client.login(process.env.token);
|
||||
logger.info("Initializing the bot");
|
||||
bot.initialize();
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ import { autoReactionsEvt } from "../types";
|
|||
const p = Permissions.FLAGS;
|
||||
|
||||
export const AddReactionsEvt = autoReactionsEvt({
|
||||
event: "message",
|
||||
event: "messageCreate",
|
||||
allowBots: true,
|
||||
allowSelf: true,
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { MessageOptions } from "discord.js";
|
||||
import { MessageEditOptions, MessageOptions } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
|
@ -14,7 +14,7 @@ export async function getCaseEmbed(
|
|||
caseOrCaseId: Case | number,
|
||||
requestMemberId?: string,
|
||||
noOriginalCaseLink?: boolean,
|
||||
): Promise<MessageOptions> {
|
||||
): Promise<MessageOptions & MessageEditOptions> {
|
||||
const theCase = await pluginData.state.cases.with("notes").find(resolveCaseId(caseOrCaseId));
|
||||
if (!theCase) {
|
||||
throw new Error("Unknown case");
|
||||
|
|
|
@ -54,14 +54,14 @@ export async function handleCompanionPermissions(
|
|||
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
||||
if (!channel || !(channel instanceof TextChannel)) continue;
|
||||
await channel.permissionOverwrites
|
||||
.get(userId as Snowflake)
|
||||
.resolve(userId as Snowflake)
|
||||
?.delete(`Companion Channel for ${oldChannel!.id} | User Left`);
|
||||
}
|
||||
|
||||
for (const [channelId, permissions] of permsToSet) {
|
||||
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
||||
if (!channel || !(channel instanceof TextChannel)) continue;
|
||||
await channel.updateOverwrite(userId, new Permissions(BigInt(permissions)).serialize(), {
|
||||
await channel.permissionOverwrites.create(userId as Snowflake, new Permissions(BigInt(permissions)).serialize(), {
|
||||
reason: `Companion Channel for ${voiceChannel!.id} | User Joined`,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import * as t from "io-ts";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { canActOn } from "../../../pluginUtils";
|
||||
|
@ -30,6 +31,6 @@ export async function addRoleAction(
|
|||
|
||||
const rolesToAdd = Array.isArray(action.role) ? action.role : [action.role];
|
||||
await target.edit({
|
||||
roles: Array.from(new Set([...target.roles.cache.array(), ...rolesToAdd])),
|
||||
roles: Array.from(new Set([...target.roles.cache.array(), ...rolesToAdd])) as Snowflake[],
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Snowflake, TextChannel } from "discord.js";
|
||||
import { Permissions, Snowflake, TextChannel } from "discord.js";
|
||||
import * as t from "io-ts";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { ActionError } from "../ActionError";
|
||||
|
@ -31,9 +31,16 @@ export async function setChannelPermissionOverridesAction(
|
|||
}
|
||||
|
||||
for (const override of action.overrides) {
|
||||
await channel.overwritePermissions(
|
||||
channel.permissionOverwrites.create(
|
||||
override.id as Snowflake,
|
||||
new Permissions(BigInt(override.allow)).add(BigInt(override.deny)).serialize(),
|
||||
);
|
||||
|
||||
/*
|
||||
await channel.permissionOverwrites overwritePermissions(
|
||||
[{ id: override.id, allow: BigInt(override.allow), deny: BigInt(override.deny), type: override.type }],
|
||||
`Custom event: ${event.name}`,
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Message } from "discord.js";
|
|||
import { messageSaverEvt } from "../types";
|
||||
|
||||
export const MessageCreateEvt = messageSaverEvt({
|
||||
event: "message",
|
||||
event: "messageCreate",
|
||||
allowBots: true,
|
||||
allowSelf: true,
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ export const MutesCmd = mutesCmd({
|
|||
await listMessage.edit({ components: [row] });
|
||||
|
||||
const filter = (iac: MessageComponentInteraction) => iac.message.id === listMessage.id;
|
||||
const collector = listMessage.createMessageComponentInteractionCollector({
|
||||
const collector = listMessage.createMessageComponentCollector({
|
||||
filter,
|
||||
time: stopCollectionDebounce,
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Snowflake } from "discord.js";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { stripObjectToScalars } from "../../../utils";
|
||||
import { memberRolesLock } from "../../../utils/lockNameHelpers";
|
||||
|
@ -15,7 +16,7 @@ export const ReapplyActiveMuteOnJoinEvt = mutesEvt({
|
|||
|
||||
if (muteRole) {
|
||||
const memberRoleLock = await pluginData.locks.acquire(memberRolesLock(member));
|
||||
await member.roles.add(muteRole);
|
||||
await member.roles.add(muteRole as Snowflake);
|
||||
memberRoleLock.unlock();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
|
|||
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
if (muteRole) {
|
||||
await member.roles.remove(muteRole);
|
||||
await member.roles.remove(muteRole as Snowflake);
|
||||
}
|
||||
if (mute.roles_to_restore) {
|
||||
const guildRoles = pluginData.guild.roles.cache;
|
||||
|
@ -26,7 +26,7 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
|
|||
for (const toRestore of mute.roles_to_restore) {
|
||||
if (guildRoles.has(toRestore as Snowflake) && toRestore !== muteRole) newRoles.push(toRestore);
|
||||
}
|
||||
await member.roles.set(newRoles);
|
||||
await member.roles.set(newRoles as Snowflake[]);
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
|
|
|
@ -69,11 +69,11 @@ export async function muteUser(
|
|||
// exclude managed roles from being removed
|
||||
const managedRoles = pluginData.guild.roles.cache.filter(x => x.managed).map(y => y.id);
|
||||
newRoles = currentUserRoles.filter(r => !managedRoles.includes(r));
|
||||
await member.roles.set(newRoles);
|
||||
await member.roles.set(newRoles as Snowflake[]);
|
||||
}
|
||||
} else {
|
||||
newRoles = currentUserRoles.filter(x => !(<string[]>removeRoles).includes(x));
|
||||
await member.roles.set(newRoles);
|
||||
await member.roles.set(newRoles as Snowflake[]);
|
||||
}
|
||||
|
||||
// set roles to be restored
|
||||
|
@ -88,7 +88,7 @@ export async function muteUser(
|
|||
// Apply mute role if it's missing
|
||||
if (!currentUserRoles.includes(muteRole as Snowflake)) {
|
||||
try {
|
||||
await member.roles.add(muteRole);
|
||||
await member.roles.add(muteRole as Snowflake);
|
||||
} catch (e) {
|
||||
const actualMuteRole = pluginData.guild.roles.cache.find(x => x.id === muteRole);
|
||||
if (!actualMuteRole) {
|
||||
|
|
|
@ -37,7 +37,7 @@ export async function unmuteUser(
|
|||
|
||||
const muteRole = pluginData.config.get().mute_role;
|
||||
if (muteRole && member.roles.cache.has(muteRole as Snowflake)) {
|
||||
await member.roles.remove(muteRole);
|
||||
await member.roles.remove(muteRole as Snowflake);
|
||||
}
|
||||
if (existingMute?.roles_to_restore) {
|
||||
const guildRoles = pluginData.guild.roles.cache;
|
||||
|
@ -46,7 +46,7 @@ export async function unmuteUser(
|
|||
for (const toRestore of existingMute.roles_to_restore) {
|
||||
if (guildRoles.has(toRestore as Snowflake) && toRestore !== muteRole) newRoles.push(toRestore);
|
||||
}
|
||||
await member.roles.set(newRoles);
|
||||
await member.roles.set(newRoles as Snowflake[]);
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
|
|
|
@ -15,7 +15,7 @@ export const ChannelJoinEvt = nameHistoryEvt({
|
|||
});
|
||||
|
||||
export const MessageCreateEvt = nameHistoryEvt({
|
||||
event: "message",
|
||||
event: "messageCreate",
|
||||
|
||||
async listener(meta) {
|
||||
meta.pluginData.state.updateQueue.add(() => updateNickname(meta.pluginData, meta.args.message.member!));
|
||||
|
|
|
@ -29,7 +29,7 @@ export const TypingEnablePingableEvt = pingableRolesEvt({
|
|||
});
|
||||
|
||||
export const MessageCreateDisablePingableEvt = pingableRolesEvt({
|
||||
event: "message",
|
||||
event: "messageCreate",
|
||||
|
||||
async listener(meta) {
|
||||
const pluginData = meta.pluginData;
|
||||
|
|
|
@ -80,7 +80,7 @@ export const RoleAddCmd = selfGrantableRolesCmd({
|
|||
|
||||
try {
|
||||
await msg.member.edit({
|
||||
roles: Array.from(newRoleIds),
|
||||
roles: Array.from(newRoleIds) as Snowflake[],
|
||||
});
|
||||
} catch {
|
||||
sendErrorMessage(
|
||||
|
|
|
@ -11,16 +11,13 @@ export async function applyBotSlowmodeToUserId(
|
|||
userId: string,
|
||||
) {
|
||||
// Deny sendMessage permission from the user. If there are existing permission overwrites, take those into account.
|
||||
const existingOverride = channel.permissionOverwrites.get(userId as Snowflake);
|
||||
const newDeniedPermissions =
|
||||
(existingOverride ? existingOverride.deny.bitfield : 0n) | Permissions.FLAGS.SEND_MESSAGES;
|
||||
const newAllowedPermissions =
|
||||
(existingOverride ? existingOverride.allow.bitfield : 0n) & ~Permissions.FLAGS.SEND_MESSAGES;
|
||||
|
||||
const existingOverride = channel.permissionOverwrites.resolve(userId as Snowflake);
|
||||
try {
|
||||
await channel.overwritePermissions([
|
||||
{ id: userId, allow: newAllowedPermissions, deny: newDeniedPermissions, type: "member" },
|
||||
]);
|
||||
if (existingOverride) {
|
||||
await existingOverride.edit({ SEND_MESSAGES: false });
|
||||
} else {
|
||||
await channel.permissionOverwrites.create(userId as Snowflake, { SEND_MESSAGES: false }, { type: 1 });
|
||||
}
|
||||
} catch (e) {
|
||||
const user = pluginData.client.users.fetch(userId as Snowflake) || new UnknownUser({ id: userId });
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ export async function clearBotSlowmodeFromUserId(
|
|||
// Previously we diffed the overrides so we could clear the "send messages" override without touching other
|
||||
// overrides. Unfortunately, it seems that was a bit buggy - we didn't always receive the event for the changed
|
||||
// overrides and then we also couldn't diff against them. For consistency's sake, we just delete the override now.
|
||||
await channel.permissionOverwrites.get(userId as Snowflake)?.delete();
|
||||
await channel.permissionOverwrites.resolve(userId as Snowflake)?.delete();
|
||||
} catch (e) {
|
||||
if (!force) {
|
||||
throw e;
|
||||
|
|
|
@ -2,7 +2,7 @@ import { usernameSaverEvt } from "../types";
|
|||
import { updateUsername } from "../updateUsername";
|
||||
|
||||
export const MessageCreateUpdateUsernameEvt = usernameSaverEvt({
|
||||
event: "message",
|
||||
event: "messageCreate",
|
||||
|
||||
async listener(meta) {
|
||||
if (meta.args.message.author.bot) return;
|
||||
|
|
|
@ -198,7 +198,7 @@ export async function displaySearch(
|
|||
await searchMsg.edit({ content: result, components: [row] });
|
||||
|
||||
const filter = (iac: MessageComponentInteraction) => iac.message.id === searchMsg.id;
|
||||
const collector = searchMsg.createMessageComponentInteractionCollector({ filter, time: 2 * MINUTES });
|
||||
const collector = searchMsg.createMessageComponentCollector({ filter, time: 2 * MINUTES });
|
||||
|
||||
collector.on("collect", async (interaction: MessageComponentInteraction) => {
|
||||
if (msg.author.id !== interaction.user.id) {
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
import { Client, Message, MessageOptions, MessageReaction, PartialUser, TextChannel, User } from "discord.js";
|
||||
import {
|
||||
Client,
|
||||
Message,
|
||||
MessageEditOptions,
|
||||
MessageOptions,
|
||||
MessageReaction,
|
||||
PartialUser,
|
||||
TextChannel,
|
||||
User,
|
||||
} from "discord.js";
|
||||
import { Awaitable } from "knub/dist/utils";
|
||||
import { MINUTES, noop } from "../utils";
|
||||
import Timeout = NodeJS.Timeout;
|
||||
|
||||
export type LoadPageFn = (page: number) => Awaitable<MessageOptions>;
|
||||
export type LoadPageFn = (page: number) => Awaitable<MessageOptions & MessageEditOptions>;
|
||||
|
||||
export interface PaginateMessageOpts {
|
||||
timeout: number;
|
||||
|
|
|
@ -23,7 +23,7 @@ export async function waitForButtonConfirm(
|
|||
const message = await channel.send({ ...toPost, components: [row] });
|
||||
|
||||
const filter = (iac: MessageComponentInteraction) => iac.message.id === message.id;
|
||||
const collector = message.createMessageComponentInteractionCollector({ filter, time: 10000 });
|
||||
const collector = message.createMessageComponentCollector({ filter, time: 10000 });
|
||||
|
||||
collector.on("collect", (interaction: MessageComponentInteraction) => {
|
||||
if (options?.restrictToId && options.restrictToId !== interaction.user.id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue