From 47664c0350dc5a579d4b41dea2830ddde07d9860 Mon Sep 17 00:00:00 2001 From: Histmy Date: Fri, 15 Jul 2022 22:28:03 +0200 Subject: [PATCH] fixed most of lame issues reported by codefactor --- src/app.ts | 11 ++++++----- src/modules/anketa.ts | 5 +++-- src/modules/komRNG.ts | 2 +- src/modules/komStatic.ts | 2 +- src/modules/spink.ts | 6 +++--- src/modules/status.ts | 6 +++--- src/modules/vojs.ts | 2 +- src/utils/types.ts | 2 +- src/utils/utils.ts | 11 +++++------ 9 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/app.ts b/src/app.ts index 33c40af..82f4e39 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,6 +1,6 @@ -import { Client, Collection, Intents, MessageActionRow, MessageButton } from "discord.js"; +import { Client, Intents, MessageActionRow, MessageButton } from "discord.js"; import { readdirSync } from "fs"; -import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, RunFunkce, SRecord, SuperListenerFunkce, CustomKomandy } from "./utils/types"; +import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, CustomKomandy } from "./utils/types"; import { adminLog, getFirstArg, formatCas, loadEnv, oddiakritikovat, sortArr } from "./utils/utils.js"; import levenshtein from "js-levenshtein"; import { emouty } from "./utils/emotes"; @@ -30,7 +30,7 @@ custom.emitter.on("komandi", (komandi, naPoslani) => { helpServer.cmds = sortArr([...komandyNaPoslani, ...naPoslani]); }); -const runEvent = (name: string, args: any[]) => { +const runEvent = (name: string, args: unknown[]) => { for (const listener of superEventy[name] || []) { if (!listener) continue; // [after] pozice v superEventy arrayi se dají nastavovat a teoreticky může nastat mezera try { @@ -178,7 +178,7 @@ client.on("messageCreate", async mes => { i.update({ content: `ok vole ${emouty.d3k}`, components: [radek] }); runKomand(cmd, cmdName); }); - collector.on("end", (c: Collection) => { + collector.on("end", c => { if (c.size) return; radek.components.forEach(btn => btn.setDisabled()); zprava.edit({ content: "pozde", components: [radek] }); @@ -191,7 +191,8 @@ client.on("messageCreate", async mes => { // Simulation of userPresenceUpdate event client.on("presenceUpdate", (bef, aft) => { - const user = aft.user as CUser; + const user = aft.user as CUser | null; + if (!user) return; if (!user.presence) user.presence = {}; if (JSON.stringify(aft.clientStatus) == JSON.stringify(user.presence)) return; diff --git a/src/modules/anketa.ts b/src/modules/anketa.ts index 8abd82e..85b2cd7 100644 --- a/src/modules/anketa.ts +++ b/src/modules/anketa.ts @@ -13,7 +13,7 @@ const exp: Modul = { run: async (mes, arg) => { const args = arg.toLocaleLowerCase().split(" "); - let settings = { + const settings = { time: 60, immediateShow: true }; @@ -24,7 +24,7 @@ const exp: Modul = { return `tuto jeste neni implemenovany ${emouty.sjeta}`; case "start": - case "zapnout": + case "zapnout": { const temp = args.slice(1).join(" "); const moznosti = temp.split(temp.indexOf("|") > -1 ? "|" : ",").reduce((acc, c) => { if (c.length) acc.push(c.trim()); @@ -80,6 +80,7 @@ const exp: Modul = { zprava.edit({ components: [], embeds: [embed] }); }); break; + } default: return `takovi to "${args[0]}" sem moc nepochitil`; diff --git a/src/modules/komRNG.ts b/src/modules/komRNG.ts index 51d0b55..d937434 100644 --- a/src/modules/komRNG.ts +++ b/src/modules/komRNG.ts @@ -8,7 +8,7 @@ const uz = ["ne", "jeste ne", "jiz brzy", "za chvili", "vubec", "nikdy", "za dlo const rand = (max: number) => Math.floor(Math.random() * max); -const choose = (arr: any[]) => arr[rand(arr.length)]; +const choose = (arr: string[]) => arr[rand(arr.length)]; const exp: Modul = { more_komandy: { diff --git a/src/modules/komStatic.ts b/src/modules/komStatic.ts index 9e3fb8a..637e837 100644 --- a/src/modules/komStatic.ts +++ b/src/modules/komStatic.ts @@ -4,7 +4,7 @@ import { emouty } from "../utils/emotes"; import { Modul } from "../utils/types"; import { formatCas } from "../utils/utils"; -const pomoc: [string[], {}] = require("../../res/pomoc.json"); +const pomoc: [string[], Record] = require("../../res/pomoc.json"); const exp: Modul = { more_komandy: { diff --git a/src/modules/spink.ts b/src/modules/spink.ts index 717ea00..4bf4164 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -179,7 +179,7 @@ const exp: Modul = { syncSpink(); const uzivatel = mes.content.match(/(?<=discord_)\d+/)?.[0]; if (!uzivatel) return; - for (const [_, guild] of mes.client.guilds.cache) { + for (const [, guild] of mes.client.guilds.cache) { const member = guild.members.cache.get(uzivatel); if (!member) continue; @@ -204,9 +204,9 @@ const exp: Modul = { if (adminRole) make("a", adminRole); continue; } - for (const [_, channel] of guild.channels.cache) { + for (const [, channel] of guild.channels.cache) { if (channel.type !== "GUILD_VOICE") continue; - for (const [_, member] of channel.members) { + for (const [, member] of channel.members) { if (member.id !== uzivatel) continue; member.voice.disconnect("spinkacek"); return; diff --git a/src/modules/status.ts b/src/modules/status.ts index a0ce1b3..df242fa 100644 --- a/src/modules/status.ts +++ b/src/modules/status.ts @@ -25,7 +25,7 @@ const prepSend = (zmeny: UserChange[]) => { poslatData({ changes }); }; -const poslatData = (data: SRecord) => { +const poslatData = (data: SRecord) => { data.pwd = process.env.statPass; fetch("http://deadfish.cz:4629/endpoint-pro-denimka/", { method: "POST", headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .catch(err => { @@ -109,8 +109,8 @@ const exp: Modul = { }, // Odeslání statusu při změně jména nebo profilovky - on_userUpdate: (_: any, aft: User) => { - if (!process.env.ignorePresence && aft.id != aft.client.user?.id) + on_userUpdate: (bef: User, aft: User) => { + if (!process.env.ignorePresence && bef.id != aft.client.user?.id) prepSend([{ ch: "user", user: aft }]); } }; diff --git a/src/modules/vojs.ts b/src/modules/vojs.ts index 1f496a1..2274c4c 100644 --- a/src/modules/vojs.ts +++ b/src/modules/vojs.ts @@ -31,7 +31,7 @@ const vypocitatCas = (conn: VoiceConnection) => { timeouty[conn.joinConfig.guildId] = setTimeout(() => rekniCas(conn, `${nula(hod)}${nula(min)}`), Number(d) - Number(c)); }; -const nula = (a: Number) => a < 10 ? `0${a}` : a; +const nula = (a: number) => a < 10 ? `0${a}` : a; const rekniCas = (conn: VoiceConnection, cas: string) => { play(conn, [{ name: "zvuky/intro.mp3", volume: 0.8 }, { name: `zvuky/${cas}.mp3`, volume: 2 }, { name: "zvuky/grg.mp3", volume: 0.5 }]) diff --git a/src/utils/types.ts b/src/utils/types.ts index 83b8107..5f1cc63 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -83,7 +83,7 @@ export type KomandNaExport = { export interface JoinHovna { conn: VoiceConnection; prev: string | boolean; -}; +} export interface CUser extends User { presence?: ClientPresenceStatusData; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index bf2f406..e67f5bb 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,7 +1,7 @@ import { AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResource, entersState, getVoiceConnection, joinVoiceChannel, PlayerSubscription, StreamType, VoiceConnection, VoiceConnectionStatus } from "@discordjs/voice"; import { Client, Guild, StageChannel, VoiceChannel } from "discord.js"; import { once } from "events"; -import { JoinHovna, MuzikaFace, RunFunkce, SRecord } from "./types"; +import { JoinHovna, KomandNaExport, MuzikaFace, RunFunkce, SRecord } from "./types"; import { existsSync } from "fs"; import { Readable } from "node:stream"; @@ -88,7 +88,6 @@ export async function joinVoice(channel: VoiceChannel | StageChannel | string, g conn = joinVoiceChannel({ channelId, guildId, - //@ts-ignore adapterCreator: guilda.voiceAdapterCreator }); @@ -109,7 +108,7 @@ export async function joinVoice(channel: VoiceChannel | StageChannel | string, g } return { conn, prev }; -}; +} const makeAudioPlayer = (co: string | MuzikaFace | Readable) => { if (typeof co == "string" || co instanceof Readable) return createAudioResource(co); @@ -123,7 +122,7 @@ export const play = (conn: VoiceConnection, co: string | string[] | MuzikaFace | const player = pripojeni[conn.joinConfig.guildId].player; if (!Array.isArray(co)) { - let aud = makeAudioPlayer(co); + const aud = makeAudioPlayer(co); player.play(aud); const funkce = () => { res(); @@ -192,7 +191,7 @@ export function adminLog(client: Client, text: string) { } } -export function sortArr(arr: any[]) { +export function sortArr(arr: KomandNaExport[]) { return arr.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0); } @@ -202,4 +201,4 @@ export function getFirstArg(fn: RunFunkce | string) { .match(/(?:function\s.*?)?\(([^)]*)\)|\w+ =>/)![1] ?.split(",")[1] ?.trim(); -}; +}