Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] Help fix #4

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ DBToken="" # https://discord.bots.gg/ Access Token
DBListToken="" # https://discordbotlist.com Access Token

# Internals
postgresToken="" # PostgreSQL DataBase Token
socketToken="" # WebSocket Token
DATABASE_URL="" # DataBase Connection String
Token="" # Bot Token
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"type": "module",
"version": "2.0.14",
"version": "2.0.15",
"scripts": {
"start": "node --max-old-space-size=8192 ./dist/index.js",
"build": "npx tsc",
"dev": "node --enable-source-maps ./dist/bot.js --debug --warn",
"lint": "npx eslint 'src/**/*.ts' --fix"
"dev": "node --enable-source-maps --experimental-wasm-modules ./dist/bot.js --debug --warn",
"lint": "npx eslint 'src/**/*.ts' --fix",
"postinstall": "mkdir ./logs"
},
"dependencies": {
"@discordjs/core": "^1.1.1",
Expand Down
5 changes: 2 additions & 3 deletions src/BaseClient/ClientHelperModules/helpHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as Discord from 'discord.js';
import * as CT from '../../Typings/Typings.js';
import SlashCommands from '../../Events/readyEvents/startupTasks/SlashCommands.js';
import replyCmd from './replyCmd.js';
import * as CT from '../../Typings/Typings.js';
import getLanguage from './getLanguage.js';

import getEmbeds from './helpHelpers/getEmbeds.js';
import replyCmd from './replyCmd.js';

/**
* Helper function to generate a message payload for a slash command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@ import error from '../../error.js';
* @param query - Optional query parameters to filter the commands.
* @returns A Promise that resolves to an array of parsed ApplicationCommand objects.
*/
export default async (guild: Discord.Guild, query?: Discord.RESTGetAPIApplicationCommandsQuery) =>
(cache.apis.get(guild.id) ?? API).applicationCommands
.getGlobalCommands(await getBotIdFromGuild(guild), query)
export default async (
guild: Discord.Guild | undefined,
client: Discord.Client<true>,
query?: Discord.RESTGetAPIApplicationCommandsQuery,
) =>
(guild ? cache.apis.get(guild.id) ?? API : API).applicationCommands
.getGlobalCommands(guild ? await getBotIdFromGuild(guild) : client.user.id, query)
.then((cmds) => {
const parsed = cmds.map((cmd) => new Classes.ApplicationCommand(guild.client, cmd));
const parsed = cmds.map((cmd) => new Classes.ApplicationCommand(client, cmd));

if (!cache.commands.cache.get(guild.id)) cache.commands.cache.set(guild.id, new Map());
if (guild && !cache.commands.cache.get(guild.id)) cache.commands.cache.set(guild.id, new Map());
parsed.forEach((p) => {
cache.commands.cache.get(guild.id)?.set(p.id, p);
if (guild) cache.commands.cache.get(guild.id)?.set(p.id, p);

if (cache.apis.get(guild.id)) return;
if (guild.client.application.commands.cache.get(p.id)) return;
guild.client.application.commands.cache.set(p.id, p);
if (guild && cache.apis.get(guild.id)) return;
if (client.application.commands.cache.get(p.id)) return;
client.application.commands.cache.set(p.id, p);
});
return parsed;
})
.catch((e) => {
error(guild, new Error((e as Discord.DiscordAPIError).message));
if (guild) error(guild, new Error((e as Discord.DiscordAPIError).message));
return e as Discord.DiscordAPIError;
});
21 changes: 14 additions & 7 deletions src/Events/guildEvents/guildDelete/log.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
import type * as Discord from 'discord.js';
import client from '../../../BaseClient/Client.js';
import * as CT from '../../../Typings/Typings.js';
import * as ch from '../../../BaseClient/ClientHelper.js';

export default async (guild: Discord.Guild | undefined) => {
const webhook = await client.fetchWebhook(
process.env.guildActionWebhookID ?? '',
process.env.guildActionWebhookToken ?? '',
);

const totalguildcount =
((await client.shard?.fetchClientValues('guilds.cache.size')) as number[] | undefined)?.reduce(
(acc, count) => acc + count,
0,
) ?? 0;

webhook?.send({
embeds: [
{
color: CT.Colors.Danger,
description: '<@&669894051851403294> joined a new Guild',
fields: [
{
name: 'Guild Name',
value: guild?.name || 'Unknown/Uncached',
},
{ name: 'Guild ID', value: String(guild?.id) || 'Unknown/Uncached' },
{ name: 'Membercount', value: String(guild?.memberCount) || 'Unknown/Uncached' },
{ name: 'Guild Owner ID', value: String(guild?.ownerId) || 'Unknown/Uncached' },
{ name: 'Guild Name', value: guild?.name || 'Unknown/Uncached', inline: true },
{ name: 'Guild ID', value: String(guild?.id) || 'Unknown/Uncached', inline: true },
{ name: 'Membercount', value: String(guild?.memberCount) || 'Unknown/Uncached', inline: true },
{ name: 'Guild Owner ID', value: String(guild?.ownerId) || 'Unknown/Uncached', inline: true },
],
timestamp: new Date().toISOString(),
footer: {
text: `Total Guilds: ${ch.splitByThousand(totalguildcount)}`,
},
},
],
});
Expand Down
5 changes: 3 additions & 2 deletions src/Events/readyEvents/startupTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import verification from './timedFiles/verification.js';
import websiteFetcher from './timedFiles/websiteFetcher.js';

export default async () => {
customAPIsHandler();
await slashCommandInitializer();

await customAPIsHandler();
customBotCommands();

voteHandler();
appealHandler();
interactionHandler();
slashCommandInitializer();
antivirusBlocklistCacher();
nitroHandler();
separators();
Expand Down
32 changes: 9 additions & 23 deletions src/Events/readyEvents/startupTasks/customBotCommands.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
import * as Discord from 'discord.js';
import client from '../../../BaseClient/Client.js';
import * as ch from '../../../BaseClient/ClientHelper.js';

export default async () => {
if (client.shard?.mode === 'process') return;

const settings = await ch.DataBase.guildsettings.findMany({
where: {
token: { not: null },
},
});

settings.forEach(async (s) => {
if (!s.token) return;

const guild = client.guilds.cache.get(s.guildid);
if (!guild) return;
ch.request.commands.getGlobalCommands(undefined, client as Discord.Client<true>);

client.guilds.cache.forEach((g) => {
const globalCommands = async () => {
if (!s.token) return;

const commands = await ch.request.commands.getGlobalCommands(guild);
const commands = await ch.request.commands.getGlobalCommands(g, client as Discord.Client<true>);

if ('message' in commands) {
ch.error(guild, new Error(commands.message));
ch.error(g, new Error(commands.message));
return;
}

commands.forEach((c) => ch.cache.commands.set(guild.id, c.id, c));
commands.forEach((c) => ch.cache.commands.set(g.id, c.id, c));
};

const guildCommands = async () => {
if (!s.token) return;

const commands = await ch.request.commands.getGuildCommands(guild);
const commands = await ch.request.commands.getGuildCommands(g);

if ('message' in commands) {
ch.error(guild, new Error(commands.message));
ch.error(g, new Error(commands.message));
return;
}

commands.forEach((c) => ch.cache.commands.set(guild.id, c.id, c));
commands.forEach((c) => ch.cache.commands.set(g.id, c.id, c));
};

globalCommands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default async () => {
await client.application?.commands.set(createCommands);
await client.application?.commands.fetch();

mainBotCommands(createCommands);
customBotCommands(createCommands);
await mainBotCommands(createCommands);
await customBotCommands(createCommands);
};

type ValueOf<T> = T[keyof T];
Expand Down
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ sms.install({

console.clear();
log(
`
+++++++++++++++ Welcome to Ayako ++++++++++++++++
`+++++++++++++++ Welcome to Ayako ++++++++++++++++
+ Restart all Shards with "restart" +
+ Restart one Shard with "restart [Shard ID]" +
+ Arguments: +
+ --debug --debug-db --warn --debug-queries +
+ --silent --put-commands +
+++++++++++++++++++++++++++++++++++++++++++++++++
`,
+++++++++++++++++++++++++++++++++++++++++++++++++`,
true,
);

Expand All @@ -33,7 +31,7 @@ const manager = new Discord.ShardingManager(
{
token: process.env.Token,
shardArgs: process.argv,
execArgv: ['--experimental-wasm-modules', '--experimental-websocket'],
execArgv: ['--experimental-wasm-modules'],
},
);

Expand Down