programovani je i pro kkty
This commit is contained in:
parent
d015f4f595
commit
228c7b2892
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "denim_3001",
|
||||
"version": "3001.44.1",
|
||||
"version": "3001.45.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "denim_3001",
|
||||
"version": "3001.44.1",
|
||||
"version": "3001.45.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@discordjs/voice": "^0.13.0",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "denim_3001",
|
||||
"version": "3001.44.1",
|
||||
"version": "3001.45.0",
|
||||
"description": "Toto je velmi kvalitní bot.",
|
||||
"repository": {
|
||||
"url": "https://github.com/Histmy/Denim-Bot/"
|
||||
|
||||
103
src/app.ts
103
src/app.ts
@ -1,7 +1,7 @@
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, Client, ComponentType, GatewayIntentBits, Message, Partials } from "discord.js";
|
||||
import { readdirSync } from "fs";
|
||||
import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, RunFunkce, CClient, HelpServer } from "./utils/types";
|
||||
import { adminLog, formatCas, oddiakritikovat, log } from "./utils/utils.js";
|
||||
import { adminLog, formatCas, oddiakritikovat, log, rand } from "./utils/utils.js";
|
||||
import levenshtein from "js-levenshtein";
|
||||
import { emouty } from "./utils/emotes";
|
||||
import { existsSync } from "fs";
|
||||
@ -15,6 +15,7 @@ const client = new Client({
|
||||
intents: [ints.Guilds, ints.GuildVoiceStates, ints.GuildPresences, ints.GuildMessages, ints.DirectMessages, ints.MessageContent]
|
||||
}) as CClient;
|
||||
const prefix = process.env.prefix || "more";
|
||||
const DJ_PREFIX = "dj:";
|
||||
const modulFolder = `${__dirname}/modules/`;
|
||||
const eventy: SRecord<ListenerFunkce[]> = {};
|
||||
const superEventy: SRecord<SuperListenerFunkce[]> = {};
|
||||
@ -114,6 +115,104 @@ const maKuldan = (id: string, komand: string, kuldan_komandu: number) => {
|
||||
return 0;
|
||||
};
|
||||
|
||||
function assume(cond: boolean, msg: string) {
|
||||
if (!cond) throw msg;
|
||||
}
|
||||
|
||||
function prase(expression: string, i: number, terminators: string[], args: string[]): [string, number, string?] {
|
||||
let ret = "";
|
||||
let escaped = false;
|
||||
|
||||
while (i < expression.length) {
|
||||
const char = expression[i];
|
||||
i++;
|
||||
|
||||
if (escaped) {
|
||||
escaped = false;
|
||||
ret += char;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (char) {
|
||||
case "~": // eskejp
|
||||
escaped = true;
|
||||
break;
|
||||
|
||||
case "[": // RNG vyber
|
||||
let option: string, term: string | undefined;
|
||||
const options: string[] = [];
|
||||
|
||||
do {
|
||||
[option, i, term] = prase(expression, i, ["|", "]"], args);
|
||||
options.push(option);
|
||||
} while (term == "|");
|
||||
|
||||
if (options.length > 0)
|
||||
ret += options[rand(options.length)];
|
||||
|
||||
break;
|
||||
|
||||
case "<": // RNG cislo
|
||||
let min: string, max: string;
|
||||
[min, i] = prase(expression, i, [","], args);
|
||||
[max, i] = prase(expression, i, [">"], args);
|
||||
|
||||
const imin = parseInt(min);
|
||||
const imax = parseInt(max);
|
||||
|
||||
assume(!Number.isNaN(min), "RNG cislo: Min neni integer");
|
||||
assume(!Number.isNaN(max), "RNG cislo: Max neni integer");
|
||||
|
||||
ret += rand(imax - imin + 1) + imin;
|
||||
|
||||
break;
|
||||
|
||||
case "{": // ARG
|
||||
let argId: string;
|
||||
[argId, i] = prase(expression, i, ["}"], args);
|
||||
|
||||
if (argId === "*") { // join args
|
||||
ret += args.join(" ");
|
||||
} else if (argId === "#") { // number of args
|
||||
ret += args.length;
|
||||
} else { // arg id #
|
||||
const numArgId = parseInt(argId);
|
||||
assume(!Number.isNaN(numArgId) && numArgId > 0 && numArgId <= args.length, "ARG: Neplatnej index argumentu");
|
||||
ret += args[numArgId - 1];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
for (const terminator of terminators) {
|
||||
if (terminator == char)
|
||||
return [ret, i, char];
|
||||
}
|
||||
|
||||
ret += char;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assume(terminators.length == 0, "Neocekavanej konec vejrazu");
|
||||
|
||||
return [ret, expression.length - 1];
|
||||
}
|
||||
|
||||
function renderMessage(expression: string, args: string[]) {
|
||||
if (!expression.toLowerCase().startsWith(DJ_PREFIX))
|
||||
return expression;
|
||||
|
||||
expression = expression.substring(DJ_PREFIX.length);
|
||||
|
||||
try {
|
||||
return prase(expression, 0, [], args)[0];
|
||||
} catch (ex) {
|
||||
return `Chyba: ${ex}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function runKomand(mes: Message, cmd: Komand, cmdName: string, arg: string) {
|
||||
if (cmd.cd) {
|
||||
const zbyva = Math.round(maKuldan(mes.author.id, cmdName, cmd.cd));
|
||||
@ -121,7 +220,7 @@ async function runKomand(mes: Message, cmd: Komand, cmdName: string, arg: string
|
||||
}
|
||||
|
||||
const akce = cmd.run;
|
||||
if (typeof akce == "string") return void mes.channel.send(akce);
|
||||
if (typeof akce == "string") return void mes.channel.send(renderMessage(akce, arg.split(" ")));
|
||||
try {
|
||||
const result = await akce(mes, arg);
|
||||
if (result) mes.channel.send(result);
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
// Komandy, který jenom pošlou random hovno a jsou nějakým způsobem ovlivněný RNG
|
||||
|
||||
import { Modul } from "../utils/types";
|
||||
import { rand } from "../utils/utils";
|
||||
|
||||
const ftipy: string[] = require("../../res/ftipy.json");
|
||||
const mista = ["na šroťák", "na vrakoviště", "na smetiště", "do kontejneru", "na skládku", "do kriminálu", "pod most", "do sběru", "do hospody", "do najt klubu", "na folmavu"];
|
||||
const uz = ["ne", "jeste ne", "jiz brzy", "za chvili", "vubec", "nikdy", "za dlouho", "za 5 let", "zejtra", "davno", "jo", "mozna"];
|
||||
|
||||
const rand = (max: number) => Math.floor(Math.random() * max);
|
||||
|
||||
const choose = (arr: string[]) => arr[rand(arr.length)];
|
||||
|
||||
const exp: Modul = {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { createServer } from "http";
|
||||
import { KomandNaExport, SRecord } from "./types";
|
||||
import { log } from "./utils";
|
||||
|
||||
createServer((_, res) => {
|
||||
const komandy: KomandNaExport[] = module.exports.komandy;
|
||||
|
||||
@ -194,3 +194,5 @@ export function log(...content: (string | Error)[]) {
|
||||
export async function sendDM(user: User, txt: string) {
|
||||
user.send(txt).catch(() => console.log(`dementovi ${user} nejde poslat DM`));
|
||||
}
|
||||
|
||||
export const rand = (max: number) => Math.floor(Math.random() * max);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user