Fix some more eslint & ts errors

pull/8/head
Skyler Grey 3 years ago
parent 5c4bacccc8
commit c634e2bc18
Signed by: Minion3665
GPG Key ID: 1AFD10256B3C714D

@ -7,7 +7,8 @@ import {
MessageSelectMenu
} from "discord.js";
import { SlashCommandBuilder } from "@discordjs/builders";
import { WrappedCheck } from "jshaiku";
// @ts-expect-error
import type { WrappedCheck } from "jshaiku";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import client from "../utils/client.js";
import addPlural from "../utils/plurals.js";
@ -17,9 +18,7 @@ const command = new SlashCommandBuilder()
.setName("categorise")
.setDescription("Categorises your servers channels");
const callback = async (
interaction: CommandInteraction
): Promise<void | unknown> => {
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const channels = interaction.guild.channels.cache.filter(
(c) => c.type !== "GUILD_CATEGORY"
);

@ -1,4 +1,4 @@
import { HistorySchema } from "../../utils/database";
import { HistorySchema } from "../../utils/database.js";
import Discord, {
CommandInteraction,
GuildMember,

@ -71,17 +71,15 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
.setRequired(false)
);
const callback = async (
interaction: CommandInteraction
): Promise<void | unknown> => {
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { log, NucleusColors, renderUser, entry, renderDelta } =
client.logger;
const user = interaction.options.getMember("user") as GuildMember;
const time = {
days: interaction.options.getInteger("days") || 0,
hours: interaction.options.getInteger("hours") || 0,
minutes: interaction.options.getInteger("minutes") || 0,
seconds: interaction.options.getInteger("seconds") || 0
days: interaction.options.getInteger("days") ?? 0,
hours: interaction.options.getInteger("hours") ?? 0,
minutes: interaction.options.getInteger("minutes") ?? 0,
seconds: interaction.options.getInteger("seconds") ?? 0
};
const config = await client.database.guilds.read(interaction.guild.id);
let serverSettingsDescription = config.moderation.mute.timeout

@ -1,5 +1,5 @@
import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js";
import { ChannelType } from "discord-api-types";
import { ChannelType } from "discord-api-types/v9";
import Discord, {
CommandInteraction,
MessageActionRow,

@ -1,5 +1,5 @@
import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js";
import { ChannelType } from "discord-api-types";
import { ChannelType } from "discord-api-types/v9";
import Discord, {
CommandInteraction,
MessageActionRow,

@ -1,5 +1,5 @@
import { LoadingEmbed } from "./../../../utils/defaultEmbeds.js";
import { ChannelType } from "discord-api-types";
import { ChannelType } from "discord-api-types/v9";
import Discord, {
CommandInteraction,
MessageActionRow,
@ -9,7 +9,6 @@ import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
import confirmationMessage from "../../../utils/confirmationMessage.js";
import getEmojiByName from "../../../utils/getEmojiByName.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import type { WrappedCheck } from "jshaiku";
import client from "../../../utils/client.js";

@ -19,7 +19,7 @@ import {
SelectMenuOption,
SlashCommandSubcommandBuilder
} from "@discordjs/builders";
import { ChannelType } from "discord-api-types";
import { ChannelType } from "discord-api-types/v9";
import client from "../../utils/client.js";
import {
toHexInteger,

@ -8,12 +8,12 @@ import Discord, {
MessageComponentInteraction,
Role
} from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import client from "../../utils/client.js";
import confirmationMessage from "../../utils/confirmationMessage.js";
import generateKeyValueList from "../../utils/generateKeyValueList.js";
import { ChannelType } from "discord-api-types";
import { ChannelType } from "discord-api-types/v9";
import getEmojiByName from "../../utils/getEmojiByName.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
@ -49,9 +49,7 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
.addChannelTypes([ChannelType.GuildText, ChannelType.GuildNews])
);
const callback = async (
interaction: CommandInteraction
): Promise<void | unknown> => {
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { renderRole, renderChannel, log, NucleusColors, entry, renderUser } =
client.logger;
await interaction.reply({
@ -340,7 +338,9 @@ const callback = async (
const check = (interaction: CommandInteraction) => {
const member = interaction.member as Discord.GuildMember;
if (!member.permissions.has("MANAGE_GUILD"))
throw "You must have the *Manage Server* permission to use this command";
throw new Error(
"You must have the *Manage Server* permission to use this command"
);
return true;
};

@ -1,5 +1,5 @@
import Discord, { CommandInteraction } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import type { CommandInteraction, GuildMember } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import confirmationMessage from "../../utils/confirmationMessage.js";
import keyValueList from "../../utils/generateKeyValueList.js";
@ -28,10 +28,11 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
.setDescription("The new name of the tag / Edit")
);
const callback = async (interaction: CommandInteraction): Promise<void> => {
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (!interaction.guild) return;
const name = interaction.options.getString("name");
const value = interaction.options.getString("value") || "";
const newname = interaction.options.getString("newname") || "";
const value = interaction.options.getString("value") ?? "";
const newname = interaction.options.getString("newname") ?? "";
if (!newname && !value)
return await interaction.reply({
embeds: [
@ -155,9 +156,11 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
};
const check = (interaction: CommandInteraction) => {
const member = interaction.member as Discord.GuildMember;
const member = interaction.member as GuildMember;
if (!member.permissions.has("MANAGE_MESSAGES"))
throw "You must have the *Manage Messages* permission to use this command";
throw new Error(
"You must have the *Manage Messages* permission to use this command"
);
return true;
};

@ -55,8 +55,9 @@ class Embed {
}
const callback = async (interaction: CommandInteraction): Promise<void> => {
if (!interaction.guild) return;
const { renderUser, renderDelta } = client.logger;
const member = (interaction.options.getMember("user") ||
const member = (interaction.options.getMember("user") ??
interaction.member) as Discord.GuildMember;
const flags: string[] = [];
if (
@ -107,26 +108,29 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
};
const members = await interaction.guild.members.fetch();
const membersArray = [...members.values()];
membersArray.sort((a, b) => a.joinedTimestamp - b.joinedTimestamp);
membersArray.sort((a, b) => {
if (a.joinedTimestamp === null) return 1;
if (b.joinedTimestamp === null) return -1;
return a.joinedTimestamp - b.joinedTimestamp;
});
const joinPos = membersArray.findIndex((m) => m.id === member.user.id);
const roles = member.roles.cache
.filter((r) => r.id !== interaction.guild.id)
.filter((r) => r.id !== interaction.guild!.id)
.sort();
let s = "";
let count = 0;
let ended = false;
roles.map((item) => {
if (ended) return;
const string = `<@&${item.id}>, `;
for (const roleId in roles) {
const string = `<@&${roleId}>, `;
if (s.length + string.length > 1000) {
ended = true;
s += `and ${roles.size - count} more`;
return;
break;
}
count++;
s += string;
});
}
if (s.length > 0 && !ended) s = s.slice(0, -2);
let perms = "";

@ -19,7 +19,7 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
const callback = async (interaction: CommandInteraction): Promise<void> => {
const { renderUser } = client.logger;
const member = (interaction.options.getMember("user") ||
const member = (interaction.options.getMember("user") ??
interaction.member) as Discord.GuildMember;
await interaction.reply({
embeds: [
@ -33,7 +33,7 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
url: member.user.displayAvatarURL({ dynamic: true })
})
)
.setImage(await member.user.displayAvatarURL({ dynamic: true }))
.setImage(member.user.displayAvatarURL({ dynamic: true }))
],
ephemeral: true,
fetchReply: true

@ -10,7 +10,6 @@ import {
SelectMenuOption,
SlashCommandSubcommandBuilder
} from "@discordjs/builders";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import { WrappedCheck } from "jshaiku";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@ -45,9 +44,7 @@ const generateFromTrack = (
return "TRACKS.VERTICAL.MIDDLE." + disabled + active;
};
const callback = async (
interaction: CommandInteraction
): Promise<void | unknown> => {
const callback = async (interaction: CommandInteraction): Promise<unknown> => {
const { renderUser } = client.logger;
const member = interaction.options.getMember("user") as GuildMember;
const guild = interaction.guild;
@ -57,7 +54,7 @@ const callback = async (
let track = 0;
let generated;
const roles = await guild.roles.fetch();
const memberRoles = await member.roles;
const memberRoles = member.roles;
let managed: boolean;
while (true) {
const data = config.tracks[track];
@ -137,9 +134,8 @@ const callback = async (
})
.join("\n");
const selected = [];
for (let i = 0; i < data.track.length; i++) {
if (memberRoles.cache.has(data.track[i]))
selected.push(data.track[i]);
for (const position of data.track) {
if (memberRoles.cache.has(position)) selected.push(position);
}
const conflict = data.retainPrevious ? false : selected.length > 1;
let conflictDropdown;
@ -278,7 +274,8 @@ const check = async (
) => {
const tracks = (await client.database.guilds.read(interaction.guild.id))
.tracks;
if (tracks.length === 0) throw "This server does not have any tracks";
if (tracks.length === 0)
throw new Error("This server does not have any tracks");
const member = interaction.member as GuildMember;
// Allow the owner to promote anyone
if (member.id === interaction.guild.ownerId) return true;
@ -297,7 +294,7 @@ const check = async (
}
// Check if the user has manage_roles permission
if (!managed && !member.permissions.has("MANAGE_ROLES"))
throw "You do not have the *Manage Roles* permission";
throw new Error("You do not have the *Manage Roles* permission");
// Allow track
return true;
};

@ -1,6 +1,5 @@
import type { CommandInteraction } from "discord.js";
import { SlashCommandBuilder } from "@discordjs/builders";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import { WrappedCheck } from "jshaiku";
import verify from "../reflex/verify.js";

@ -1,5 +1,4 @@
import fs from "fs";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import * as readLine from "node:readline/promises";

@ -40,7 +40,17 @@ export async function callback(client, channel) {
displayName = "Channel";
}
}
const list = {
const list: {
channelId: string;
name: string;
topic?: string | null;
type: any;
category: any;
nsfw?: boolean | null;
created: any;
deleted: any;
deletedBy: any;
} = {
channelId: entry(channel.id, `\`${channel.id}\``),
name: entry(channel.id, `${channel.name}`),
topic: null,

@ -1,5 +1,4 @@
import type { Guild } from "discord.js";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import type { HaikuClient } from "jshaiku";
import guide from "../reflex/guide.js";

@ -1,4 +1,3 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import { HaikuClient } from "jshaiku";
import {
@ -14,12 +13,11 @@ import createLogException from "../utils/createLogException.js";
import getEmojiByName from "../utils/getEmojiByName.js";
import client from "../utils/client.js";
import { callback as a } from "../reflex/statsChannelUpdate.js";
import type { Message } from "discord.js";
import { Message, ThreadChannel } from "discord.js";
export const event = "messageCreate";
export async function callback(_client: HaikuClient, message: Message) {
if (!message) return;
if (!message.guild) return;
if (message.author.bot) return;
if (message.channel.type === "DM") return;
@ -112,18 +110,14 @@ export async function callback(_client: HaikuClient, message: Message) {
if (fileNames.files.length > 0) {
for (const element of fileNames.files) {
if (!message) return;
const url = element.url ? element.url : element.local;
if (url !== undefined) {
if (
/\.(jpg|jpeg|png|gif|gifv|webm|webp|mp4|wav|mp3|ogg)$/.test(
url
)
/\.(jpg|jpeg|png|gif|gifv|webm|webp|mp4|wav|mp3|ogg)$/.test(url)
) {
if (
config.filters.images.NSFW &&
!(message.channel.type === "GUILD_PUBLIC_THREAD"
? false
!(message.channel instanceof ThreadChannel
? message.channel.parent?.nsfw
: message.channel.nsfw)
) {
if (await NSFWCheck(url)) {
@ -234,7 +228,7 @@ export async function callback(_client: HaikuClient, message: Message) {
}
}
if (config.filters.malware) {
if (!MalwareCheck(url)) {
if (!(await MalwareCheck(url))) {
createLogException(
message.guild.id,
message.channel.id,
@ -268,8 +262,6 @@ export async function callback(_client: HaikuClient, message: Message) {
}
}
}
}
if (!message) return;
const linkDetectionTypes = await LinkCheck(message);
if (linkDetectionTypes.length > 0) {
@ -363,7 +355,6 @@ export async function callback(_client: HaikuClient, message: Message) {
}
if (config.filters.pings.roles) {
for (const roleId in message.mentions.roles) {
if (!message) return;
if (!config.filters.pings.allowed.roles.includes(roleId)) {
createLogException(
message.guild.id,

@ -1,5 +1,4 @@
import type Discord from "discord.js";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import type { HaikuClient } from "jshaiku";
export const event = "webhookUpdate";

@ -5,8 +5,8 @@ import { Guilds, History, ModNotes, Premium } from "./utils/database.js";
import client from "./utils/client.js";
import EventScheduler from "./utils/eventScheduler.js";
await client.registerCommandsIn("./commands");
await client.registerEventsIn("./events");
await client.registerCommandsIn(`dist/commands`);
await client.registerEventsIn(`dist/events`);
client.on("ready", () => {
runServer(client);
});

@ -22,7 +22,7 @@ export default async function logAttachment(
size: attachment.size
});
}
const links = message.content.match(/https?:\/\/\S+/gi) || [];
const links = message.content.match(/https?:\/\/\S+/gi) ?? [];
for (const link of links) {
if (
link

@ -1,4 +1,3 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import * as us from "unscan";
import fetch from "node-fetch";
@ -17,13 +16,13 @@ interface MalwareSchema {
export async function testNSFW(link: string): Promise<NSFWSchema> {
const p = await saveAttachment(link);
const result = await us.nsfw.file(p);
return result;
return { nsfw: result.nsfw ?? false };
}
export async function testMalware(link: string): Promise<MalwareSchema> {
const p = await saveAttachment(link);
const result = await us.malware.file(p);
return result;
return { safe: result.safe ?? true };
}
export async function saveAttachment(link: string): Promise<string> {

@ -1,6 +1,5 @@
import type Discord from "discord.js";
import { Collection, MongoClient } from "mongodb";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import structuredClone from "@ungap/structured-clone";
import config from "../config/main.json" assert { type: "json" };
@ -95,10 +94,10 @@ export class Guilds {
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async remove(
guild: string,
key: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any,
innerKey?: string | null
) {

@ -11,7 +11,6 @@ class EmojiEmbed extends MessageEmbed {
_title = "";
_emoji: string | null = null;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
// This *is* meant to be an accessor rather than a property
override get title() {

Loading…
Cancel
Save