Apollo Initial Files

This commit is contained in:
2024-10-26 20:33:18 +08:00
commit 2d302551f9
82 changed files with 10643 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
export class MissingPermissionsException {
public message = "Missing permissions:";
constructor(public permissions: string[]) {}
public toString() {
return `${this.message} ${this.permissions.join(", ")}`;
}
}
+21
View File
@@ -0,0 +1,21 @@
import { ChatInputCommandInteraction, PermissionResolvable } from "discord.js";
import { Command } from "../interfaces/Command";
export interface PermissionResult {
result: boolean;
missing: string[];
}
export async function checkPermissions(
command: Command,
interaction: ChatInputCommandInteraction
): Promise<PermissionResult> {
const member = await interaction.guild!.members.fetch({ user: interaction.client.user!.id });
const requiredPermissions = command.permissions as PermissionResolvable[];
if (!command.permissions) return { result: true, missing: [] };
const missing = member.permissions.missing(requiredPermissions);
return { result: !Boolean(missing.length), missing };
}
+19
View File
@@ -0,0 +1,19 @@
import "dotenv/config";
import { Config } from "../interfaces/Config";
let config: Config;
try {
config = require("../config.json");
} catch (error) {
config = {
TOKEN: process.env.TOKEN || "",
MAX_PLAYLIST_SIZE: parseInt(process.env.MAX_PLAYLIST_SIZE!) || 10,
PRUNING: process.env.PRUNING === "true" ? true : false,
STAY_TIME: parseInt(process.env.STAY_TIME!) || 30,
DEFAULT_VOLUME: parseInt(process.env.DEFAULT_VOLUME!) || 100,
LOCALE: process.env.LOCALE || "en"
};
}
export { config };
+62
View File
@@ -0,0 +1,62 @@
import i18n from "i18n";
import { join } from "path";
import { config } from "./config";
i18n.configure({
locales: [
"ar",
"bg",
"cs",
"de",
"el",
"en",
"es",
"fa",
"fr",
"id",
"it",
"ja",
"ko",
"mi",
"nb",
"nl",
"pl",
"pt_br",
"ro",
"ru",
"sv",
"th",
"tr",
"uk",
"vi",
"zh_cn",
"zh_sg",
"zh_tw"
],
directory: join(__dirname, "..", "locales"),
defaultLocale: "en",
retryInDefaultLocale: true,
objectNotation: true,
register: global,
logWarnFn: function (msg) {
console.log(msg);
},
logErrorFn: function (msg) {
console.log(msg);
},
missingKeyFn: function (locale, value) {
return value;
},
mustacheConfig: {
tags: ["{{", "}}"],
disable: false
}
});
i18n.setLocale(config.LOCALE);
export { i18n };
+6
View File
@@ -0,0 +1,6 @@
export const videoPattern = /^(https?:\/\/)?(www\.)?(m\.|music\.)?(youtube\.com|youtu\.?be)\/.+$/;
export const playlistPattern = /^.*(list=)([^#\&\?]*).*/;
export const scRegex = /^https?:\/\/(soundcloud\.com)\/(.*)$/;
export const mobileScRegex = /^https?:\/\/(soundcloud\.app\.goo\.gl)\/(.*)$/;
export const isURL =
/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
+4
View File
@@ -0,0 +1,4 @@
import { GuildMember } from "discord.js";
export const canModifyQueue = (member: GuildMember) =>
member.voice.channelId === member.guild.members.me!.voice.channelId;
+13
View File
@@ -0,0 +1,13 @@
import { ButtonInteraction, CommandInteraction } from "discord.js";
export async function safeReply(interaction: CommandInteraction | ButtonInteraction, content: string) {
try {
if (interaction.deferred || interaction.replied) {
await interaction.followUp(content);
} else {
await interaction.reply(content);
}
} catch (error) {
console.error(error);
}
}