Improve typing, delete an unnecessary file, fix some admin panel errors (#70)

pull/75/head
Skyler 3 years ago committed by GitHub
commit 0ec719696d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -189,8 +189,8 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
return; return;
} }
const guild = (await client.guilds.fetch(GuildID)) as Guild | null; const guild = (await client.guilds.fetch(GuildID)) as Guild | null;
if (!guild) {
await i.deferUpdate(); await i.deferUpdate();
if (!guild) {
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger") new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")
@ -200,7 +200,6 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
return; return;
} }
if (i.customId === "stats") { if (i.customId === "stats") {
await i.deferUpdate();
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
@ -238,7 +237,6 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
components: [] components: []
}); });
} else if (i.customId === "data") { } else if (i.customId === "data") {
await i.deferUpdate();
// Get all the data and convert to a string // Get all the data and convert to a string
const data = await client.database.guilds.read(guild.id); const data = await client.database.guilds.read(guild.id);
const stringified = JSON.stringify(data, null, 2); const stringified = JSON.stringify(data, null, 2);
@ -277,7 +275,6 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
components: [] components: []
}); });
} else if (i.customId === "cache") { } else if (i.customId === "cache") {
await i.deferUpdate();
await client.memory.forceUpdate(guild.id); await client.memory.forceUpdate(guild.id);
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [

@ -144,12 +144,14 @@ export class Guilds {
} }
async staffChannels(): Promise<string[]> { async staffChannels(): Promise<string[]> {
const entries = (await this.guilds const entries = (
await this.guilds
.find( .find(
{ "logging.staff.channel": { $exists: true } }, { "logging.staff.channel": { $exists: true } },
{ projection: { "logging.staff.channel": 1, _id: 0 } } { projection: { "logging.staff.channel": 1, _id: 0 } }
) )
.toArray()).map((e) => e.logging.staff.channel); .toArray()
).map((e) => e.logging.staff.channel);
const out: string[] = []; const out: string[] = [];
for (const entry of entries) { for (const entry of entries) {
if (entry) out.push(entry); if (entry) out.push(entry);

@ -1,22 +1,40 @@
import type Discord from "discord.js"; import type Discord from "discord.js";
import client from "./client.js"; import client from "./client.js";
/**
* @param name The name of the command, not including a leading slash. This can be space or slash separated e.g. "mod/about" or "mod about"
* @returns A string which when put into Discord will mention the command if the command exists or a codeblock with the command name if it does not
*
* @throws Will throw an error if as empty string is passed
**/
export const getCommandMentionByName = (name: string): string => { export const getCommandMentionByName = (name: string): string => {
const split = name.replaceAll("/", " ").split(" "); const split = name.replaceAll("/", " ").split(" ");
const commandName: string = split[0]!; const commandName: string | undefined = split[0];
if (commandName === undefined) throw new RangeError(`Invalid command ${name} provided to getCommandByName`);
const filterCommand = (command: Discord.ApplicationCommand) => command.name === commandName; const filterCommand = (command: Discord.ApplicationCommand) => command.name === commandName;
const command = client.fetchedCommands.filter((c) => filterCommand(c)); const command = client.fetchedCommands.filter((c) => filterCommand(c));
if (command.size === 0) return `\`/${name.replaceAll("/", " ")}\``; const commandID = command.first()?.id;
const commandID = command.first()!.id;
if (commandID === undefined) return `\`/${name.replaceAll("/", " ")}\``;
return `</${split.join(" ")}:${commandID}>`; return `</${split.join(" ")}:${commandID}>`;
}; };
/**
* @param name The name of the command, not including a leading slash. This can be space or slash separated e.g. "mod/about" or "mod about"
* @returns An object containing the command name, the command description and a string which when put into Discord will mention the command
*
* @throws Will throw an error if the command doesn't exist
* @throws Will throw an error if as empty string is passed
**/
export const getCommandByName = (name: string): { name: string; description: string; mention: string } => { export const getCommandByName = (name: string): { name: string; description: string; mention: string } => {
const split = name.replaceAll(" ", "/"); const split = name.replaceAll(" ", "/");
const command = client.commands["commands/" + split]!; const command = client.commands["commands/" + split];
// console.log(command)
if (command === undefined) throw new RangeError(`Invalid command ${name} provided to getCommandByName`);
const mention = getCommandMentionByName(name); const mention = getCommandMentionByName(name);
return { return {
name: command[1].name, name: command[1].name,

@ -18,7 +18,7 @@ function getEmojiPaths(obj: EmojisIndex, path: string[] = []) {
} }
getEmojiPaths(emojis); getEmojiPaths(emojis);
function getEmojiByName(name: (typeof EMOJIPATHS)[number], format?: string): string { function getEmojiByName(name: typeof EMOJIPATHS[number], format?: string): string {
const parts = name.split("."); const parts = name.split(".");
let id: string | EmojisIndex | EmojisIndex[] | undefined = emojis; let id: string | EmojisIndex | EmojisIndex[] | undefined = emojis;
for (const part of parts) { for (const part of parts) {

@ -1,80 +0,0 @@
import * as fs from "fs";
import client from "../client.js";
import _ from "lodash";
const dir = "./data";
const files = fs.readdirSync(dir);
for (const file of files) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let rsmData: any;
try {
rsmData = JSON.parse(fs.readFileSync(`${dir}/${file}`, "utf8"));
} catch {
continue;
}
if (!rsmData.version || rsmData.version < 3) continue;
const nucleusData = await client.database.guilds.readOld(rsmData.guild_info.id);
const rsmToNucleus = {
id: rsmData.guild_info.id,
version: 1,
singleEventNotifications: {},
filters: {
images: {
NSFW: rsmData.images?.nsfw,
size: rsmData.images?.toosmall
},
malware: null,
wordFilter: {
enabled: true,
words: {
strict: rsmData.wordfilter?.strict,
loose: rsmData.wordfilter?.soft
},
allowed: {
users: rsmData.wordfilter?.ignore?.members,
roles: rsmData.wordfilter?.ignore?.roles,
channels: rsmData.wordfilter?.ignore?.channels
}
},
invite: {
enabled: rsmData.invite?.enabled,
allowed: {
channels: rsmData.invite?.whitelist?.members,
roles: rsmData.invite?.whitelist?.roles,
users: rsmData.invite?.whitelist?.channels
}
}
},
welcome: {
enabled: true,
role: rsmData.welcome?.role,
channel: rsmData.welcome?.message?.channel,
message: rsmData.welcome?.message?.text ?? null
},
logging: {
logs: {
enabled: true,
channel: rsmData.log_info?.log_channel
},
staff: {
channel: rsmData.log_info?.staff
}
},
verify: {
enabled: true,
role: rsmData.verify_role
},
tickets: {
enabled: true,
category: rsmData.modmail?.cat,
supportRole: rsmData.modmail?.mention,
maxTickets: rsmData.modmail?.max
},
tags: rsmData.tags
} as Partial<ReturnType<typeof client.database.guilds.read>>;
// console.log(rsmToNucleus)
const merged = _.merge(nucleusData, rsmToNucleus);
// console.log(merged)
await client.database.guilds.write(merged.id!, merged);
}

@ -0,0 +1,7 @@
type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends (infer U)[]
? RecursivePartial<U>[]
: T[P] extends object
? RecursivePartial<T[P]>
: T[P];
};
Loading…
Cancel
Save