Fixed dum naucse err

added custom log with time and color

random spink max 15 mins now
This commit is contained in:
Histmy 2022-09-02 20:07:21 +02:00
parent 3af5607c1b
commit 26d7e8127d
12 changed files with 41 additions and 37 deletions

4
package-lock.json generated
View File

@ -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",

View File

@ -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/"

View File

@ -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?` : ""}`);
}

View File

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

View File

@ -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 width="100%" class="lista">(?<kontent>.+)<\/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(/<a href="d.+?&(?<odkaz>id=.+?)".+?Pridany (?<datum>\d\d\/\d\d\/\d{4})/is);
const datum = detaily!.groups!.datum;

View File

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

View File

@ -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<Spinkackar>;
const budouciSpinky: SRecord<NodeJS.Timeout> = {};
@ -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);

View File

@ -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<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 => {
console.log("err:", err);
log("err:", err);
const client: Client<boolean> = module.exports.client;
adminLog(client, "stat nejede");
});

View File

@ -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<NodeJS.Timeout> = {};
@ -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);
};

View File

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

View File

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

View File

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