Denim-Bot/src/modules/komComplex.ts
2022-06-12 16:24:19 +02:00

158 lines
5.0 KiB
TypeScript

// Komandy, který buď nějakým způsobem mění funkci nebo "vzhled" bota
// nebo donutí bota něco udělat (odeslání zprávy nebo smazání originální zprávy se nepočítá)
import { ActivityType, Message, MessageReaction, PresenceStatusData } from "discord.js";
import { emouty } from "../utils/emotes";
import { Modul, SRecord } from "../utils/types";
import { formatter, ping } from "../utils/utils";
const changeStatus = (mes: Message, status: PresenceStatusData) => {
mes.client.user?.setStatus(status);
return "ano pane";
};
const changeActivity = (mes: Message, activity: Exclude<ActivityType, "CUSTOM"> | undefined = undefined, txt: string = "") => {
mes.client.user?.setActivity({ name: txt, type: activity });
mes.react(emouty.d3k);
return "ano pane";
};
const sleep = (time: number) => new Promise<void>(res => setTimeout(res, time));
const exp: Modul = {
more_komandy: {
online: {
als: ["onlajn", "zelenej"],
run: mes => changeStatus(mes, "online")
},
idle: {
als: ["zlutej", "afk", "idle", "nepritomnej"],
run: mes => changeStatus(mes, "idle")
},
dnd: {
als: ["nerusit", "cervenej"],
run: mes => changeStatus(mes, "dnd")
},
offline: {
als: ["oflajn", "neviditelnej"],
run: mes => changeStatus(mes, "invisible")
},
hraj: (mes, co) => changeActivity(mes, "PLAYING", co),
sleduj: (mes, co) => changeActivity(mes, "WATCHING", co),
poslouchej: (mes, co) => changeActivity(mes, "LISTENING", co),
soutez: (mes, vcem) => changeActivity(mes, "COMPETING", vcem),
nedelej: mes => changeActivity(mes),
fight: {
als: ["figh", "fajt"],
run: (mes, skym) => {
if (!ping.test(skym)) return "tak si kokot ti kokote";
const vyherce = Math.random() < 0.5 ? mes.author : skym;
return `tento figh vyhrál: ${vyherce}!`;
}
},
status: (mes, koho) => {
if (!ping.test(koho)) return "tak si kokot ti kokote";
const uzivatel = mes.mentions.members!.first()!;
const embed = {
title: `Informace o statusech pro ${uzivatel.displayName}:`,
color: 431075,
description: ""
};
const presence = uzivatel.presence?.clientStatus;
if (!(presence && Object.keys(presence).length)) {
embed.description = "*Všude je offline*";
} else {
const zarizeni: SRecord<string> = { desktop: "Počítač", mobile: "Mobil", web: "Web" };
const statusy = { online: "🟢", idle: "🟡", dnd: "🔴" };
const uStatusy: string[] = [];
const klice = Object.keys(presence) as ("web" | "mobile" | "desktop")[];
klice.forEach(status => {
uStatusy.push(`${zarizeni[status]}: ${statusy[presence[status]!]}`);
});
embed.description = uStatusy.join("\n");
}
return { embeds: [embed] };
},
zareaguj: {
als: ["react"],
arg: "emout/emouty",
run: async (mes, arg) => {
const emouty = arg.split(" ");
let naCo: Message;
if (mes.reference) {
naCo = await mes.channel.messages.fetch(mes.reference.messageId!);
} else {
const msgs = [...mes.channel.messages.cache.values()];
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>[] = [];
if (mes.channel.type != "DM") mes.delete();
emouty.forEach(emout => {
reakce.push(naCo.react(emout)
.catch(() => { }));
});
if (!(await Promise.all(reakce)).every(r => !!r != false)) return "retarde";
}
},
odpocitej: mes => {
const randomshit = (mes: Message, argument: string[]) => {
mes.edit(argument[0]);
argument.splice(0, 1);
if (argument.length) setTimeout(() => randomshit(mes, argument), 1000);
};
mes.channel.send(":stop_button:").then(mes => randomshit(mes, [":five:", ":four:", ":three:", ":two:", ":one:", ":ok:"]));
},
pocasi: () => {
const embed = {
title: "Počasí",
image: { url: "attachment://pocasi.png" }
};
return { embeds: [embed], files: ["https://util.deadfish.cz/morepocasi/v/49.4348358/12.8147250/pocasi.png"] };
},
pockej: {
als: ["cekej"],
arg: "počet sekund",
run: (mes, arg) => {
let cas: number;
if (arg.length) {
cas = Number(arg);
if (isNaN(cas)) return "cos to tam napsal ty kkt";
} else {
cas = Math.floor(Math.random() * 10740 + 60);
}
setTimeout(async () => {
const chanel = await mes.author.createDM();
for (let i = 0; i < 15; i++) {
chanel.send("uz?");
await sleep(200);
}
}, cas * 1000);
const datum = new Date();
datum.setSeconds(datum.getSeconds() + cas);
return `doufam ze v ${formatter(datum)} to uz bude`;
}
}
}
};
module.exports = exp;