From 26d7e8127ddbbb68517dcff6bb441a911cbacefa Mon Sep 17 00:00:00 2001 From: Histmy Date: Fri, 2 Sep 2022 20:07:21 +0200 Subject: [PATCH] Fixed dum naucse err added custom log with time and color random spink max 15 mins now --- package-lock.json | 4 ++-- package.json | 2 +- src/app.ts | 10 +++++----- src/modules/komComplex.ts | 1 - src/modules/novaOrdinacka.ts | 3 ++- src/modules/onReady.ts | 4 ++-- src/modules/spink.ts | 10 +++++----- src/modules/status.ts | 4 ++-- src/modules/vojs.ts | 4 ++-- src/modules/zbytek.ts | 6 +++--- src/utils/customCommands.ts | 4 ++-- src/utils/utils.ts | 26 +++++++++++++++----------- 12 files changed, 41 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index bdd58b6..a692c54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "denim_3001", - "version": "3001.41.1", + "version": "3001.41.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.41.1", + "version": "3001.41.2", "license": "ISC", "dependencies": { "@discordjs/voice": "^0.11.0", diff --git a/package.json b/package.json index 5d7e19c..3a958d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.41.1", + "version": "3001.41.2", "description": "Toto je velmi kvalitní bot.", "repository": { "url": "https://github.com/Histmy/Denim-Bot/" diff --git a/src/app.ts b/src/app.ts index c89bc46..f5a48fe 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,7 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, Client, GatewayIntentBits, Message, Partials } from "discord.js"; import { readdirSync } from "fs"; 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 { adminLog, getFirstArg, formatCas, loadEnv, oddiakritikovat, sortArr, log } from "./utils/utils.js"; import levenshtein from "js-levenshtein"; import { emouty } from "./utils/emotes"; @@ -50,7 +50,7 @@ const runEvent = (name: string, args: unknown[]) => { if (listener(...args)) return true; // if listener returns true, it means, we shouldn't continue with execustion } catch (e) { if (process.env.dieOnError) throw e; - console.log("error pri spusteni super listeneru", e); + log("error pri spusteni super listeneru", e as Error); adminLog(client, "error pri supereventu"); } } @@ -60,7 +60,7 @@ const runEvent = (name: string, args: unknown[]) => { listener(...args); } catch (e) { if (process.env.dieOnError) throw e; - console.log("error pri spousteni eventu", e); + log("error pri spousteni eventu", e as Error); adminLog(client, "error pri eventu"); } }); @@ -70,7 +70,7 @@ const runEvent = (name: string, args: unknown[]) => { readdirSync(modulFolder).forEach(soubor => { if (!soubor.endsWith(".js")) return; const modul: Modul = require(`${modulFolder}${soubor}`); - console.log(`Loaded: ${modulFolder}${soubor}`); + log(`Loaded: ${modulFolder}${soubor}`); modul.client = client; Object.keys(modul).forEach(name => { @@ -144,7 +144,7 @@ async function runKomand(mes: Message, cmd: Komand, cmdName: string, arg: string if (result) mes.channel.send(result); } catch (e) { if (process.env.dieOnError) throw e; - console.log("error pri spousteni akce", e); + log("error pri spousteni akce", e as Error); const admin = process.env.adminID; mes.channel.send(`pri spousteni thohoto komandu nastala chyba ${admin ? `<@${admin}> uz?` : ""}`); } diff --git a/src/modules/komComplex.ts b/src/modules/komComplex.ts index 3be0595..cd413ae 100644 --- a/src/modules/komComplex.ts +++ b/src/modules/komComplex.ts @@ -91,7 +91,6 @@ const exp: Modul = { naCo = await mes.channel.messages.fetch(mes.reference.messageId!); } else { const msgs = [...mes.channel.messages.cache.values()]; - console.log(msgs.length); if (msgs.length < 2) { naCo = (await mes.channel.messages.fetch({ limit: 2 })).at(1)!; } diff --git a/src/modules/novaOrdinacka.ts b/src/modules/novaOrdinacka.ts index 0bb44c6..9b4d708 100644 --- a/src/modules/novaOrdinacka.ts +++ b/src/modules/novaOrdinacka.ts @@ -2,6 +2,7 @@ import { Client, TextChannel } from "discord.js"; import fetch from "node-fetch"; import { emouty } from "../utils/emotes"; import { Modul } from "../utils/types"; +import { log } from "../utils/utils"; let posledniDatum = ""; let client: Client; @@ -28,7 +29,7 @@ function hendelieren() { .then(r => r.text()) .then(txt => { const tabule = txt.match(/(?.+)<\/table>/is); - if (!tabule) return console.log("nenašel jsem tabuleho"); + if (!tabule) return log(new Error("nenašel jsem tabuleho")); const detaily = tabule.groups!.kontent.match(/\d\d\/\d\d\/\d{4})/is); const datum = detaily!.groups!.datum; diff --git a/src/modules/onReady.ts b/src/modules/onReady.ts index 9718c0f..06533a1 100644 --- a/src/modules/onReady.ts +++ b/src/modules/onReady.ts @@ -2,11 +2,11 @@ import { Client } from "discord.js"; import { Modul } from "../utils/types"; -import { adminLog } from "../utils/utils"; +import { adminLog, log } from "../utils/utils"; const exp: Modul = { on_ready: async () => { - console.log("A jedeš!"); + log("A jedeš!"); if (process.argv.length < 3) return; const client: Client = module.exports.client; adminLog(client, "pošel jsem"); diff --git a/src/modules/spink.ts b/src/modules/spink.ts index 9546428..8831d34 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -4,7 +4,7 @@ import { ChannelType, Message, Presence, Role, TextBasedChannel, User, VoiceStat import fetch from "node-fetch"; import { emouty } from "../utils/emotes"; import { Modul, Spinkackar, SRecord } from "../utils/types"; -import { formatCas, formatter, oddiakritikovat, ping } from "../utils/utils"; +import { formatCas, formatter, log, oddiakritikovat, ping } from "../utils/utils"; let spinkacky: SRecord; const budouciSpinky: SRecord = {}; @@ -105,8 +105,8 @@ const exp: Modul = { if (kdy == "random") { random = true; - spink.setSeconds(Math.random() * 10740 + 60); - console.log(`random spink pro ${oddiakritikovat(mes.member?.displayName || "neznamejmeno")} byl nastaven na ${formatter(spink)}`); + spink.setSeconds(Math.random() * 540 + 60); + log(`random spink pro ${oddiakritikovat(mes.member?.displayName || "neznamejmeno")} byl nastaven na ${formatter(spink)}`); } else if (/^\d+$/.test(kdy) || !kdy) spink.setTime(tedT + Number(kdy || 7200) * 1000); else { @@ -171,7 +171,7 @@ const exp: Modul = { on_voiceStateUpdate: (bef: VoiceState, aft: VoiceState) => { if (!aft.channel || bef.channel) return; if (spinkacky[aft.id]?.spinkacek) aft.disconnect("spinkacek") - .catch(err => console.log("spinkacek odpojit se nepovedlo nebo co:", err)); + .catch(err => log("spinkacek odpojit se nepovedlo nebo co:", err)); }, super_on_messageCreate: (mes: Message, cmd?: string) => { @@ -190,7 +190,7 @@ const exp: Modul = { const make = (akce: "a" | "r", role: Role) => { const handle = (e: Error) => { if (e.message == "Missing Permissions") return; - console.log("chyba pri davani/odebirani role", e); + log("chyba pri davani/odebirani role", e); }; if (akce == "a") member.roles.add(role).catch(handle); else member.roles.remove(role).catch(handle); diff --git a/src/modules/status.ts b/src/modules/status.ts index df242fa..9f87f23 100644 --- a/src/modules/status.ts +++ b/src/modules/status.ts @@ -2,7 +2,7 @@ import { Client, Guild, Presence, User } from "discord.js"; import fetch from "node-fetch"; import { FakePresence, Modul, SRecord, StatusyINaFounu, UserChange, ZmenovejObjekt } from "../utils/types"; -import { adminLog } from "../utils/utils"; +import { adminLog, log } from "../utils/utils"; const role = { online: "Online", idle: "Idle", dnd: "DND", offline: "Offline" }; const statusy = { Offline: "0", Online: "1", Idle: "2", DND: "3", OnlinePhone: "11", IdlePhone: "12", DNDPhone: "13" }; @@ -29,7 +29,7 @@ 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 => { - console.log("err:", err); + log("err:", err); const client: Client = module.exports.client; adminLog(client, "stat nejede"); }); diff --git a/src/modules/vojs.ts b/src/modules/vojs.ts index 1b2aacf..0e57abd 100644 --- a/src/modules/vojs.ts +++ b/src/modules/vojs.ts @@ -4,7 +4,7 @@ import { getVoiceConnection, VoiceConnection, VoiceConnectionStatus } from "@dis import { ChannelType, GuildMember, VoiceChannel } from "discord.js"; import { emouty } from "../utils/emotes"; import { Modul, MuzikaFace, SRecord } from "../utils/types"; -import { canAnounceTime, handlePrevVoice, joinVoice, play } from "../utils/utils"; +import { canAnounceTime, handlePrevVoice, joinVoice, log, play } from "../utils/utils"; const timeouty: SRecord = {}; @@ -39,7 +39,7 @@ const rekniCas = (guild: string, conn: VoiceConnection, cas: string) => { .then(() => { vypocitatCas(guild, conn); }) - .catch(err => { console.log("cas error:", err); }); + .catch(err => { log("cas error:", err); }); else vypocitatCas(guild, conn); }; diff --git a/src/modules/zbytek.ts b/src/modules/zbytek.ts index 76dc2a2..805de1f 100644 --- a/src/modules/zbytek.ts +++ b/src/modules/zbytek.ts @@ -6,7 +6,7 @@ import { emouty } from "../utils/emotes"; import { createServer } from "http"; import { Modul } from "../utils/types"; import fetch from "node-fetch"; -import { formatCas } from "../utils/utils"; +import { formatCas, log } from "../utils/utils"; let spim = false; @@ -16,7 +16,7 @@ const exp: Modul = { debug_log: { hidden: true, run: (_, arg) => { - console.log("log:", arg); + log("log:", arg); return "je to v konzoli"; } }, @@ -90,7 +90,7 @@ const exp: Modul = { res.end("OK"); }).catch((e: Error) => { if (e.message.search("2000 or fewer")) return res.end("content je moc dlouhej"); - console.log("error pri posilani upozorneni", e); + log("error pri posilani upozorneni", e); res.statusCode = 500; res.end("neco se posralo"); }); diff --git a/src/utils/customCommands.ts b/src/utils/customCommands.ts index 4057245..ca54b04 100644 --- a/src/utils/customCommands.ts +++ b/src/utils/customCommands.ts @@ -38,10 +38,10 @@ function save(nesend?: true) { export const naucse: RunFunkce = (mes, arg) => { const args = arg.split(" ").filter(v => v != ""); - args[0] = oddiakritikovat(args[0].toLowerCase()); - if (args.length == 0) return "a co se mam jako naucit"; if (args.length == 1) return "a co bich nato mnel rict????"; + + args[0] = oddiakritikovat(args[0].toLowerCase()); if (module.exports.realKomandy[args[0]] || customKomandi[args[0]] || module.exports.realAliasy[args[0]] || customAliasy[args[0]]) return "tuten komand uz ale egzistuje"; customKomandi[args[0]] = { text: args.splice(1).join(" "), owner: mes.author.id }; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 5cdb33c..78044f1 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -78,7 +78,7 @@ export async function joinVoice(channel: VoiceChannel | StageChannel | string, g await entersState(conn, VoiceConnectionStatus.Ready, 3e4) .catch(err => { conn!.destroy(); - console.log("pri pripojovani do vojsu nastala chyba:"); + log("pri pripojovani do vojsu nastala chyba:"); throw err; }); return { conn, prev: true }; @@ -100,11 +100,11 @@ export async function joinVoice(channel: VoiceChannel | StageChannel | string, g if (!prev) { const player = createAudioPlayer(); - player.on("error", e => console.log("chyba pri hrani", e)); + player.on("error", e => log("chyba pri hrani", e)); pripojeni[guildId] = conn.subscribe(player)!; conn.on("error", e => { if (e.message.startsWith("Cannot perform IP discovery")) return; - console.log("error nekde v conn", e); + log("error nekde v conn", e); }); } @@ -204,14 +204,18 @@ export function getFirstArg(fn: RunFunkce | string) { ?.trim(); } -export function getCurrentPlayer(guildId: string) { - return pripojeni[guildId]?.player; -} +export const getCurrentPlayer = (guildId: string) => pripojeni[guildId]?.player; -export function configureTimeAnouncment(guild: string, state: boolean) { - timeAnouncability[guild] = state; -} +export const configureTimeAnouncment = (guild: string, state: boolean) => { timeAnouncability[guild] = state; }; -export function canAnounceTime(guild: string) { - return (timeAnouncability[guild] ?? true); +export const canAnounceTime = (guild: string) => timeAnouncability[guild] ?? true; + +export function log(...content: (string | Error)[]) { + const jo = content.map(h => { + if (typeof h == "string") return h; + return `\x1b[31m${h.stack || h}\x1b[0m`; + }); + + const d = new Date(); + console.log(`[${d.getDate()}.${d.getMonth() + 1}. ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}]:`, ...jo); }