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",
|
"name": "denim_3001",
|
||||||
"version": "3001.44.1",
|
"version": "3001.45.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "denim_3001",
|
"name": "denim_3001",
|
||||||
"version": "3001.44.1",
|
"version": "3001.45.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/voice": "^0.13.0",
|
"@discordjs/voice": "^0.13.0",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "denim_3001",
|
"name": "denim_3001",
|
||||||
"version": "3001.44.1",
|
"version": "3001.45.0",
|
||||||
"description": "Toto je velmi kvalitní bot.",
|
"description": "Toto je velmi kvalitní bot.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "https://github.com/Histmy/Denim-Bot/"
|
"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 { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, Client, ComponentType, GatewayIntentBits, Message, Partials } from "discord.js";
|
||||||
import { readdirSync } from "fs";
|
import { readdirSync } from "fs";
|
||||||
import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, RunFunkce, CClient, HelpServer } from "./utils/types";
|
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 levenshtein from "js-levenshtein";
|
||||||
import { emouty } from "./utils/emotes";
|
import { emouty } from "./utils/emotes";
|
||||||
import { existsSync } from "fs";
|
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]
|
intents: [ints.Guilds, ints.GuildVoiceStates, ints.GuildPresences, ints.GuildMessages, ints.DirectMessages, ints.MessageContent]
|
||||||
}) as CClient;
|
}) as CClient;
|
||||||
const prefix = process.env.prefix || "more";
|
const prefix = process.env.prefix || "more";
|
||||||
|
const DJ_PREFIX = "dj:";
|
||||||
const modulFolder = `${__dirname}/modules/`;
|
const modulFolder = `${__dirname}/modules/`;
|
||||||
const eventy: SRecord<ListenerFunkce[]> = {};
|
const eventy: SRecord<ListenerFunkce[]> = {};
|
||||||
const superEventy: SRecord<SuperListenerFunkce[]> = {};
|
const superEventy: SRecord<SuperListenerFunkce[]> = {};
|
||||||
@ -114,6 +115,104 @@ const maKuldan = (id: string, komand: string, kuldan_komandu: number) => {
|
|||||||
return 0;
|
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) {
|
async function runKomand(mes: Message, cmd: Komand, cmdName: string, arg: string) {
|
||||||
if (cmd.cd) {
|
if (cmd.cd) {
|
||||||
const zbyva = Math.round(maKuldan(mes.author.id, cmdName, 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;
|
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 {
|
try {
|
||||||
const result = await akce(mes, arg);
|
const result = await akce(mes, arg);
|
||||||
if (result) mes.channel.send(result);
|
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
|
// Komandy, který jenom pošlou random hovno a jsou nějakým způsobem ovlivněný RNG
|
||||||
|
|
||||||
import { Modul } from "../utils/types";
|
import { Modul } from "../utils/types";
|
||||||
|
import { rand } from "../utils/utils";
|
||||||
|
|
||||||
const ftipy: string[] = require("../../res/ftipy.json");
|
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 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 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 choose = (arr: string[]) => arr[rand(arr.length)];
|
||||||
|
|
||||||
const exp: Modul = {
|
const exp: Modul = {
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { createServer } from "http";
|
import { createServer } from "http";
|
||||||
import { KomandNaExport, SRecord } from "./types";
|
import { KomandNaExport, SRecord } from "./types";
|
||||||
import { log } from "./utils";
|
|
||||||
|
|
||||||
createServer((_, res) => {
|
createServer((_, res) => {
|
||||||
const komandy: KomandNaExport[] = module.exports.komandy;
|
const komandy: KomandNaExport[] = module.exports.komandy;
|
||||||
|
|||||||
@ -194,3 +194,5 @@ export function log(...content: (string | Error)[]) {
|
|||||||
export async function sendDM(user: User, txt: string) {
|
export async function sendDM(user: User, txt: string) {
|
||||||
user.send(txt).catch(() => console.log(`dementovi ${user} nejde poslat DM`));
|
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