diff --git a/.env.example b/.env.example deleted file mode 100644 index 93e0852..0000000 --- a/.env.example +++ /dev/null @@ -1,6 +0,0 @@ -TOKEN poviné nečekaně token na discord aplikaci -PREFIX nepoviné, default = "more" -IGNORE_MESS nepoviné, pokud se nastaví na cokoliv (nejlépe "true"), bot bude nečekaně ignorovat všechny příchozí zprávy -IGNORE_PRESENCE nepoviné, pokud se nastaví na cokoliv (nejlépe "true"), bot bude nečekaně ignorovat jakékoliv změny presence a nebude měnit status-role -ADMIN_CHANNEL nepoviné, channelID kanálu, odkud půjde úspěšně spustit update -ADMIN_ID nepoviné, ID uživatele, který bude moci úspěšně spustit update diff --git a/.gitignore b/.gitignore index 30c5de7..9ee482f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules -.env +config.json out diff --git a/example.config.json b/example.config.json new file mode 100644 index 0000000..96ef876 --- /dev/null +++ b/example.config.json @@ -0,0 +1,8 @@ +{ + "token": "povinné, string - token na discord aplikaci", + "prefix": "povinné, string - text na začátku zprávy na kterou by měl bot zareagovat", + "ignoreMess": "nepovinné, boolean - bot nebude reagovat na žádné zprávy", + "ignorePresence": "nepovinné, boolean - bot nebude reagovat na změny presence", + "adminChannel": "nepovinné, string - ID kanálu, odkud půjde spustit komand update a pokud je bot spuštěn přes start.sh a bot spadne po 24 hodinách, pošle sem zprávu, která o tom informuje", + "adminID": "nepovinné, string - ID uživatele, který bude moci spustit komand update a pokud je bot spuštěn přes start.sh a bot spadne po 24 hodinách, pošle mu zprávu, která o tom informuje" +} diff --git a/package-lock.json b/package-lock.json index 929ae94..5f3c5e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,17 @@ { "name": "denim_3001", - "version": "3001.22.1", + "version": "3001.23.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.22.1", + "version": "3001.23.0", "license": "ISC", "dependencies": { "@discordjs/opus": "github:discordjs/opus", "@discordjs/voice": "^0.6.0", "discord.js": "^13.0.1", - "dotenv": "^8.2.0", "node-fetch": "^2.6.1", "tweetnacl": "^1.0.3", "yt-search": "^2.7.5", @@ -751,14 +750,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/dotenv": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", - "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", - "engines": { - "node": ">=10" - } - }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -2210,11 +2201,6 @@ "is-obj": "^2.0.0" } }, - "dotenv": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", - "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==" - }, "eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", diff --git a/package.json b/package.json index 2d0d161..75a90a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.22.1", + "version": "3001.23.0", "description": "Toto je velmi kvalitní bot.", "repository": { "url": "https://github.com/Histmy/Denim-Bot/" @@ -16,7 +16,6 @@ "@discordjs/opus": "github:discordjs/opus", "@discordjs/voice": "^0.6.0", "discord.js": "^13.0.1", - "dotenv": "^8.2.0", "node-fetch": "^2.6.1", "tweetnacl": "^1.0.3", "yt-search": "^2.7.5", diff --git a/src/app.ts b/src/app.ts index 9a66b5d..65f336e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,16 +1,13 @@ -import { getVoiceConnections } from "@discordjs/voice"; -import { Client, Intents, Message } from "discord.js"; -import { config } from "dotenv"; +import { Client, Intents } from "discord.js"; import { readdirSync } from "fs"; -import { emouty } from "./utils/emotes"; import { Komand, ListenerFunkce, Modul, SuperListenerFunkce } from "./utils/types"; -import { formatCas, oddiakritikovat } from "./utils/utils.js"; +import { formatCas, loadEnv, oddiakritikovat } from "./utils/utils.js"; const ints = Intents.FLAGS; const client = new Client({ intents: [ints.GUILDS, ints.GUILD_VOICE_STATES, ints.GUILD_PRESENCES, ints.GUILD_MESSAGES] }); -config(); +loadEnv(); -const prefix = process.env.PREFIX || "more"; +const prefix = process.env.prefix || "more"; const modulFolder = `${__dirname}/modules/`; const eventy: Record = {}; const superEventy: Record = {}; @@ -65,27 +62,6 @@ readdirSync(modulFolder).forEach(soubor => { }); }); -const spim = (mes: Message) => { - const cont = mes.content.toLocaleLowerCase(); - if (cont === `${prefix} zapni se`) { - if (spink) { - spink = false; - mes.client.user?.setStatus("online"); - mes.channel.send("dobré ráno magoří"); - } - else mes.channel.send("tak jsi kokot?"); - } else if (!spink) { - if (cont === `${prefix} vypni se`) { - mes.react(emouty.purfieRIP); - getVoiceConnections().forEach(con => con.disconnect()); - mes.client.user?.setStatus("invisible"); - spink = true; - } - else return false; - } - return true; -}; - const maKuldan = (id: string, komand: string, kuldan_komandu: number) => { if (!kuldan_log[komand]) kuldan_log[komand] = {}; @@ -98,7 +74,7 @@ const maKuldan = (id: string, komand: string, kuldan_komandu: number) => { }; client.on("messageCreate", mes => { - if (process.env.IGNORE_MESS || spim(mes)) return; + if (process.env.ignoreMess) return; const [mes_prefix, komandSDiakritikou, ...args] = mes.content.split(" "); if (mes_prefix.toLowerCase() !== prefix) return void runEvent("message", [mes]); @@ -119,7 +95,7 @@ client.on("messageCreate", mes => { const akce = cmd.run; if (typeof akce === "string") return void mes.channel.send(akce); const result = akce(celArgs, mes); - if (result && !(result instanceof Promise)) mes.channel.send(result); + if (typeof result == "string") mes.channel.send(result); }); -client.login(process.env.TOKEN); +client.login(process.env.token); diff --git a/src/modules/onReady.ts b/src/modules/onReady.ts index e8d6a52..177fb62 100644 --- a/src/modules/onReady.ts +++ b/src/modules/onReady.ts @@ -7,9 +7,9 @@ module.exports = { console.log("A jedeš!"); if (process.argv.length < 3) return; const client: Client = module.exports.client; - const admin = client.users.cache.get(process.env.ADMIN_ID ?? ""); - if (!admin) return; - await admin.createDM(); - admin.dmChannel?.send("pošel jsem ty magore"); + const admin = client.users.cache.get(process.env.adminID ?? ""); + if (admin) (await admin.createDM()).send("pošel jsem ty magore"); + const channel = client.channels.cache.get(process.env.adminChannel ?? ""); + if (channel && channel.isText()) channel.send("pošel jsem magoří"); } }; diff --git a/src/modules/spink.ts b/src/modules/spink.ts index 143f121..643c83b 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -9,7 +9,7 @@ import { formatCas } from "../utils/utils"; const spinkacky: string[] = []; const contactSpinkServer = async (akce: string, id: string, nick: string = "", avatar: string | null = "") => { - const options = `heslo=${process.env.SPINK_PASS}&akce=${akce}&id=${id}&nick=${encodeURIComponent(nick)}&avatar=${encodeURIComponent(avatar ?? "")}`; + const options = `heslo=${process.env.spinkPass}&akce=${akce}&id=${id}&nick=${encodeURIComponent(nick)}&avatar=${encodeURIComponent(avatar ?? "")}`; return await fetch(`https://spinkacek.ga/extapi.php?${options}`) .then(r => r.text()) .then(text => text); diff --git a/src/modules/status.ts b/src/modules/status.ts index c49e144..918c60c 100644 --- a/src/modules/status.ts +++ b/src/modules/status.ts @@ -25,7 +25,7 @@ const prepSend = (zmeny: UserChange[]) => { }; const poslatData = (data: Record) => { - data.pwd = process.env.STAT_PASS; + data.pwd = process.env.statPass; fetch("http://deadfish.cz:4629/endpoint-pro-denimka/", { method: "POST", headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); }; @@ -50,7 +50,7 @@ const ziju = () => { setTimeout(ziju, 60_000); }; -if (!process.env.IGNORE_PRESENCE) ziju(); +if (!process.env.ignorePresence) ziju(); const getRole = (status: StatusyINaFounu, server: Guild) => server.roles.cache.find(role => role.name === `Status${status}`); @@ -59,7 +59,7 @@ module.exports = { // Změna rolí podle statusu a odeslání statusu on_presenceUpdate: (bef: Presence, aft: Presence) => { - if (process.env.IGNORE_PRESENCE) return; + if (process.env.ignorePresence) return; const [statusPred, statusPo] = statusOnFoun(bef as FakePresence, aft as FakePresence); if (statusPred === statusPo) return; @@ -75,7 +75,7 @@ module.exports = { // Odeslání statusů při startu bota on_ready: () => { - if (process.env.IGNORE_PRESENCE) return; + if (process.env.ignorePresence) return; const client: Client = module.exports.client; const guildy = client.guilds.cache; @@ -104,7 +104,7 @@ module.exports = { // Odeslání statusu při změně jména nebo profilovky on_userUpdate: (_: any, aft: User) => { - if (!process.env.IGNORE_PRESENCE && aft.id !== aft.client.user?.id) + if (!process.env.ignorePresence && aft.id != aft.client.user?.id) prepSend([{ ch: "user", user: aft }]); } }; diff --git a/src/modules/zbytek.ts b/src/modules/zbytek.ts index a6b0af5..fa79e42 100644 --- a/src/modules/zbytek.ts +++ b/src/modules/zbytek.ts @@ -2,6 +2,9 @@ import { getVoiceConnections } from "@discordjs/voice"; import { Message } from "discord.js"; +import { emouty } from "../utils/emotes"; + +let spim = false; module.exports = { more_komandy: { @@ -12,11 +15,36 @@ module.exports = { }, update: (_: any, mes: Message) => { - if (mes.channel.id != process.env.ADMIN_CHANNEL && mes.author.id != process.env.ADMIN_ID) return "nato nemas prava kokote"; + if (mes.channel.id != process.env.adminChannel && mes.author.id != process.env.adminID) return "nato nemas prava kokote"; getVoiceConnections().forEach(con => con.disconnect()); mes.react("👋") .then(() => process.exit()); } + }, + + super_on_message: { + pos: 0, + fun: (mes: Message) => { + const cont = mes.content.toLowerCase(); + const prefix = process.env.prefix; + if (cont == `${prefix} zapni se`) { + if (spim) { + spim = false; + mes.client.user?.setStatus("online"); + mes.channel.send("dobré ráno magoří"); + } + else mes.channel.send("tak jsi kokot?"); + } else if (!spim) { + if (cont == `${prefix} vypni se`) { + mes.react(emouty.purfieRIP); + getVoiceConnections().forEach(con => con.disconnect()); + mes.client.user?.setStatus("invisible"); + spim = true; + } + else return; + } + return true; + } } }; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 7ff9b30..49e8704 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -2,6 +2,7 @@ import { AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResourc import { Guild, StageChannel, VoiceChannel } from "discord.js"; import { once } from "events"; import { MuzikaFace } from "./types"; +import { existsSync } from "fs"; const pripojeni: Record = {}; @@ -152,3 +153,8 @@ export const handlePrevVoice = (guild: Guild, prev: boolean | string) => { if (prev === false) return leave(guild.id); // Nebyl jsem ve vojsu vůbec joinVoice(prev, guild); // Byl jsem jinde }; + +export function loadEnv() { + if (!existsSync("config.json")) throw new Error("config.json neexistuje"); + process.env = { ...process.env, ...require("../../config.json") }; +}