mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
Various bugfixes and change ct.anyId return to Snowflake
This commit is contained in:
parent
c932269b7d
commit
bc1330bf33
7 changed files with 19 additions and 13 deletions
|
@ -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 { baseCommandParameterTypeHelpers, baseTypeConverters, CommandContext, TypeConversionError } from "knub";
|
||||||
import { createTypeHelper } from "knub-command-manager";
|
import { createTypeHelper } from "knub-command-manager";
|
||||||
import {
|
import {
|
||||||
|
@ -72,16 +72,16 @@ export const commandTypes = {
|
||||||
|
|
||||||
async anyId(value: string, context: CommandContext<any>) {
|
async anyId(value: string, context: CommandContext<any>) {
|
||||||
const userId = resolveUserId(context.pluginData.client, value);
|
const userId = resolveUserId(context.pluginData.client, value);
|
||||||
if (userId) return userId;
|
if (userId) return userId as Snowflake;
|
||||||
|
|
||||||
const channelIdMatch = value.match(channelMentionRegex);
|
const channelIdMatch = value.match(channelMentionRegex);
|
||||||
if (channelIdMatch) return channelIdMatch[1];
|
if (channelIdMatch) return channelIdMatch[1] as Snowflake;
|
||||||
|
|
||||||
const roleIdMatch = value.match(roleMentionRegex);
|
const roleIdMatch = value.match(roleMentionRegex);
|
||||||
if (roleIdMatch) return roleIdMatch[1];
|
if (roleIdMatch) return roleIdMatch[1] as Snowflake;
|
||||||
|
|
||||||
if (isValidSnowflake(value)) {
|
if (isValidSnowflake(value)) {
|
||||||
return value;
|
return value as Snowflake;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new TypeConversionError(`Could not parse ID: \`${disableInlineCode(value)}\``);
|
throw new TypeConversionError(`Could not parse ID: \`${disableInlineCode(value)}\``);
|
||||||
|
@ -112,7 +112,7 @@ export const commandTypeHelpers = {
|
||||||
resolvedUserLoose: createTypeHelper<Promise<User | UnknownUser>>(commandTypes.resolvedUserLoose),
|
resolvedUserLoose: createTypeHelper<Promise<User | UnknownUser>>(commandTypes.resolvedUserLoose),
|
||||||
resolvedMember: createTypeHelper<Promise<GuildMember>>(commandTypes.resolvedMember),
|
resolvedMember: createTypeHelper<Promise<GuildMember>>(commandTypes.resolvedMember),
|
||||||
messageTarget: createTypeHelper<Promise<MessageTarget>>(commandTypes.messageTarget),
|
messageTarget: createTypeHelper<Promise<MessageTarget>>(commandTypes.messageTarget),
|
||||||
anyId: createTypeHelper<Promise<string>>(commandTypes.anyId),
|
anyId: createTypeHelper<Promise<Snowflake>>(commandTypes.anyId),
|
||||||
regex: createTypeHelper<RegExp>(commandTypes.regex),
|
regex: createTypeHelper<RegExp>(commandTypes.regex),
|
||||||
timezone: createTypeHelper<string>(commandTypes.timezone),
|
timezone: createTypeHelper<string>(commandTypes.timezone),
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,7 @@ export const ReloadServerCmd = botControlCmd({
|
||||||
},
|
},
|
||||||
|
|
||||||
signature: {
|
signature: {
|
||||||
guildId: ct.string(),
|
guildId: ct.anyId(),
|
||||||
},
|
},
|
||||||
|
|
||||||
async run({ pluginData, message: msg, args }) {
|
async run({ pluginData, message: msg, args }) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { Snowflake } from "discord.js";
|
||||||
import { GlobalPluginData } from "knub";
|
import { GlobalPluginData } from "knub";
|
||||||
import { SECONDS } from "../../../utils";
|
import { SECONDS } from "../../../utils";
|
||||||
import { GuildConfigReloaderPluginType } from "../types";
|
import { GuildConfigReloaderPluginType } from "../types";
|
||||||
|
@ -11,7 +12,7 @@ export async function reloadChangedGuilds(pluginData: GlobalPluginData<GuildConf
|
||||||
for (const item of changedConfigs) {
|
for (const item of changedConfigs) {
|
||||||
if (!item.key.startsWith("guild-")) continue;
|
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}`);
|
console.log(`Config changed, reloading guild ${guildId}`);
|
||||||
await pluginData.getKnubInstance().reloadGuild(guildId);
|
await pluginData.getKnubInstance().reloadGuild(guildId);
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,10 @@ export const VoiceStateUpdateAlertEvt = locateUserEvt({
|
||||||
|
|
||||||
triggeredAlerts.forEach(alert => {
|
triggeredAlerts.forEach(alert => {
|
||||||
const txtChannel = meta.pluginData.guild.channels.resolve(alert.channel_id as Snowflake) as TextChannel;
|
const txtChannel = meta.pluginData.guild.channels.resolve(alert.channel_id as Snowflake) as TextChannel;
|
||||||
txtChannel.send(
|
txtChannel.send({
|
||||||
`🔴 <@!${alert.requestor_id}> the user <@!${alert.user_id}> disconnected out of \`<#!${voiceChannel.id}>\``,
|
content: `🔴 <@!${alert.requestor_id}> the user <@!${alert.user_id}> disconnected out of \`${voiceChannel.name}\``,
|
||||||
);
|
allowedMentions: { users: [alert.requestor_id as Snowflake] },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ export async function createOrReuseInvite(vc: VoiceChannel) {
|
||||||
const existingInvites = await vc.fetchInvites();
|
const existingInvites = await vc.fetchInvites();
|
||||||
|
|
||||||
if (existingInvites.size !== 0) {
|
if (existingInvites.size !== 0) {
|
||||||
return existingInvites[0];
|
return existingInvites.first()!;
|
||||||
} else {
|
} else {
|
||||||
return vc.createInvite();
|
return vc.createInvite();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ export const ButtonInteractionEvt = reactionRolesEvt({
|
||||||
};
|
};
|
||||||
|
|
||||||
if (context.stateless) {
|
if (context.stateless) {
|
||||||
|
if (context.roleOrMenu == null) {
|
||||||
|
// Not reaction from this plugin
|
||||||
|
return;
|
||||||
|
}
|
||||||
const timeSinceCreation = moment.utc().valueOf() - idToTimestamp(int.message.id)!;
|
const timeSinceCreation = moment.utc().valueOf() - idToTimestamp(int.message.id)!;
|
||||||
if (timeSinceCreation >= BUTTON_INVALIDATION_TIME) {
|
if (timeSinceCreation >= BUTTON_INVALIDATION_TIME) {
|
||||||
sendEphemeralReply(
|
sendEphemeralReply(
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { GuildPluginData } from "knub";
|
||||||
import { ReactionRolesPluginType } from "../types";
|
import { ReactionRolesPluginType } from "../types";
|
||||||
import { ButtonMenuActions } from "./buttonMenuActions";
|
import { ButtonMenuActions } from "./buttonMenuActions";
|
||||||
|
|
||||||
export const BUTTON_CONTEXT_SEPARATOR = "::";
|
export const BUTTON_CONTEXT_SEPARATOR = ":rb:";
|
||||||
|
|
||||||
export async function getButtonAction(pluginData: GuildPluginData<ReactionRolesPluginType>, roleOrMenu: string) {
|
export async function getButtonAction(pluginData: GuildPluginData<ReactionRolesPluginType>, roleOrMenu: string) {
|
||||||
if (await pluginData.guild.roles.fetch(roleOrMenu as Snowflake).catch(() => false)) {
|
if (await pluginData.guild.roles.fetch(roleOrMenu as Snowflake).catch(() => false)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue