nabidni, paging, rm traces of zaznamy.dlog

This commit is contained in:
Histmy 2023-08-20 18:09:32 +02:00
parent 59e51edfc8
commit 55e2acd5f5
7 changed files with 149 additions and 57 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.52.1", "version": "3001.53.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.52.1", "version": "3001.53.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@discordjs/voice": "^0.16.0", "@discordjs/voice": "^0.16.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.52.1", "version": "3001.53.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/"

View File

@ -1,7 +1,7 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, Client, CommandInteraction, ComponentType, GatewayIntentBits, Message, Partials } from "discord.js"; import { ChannelType, Client, CommandInteraction, GatewayIntentBits, Message, Partials } from "discord.js";
import { readdirSync } from "fs"; import { readdirSync } from "fs";
import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, CClient, HelpServer, KomandRaw } from "./utils/types"; import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, CClient, HelpServer, KomandRaw } from "./utils/types";
import { adminLog, formatCas, oddiakritikovat, log, rand, prefix } from "./utils/utils.js"; import { adminLog, formatCas, oddiakritikovat, log, rand, prefix, nabidni } from "./utils/utils.js";
import levenshtein from "js-levenshtein"; import levenshtein from "js-levenshtein";
import { emouty } from "./utils/emotes"; import { emouty } from "./utils/emotes";
@ -290,31 +290,24 @@ client.on("messageCreate", async mes => {
if (!slova.length) return void mes.channel.send("co to znamena ti gadzovko"); if (!slova.length) return void mes.channel.send("co to znamena ti gadzovko");
const nabidka = slova.sort().slice(0, 5); const nabidka = slova.sort().slice(0, 5);
const radek = new ActionRowBuilder<ButtonBuilder>();
nabidka.forEach((cmd, i) => {
const nazev = cmd.length > 80 ? `${cmd.slice(0, 77)}...` : cmd;
radek.addComponents(new ButtonBuilder({ customId: `${i}`, label: nazev, style: ButtonStyle.Primary }));
});
const zprava = await mes.channel.send({ content: "nemnel sy na misli:", components: [radek] }); nabidni({
const collector = mes.channel.createMessageComponentCollector<ComponentType.Button>({ filter: i => i.message.id == zprava.id && mes.author.id == i.user.id, time: 18e4 }); nabidka,
collector.on("collect", i => { channel: mes.channel,
const lookupId = Number(i.customId); zpravec: { content: "nemnel sy na misli:" },
if (isNaN(lookupId)) return void mes.channel.send("neco nefunguje idk"); onCollect: (i, lookupId, radek) => {
const komand = nabidka[lookupId]; if (i.member?.user.id != mes.author.id) return;
const cmdName = client.aliasy[komand] ?? komand; const komand = nabidka[lookupId];
const cmd = client.komandy[cmdName]; const cmdName = client.aliasy[komand] ?? komand;
radek.components.forEach(btn => btn.setDisabled()); const cmd = client.komandy[cmdName];
i.update({ content: `ok vole ${emouty.d3k}`, components: [radek] }); radek.components.forEach(btn => btn.setDisabled());
i.update({ content: `ok vole ${emouty.d3k}`, components: [radek] });
if (mes.channel.type == ChannelType.DM && cmd?.DMUnsafe) return void mes.channel.send("tuten komand bohuzel v sz nefunkuje"); if (mes.channel.type == ChannelType.DM && cmd?.DMUnsafe) return void mes.channel.send("tuten komand bohuzel v sz nefunkuje");
runKomand(mes, cmd, cmdName, celArgs); runKomand(mes, cmd, cmdName, celArgs);
}); },
collector.on("end", c => { konecnaZprava: "pozde"
if (c.size) return;
radek.components.forEach(btn => btn.setDisabled());
zprava.edit({ content: "pozde", components: [radek] });
}); });
}); });

View File

