nabidni, paging, rm traces of zaznamy.dlog
This commit is contained in:
parent
59e51edfc8
commit
55e2acd5f5
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "denim_3001",
|
||||
"version": "3001.52.1",
|
||||
"version": "3001.53.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "denim_3001",
|
||||
"version": "3001.52.1",
|
||||
"version": "3001.53.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@discordjs/voice": "^0.16.0",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "denim_3001",
|
||||
"version": "3001.52.1",
|
||||
"version": "3001.53.0",
|
||||
"description": "Toto je velmi kvalitní bot.",
|
||||
"repository": {
|
||||
"url": "https://github.com/Histmy/Denim-Bot/"
|
||||
|
||||
27
src/app.ts
27
src/app.ts
@ -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 { 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 { emouty } from "./utils/emotes";
|
||||
|
||||
@ -290,17 +290,13 @@ client.on("messageCreate", async mes => {
|
||||
if (!slova.length) return void mes.channel.send("co to znamena ti gadzovko");
|
||||
|
||||
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] });
|
||||
const collector = mes.channel.createMessageComponentCollector<ComponentType.Button>({ filter: i => i.message.id == zprava.id && mes.author.id == i.user.id, time: 18e4 });
|
||||
collector.on("collect", i => {
|
||||
const lookupId = Number(i.customId);
|
||||
if (isNaN(lookupId)) return void mes.channel.send("neco nefunguje idk");
|
||||
nabidni({
|
||||
nabidka,
|
||||
channel: mes.channel,
|
||||
zpravec: { content: "nemnel sy na misli:" },
|
||||
onCollect: (i, lookupId, radek) => {
|
||||
if (i.member?.user.id != mes.author.id) return;
|
||||
const komand = nabidka[lookupId];
|
||||
const cmdName = client.aliasy[komand] ?? komand;
|
||||
const cmd = client.komandy[cmdName];
|
||||
@ -310,11 +306,8 @@ client.on("messageCreate", async mes => {
|
||||
if (mes.channel.type == ChannelType.DM && cmd?.DMUnsafe) return void mes.channel.send("tuten komand bohuzel v sz nefunkuje");
|
||||
|
||||
runKomand(mes, cmd, cmdName, celArgs);
|
||||
});
|
||||
collector.on("end", c => {
|
||||
if (c.size) return;
|
||||
radek.components.forEach(btn => btn.setDisabled());
|
||||
zprava.edit({ content: "pozde", components: [radek] });
|
||||
},
|
||||
konecnaZprava: "pozde"
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { CClient, HelpServer, Komand, KomandNaExport, Modul, SRecord } from "../utils/types";
|
||||
import { join } from "path";
|
||||
import { existsSync, readFileSync, writeFileSync } from "fs";
|
||||
import { oddiakritikovat, prefix } from "../utils/utils";
|
||||
import { oddiakritikovat, prefix, strankovani } from "../utils/utils";
|
||||
import { APIEmbed } from "discord.js";
|
||||
|
||||
let client: CClient;
|
||||
@ -251,24 +251,35 @@ const exp: Modul = {
|
||||
}
|
||||
},
|
||||
|
||||
aliasy: (_, arg) => {
|
||||
aliasy: (mes, arg) => {
|
||||
const name = arg.toLowerCase();
|
||||
const cmdName = client.aliasy[name] ?? name;
|
||||
|
||||
const list: string[] = [];
|
||||
let celkovadylka = 0;
|
||||
const stranky: string[][] = [];
|
||||
for (const key in client.aliasy) {
|
||||
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 = {
|
||||
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);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -5,16 +5,13 @@ import { Client, Message, Presence, TextChannel, User } from "discord.js";
|
||||
import { createServer } from "http";
|
||||
import { Modul } from "../utils/types";
|
||||
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 { appendFileSync } from "fs";
|
||||
|
||||
const zpravy = new Map<string, Map<string, number[]>>();
|
||||
const dobaOmezení = 20_000;
|
||||
let client: Client;
|
||||
|
||||
let restartPozadavky: { id: string, kdy: number; }[] = [];
|
||||
|
||||
const exp: Modul = {
|
||||
more_komandy: {
|
||||
|
||||
@ -48,23 +45,40 @@ const exp: Modul = {
|
||||
run: mes => {
|
||||
const sudo = mes.channel.id == process.env.adminChannel || mes.author.id == process.env.adminID;
|
||||
|
||||
restartPozadavky = restartPozadavky.filter(pozadavek => {
|
||||
return pozadavek.kdy > Date.now() - 6e4;
|
||||
});
|
||||
|
||||
if (!sudo) {
|
||||
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`;
|
||||
}
|
||||
|
||||
function udelat() {
|
||||
getVoiceConnections().forEach(con => con.destroy());
|
||||
client.user?.setStatus("invisible");
|
||||
mes.react("👋")
|
||||
.then(() => process.exit(69));
|
||||
}
|
||||
|
||||
if (!sudo) {
|
||||
const souhlasatori: string[] = [mes.author.id];
|
||||
|
||||
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();
|
||||
}
|
||||
},
|
||||
|
||||
lastuptime: () => {
|
||||
@ -117,9 +131,6 @@ const exp: Modul = {
|
||||
// Nastavení clienta
|
||||
client = module.exports.client;
|
||||
|
||||
// Záznam
|
||||
appendFileSync("zaznamy.dlog", `ziju${Date.now().toString(36)}\n`);
|
||||
|
||||
// OG onReady
|
||||
log("A jedeš!");
|
||||
if (process.argv.length >= 4) adminLog(client, "pošel jsem");
|
||||
|
||||
@ -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";
|
||||
|
||||
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 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: () => { }
|
||||
});
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user