Bot now listens on DM

even better react
This commit is contained in:
Histmy 2022-06-12 16:24:19 +02:00
parent a246a5007f
commit 8820aa5c20
9 changed files with 65 additions and 48 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.38.3", "version": "3001.39.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.38.3", "version": "3001.39.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@discordjs/voice": "^0.10.0", "@discordjs/voice": "^0.10.0",

View File

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

@ -11,7 +11,10 @@ const custom: CustomKomandy = require("./utils/customCommands");
loadEnv(); loadEnv();
const ints = Intents.FLAGS; const ints = Intents.FLAGS;
const client = new Client({ intents: [ints.GUILDS, ints.GUILD_VOICE_STATES, ints.GUILD_PRESENCES, ints.GUILD_MESSAGES] }); const client = new Client({
partials: ["CHANNEL"],
intents: [ints.GUILDS, ints.GUILD_VOICE_STATES, ints.GUILD_PRESENCES, ints.GUILD_MESSAGES, ints.DIRECT_MESSAGES]
});
const prefix = process.env.prefix || "more"; const prefix = process.env.prefix || "more";
const modulFolder = `${__dirname}/modules/`; const modulFolder = `${__dirname}/modules/`;
const eventy: SRecord<ListenerFunkce[]> = {}; const eventy: SRecord<ListenerFunkce[]> = {};
@ -91,7 +94,7 @@ readdirSync(modulFolder).forEach(soubor => {
komandy[cmdName] = { run: value }; komandy[cmdName] = { run: value };
toCoExportuju.arg = fnToArg(value); toCoExportuju.arg = fnToArg(value);
} else { } else {
komandy[cmdName] = { run: value.run, cd: value.cd }; komandy[cmdName] = { run: value.run, cd: value.cd, DMUnsafe: value.DMUnsafe };
Object.assign(toCoExportuju, { als: value.als, arg: value.arg ?? fnToArg(value.run) }); Object.assign(toCoExportuju, { als: value.als, arg: value.arg ?? fnToArg(value.run) });
hide = !!value.hidden; hide = !!value.hidden;
value.als?.forEach(al => aliasy[al] = cmdName); value.als?.forEach(al => aliasy[al] = cmdName);
@ -153,6 +156,7 @@ client.on("messageCreate", async mes => {
const cmdName = aliasy[komand] ?? komand; const cmdName = aliasy[komand] ?? komand;
if (runEvent("message", [mes, cmdName])) return; if (runEvent("message", [mes, cmdName])) return;
const cmd = komandy[cmdName] ?? customKomandy[cmdName]; const cmd = komandy[cmdName] ?? customKomandy[cmdName];
if (cmd.DMUnsafe && mes.channel.type == "DM") return void mes.channel.send("tuten komand bohuzel v sz nefunkuje");
if (!cmd) { if (!cmd) {
const slova: string[] = []; const slova: string[] = [];

View File

@ -1,30 +1,31 @@
// Komandy, který pošlou jenom celArgs a random hovno // Komandy, který pošlou jenom celArgs a random hovno
import { Message } from "discord.js";
import { emouty } from "../utils/emotes"; import { emouty } from "../utils/emotes";
import { Modul } from "../utils/types"; import { Modul } from "../utils/types";
const delAndReturn = (mes: Message, co: string) => {
if (mes.channel.type != "DM") mes.delete();
return co;
};
const exp: Modul = { const exp: Modul = {
more_komandy: { more_komandy: {
rekni: (mes, co) => { rekni: (mes, co) => {
if (mes.author.bot) return "ne"; if (mes.author.bot) return "ne";
const corict = co || `co mam jako rict ${mes.author}`; return delAndReturn(mes, co || `co mam jako rict ${mes.author}`);
mes.delete();
return corict;
}, },
clap: (mes, text) => { clap: (mes, text) => {
mes.delete(); return delAndReturn(mes, `${text} ${emouty.clap}`);
return `${text} ${emouty.clap}`;
}, },
clap2: (mes, text) => { clap2: (mes, text) => {
mes.delete(); return delAndReturn(mes, `${emouty.clap2} ${text}`);
return `${emouty.clap2} ${text}`;
}, },
voliz: (mes, co) => { voliz: (mes, co) => {
mes.delete(); return delAndReturn(mes, `${emouty.lickL}${co}${emouty.lickR}`);
return `${emouty.lickL}${co}${emouty.lickR}`;
}, },
pozdrav: (_, koho) => `zdravim ${koho}`, pozdrav: (_, koho) => `zdravim ${koho}`,

View File

@ -91,11 +91,15 @@ const exp: Modul = {
naCo = await mes.channel.messages.fetch(mes.reference.messageId!); naCo = await mes.channel.messages.fetch(mes.reference.messageId!);
} else { } else {
const msgs = [...mes.channel.messages.cache.values()]; const msgs = [...mes.channel.messages.cache.values()];
naCo = msgs[msgs.length - 2]; console.log(msgs.length);
if (msgs.length < 2) {
naCo = (await mes.channel.messages.fetch({ limit: 2 })).at(1)!;
}
else naCo = msgs[msgs.length - 2];
} }
const reakce: Promise<void | MessageReaction>[] = []; const reakce: Promise<void | MessageReaction>[] = [];
mes.delete(); if (mes.channel.type != "DM") mes.delete();
emouty.forEach(emout => { emouty.forEach(emout => {
reakce.push(naCo.react(emout) reakce.push(naCo.react(emout)
.catch(() => { })); .catch(() => { }));

View File

@ -6,30 +6,33 @@ import { joinVoice, play } from "../utils/utils";
const exp: Modul = { const exp: Modul = {
more_komandy: { more_komandy: {
zahraj: async (mes, txt) => { zahraj: {
let url: string; DMUnsafe: true,
const druh = await validate(txt); run: async (mes, txt) => {
if (druh && druh != "search") { let url: string;
if (druh != "yt_video" && druh != "so_track") return "tuto neumim zahrat"; const druh = await validate(txt);
url = txt; if (druh && druh != "search") {
if (druh == "yt_video") { if (druh != "yt_video" && druh != "so_track") return "tuto neumim zahrat";
video_basic_info(url).then(v => mes.channel.send(`hraju \`${v.video_details.title}\``)); url = txt;
if (druh == "yt_video") {
video_basic_info(url).then(v => mes.channel.send(`hraju \`${v.video_details.title}\``));
} else {
soundcloud(url).then(s => mes.channel.send(`hraju \`${s.name}\``));
}
} else { } else {
soundcloud(url).then(s => mes.channel.send(`hraju \`${s.name}\``)); const msg = mes.channel.send("hledam");
const hledani = await search(txt, { limit: 1 });
url = hledani[0].url;
msg.then(m => m.edit(`hraju \`${hledani[0].title}\``));
} }
} else {
const msg = mes.channel.send("hledam"); const kanel = mes.member?.voice.channel;
const hledani = await search(txt, { limit: 1 }); if (!kanel) return "nejsi ve vojsu ty kkt";
url = hledani[0].url; const { conn } = await joinVoice(kanel);
msg.then(m => m.edit(`hraju \`${hledani[0].title}\``));
const src = await stream(url);
play(conn, { name: src.stream, volume: 1, type: src.type });
} }
const kanel = mes.member?.voice.channel;
if (!kanel) return "nejsi ve vojsu ty kkt";
const { conn } = await joinVoice(kanel);
const src = await stream(url);
play(conn, { name: src.stream, volume: 1, type: src.type });
} }
} }
}; };

View File

@ -1,6 +1,6 @@
// Modul dedikovaný funkci spinkáček // Modul dedikovaný funkci spinkáček
import { GuildMember, Message, Presence, Role, TextBasedChannel, VoiceState } from "discord.js"; import { Message, Presence, Role, TextBasedChannel, User, VoiceState } from "discord.js";
import fetch from "node-fetch"; import fetch from "node-fetch";
import { emouty } from "../utils/emotes"; import { emouty } from "../utils/emotes";
import { Modul, Spinkackar, SRecord } from "../utils/types"; import { Modul, Spinkackar, SRecord } from "../utils/types";
@ -36,10 +36,10 @@ const syncSpink = () => {
syncSpink(); syncSpink();
const handleSpink = async (act: "spinkacek" | "vstavacek", member: GuildMember) => { const handleSpink = async (act: "spinkacek" | "vstavacek", user: User) => {
const ok = act == "spinkacek" const ok = act == "spinkacek"
? await contactSpinkServer(act, member.id, member.user.username, member.user.avatarURL()) ? await contactSpinkServer(act, user.id, user.username, user.avatarURL())
: await contactSpinkServer(act, member.id); : await contactSpinkServer(act, user.id);
return ok.startsWith("OK") ? ok : false; return ok.startsWith("OK") ? ok : false;
}; };
@ -54,7 +54,7 @@ const ifUzRemove = (m: Message) => {
return false; return false;
}; };
const tovjemamvolepreceroliky = async (roliky: GuildMember) => { const tovjemamvolepreceroliky = async (roliky: User) => {
const odpoved = await handleSpink("vstavacek", roliky); const odpoved = await handleSpink("vstavacek", roliky);
if (!odpoved) return "uz jsi vzhuru ty hajzle"; if (!odpoved) return "uz jsi vzhuru ty hajzle";
const cas = Number(odpoved.slice(3)); const cas = Number(odpoved.slice(3));
@ -66,7 +66,7 @@ const tovjemamvolepreceroliky = async (roliky: GuildMember) => {
else if (cas < 30) zpr = "dobrej mikrospánek debile"; else if (cas < 30) zpr = "dobrej mikrospánek debile";
else if (cas < 10800) zpr = "dobrej fake spink debile"; else if (cas < 10800) zpr = "dobrej fake spink debile";
return `dobry rano hajzle ${roliky.user}\nspal sy ${formatedCas}\n${zpr}`; return `dobry rano hajzle ${roliky}\nspal sy ${formatedCas}\n${zpr}`;
}; };
const exp: Modul = { const exp: Modul = {
@ -76,7 +76,7 @@ const exp: Modul = {
als: ["spink", "spoink", "spinkake", "spoinkacek", "gn", emouty.spinkacek, emouty.gn], als: ["spink", "spoink", "spinkake", "spoinkacek", "gn", emouty.spinkacek, emouty.gn],
run: async mes => { run: async mes => {
if (mes.author.bot) return `až někdy${emouty.kapp}`; if (mes.author.bot) return `až někdy${emouty.kapp}`;
if (await handleSpink("spinkacek", mes.member!)) { if (await handleSpink("spinkacek", mes.author)) {
mes.react(emouty.spinkacek); mes.react(emouty.spinkacek);
ifUzRemove(mes); ifUzRemove(mes);
} }
@ -89,7 +89,7 @@ const exp: Modul = {
run: async mes => { run: async mes => {
if (mes.author.bot) return emouty.sjeta; if (mes.author.bot) return emouty.sjeta;
return tovjemamvolepreceroliky(mes.member!); return tovjemamvolepreceroliky(mes.author);
} }
}, },
@ -127,7 +127,7 @@ const exp: Modul = {
ifUzRemove(mes); ifUzRemove(mes);
budouciSpinky[mes.author.id] = setTimeout(() => { budouciSpinky[mes.author.id] = setTimeout(() => {
handleSpink("spinkacek", mes.member!); handleSpink("spinkacek", mes.author);
mes.react(emouty.spinkacek); mes.react(emouty.spinkacek);
}, Number(spink) - tedT); }, Number(spink) - tedT);
if (!random) return `tvuj spinkacek byl naplanovan na ${formatter(spink)}`; if (!random) return `tvuj spinkacek byl naplanovan na ${formatter(spink)}`;
@ -230,12 +230,12 @@ const exp: Modul = {
const prop = autoSpinky[aft.userId]; const prop = autoSpinky[aft.userId];
if (!prop) return; if (!prop) return;
if (!befoff && aftoff) { if (!befoff && aftoff) {
handleSpink("spinkacek", aft.member!); handleSpink("spinkacek", aft.member!.user);
} }
if (befoff && !aftoff) { if (befoff && !aftoff) {
if (prop[0]) delete autoSpinky[aft.userId]; if (prop[0]) delete autoSpinky[aft.userId];
const kanel = prop[1]; const kanel = prop[1];
if (kanel?.isText()) kanel.send(await tovjemamvolepreceroliky(aft.member!)); if (kanel?.isText()) kanel.send(await tovjemamvolepreceroliky(aft.member!.user));
} }
} }
}; };

View File

@ -65,6 +65,7 @@ const exp: Modul = {
vojs: { vojs: {
cd: 1800, cd: 1800,
arg: "potichu (nepovinné)", arg: "potichu (nepovinné)",
DMUnsafe: true,
run: (mes, arg) => { run: (mes, arg) => {
const channel = mes.member?.voice.channel; const channel = mes.member?.voice.channel;
if (!channel) return `di si tam sam ne ty gadzo ${mes.author}`; if (!channel) return `di si tam sam ne ty gadzo ${mes.author}`;
@ -90,6 +91,7 @@ const exp: Modul = {
vypadni: { vypadni: {
als: ["odejdi", "disconnect", "leave", "odpoj", "votpoj", "vodpoj", "vodprejskni", "tahni"], als: ["odejdi", "disconnect", "leave", "odpoj", "votpoj", "vodpoj", "vodprejskni", "tahni"],
DMUnsafe: true,
run: mes => { run: mes => {
const vojs = getVoiceConnection(mes.guildId!); const vojs = getVoiceConnection(mes.guildId!);
if (!vojs) return 'nejsem ve vojsu'; if (!vojs) return 'nejsem ve vojsu';
@ -101,6 +103,7 @@ const exp: Modul = {
vytah: { vytah: {
als: ["vitah"], als: ["vitah"],
DMUnsafe: true,
run: (mes, parto) => { run: (mes, parto) => {
if (!mes.member?.voice.channel) return `nejsi ve vojsu ty gadzo ${mes.author}`; if (!mes.member?.voice.channel) return `nejsi ve vojsu ty gadzo ${mes.author}`;
if (!parto) return `napis do jakiho patra ${mes.author}`; if (!parto) return `napis do jakiho patra ${mes.author}`;

View File

@ -16,6 +16,7 @@ type KomandRaw = {
run: string | RunFunkce; run: string | RunFunkce;
cd?: number; cd?: number;
hidden?: true; hidden?: true;
DMUnsafe?: true;
} & BaseKomandProps; } & BaseKomandProps;
export type ListenerFunkce = (...args: any[]) => void; export type ListenerFunkce = (...args: any[]) => void;
@ -41,6 +42,7 @@ export type Modul = {
export interface Komand { export interface Komand {
run: RunFunkce | string; run: RunFunkce | string;
cd?: number; cd?: number;
DMUnsafe?: true;
} }
export interface Spinkackar { export interface Spinkackar {