mirror of
https://github.com/SrIzan10/vinci.git
synced 2026-06-05 16:57:01 +00:00
fix: ts type errors and migrate to v3
This commit is contained in:
@@ -2,7 +2,7 @@ import TicTacToe from 'discord-tictactoe';
|
||||
import { commandModule, CommandType } from '@sern/handler'
|
||||
import { publish } from "#plugins";
|
||||
import { ownerOnly } from "#plugins";
|
||||
import { ApplicationCommandOptionType } from "discord.js";
|
||||
import { ApplicationCommandOptionType, ChatInputCommandInteraction, CommandInteraction, Interaction } from "discord.js";
|
||||
const game = new TicTacToe({language: 'en'})
|
||||
|
||||
export default commandModule({
|
||||
@@ -19,6 +19,7 @@ export default commandModule({
|
||||
}
|
||||
],
|
||||
execute: async (ctx, options) => {
|
||||
await game.handleInteraction(ctx.interaction)
|
||||
ctx.reply({ content: 'comando desactivado temporalmente :(', ephemeral: true })
|
||||
// game.handleInteraction(ctx.interaction as ChatInputCommandInteraction)
|
||||
},
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { commandModule, CommandType } from "@sern/handler";
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ComponentType } from "discord.js";
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonComponentData, ButtonInteraction, ButtonStyle, ComponentType } from "discord.js";
|
||||
import db from "../../schemas/suggestions.js";
|
||||
|
||||
export default commandModule({
|
||||
@@ -7,15 +7,15 @@ export default commandModule({
|
||||
async execute(interaction) {
|
||||
const convertToNumber = Number(interaction.component.label!)
|
||||
const row2 = new ActionRowBuilder<ButtonBuilder>().setComponents(
|
||||
new ButtonBuilder(interaction.message!.components[1].components[0].data),
|
||||
new ButtonBuilder(interaction.message!.components[1].components[1].data)
|
||||
new ButtonBuilder(interaction.message!.components[1].components[0].data as ButtonComponentData),
|
||||
new ButtonBuilder(interaction.message!.components[1].components[1].data as ButtonComponentData)
|
||||
)
|
||||
if (await db.exists({msgid: interaction.message.id, userid: interaction.user.id, upordown: 1})) {
|
||||
await db.findOneAndUpdate({msgid: interaction.message.id, userid: interaction.user.id, upordown: 1}, {upordown: -1}, {returnOriginal: false})
|
||||
// god forbid I use any! I'm literally done with trying to solve this dude
|
||||
const upvoteLabel = JSON.stringify(interaction.message!.components[0].components[0].data) as string
|
||||
const downvotebuttons = new ActionRowBuilder<ButtonBuilder>().setComponents(
|
||||
new ButtonBuilder(interaction.message!.components[0].components[0].data)
|
||||
new ButtonBuilder(interaction.message!.components[0].components[0].data as ButtonComponentData)
|
||||
.setLabel((Number(JSON.parse(upvoteLabel).label) - 1).toString()),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('suggestions-no')
|
||||
@@ -29,7 +29,7 @@ export default commandModule({
|
||||
return await interaction.reply({content: 'Ya has hecho downvote.', ephemeral: true})
|
||||
} else {
|
||||
const downvotebuttons = new ActionRowBuilder<ButtonBuilder>().setComponents(
|
||||
new ButtonBuilder(interaction.message!.components[0].components[0].data),
|
||||
new ButtonBuilder(interaction.message!.components[0].components[0].data as ButtonComponentData),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('suggestions-no')
|
||||
.setEmoji('❎')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { commandModule, CommandType } from "@sern/handler";
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ComponentType } from "discord.js";
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonComponentData, ButtonInteraction, ButtonStyle, ComponentType } from "discord.js";
|
||||
import db from "../../schemas/suggestions.js";
|
||||
|
||||
export default commandModule({
|
||||
@@ -7,8 +7,8 @@ export default commandModule({
|
||||
async execute(interaction) {
|
||||
const convertToNumber = Number(interaction.component.label!)
|
||||
const row2 = new ActionRowBuilder<ButtonBuilder>().setComponents(
|
||||
new ButtonBuilder(interaction.message!.components[1].components[0].data),
|
||||
new ButtonBuilder(interaction.message!.components[1].components[1].data)
|
||||
new ButtonBuilder(interaction.message!.components[1].components[0].data as ButtonComponentData),
|
||||
new ButtonBuilder(interaction.message!.components[1].components[1].data as ButtonComponentData)
|
||||
)
|
||||
if (await db.exists({msgid: interaction.message.id, userid: interaction.user.id, upordown: -1})) {
|
||||
await db.findOneAndUpdate({msgid: interaction.message.id, userid: interaction.user.id, upordown: -1}, {upordown: 1}, {returnOriginal: false})
|
||||
@@ -20,7 +20,7 @@ export default commandModule({
|
||||
.setEmoji('✅')
|
||||
.setLabel((convertToNumber + 1).toString())
|
||||
.setStyle(ButtonStyle.Success),
|
||||
new ButtonBuilder(interaction.message!.components[0].components[1].data)
|
||||
new ButtonBuilder(interaction.message!.components[0].components[1].data as ButtonComponentData)
|
||||
.setLabel((Number(JSON.parse(upvoteLabel).label) - 1).toString()),
|
||||
)
|
||||
await interaction.message.edit({components: [downvotebuttons, row2]})
|
||||
@@ -34,7 +34,7 @@ export default commandModule({
|
||||
.setEmoji('✅')
|
||||
.setLabel((convertToNumber + 1).toString())
|
||||
.setStyle(ButtonStyle.Success),
|
||||
new ButtonBuilder(interaction.message!.components[0].components[1].data)
|
||||
new ButtonBuilder(interaction.message!.components[0].components[1].data as ButtonComponentData)
|
||||
)
|
||||
|
||||
const addToDB = new db({
|
||||
|
||||
@@ -15,7 +15,7 @@ export default commandModule({
|
||||
name: "channel",
|
||||
type: ApplicationCommandOptionType.Channel,
|
||||
description: "The channel to send the message to",
|
||||
channelTypes: [ChannelType.GuildText],
|
||||
channel_types: [ChannelType.GuildText],
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
|
||||
10
dependencies.d.ts
vendored
Normal file
10
dependencies.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { SernEmitter, Logging, CoreModuleStore, ModuleManager, ErrorHandling, CoreDependencies, Singleton } from '@sern/handler'
|
||||
import { Client } from 'discord.js'
|
||||
|
||||
declare global {
|
||||
interface Dependencies extends CoreDependencies {
|
||||
'@sern/client': Singleton<Client>
|
||||
}
|
||||
}
|
||||
|
||||
export {}
|
||||
19
index.ts
19
index.ts
@@ -1,5 +1,5 @@
|
||||
import { DefaultLogging, Dependencies, single, Singleton } from '@sern/handler';
|
||||
import { ActivityType } from 'discord.js';
|
||||
import { DefaultLogging, makeDependencies, single, Singleton } from '@sern/handler';
|
||||
import { ActivityOptions, ActivityType } from 'discord.js';
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
import { Sern } from '@sern/handler';
|
||||
import { config as dotenv } from 'dotenv';
|
||||
@@ -41,18 +41,14 @@ interface MyDependencies extends Dependencies {
|
||||
'@sern/logger' : Singleton<DefaultLogging>
|
||||
}
|
||||
|
||||
export const useContainer = Sern.makeDependencies<MyDependencies>({
|
||||
build: root => root
|
||||
.add({ '@sern/client': single(client) })
|
||||
.upsert({ '@sern/logger': single(new DefaultLogging()) })
|
||||
await makeDependencies<MyDependencies>({
|
||||
build: (root) => root.add({ '@sern/client': single(() => client) }),
|
||||
});
|
||||
|
||||
Sern.init({
|
||||
commands: 'dist/commands',
|
||||
events: 'dist/events',
|
||||
defaultPrefix: process.env.PREFIX,
|
||||
containerConfig: {
|
||||
get: useContainer
|
||||
}
|
||||
});
|
||||
|
||||
client.on('ready', async () => {
|
||||
@@ -67,10 +63,9 @@ client.on('ready', async () => {
|
||||
{ name: 'tus comandos', type: ActivityType.Listening },
|
||||
{ name: 'tu voz', type: ActivityType.Listening },
|
||||
{ name: 'ahora v1.0!', type: ActivityType.Playing },
|
||||
];
|
||||
] as ActivityOptions[];
|
||||
const randomStatus = statuses[Math.floor(Math.random() * statuses.length)];
|
||||
// @ts-ignore
|
||||
client.user!.setActivity(randomStatus);
|
||||
client.user.setActivity(randomStatus);
|
||||
}, 10000);
|
||||
|
||||
if (!devMode) {
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"@discordjs/opus": "^0.9.0",
|
||||
"@discordjs/voice": "^0.15.0",
|
||||
"@napi-rs/canvas": "^0.1.30",
|
||||
"@sern/handler": "^2.5.3",
|
||||
"@sern/handler": "^3.0.3",
|
||||
"axios": "^1.1.3",
|
||||
"dayjs": "^1.11.6",
|
||||
"discord-tictactoe": "^4.0.0",
|
||||
@@ -61,6 +61,6 @@
|
||||
"@types/express": "^4.17.14",
|
||||
"ts-node": "10.9.1",
|
||||
"tsc-watch": "^5.0.3",
|
||||
"typescript": "^4.9.3"
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// @ts-nocheck
|
||||
/**
|
||||
* This is publish plugin, it allows you to publish your application commands using the discord.js library with ease.
|
||||
* @plugin
|
||||
* [DEPRECATED] It allows you to publish your application commands using the discord.js library with ease.
|
||||
*
|
||||
* @author @EvolutionX-10 [<@697795666373640213>]
|
||||
* @version 2.0.0
|
||||
@@ -16,6 +17,7 @@
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
* @end
|
||||
*/
|
||||
import {
|
||||
CommandInitPlugin,
|
||||
@@ -23,13 +25,14 @@ import {
|
||||
controller,
|
||||
SernOptionsData,
|
||||
SlashCommand,
|
||||
Service,
|
||||
} from "@sern/handler";
|
||||
import {
|
||||
ApplicationCommandData,
|
||||
ApplicationCommandType,
|
||||
ApplicationCommandOptionType,
|
||||
PermissionResolvable,
|
||||
} from "discord.js";
|
||||
import { useContainer } from "../index.js";
|
||||
|
||||
export const CommandTypeRaw = {
|
||||
[CommandType.Both]: ApplicationCommandType.ChatInput,
|
||||
@@ -43,11 +46,17 @@ export function publish<
|
||||
| CommandType.Both
|
||||
| CommandType.Slash
|
||||
| CommandType.CtxMsg
|
||||
| CommandType.CtxUser
|
||||
| CommandType.CtxUser,
|
||||
>(options?: PublishOptions) {
|
||||
return CommandInitPlugin<T>(async ({ module }) => {
|
||||
// Users need to provide their own useContainer function.
|
||||
const [client] = useContainer("@sern/client");
|
||||
let client;
|
||||
try {
|
||||
client = (await import("@sern/handler")).Service("@sern/client");
|
||||
} catch {
|
||||
const { useContainer } = await import("../index.js");
|
||||
client = useContainer("@sern/client")[0];
|
||||
}
|
||||
const defaultOptions = {
|
||||
guildIds: [],
|
||||
dmPermission: undefined,
|
||||
@@ -89,7 +98,7 @@ export function publish<
|
||||
description: cmd(module.description, ""),
|
||||
options: cmd(
|
||||
optionsTransformer((module as SlashCommand).options ?? []),
|
||||
[]
|
||||
[],
|
||||
),
|
||||
defaultMemberPermissions,
|
||||
dmPermission,
|
||||
@@ -101,17 +110,17 @@ export function publish<
|
||||
|
||||
if (!guildIds.length) {
|
||||
const cmd = (await client.application!.commands.fetch()).find(
|
||||
(c) => c.name === module.name && c.type === curAppType
|
||||
(c) => c.name === module.name && c.type === curAppType,
|
||||
);
|
||||
if (cmd) {
|
||||
if (!cmd.equals(commandData, true)) {
|
||||
logged(
|
||||
`Found differences in global command ${module.name}`
|
||||
`Found differences in global command ${module.name}`,
|
||||
);
|
||||
cmd.edit(commandData).then(
|
||||
log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
)
|
||||
`${module.name} updated with new data successfully!`,
|
||||
),
|
||||
);
|
||||
}
|
||||
return controller.next();
|
||||
@@ -127,7 +136,7 @@ export function publish<
|
||||
const guild = await client.guilds.fetch(id).catch(c);
|
||||
if (!guild) continue;
|
||||
const guildCmd = (await guild.commands.fetch()).find(
|
||||
(c) => c.name === module.name && c.type === curAppType
|
||||
(c) => c.name === module.name && c.type === curAppType,
|
||||
);
|
||||
if (guildCmd) {
|
||||
if (!guildCmd.equals(commandData, true)) {
|
||||
@@ -136,8 +145,8 @@ export function publish<
|
||||
.edit(commandData)
|
||||
.then(
|
||||
log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
)
|
||||
`${module.name} updated with new data successfully!`,
|
||||
),
|
||||
)
|
||||
.catch(c);
|
||||
continue;
|
||||
@@ -159,9 +168,19 @@ export function publish<
|
||||
}
|
||||
|
||||
export function optionsTransformer(ops: Array<SernOptionsData>) {
|
||||
return ops.map((el) =>
|
||||
el.autocomplete ? (({ command, ...el }) => el)(el) : el
|
||||
);
|
||||
return ops.map((el) => {
|
||||
switch (el.type) {
|
||||
case ApplicationCommandOptionType.String:
|
||||
case ApplicationCommandOptionType.Number:
|
||||
case ApplicationCommandOptionType.Integer: {
|
||||
return el.autocomplete && "command" in el
|
||||
? (({ command, ...el }) => el)(el)
|
||||
: el;
|
||||
}
|
||||
default:
|
||||
return el;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export type NonEmptyArray<T extends `${number}` = `${number}`> = [T, ...T[]];
|
||||
@@ -193,4 +212,4 @@ export type PublishOptions = BasePublishOptions &
|
||||
| Required<Pick<BasePublishOptions, "dmPermission">>
|
||||
| Required<Pick<BasePublishOptions, "guildIds">>
|
||||
)
|
||||
);
|
||||
);
|
||||
28
yarn.lock
28
yarn.lock
@@ -925,14 +925,14 @@
|
||||
resolved "https://registry.yarnpkg.com/@sapphire/snowflake/-/snowflake-3.5.1.tgz#254521c188b49e8b2d4cc048b475fb2b38737fec"
|
||||
integrity sha512-BxcYGzgEsdlG0dKAyOm0ehLGm2CafIrfQTZGWgkfKYbj+pNNsorZ7EotuZukc2MT70E0UbppVbtpBrqpzVzjNA==
|
||||
|
||||
"@sern/handler@^2.5.3":
|
||||
version "2.5.3"
|
||||
resolved "https://registry.npmjs.org/@sern/handler/-/handler-2.5.3.tgz"
|
||||
"@sern/handler@^3.0.3":
|
||||
version "3.0.3"
|
||||
resolved "https://registry.yarnpkg.com/@sern/handler/-/handler-3.0.3.tgz#6b286219a7091693d298e38636c49808ebfd3840"
|
||||
integrity sha512-kQBHXE+yejAMCWH7+XqwJViCYgSt8dtVb0cyPp36pMCgjodYIXk8lJ26eQ3KVy3PTSMIlgnw1QztZCrAYa6qTw==
|
||||
dependencies:
|
||||
iti "^0.6.0"
|
||||
rxjs "^7.8.0"
|
||||
ts-pattern "^4.1.4"
|
||||
ts-results-es "^3.5.0"
|
||||
ts-results-es "^3.6.1"
|
||||
|
||||
"@sindresorhus/is@^5.2.0":
|
||||
version "5.3.0"
|
||||
@@ -2524,13 +2524,10 @@ ts-node@10.9.1:
|
||||
v8-compile-cache-lib "^3.0.1"
|
||||
yn "3.1.1"
|
||||
|
||||
ts-pattern@^4.1.4:
|
||||
version "4.2.1"
|
||||
resolved "https://registry.npmjs.org/ts-pattern/-/ts-pattern-4.2.1.tgz"
|
||||
|
||||
ts-results-es@^3.5.0:
|
||||
version "3.5.0"
|
||||
resolved "https://registry.npmjs.org/ts-results-es/-/ts-results-es-3.5.0.tgz"
|
||||
ts-results-es@^3.6.1:
|
||||
version "3.6.1"
|
||||
resolved "https://registry.yarnpkg.com/ts-results-es/-/ts-results-es-3.6.1.tgz#2249aca8690b3b68445873c2a3da9517db98a16b"
|
||||
integrity sha512-J1i9VBJd6PV+W9ZYJLNGiwzEW34f+dbrB8GzL5VEUdDEWQqU89DtSx4oeX01h5e+GP1xI4e7CRn7fbYeNKdZOg==
|
||||
|
||||
tsc-watch@^5.0.3:
|
||||
version "5.0.3"
|
||||
@@ -2562,9 +2559,10 @@ type-is@~1.6.18:
|
||||
media-typer "0.3.0"
|
||||
mime-types "~2.1.24"
|
||||
|
||||
typescript@^4.9.3:
|
||||
version "4.9.5"
|
||||
resolved "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz"
|
||||
typescript@^5.2.2:
|
||||
version "5.2.2"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78"
|
||||
integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==
|
||||
|
||||
undici@5.22.1:
|
||||
version "5.22.1"
|
||||
|
||||
Reference in New Issue
Block a user