@ -1,7 +1,7 @@
import { CClient, HelpServer, Komand, KomandNaExport, Modul, SRecord } from "../utils/types"; import { CClient, HelpServer, Komand, KomandNaExport, Modul, SRecord } from "../utils/types";
import { join } from "path"; import { join } from "path";
import { existsSync, readFileSync, writeFileSync } from "fs"; import { existsSync, readFileSync, writeFileSync } from "fs";
import { oddiakritikovat, prefix } from "../utils/utils"; import { oddiakritikovat, prefix, strankovani } from "../utils/utils";
import { APIEmbed } from "discord.js"; import { APIEmbed } from "discord.js";
let client: CClient; let client: CClient;
@ -251,24 +251,35 @@ const exp: Modul = {
} }
}, },
aliasy: (_, arg) => { aliasy: (mes, arg) => {
const name = arg.toLowerCase(); const name = arg.toLowerCase();
const cmdName = client.aliasy[name] ?? name; const cmdName = client.aliasy[name] ?? name;
const list: string[] = []; let celkovadylka = 0;
const stranky: string[][] = [];
for (const key in client.aliasy) { for (const key in client.aliasy) {
const val = client.aliasy[key]; const val = client.aliasy[key];
if (val == cmdName) list.push(key); if (val != cmdName) continue;
celkovadylka += key.length + 3;
if (stranky[Math.floor(celkovadylka / 1024)]?.length == 20) celkovadylka += 1024 - (celkovadylka % 1024);
const stranka = stranky[Math.floor(celkovadylka / 1024)] ??= [];
stranka.push(key);
} }
if (!list.length) return `"${name}" bud nen9 komand ani ajilas nebo nema ajilasi vubec`; if (!celkovadylka) return `"${name}" bud nen9 komand ani ajilas nebo nema ajilasi vubec`;
const zacatekNazvu = `alijasy pro **${cmdName}**:`;
const embed: APIEmbed = { const embed: APIEmbed = {
color: 13697024, color: 13697024,
fields: [{ name: `alijasy pro **${cmdName}**:`, value: `${list.join("\n• ")}` }] fields: [{ name: zacatekNazvu, value: `${stranky[0].join("\n• ")}` }]
}; };
return { embeds: [embed] }; if (celkovadylka <= 1024) return { embeds: [embed] };
embed.fields![0].name += ` (1/${stranky.length})`;
strankovani(mes.channel, embed, zacatekNazvu, stranky);
} }
}, },

View File

