From 8820aa5c20f8a54e856c39392529bba09c8ce3d3 Mon Sep 17 00:00:00 2001 From: Histmy Date: Sun, 12 Jun 2022 16:24:19 +0200 Subject: [PATCH] Bot now listens on DM even better react --- package-lock.json | 4 ++-- package.json | 2 +- src/app.ts | 8 +++++-- src/modules/komArgs.ts | 19 +++++++++-------- src/modules/komComplex.ts | 8 +++++-- src/modules/muzika.ts | 45 +++++++++++++++++++++------------------ src/modules/spink.ts | 22 +++++++++---------- src/modules/vojs.ts | 3 +++ src/utils/types.ts | 2 ++ 9 files changed, 65 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2a8e593..3743c74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "denim_3001", - "version": "3001.38.3", + "version": "3001.39.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.38.3", + "version": "3001.39.0", "license": "ISC", "dependencies": { "@discordjs/voice": "^0.10.0", diff --git a/package.json b/package.json index 15c8e54..a611047 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.38.3", + "version": "3001.39.0", "description": "Toto je velmi kvalitní bot.", "repository": { "url": "https://github.com/Histmy/Denim-Bot/" diff --git a/src/app.ts b/src/app.ts index 272d5f5..918316f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -11,7 +11,10 @@ const custom: CustomKomandy = require("./utils/customCommands"); loadEnv(); 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 modulFolder = `${__dirname}/modules/`; const eventy: SRecord = {}; @@ -91,7 +94,7 @@ readdirSync(modulFolder).forEach(soubor => { komandy[cmdName] = { run: value }; toCoExportuju.arg = fnToArg(value); } 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) }); hide = !!value.hidden; value.als?.forEach(al => aliasy[al] = cmdName); @@ -153,6 +156,7 @@ client.on("messageCreate", async mes => { const cmdName = aliasy[komand] ?? komand; if (runEvent("message", [mes, cmdName])) return; 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) { const slova: string[] = []; diff --git a/src/modules/komArgs.ts b/src/modules/komArgs.ts index ab13805..cf4c596 100644 --- a/src/modules/komArgs.ts +++ b/src/modules/komArgs.ts @@ -1,30 +1,31 @@ // Komandy, který pošlou jenom celArgs a random hovno +import { Message } from "discord.js"; import { emouty } from "../utils/emotes"; import { Modul } from "../utils/types"; +const delAndReturn = (mes: Message, co: string) => { + if (mes.channel.type != "DM") mes.delete(); + return co; +}; + const exp: Modul = { more_komandy: { rekni: (mes, co) => { if (mes.author.bot) return "ne"; - const corict = co || `co mam jako rict ${mes.author}`; - mes.delete(); - return corict; + return delAndReturn(mes, co || `co mam jako rict ${mes.author}`); }, clap: (mes, text) => { - mes.delete(); - return `${text} ${emouty.clap}`; + return delAndReturn(mes, `${text} ${emouty.clap}`); }, clap2: (mes, text) => { - mes.delete(); - return `${emouty.clap2} ${text}`; + return delAndReturn(mes, `${emouty.clap2} ${text}`); }, voliz: (mes, co) => { - mes.delete(); - return `${emouty.lickL}${co}${emouty.lickR}`; + return delAndReturn(mes, `${emouty.lickL}${co}${emouty.lickR}`); }, pozdrav: (_, koho) => `zdravim ${koho}`, diff --git a/src/modules/komComplex.ts b/src/modules/komComplex.ts index c687738..c3ebd05 100644 --- a/src/modules/komComplex.ts +++ b/src/modules/komComplex.ts @@ -91,11 +91,15 @@ const exp: Modul = { naCo = await mes.channel.messages.fetch(mes.reference.messageId!); } else { 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[] = []; - mes.delete(); + if (mes.channel.type != "DM") mes.delete(); emouty.forEach(emout => { reakce.push(naCo.react(emout) .catch(() => { })); diff --git a/src/modules/muzika.ts b/src/modules/muzika.ts index 4b7cfa2..6cc73fd 100644 --- a/src/modules/muzika.ts +++ b/src/modules/muzika.ts @@ -6,30 +6,33 @@ import { joinVoice, play } from "../utils/utils"; const exp: Modul = { more_komandy: { - zahraj: async (mes, txt) => { - let url: string; - const druh = await validate(txt); - if (druh && druh != "search") { - if (druh != "yt_video" && druh != "so_track") return "tuto neumim zahrat"; - url = txt; - if (druh == "yt_video") { - video_basic_info(url).then(v => mes.channel.send(`hraju \`${v.video_details.title}\``)); + zahraj: { + DMUnsafe: true, + run: async (mes, txt) => { + let url: string; + const druh = await validate(txt); + if (druh && druh != "search") { + if (druh != "yt_video" && druh != "so_track") return "tuto neumim zahrat"; + 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 { - 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 hledani = await search(txt, { limit: 1 }); - url = hledani[0].url; - msg.then(m => m.edit(`hraju \`${hledani[0].title}\``)); + + 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 }); } - - 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 }); } } }; diff --git a/src/modules/spink.ts b/src/modules/spink.ts index 2e88d2b..717ea00 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -1,6 +1,6 @@ // 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 { emouty } from "../utils/emotes"; import { Modul, Spinkackar, SRecord } from "../utils/types"; @@ -36,10 +36,10 @@ const syncSpink = () => { syncSpink(); -const handleSpink = async (act: "spinkacek" | "vstavacek", member: GuildMember) => { +const handleSpink = async (act: "spinkacek" | "vstavacek", user: User) => { const ok = act == "spinkacek" - ? await contactSpinkServer(act, member.id, member.user.username, member.user.avatarURL()) - : await contactSpinkServer(act, member.id); + ? await contactSpinkServer(act, user.id, user.username, user.avatarURL()) + : await contactSpinkServer(act, user.id); return ok.startsWith("OK") ? ok : false; }; @@ -54,7 +54,7 @@ const ifUzRemove = (m: Message) => { return false; }; -const tovjemamvolepreceroliky = async (roliky: GuildMember) => { +const tovjemamvolepreceroliky = async (roliky: User) => { const odpoved = await handleSpink("vstavacek", roliky); if (!odpoved) return "uz jsi vzhuru ty hajzle"; 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 < 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 = { @@ -76,7 +76,7 @@ const exp: Modul = { als: ["spink", "spoink", "spinkake", "spoinkacek", "gn", emouty.spinkacek, emouty.gn], run: async mes => { 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); ifUzRemove(mes); } @@ -89,7 +89,7 @@ const exp: Modul = { run: async mes => { if (mes.author.bot) return emouty.sjeta; - return tovjemamvolepreceroliky(mes.member!); + return tovjemamvolepreceroliky(mes.author); } }, @@ -127,7 +127,7 @@ const exp: Modul = { ifUzRemove(mes); budouciSpinky[mes.author.id] = setTimeout(() => { - handleSpink("spinkacek", mes.member!); + handleSpink("spinkacek", mes.author); mes.react(emouty.spinkacek); }, Number(spink) - tedT); if (!random) return `tvuj spinkacek byl naplanovan na ${formatter(spink)}`; @@ -230,12 +230,12 @@ const exp: Modul = { const prop = autoSpinky[aft.userId]; if (!prop) return; if (!befoff && aftoff) { - handleSpink("spinkacek", aft.member!); + handleSpink("spinkacek", aft.member!.user); } if (befoff && !aftoff) { if (prop[0]) delete autoSpinky[aft.userId]; const kanel = prop[1]; - if (kanel?.isText()) kanel.send(await tovjemamvolepreceroliky(aft.member!)); + if (kanel?.isText()) kanel.send(await tovjemamvolepreceroliky(aft.member!.user)); } } }; diff --git a/src/modules/vojs.ts b/src/modules/vojs.ts index 69bd78d..1f496a1 100644 --- a/src/modules/vojs.ts +++ b/src/modules/vojs.ts @@ -65,6 +65,7 @@ const exp: Modul = { vojs: { cd: 1800, arg: "potichu (nepovinné)", + DMUnsafe: true, run: (mes, arg) => { const channel = mes.member?.voice.channel; if (!channel) return `di si tam sam ne ty gadzo ${mes.author}`; @@ -90,6 +91,7 @@ const exp: Modul = { vypadni: { als: ["odejdi", "disconnect", "leave", "odpoj", "votpoj", "vodpoj", "vodprejskni", "tahni"], + DMUnsafe: true, run: mes => { const vojs = getVoiceConnection(mes.guildId!); if (!vojs) return 'nejsem ve vojsu'; @@ -101,6 +103,7 @@ const exp: Modul = { vytah: { als: ["vitah"], + DMUnsafe: true, run: (mes, parto) => { if (!mes.member?.voice.channel) return `nejsi ve vojsu ty gadzo ${mes.author}`; if (!parto) return `napis do jakiho patra ${mes.author}`; diff --git a/src/utils/types.ts b/src/utils/types.ts index c4cbc7f..83b8107 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -16,6 +16,7 @@ type KomandRaw = { run: string | RunFunkce; cd?: number; hidden?: true; + DMUnsafe?: true; } & BaseKomandProps; export type ListenerFunkce = (...args: any[]) => void; @@ -41,6 +42,7 @@ export type Modul = { export interface Komand { run: RunFunkce | string; cd?: number; + DMUnsafe?: true; } export interface Spinkackar {