#Decorators Message Context?
1 messages · Page 1 of 1 (latest)
also is there any advantage to using shapeshift over zod?
e.g.
export class ConfigCommand extends Command {
guildSupportChannels: Map<string, Channel> = new Map();
guildSettingsEmbeds: Map<string, EmbedBuilder> = new Map();
guildPermittedRoles: Map<string, string[]> = new Map();
guildSupportEnabled: Map<string, boolean> = new Map();
guildCustomUrls: Map<string, string[]> = new Map();
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder //
.setName(this.name)
.setDescription(this.description)
);
}
public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
const curChannel = interaction.channel;
if (curChannel?.type === ChannelType.GuildText && interaction.guild !== null) {
await this.updateSettingsEmbed(interaction);
} else {
await interaction.reply({ content: 'This command can only be used in a text channel in a guild', ephemeral: true });
}
}
@RequiresGuildContext()
@RequiresUserPermissions(['Administrator', 'ManageGuild'])
private async updateSettingsEmbed(interaction: Command.ChatInputCommandInteraction) {
RequiresGuildContext requires the decorated method's first parameter to be a Message. Note to self add support for Interaction class. Anyway that's your answer.
copy that, okay, so
And subcommands can have preconditions including runIn to limit it to a guild
if I make the first parameter the message of the interaction, does that count or no?
yeah I figured out the subcommands part, but I saw the requirement for message -- just wondering if I can finagle it
cause the types for user.permissions is weird
string | ReadOnly<PermissionsBitField>
No. In JavaScript arguments are as provided when the method is called. You can't just type an arg as something else and it magically works.
no I meant, if I changed my
updateSettingsEmbed
to private async updateSettingsEmbed(message: Message, interaction: Command.ChatInputCommandInteraction) {
Oh yeah you could but I would recommend making a PR to support interactions instead
copy that, will do now
Much better and helps everyone and saves me work too 
I just forgot to add it ages ago
And kept forgetting
lol you know I love the package too much and will do it oh no
can you point me to the right dir
can find it, just lazy
meh one sec
Tip: yarn install in the mono repo then yarn build because decorators depends on packages within the workspace
No rush
I know I'm all about dat efficiency
Out for dinner anyway so can't really release anyway
one quick question, you probably know this better than me
Same 
BaseInteraction from djs catches all
The others extend that class
you prefer yarn over bun?
I think bun has potential (unlike deno
) but it doesn't have an equivalent of publishing packages yet so it's irrelevant for libraries
yeah true, I mean it does drop-in-replace NodeJS and it's webserver is like
900 times faster
like if you're using Node WebSockets
you should switch
cause their websockets are like 98 times faster or some stupid number and native
I tried bun here but I was stuck on publishing https://github.com/favware/graphql-pokemon/tree/refactor/switch-to-bun
which part? workflow or docker?
Workflow
That project is fully automated
Releases are done from GH workflow
As well as docker image updates and updating the docker container on my vps
the automatic data update?
cause that's still running yarn in the errored command I see
Continuous deployment
Also yes I just found that out ffs
I made some typo somewhere in the script
Cry
hahahaha
all good man the amount of times my bugs are the dumbest thing
it looks like your script is stopping for some reason on Generate JavaScript Companion library
is there some error throwing? It looks like it's just skipping
It's been broken for a while because bulbapedia (the website I scrape) added cloudflare captcha for a while and even flaresolverr couldn't flawlessly get by it. Now they disabled the captcha again so the script finally got to the last few lines but now there's a bug in writing the output
hehehe I have a Browserless up that gets past all of that
Oh normally it's perfect https://github.com/FlareSolverr/FlareSolverr
But query it over a 1000 times in rapid succession....
Lol they just released Pingora, their rust based API framework, maybe with that knowledge you can make it even better
I just use a Playwright browser
found this today though https://github.com/Skyvern-AI/skyvern
Idk. Maybe if I run into the issue again but I hope they'll keep captcha off now
It was because they noticed an increased network activity over November December relates to DDOS
Who would want to DDOS bulbapedia
Despots is2g
this look good?
export const RequiresClientPermissions = (...permissionsResolvable: PermissionResolvable[]): MethodDecorator => {
const resolved = new PermissionsBitField(permissionsResolvable);
const resolvedIncludesServerPermissions = Boolean(resolved.bitfield & DMAvailablePermissions.bitfield);
return createFunctionPrecondition((context: Message | BaseInteraction) => {
if (context instanceof Message) {
if (resolvedIncludesServerPermissions && isDMChannel(context.channel)) {
throw new UserError({
identifier: DecoratorIdentifiers.RequiresClientPermissionsGuildOnly,
message: 'Sorry, but that command can only be used in a server because I do not have sufficient permissions in DMs'
});
}
if (isGuildBasedChannel(context.channel)) {
const missingPermissions = context.channel.permissionsFor(context.guild!.members.me!).missing(resolved);
if (missingPermissions.length) {
throw new UserError({
identifier: DecoratorIdentifiers.RequiresClientPermissionsMissingPermissions,
message: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingPermissions}`,
context: {
missing: missingPermissions
}
});
}
}
} else {
if (resolvedIncludesServerPermissions && isDMChannel(context.channel)) {
throw new UserError({
identifier: DecoratorIdentifiers.RequiresClientPermissionsGuildOnly,
message: 'Sorry, but that command can only be used in a server because I do not have sufficient permissions in DMs'
});
}
if (context.channel && isGuildBasedChannel(context.channel)) {
const missingPermissions = context.channel.permissionsFor(context.guild!.members.me!).missing(resolved);
if (missingPermissions.length) {
throw new UserError({
identifier: DecoratorIdentifiers.RequiresClientPermissionsMissingPermissions,
message: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingPermissions}`,
context: {
missing: missingPermissions
}
});
}
}
}
return true;
});
};
Can you dump it on https://hastebin.skyra.pw instead? I'm on mobile so that's a bit hard to read (no syntax highlighting, wrapping)
just swapped the message for context and checked the class instnace
yeh
that's just client perms just as an example of what i had in mind
Deduplicate it, no instanceof check like that.