Various bugfixes and change ct.anyId return to Snowflake

This commit is contained in:
Dark 2021-07-27 04:19:11 +02:00
parent c932269b7d
commit bc1330bf33
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
7 changed files with 19 additions and 13 deletions

View file

@ -1,4 +1,4 @@
import { GuildChannel, GuildMember, User } from "discord.js";
import { GuildChannel, GuildMember, Snowflake, User } from "discord.js";
import { baseCommandParameterTypeHelpers, baseTypeConverters, CommandContext, TypeConversionError } from "knub";
import { createTypeHelper } from "knub-command-manager";
import {
@ -72,16 +72,16 @@ export const commandTypes = {
async anyId(value: string, context: CommandContext<any>) {
const userId = resolveUserId(context.pluginData.client, value);
if (userId) return userId;
if (userId) return userId as Snowflake;
const channelIdMatch = value.match(channelMentionRegex);
if (channelIdMatch) return channelIdMatch[1];
if (channelIdMatch) return channelIdMatch[1] as Snowflake;
const roleIdMatch = value.match(roleMentionRegex);
if (roleIdMatch) return roleIdMatch[1];
if (roleIdMatch) return roleIdMatch[1] as Snowflake;
if (isValidSnowflake(value)) {
return value;
return value as Snowflake;
}
throw new TypeConversionError(`Could not parse ID: \`${disableInlineCode(value)}\``);
@ -112,7 +112,7 @@ export const commandTypeHelpers = {
resolvedUserLoose: createTypeHelper<Promise<User | UnknownUser>>(commandTypes.resolvedUserLoose),
resolvedMember: createTypeHelper<Promise<GuildMember>>(commandTypes.resolvedMember),
messageTarget: createTypeHelper<Promise<MessageTarget>>(commandTypes.messageTarget),
anyId: createTypeHelper<Promise<string>>(commandTypes.anyId),
anyId: createTypeHelper<Promise<Snowflake>>(commandTypes.anyId),
regex: createTypeHelper<RegExp>(commandTypes.regex),
timezone: createTypeHelper<string>(commandTypes.timezone),
};

View file

@ -11,7 +11,7 @@ export const ReloadServerCmd = botControlCmd({
},
signature: {
guildId: ct.string(),
guildId: ct.anyId(),
},
async run({ pluginData, message: msg, args }) {

View file

@ -1,3 +1,4 @@
import { Snowflake } from "discord.js";
import { GlobalPluginData } from "knub";
import { SECONDS } from "../../../utils";
import { GuildConfigReloaderPluginType } from "../types";
@ -11,7 +12,7 @@ export async function reloadChangedGuilds(pluginData: GlobalPluginData<GuildConf
for (const item of changedConfigs) {
if (!item.key.startsWith("guild-")) continue;
const guildId = item.key.slice("guild-".length);
const guildId = item.key.slice("guild-".length) as Snowflake;
console.log(`Config changed, reloading guild ${guildId}`);
await pluginData.getKnubInstance().reloadGuild(guildId);

View file

@ -18,9 +18,10 @@ export const VoiceStateUpdateAlertEvt = locateUserEvt({
triggeredAlerts.forEach(alert => {
const txtChannel = meta.pluginData.guild.channels.resolve(alert.channel_id as Snowflake) as TextChannel;
txtChannel.send(
`🔴 <@!${alert.requestor_id}> the user <@!${alert.user_id}> disconnected out of \`<#!${voiceChannel.id}>\``,
);
txtChannel.send({
content: `🔴 <@!${alert.requestor_id}> the user <@!${alert.user_id}> disconnected out of \`${voiceChannel.name}\``,
allowedMentions: { users: [alert.requestor_id as Snowflake] },
});
});
}
},

View file

@ -4,7 +4,7 @@ export async function createOrReuseInvite(vc: VoiceChannel) {
const existingInvites = await vc.fetchInvites();
if (existingInvites.size !== 0) {
return existingInvites[0];
return existingInvites.first()!;
} else {
return vc.createInvite();
}

View file

@ -32,6 +32,10 @@ export const ButtonInteractionEvt = reactionRolesEvt({
};
if (context.stateless) {
if (context.roleOrMenu == null) {
// Not reaction from this plugin
return;
}
const timeSinceCreation = moment.utc().valueOf() - idToTimestamp(int.message.id)!;
if (timeSinceCreation >= BUTTON_INVALIDATION_TIME) {
sendEphemeralReply(

View file

@ -3,7 +3,7 @@ import { GuildPluginData } from "knub";
import { ReactionRolesPluginType } from "../types";
import { ButtonMenuActions } from "./buttonMenuActions";
export const BUTTON_CONTEXT_SEPARATOR = "::";
export const BUTTON_CONTEXT_SEPARATOR = ":rb:";
export async function getButtonAction(pluginData: GuildPluginData<ReactionRolesPluginType>, roleOrMenu: string) {
if (await pluginData.guild.roles.fetch(roleOrMenu as Snowflake).catch(() => false)) {