fixed most of lame issues reported by codefactor

This commit is contained in:
Histmy 2022-07-15 22:28:03 +02:00
parent ff3e9f1d51
commit 47664c0350
9 changed files with 24 additions and 23 deletions

View File

@ -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<any, any>) => {
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;

View File

@ -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<string[]>((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`;

View File

@ -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: {

View File

@ -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<string, unknown>] = require("../../res/pomoc.json");
const exp: Modul = {
more_komandy: {

View File

@ -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;

View File

@ -25,7 +25,7 @@ const prepSend = (zmeny: UserChange[]) => {
poslatData({ changes });
};
const poslatData = (data: SRecord<any>) => {
const poslatData = (data: SRecord<unknown>) => {
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 }]);
}
};

View File

@ -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 }])

View File

@ -83,7 +83,7 @@ export type KomandNaExport = {
export interface JoinHovna {
conn: VoiceConnection;
prev: string | boolean;
};
}
export interface CUser extends User {
presence?: ClientPresenceStatusData;

View File

@ -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();
};
}