added http server for anouncing all commands, their aliasses and
sometimes argument meaning

beginning of 3001.32
This commit is contained in:
Histmy 2021-11-18 18:59:39 +01:00
parent 9c3dc5af59
commit 1711416335
11 changed files with 106 additions and 52 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "denim_3001",
"version": "3001.31.0",
"version": "3001.32.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "denim_3001",
"version": "3001.31.0",
"version": "3001.32.0",
"license": "ISC",
"dependencies": {
"@discordjs/opus": "github:discordjs/opus",

View File

@ -1,6 +1,6 @@
{
"name": "denim_3001",
"version": "3001.31.0",
"version": "3001.32.0",
"description": "Toto je velmi kvalitní bot.",
"repository": {
"url": "https://github.com/Histmy/Denim-Bot/"

View File

@ -1,6 +1,6 @@
import { Client, Intents } from "discord.js";
import { readdirSync } from "fs";
import { EventSOn, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce } from "./utils/types";
import { EventSOn, KoamndNaExport, Komand, ListenerFunkce, Modul, RunFunkce, SRecord, SuperListenerFunkce } from "./utils/types";
import { formatCas, loadEnv, oddiakritikovat } from "./utils/utils.js";
loadEnv();
@ -27,6 +27,16 @@ const runEvent = (name: string, args: any[]) => {
});
};
const getTenParam = (fn: RunFunkce): string | undefined => fn.toString()
.match(/(?:function\s.*?)?\(([^)]*)\)/)![1]
.split(",")[1]
?.trim();
const fnToArg = (fn: RunFunkce | string) => {
if (typeof fn != "function") return;
return getTenParam(fn);
};
readdirSync(modulFolder).forEach(soubor => {
if (!soubor.endsWith(".js")) return;
const modul: Modul = require(`${modulFolder}${soubor}`);
@ -52,12 +62,18 @@ readdirSync(modulFolder).forEach(soubor => {
const n = modul[name]!;
Object.keys(n).forEach(cmdName => {
const value = n[cmdName];
const toCoExportuju: KoamndNaExport = { name: cmdName };
let hide = false;
if (typeof value !== "object") {
komandy[cmdName] = { run: value };
toCoExportuju.arg = fnToArg(value);
} else {
komandy[cmdName] = { run: value.run, cd: value.cd };
Object.assign(toCoExportuju, { als: value.als, arg: value.arg ?? fnToArg(value.run) });
hide = !!value.hidden;
value.als?.forEach(al => aliasy[al] = cmdName);
}
if (!hide) komandyNaPoslani.push(toCoExportuju);
});
}
});

View File

@ -5,33 +5,33 @@ import { Modul } from "../utils/types";
const exp: Modul = {
more_komandy: {
rekni: (mes, arg) => {
rekni: (mes, co) => {
if (mes.author.bot) return "ne";
const corict = arg || `co mam jako rict ${mes.author}`;
const corict = co || `co mam jako rict ${mes.author}`;
mes.delete();
return corict;
},
clap: (mes, arg) => {
clap: (mes, text) => {
mes.delete();
return `${arg} ${emouty.clap}`;
return `${text} ${emouty.clap}`;
},
clap2: (mes, arg) => {
clap2: (mes, text) => {
mes.delete();
return `${emouty.clap2} ${arg}`;
return `${emouty.clap2} ${text}`;
},
voliz: (mes, arg) => {
voliz: (mes, co) => {
mes.delete();
return `${emouty.lickL}${arg}${emouty.lickR}`;
return `${emouty.lickL}${co}${emouty.lickR}`;
},
pozdrav: (_, arg) => `zdravim ${arg}`,
pozdrav: (_, koho) => `zdravim ${koho}`,
zhejti: (_, arg) => `${arg} je pycovina zasrana vimrdana`,
zhejti: (_, koho) => `${koho} je pycovina zasrana vimrdana`,
uraz: (_, arg) => `${arg} , u suck`
uraz: (_, koho) => `${koho} , u suck`
}
};

View File

@ -39,24 +39,24 @@ const exp: Modul = {
run: (mes) => changeStatus(mes, "invisible")
},
hraj: (mes, arg) => changeActivity(mes, "PLAYING", arg),
sleduj: (mes, arg) => changeActivity(mes, "WATCHING", arg),
poslouchej: (mes, arg) => changeActivity(mes, "LISTENING", arg),
soutez: (mes, arg) => changeActivity(mes, "COMPETING", arg),
hraj: (mes, co) => changeActivity(mes, "PLAYING", co),
sleduj: (mes, co) => changeActivity(mes, "WATCHING", co),
poslouchej: (mes, co) => changeActivity(mes, "LISTENING", co),
soutez: (mes, vcem) => changeActivity(mes, "COMPETING", vcem),
nedelej: (mes) => changeActivity(mes),
fight: {
als: ["figh", "fajt"],
run: (mes, arg) => {
if (!ping.test(arg)) return "tak si kokot ti kokote";
run: (mes, skym) => {
if (!ping.test(skym)) return "tak si kokot ti kokote";
const vyherce = Math.random() < 0.5 ? mes.author : arg;
const vyherce = Math.random() < 0.5 ? mes.author : skym;
return `tento figh vyhrál: ${vyherce}!`;
}
},
status: (mes, arg) => {
if (!ping.test(arg)) return "tak si kokot ti kokote";
status: (mes, koho) => {
if (!ping.test(koho)) return "tak si kokot ti kokote";
const uzivatel = mes.mentions.members!.first()!;
const embed = {
@ -82,6 +82,7 @@ const exp: Modul = {
zareaguj: {
als: ["react"],
arg: "emout/emouty",
run: async (mes, arg) => {
const emouty = arg.match(/<a?:\w{1,32}:\d+>/g);
if (!emouty) return "retard";
@ -118,6 +119,7 @@ const exp: Modul = {
pockej: {
als: ["cekej"],
arg: "počet sekund",
run: (mes, arg) => {
let cas: number;
if (arg.length) {

View File

@ -22,35 +22,42 @@ const exp: Modul = {
je: {
cd: 1800,
arg: "kdo/co",
run: () => rand(2) ? "jo je" : "ne neni"
},
ma: () => rand(2) ? "jo ma" : "ne nema",
ma: {
arg: "kdo/co",
run: () => rand(2) ? "jo ma" : "ne nema"
},
nazor: (_, arg) => rand(2) ? `mam rad ${arg}` : `${arg} je picovina`,
nazor: {
arg: "koho/co",
run: (_, arg) => rand(2) ? `mam rad ${arg}` : `${arg} je picovina`
},
si: {
als: ["jsi"],
run: (_, arg) => {
const corict = arg.replace(/\?/g, "");
run: (_, co) => {
const corict = co.replace(/\?/g, "");
return rand(2) ? `jo sem ${corict}` : `ne nejsem ${corict}`;
}
},
mas: (_, arg) => {
const corict = arg.replace(/\?/g, "");
mas: (_, co) => {
const corict = co.replace(/\?/g, "");
return rand(2) ? `jo mam ${corict}` : `ne nemam ${corict}`;
},
jakmoc: {
cd: 1800,
run: (_, arg) => `${arg} na ${rand(101)}%`
run: (_, co) => `${co} na ${rand(101)}%`
},
jakmoc0: {
cd: 1800,
run: (_, arg) => `${arg} na ${rand(1001)}`
run: (_, co) => `${co} na ${rand(1001)}`
},
uz: {
@ -58,10 +65,13 @@ const exp: Modul = {
run: () => choose(uz)
},
vyber: (_, arg) => {
if (!arg.length) return "co vole";
const moznosti = arg.split(arg.indexOf("|") > -1 ? "|" : ",").filter(m => m.length);
return choose(moznosti) || "kokot";
vyber: {
arg: "co (odděleno čárkami nebo \"|\")",
run: (_, arg) => {
if (!arg.length) return "co vole";
const moznosti = arg.split(arg.indexOf("|") > -1 ? "|" : ",").filter(m => m.length);
return choose(moznosti) || "kokot";
}
}
}
};

View File

@ -129,6 +129,7 @@ const exp: Modul = {
ps: {
als: ["poslednispink"],
arg: "kdo (nepovinné)",
run: (mes, arg) => {
const f = arg != "";
if (!ping.test(arg) && f) return "sikkt";

View File

@ -64,6 +64,7 @@ const exp: Modul = {
vojs: {
cd: 1800,
arg: "potichu (nepovinné)",
run: (mes, arg) => {
const channel = mes.member?.voice.channel;
if (!channel) return `di si tam sam ne ty gadzo ${mes.author}`;
@ -100,11 +101,11 @@ const exp: Modul = {
vytah: {
als: ["vitah"],
run: (mes, arg) => {
run: (mes, parto) => {
if (!mes.member?.voice.channel) return `nejsi ve vojsu ty gadzo ${mes.author}`;
if (!arg) return `napis do jakiho patra ${mes.author}`;
if (!parto) return `napis do jakiho patra ${mes.author}`;
vytahnout(mes.member, Number(arg) || 0);
vytahnout(mes.member, Number(parto) || 0);
}
},
@ -162,13 +163,16 @@ const exp: Modul = {
}
},
outro: async (mes) => {
const channel = mes.member?.voice.channel;
if (!channel) return "co to znamena ti gadzovko";
outro: {
hidden: true,
run: async (mes) => {
const channel = mes.member?.voice.channel;
if (!channel) return "co to znamena ti gadzovko";
const { conn, prev } = await joinVoice(channel);
await play(conn, { name: "zvuky/pocasi/outro.mp3", volume: 30 });
handlePrevVoice(mes.guild!, prev);
const { conn, prev } = await joinVoice(channel);
await play(conn, { name: "zvuky/pocasi/outro.mp3", volume: 30 });
handlePrevVoice(mes.guild!, prev);
}
}
}
};

View File

@ -12,9 +12,12 @@ let spim = false;
const exp: Modul = {
more_komandy: {
debug_log: (_, arg) => {
console.log("log: ", arg);
return "je to v konzoli";
debug_log: {
hidden: true,
run: (_, arg) => {
console.log("log: ", arg);
return "je to v konzoli";
}
},
update: async (mes) => {

9
src/utils/helpServer.ts Normal file
View File

@ -0,0 +1,9 @@
import { createServer } from "http";
import { KoamndNaExport } from "./types";
createServer((_, res) => {
const komandi: KoamndNaExport[] = module.exports.cmds;
const odpoved = JSON.stringify({ komandy: komandi });
res.setHeader("Content-Type", "application/json");
res.end(odpoved);
}).listen(5712);

View File

@ -2,13 +2,18 @@ import { Client, ClientEvents, ClientPresenceStatusData, Message, MessageOptions
type OutputRunFunkce = string | MessageOptions | void;
type RunFunkce = (message: Message, argumenty: string) => OutputRunFunkce | Promise<OutputRunFunkce>;
export type RunFunkce = (message: Message, argumenty: string) => OutputRunFunkce | Promise<OutputRunFunkce>;
interface KomandRaw {
interface BaseKomandProps {
als?: string[];
cd?: number;
arg?: string;
}
type KomandRaw = {
run: string | RunFunkce;
};
cd?: number;
hidden?: true;
} & BaseKomandProps;
export type ListenerFunkce = (...args: any[]) => void;
@ -62,3 +67,7 @@ export interface MuzikaFace {
name: string;
volume: number;
}
export type KoamndNaExport = {
name: string;
} & BaseKomandProps;