@ -5,16 +5,13 @@ import { Client, Message, Presence, TextChannel, User } from "discord.js";
import { createServer } from "http"; import { createServer } from "http";
import { Modul } from "../utils/types"; import { Modul } from "../utils/types";
import fetch from "node-fetch"; import fetch from "node-fetch";
import { adminLog, formatCas, log, sendDM } from "../utils/utils"; import { adminLog, formatCas, log, nabidni, sendDM } from "../utils/utils";
import { emouty } from "../utils/emotes"; import { emouty } from "../utils/emotes";
import { appendFileSync } from "fs";
const zpravy = new Map<string, Map<string, number[]>>(); const zpravy = new Map<string, Map<string, number[]>>();
const dobaOmezení = 20_000; const dobaOmezení = 20_000;
let client: Client; let client: Client;
let restartPozadavky: { id: string, kdy: number; }[] = [];
const exp: Modul = { const exp: Modul = {
more_komandy: { more_komandy: {
@ -48,22 +45,39 @@ const exp: Modul = {
run: mes => { run: mes => {
const sudo = mes.channel.id == process.env.adminChannel || mes.author.id == process.env.adminID; const sudo = mes.channel.id == process.env.adminChannel || mes.author.id == process.env.adminID;
restartPozadavky = restartPozadavky.filter(pozadavek => { function udelat() {
return pozadavek.kdy > Date.now() - 6e4; getVoiceConnections().forEach(con => con.destroy());
}); client.user?.setStatus("invisible");
mes.react("👋")
if (!sudo) { .then(() => process.exit(69));
if (!restartPozadavky.find(el => el.id == mes.author.id)) restartPozadavky.push({ id: mes.author.id, kdy: Date.now() });
if (restartPozadavky.length == 1)
return "jelikoz nesi hlava zpravne namazana musi se s tebou zhotnout jeste 2 hajzlaty";
if (restartPozadavky.length == 2)
return `heste jeden`;
} }
getVoiceConnections().forEach(con => con.destroy()); if (!sudo) {
client.user?.setStatus("invisible"); const souhlasatori: string[] = [mes.author.id];
mes.react("👋")
.then(() => process.exit(69)); nabidni({
channel: mes.channel,
nabidka: ["souhlasim"],
zpravec: { content: "jelikoz nesi hlava zpravne namazana musi se z tebou zhotnout jeste 2 hajzlaty do 60 se kund" },
onCollect: i => {
if (souhlasatori.includes(i.member!.user.id)) return i.reply({
ephemeral: true,
content: "ti us sy na to klyknul ti suraku"
});
souhlasatori.push(i.member!.user.id);
if (souhlasatori.length == 3) udelat();
else i.update({ content: "heste jeden" });
},
konecnaZprava: "restart se nekona, ste kundi so se neumy dohodnout",
timeout: 6e4,
stejne: true
});
return;
}
udelat();
} }
}, },
@ -117,9 +131,6 @@ const exp: Modul = {
// Nastavení clienta // Nastavení clienta
client = module.exports.client; client = module.exports.client;
// Záznam
appendFileSync("zaznamy.dlog", `ziju${Date.now().toString(36)}\n`);
// OG onReady // OG onReady
log("A jedeš!"); log("A jedeš!");
if (process.argv.length >= 4) adminLog(client, "pošel jsem"); if (process.argv.length >= 4) adminLog(client, "pošel jsem");

View File

@ -1,4 +1,4 @@
import { ChannelType, Client, User } from "discord.js"; import { APIEmbed, ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, ChannelType, Client, Collection, ComponentType, MessageCreateOptions, TextBasedChannel, User } from "discord.js";
import { existsSync } from "fs"; import { existsSync } from "fs";
if (!existsSync("config.json")) throw new Error("config.json neexistuje"); if (!existsSync("config.json")) throw new Error("config.json neexistuje");
@ -97,3 +97,81 @@ export async function sendDM(user: User, txt: string) {
export const rand = (max: number) => Math.floor(Math.random() * max); export const rand = (max: number) => Math.floor(Math.random() * max);
export const prefix = process.env.prefix || "more"; export const prefix = process.env.prefix || "more";
type Nastaveni = {
nabidka: (string | (({ val: string; } | { emoji: string; }) & { disabled?: boolean; }))[];
channel: TextBasedChannel;
zpravec: MessageCreateOptions;
onCollect: (i: ButtonInteraction, id: number, radek: ActionRowBuilder<ButtonBuilder>) => void;
timeout?: number;
} & ({
onEnd: (c: Collection<string, ButtonInteraction<CacheType>>) => void;
} | {
konecnaZprava: string;
stejne?: boolean;
});
export async function nabidni(nastaveni: Nastaveni) {
const radek = new ActionRowBuilder<ButtonBuilder>();
nastaveni.nabidka.forEach((moznost, i) => {
const component = new ButtonBuilder({ customId: `${i}`, style: ButtonStyle.Primary });
const ejtoString = typeof moznost == "string";
if (ejtoString || "val" in moznost) {
const value = ejtoString ? moznost : moznost.val;
const nazev = value.length > 80 ? `${value.slice(0, 77)}...` : value;
component.setLabel(nazev);
} else {
component.setEmoji(moznost.emoji);
}
if (!ejtoString && moznost.disabled) component.setDisabled();
radek.addComponents(component);
});
const zprava = await nastaveni.channel.send({ ...nastaveni.zpravec, components: [radek] });
const collector = nastaveni.channel.createMessageComponentCollector<ComponentType.Button>({ filter: i => i.message.id == zprava.id, time: nastaveni.timeout ?? 18e4 });
collector.on("collect", i => {
const lookupId = Number(i.customId);
if (isNaN(lookupId)) return void nastaveni.channel.send("neco nefunguje idk");
nastaveni.onCollect(i, lookupId, radek);
});
collector.on("end", c => {
if ("onEnd" in nastaveni)
nastaveni.onEnd(c);
else if (!c.size || nastaveni.stejne) {
radek.components.forEach(btn => btn.setDisabled());
zprava.edit({ content: nastaveni.konecnaZprava, components: [radek] });
}
});
}
export const strankovani = (channel: TextBasedChannel, embed: APIEmbed, zacatekNazvu: string, stranky: string[][]) => {
let aktualniStranka = 0;
nabidni({
channel: channel,
nabidka: [{ emoji: "⬅️", disabled: true }, { emoji: "➡️" }],
zpravec: { embeds: [embed] },
onCollect: (i, id, radek) => {
// Výpočet nový stánky
aktualniStranka += (!id) ? -1 : 1;
// Úprava aktivnosti tlačítek
radek.components[0].setDisabled(!aktualniStranka);
radek.components[1].setDisabled(aktualniStranka + 1 == stranky.length);
// Úprava embedu
embed.fields![0] = {
name: `${zacatekNazvu} (${aktualniStranka + 1}/${stranky.length})`,
value: `${stranky[aktualniStranka].join("\n• ")}`
};
// Odeslání
i.update({ embeds: [embed], components: [radek] });
},
onEnd: () => { }
});
};

View File

@ -23,7 +23,6 @@ while true; do
echo Poslo to dostatecne malo, restartuju echo Poslo to dostatecne malo, restartuju
else else
echo Poslo to moc, seru na to echo Poslo to moc, seru na to
echo osel$(date +"%s") >>zaznamy.dlog
break break
fi fi
i=$(($i + 1)) i=$(($i + 1))