diff --git a/src/modules/komComplex.ts b/src/modules/komComplex.ts index cd413ae..a798195 100644 --- a/src/modules/komComplex.ts +++ b/src/modules/komComplex.ts @@ -17,8 +17,6 @@ const changeActivity = (mes: Message, activity: Exclude new Promise(res => setTimeout(res, time)); - const exp: Modul = { more_komandy: { @@ -128,7 +126,7 @@ const exp: Modul = { pockej: { als: ["cekej"], arg: "počet sekund", - run: (mes, arg) => { + run: async (mes, arg) => { if (mes.author.id == mes.client.user?.id) return emouty.sjeta; let cas: number; if (arg.length) { @@ -138,11 +136,16 @@ const exp: Modul = { cas = Math.floor(Math.random() * 10740 + 60); } + const channel = await mes.author.createDM(); + try { + await channel.send(`test ${emouty.d3k}`); + } catch { + return "ja ti ale napsat nemuzu ti kundo"; + } + setTimeout(async () => { - const chanel = await mes.author.createDM(); for (let i = 0; i < 15; i++) { - chanel.send("uz?"); - await sleep(200); + await channel.send("uz?"); } }, cas * 1000); diff --git a/src/modules/spink.ts b/src/modules/spink.ts index d598a3d..7295048 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -4,7 +4,7 @@ import { ChannelType, Message, Presence, Role, TextBasedChannel, User, VoiceStat import fetch from "node-fetch"; import { emouty } from "../utils/emotes"; import { Modul, Spinkackar, SRecord } from "../utils/types"; -import { formatCas, formatter, log, oddiakritikovat, ping } from "../utils/utils"; +import { formatCas, formatter, log, oddiakritikovat, ping, sendDM } from "../utils/utils"; let spinkacky: SRecord; const budouciSpinky: SRecord = {}; @@ -237,8 +237,7 @@ const exp: Modul = { mes.delete(); (async () => { - const chanel = mes.author.dmChannel ?? await mes.author.createDM(); - chanel.send("spis tak nepis"); + sendDM(mes.author, "spis tak nepis"); })(); return true; } diff --git a/src/modules/zbytek.ts b/src/modules/zbytek.ts index 2d0fc9c..6d733f9 100644 --- a/src/modules/zbytek.ts +++ b/src/modules/zbytek.ts @@ -6,7 +6,7 @@ import { emouty } from "../utils/emotes"; import { createServer } from "http"; import { Modul } from "../utils/types"; import fetch from "node-fetch"; -import { formatCas, log } from "../utils/utils"; +import { formatCas, log, sendDM } from "../utils/utils"; let spim = false; @@ -100,9 +100,7 @@ const exp: Modul = { on_userUpdate: (bef: User, aft: User) => { if (bef.avatar == aft.avatar) return; - aft.createDM().then(ch => { - ch.send("cus bracho vydim ze sis zmenim profilofku na dalsi mrdku estli chces abi se ukazovala na na v3ech sr4kach kterz sou na dedfis.cy tak se tam prosymte prihlas haby se mohla zmnenit syk"); - }); + sendDM(aft, "cus bracho vydim ze sis zmenim profilofku na dalsi mrdku estli chces abi se ukazovala na na v3ech sr4kach kterz sou na dedfis.cy tak se tam prosymte prihlas haby se mohla zmnenit syk"); } }; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 5337905..885a902 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,5 +1,5 @@ import { AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResource, entersState, getVoiceConnection, joinVoiceChannel, PlayerSubscription, StreamType, VoiceConnection, VoiceConnectionStatus } from "@discordjs/voice"; -import { ChannelType, Client, Guild, StageChannel, VoiceChannel } from "discord.js"; +import { ChannelType, Client, Guild, StageChannel, User, VoiceChannel } from "discord.js"; import { once } from "events"; import { FakePresence, JoinHovna, KomandNaExport, MuzikaFace, RunFunkce, SRecord, StatusyINaFounu } from "./types"; import { existsSync } from "fs"; @@ -184,7 +184,8 @@ export function adminLog(client: Client, text: string) { adminChannel.send(text); } if (process.env.adminID) { - client.users.cache.get(process.env.adminID)?.createDM().then(ch => ch.send(text)); + const user = client.users.cache.get(process.env.adminID); + if (user) sendDM(user, text); } } @@ -239,3 +240,8 @@ export const statusOnFoun = (bef: FakePresence | null, aft: FakePresence) => { }; export const getGuildConnection = (guildId: string) => pripojeni[guildId]?.connection; + +export async function sendDM(user: User, txt: string) { + const channel = await user.createDM(); + channel.send(txt).catch(() => console.log(`dementovi ${user} nejde poslat DM`)); +}