Transision from .env to config.json...

spim moved to 'zbytek.ts'
dead logging also to admin channel
This commit is contained in:
Histmy 2021-09-07 14:28:35 +02:00
parent 7f0e794a60
commit eab4f5825e
11 changed files with 64 additions and 67 deletions

View File

@ -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

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
node_modules node_modules
.env config.json
out out

8
example.config.json Normal file
View File

@ -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"
}

18
package-lock.json generated
View File

@ -1,18 +1,17 @@
{ {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.22.1", "version": "3001.23.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.22.1", "version": "3001.23.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@discordjs/opus": "github:discordjs/opus", "@discordjs/opus": "github:discordjs/opus",
"@discordjs/voice": "^0.6.0", "@discordjs/voice": "^0.6.0",
"discord.js": "^13.0.1", "discord.js": "^13.0.1",
"dotenv": "^8.2.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"tweetnacl": "^1.0.3", "tweetnacl": "^1.0.3",
"yt-search": "^2.7.5", "yt-search": "^2.7.5",
@ -751,14 +750,6 @@
"url": "https://github.com/sponsors/sindresorhus" "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": { "node_modules/eastasianwidth": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
@ -2210,11 +2201,6 @@
"is-obj": "^2.0.0" "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": { "eastasianwidth": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",

View File

@ -1,6 +1,6 @@
{ {
"name": "denim_3001", "name": "denim_3001",
"version": "3001.22.1", "version": "3001.23.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/"
@ -16,7 +16,6 @@
"@discordjs/opus": "github:discordjs/opus", "@discordjs/opus": "github:discordjs/opus",
"@discordjs/voice": "^0.6.0", "@discordjs/voice": "^0.6.0",
"discord.js": "^13.0.1", "discord.js": "^13.0.1",
"dotenv": "^8.2.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"tweetnacl": "^1.0.3", "tweetnacl": "^1.0.3",
"yt-search": "^2.7.5", "yt-search": "^2.7.5",

View File

@ -1,16 +1,13 @@
import { getVoiceConnections } from "@discordjs/voice"; import { Client, Intents } from "discord.js";
import { Client, Intents, Message } from "discord.js";
import { config } from "dotenv";
import { readdirSync } from "fs"; import { readdirSync } from "fs";
import { emouty } from "./utils/emotes";
import { Komand, ListenerFunkce, Modul, SuperListenerFunkce } from "./utils/types"; 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 ints = Intents.FLAGS;
const client = new Client({ intents: [ints.GUILDS, ints.GUILD_VOICE_STATES, ints.GUILD_PRESENCES, ints.GUILD_MESSAGES] }); 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 modulFolder = `${__dirname}/modules/`;
const eventy: Record<string, ListenerFunkce[]> = {}; const eventy: Record<string, ListenerFunkce[]> = {};
const superEventy: Record<string, SuperListenerFunkce[]> = {}; const superEventy: Record<string, SuperListenerFunkce[]> = {};
@ -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) => { const maKuldan = (id: string, komand: string, kuldan_komandu: number) => {
if (!kuldan_log[komand]) kuldan_log[komand] = {}; if (!kuldan_log[komand]) kuldan_log[komand] = {};
@ -98,7 +74,7 @@ const maKuldan = (id: string, komand: string, kuldan_komandu: number) => {
}; };
client.on("messageCreate", mes => { 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(" "); const [mes_prefix, komandSDiakritikou, ...args] = mes.content.split(" ");
if (mes_prefix.toLowerCase() !== prefix) return void runEvent("message", [mes]); if (mes_prefix.toLowerCase() !== prefix) return void runEvent("message", [mes]);
@ -119,7 +95,7 @@ client.on("messageCreate", mes => {
const akce = cmd.run; const akce = cmd.run;
if (typeof akce === "string") return void mes.channel.send(akce); if (typeof akce === "string") return void mes.channel.send(akce);
const result = akce(celArgs, mes); 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);

View File

@ -7,9 +7,9 @@ module.exports = {
console.log("A jedeš!"); console.log("A jedeš!");
if (process.argv.length < 3) return; if (process.argv.length < 3) return;
const client: Client = module.exports.client; const client: Client = module.exports.client;
const admin = client.users.cache.get(process.env.ADMIN_ID ?? ""); const admin = client.users.cache.get(process.env.adminID ?? "");
if (!admin) return; if (admin) (await admin.createDM()).send("pošel jsem ty magore");
await admin.createDM(); const channel = client.channels.cache.get(process.env.adminChannel ?? "");
admin.dmChannel?.send("pošel jsem ty magore"); if (channel && channel.isText()) channel.send("pošel jsem magoří");
} }
}; };

View File

@ -9,7 +9,7 @@ import { formatCas } from "../utils/utils";
const spinkacky: string[] = []; const spinkacky: string[] = [];
const contactSpinkServer = async (akce: string, id: string, nick: string = "", avatar: string | null = "") => { 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}`) return await fetch(`https://spinkacek.ga/extapi.php?${options}`)
.then(r => r.text()) .then(r => r.text())
.then(text => text); .then(text => text);

View File

@ -25,7 +25,7 @@ const prepSend = (zmeny: UserChange[]) => {
}; };
const poslatData = (data: Record<string, any>) => { const poslatData = (data: Record<string, any>) => {
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) }); 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); setTimeout(ziju, 60_000);
}; };
if (!process.env.IGNORE_PRESENCE) ziju(); if (!process.env.ignorePresence) ziju();
const getRole = (status: StatusyINaFounu, server: Guild) => const getRole = (status: StatusyINaFounu, server: Guild) =>
server.roles.cache.find(role => role.name === `Status${status}`); server.roles.cache.find(role => role.name === `Status${status}`);
@ -59,7 +59,7 @@ module.exports = {
// Změna rolí podle statusu a odeslání statusu // Změna rolí podle statusu a odeslání statusu
on_presenceUpdate: (bef: Presence, aft: Presence) => { 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); const [statusPred, statusPo] = statusOnFoun(bef as FakePresence, aft as FakePresence);
if (statusPred === statusPo) return; if (statusPred === statusPo) return;
@ -75,7 +75,7 @@ module.exports = {
// Odeslání statusů při startu bota // Odeslání statusů při startu bota
on_ready: () => { on_ready: () => {
if (process.env.IGNORE_PRESENCE) return; if (process.env.ignorePresence) return;
const client: Client = module.exports.client; const client: Client = module.exports.client;
const guildy = client.guilds.cache; const guildy = client.guilds.cache;
@ -104,7 +104,7 @@ module.exports = {
// Odeslání statusu při změně jména nebo profilovky // Odeslání statusu při změně jména nebo profilovky
on_userUpdate: (_: any, aft: User) => { 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 }]); prepSend([{ ch: "user", user: aft }]);
} }
}; };

View File

@ -2,6 +2,9 @@
import { getVoiceConnections } from "@discordjs/voice"; import { getVoiceConnections } from "@discordjs/voice";
import { Message } from "discord.js"; import { Message } from "discord.js";
import { emouty } from "../utils/emotes";
let spim = false;
module.exports = { module.exports = {
more_komandy: { more_komandy: {
@ -12,11 +15,36 @@ module.exports = {
}, },
update: (_: any, mes: Message) => { 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()); getVoiceConnections().forEach(con => con.disconnect());
mes.react("👋") mes.react("👋")
.then(() => process.exit()); .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;
}
} }
}; };

View File

@ -2,6 +2,7 @@ import { AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResourc
import { Guild, StageChannel, VoiceChannel } from "discord.js"; import { Guild, StageChannel, VoiceChannel } from "discord.js";
import { once } from "events"; import { once } from "events";
import { MuzikaFace } from "./types"; import { MuzikaFace } from "./types";
import { existsSync } from "fs";
const pripojeni: Record<string, PlayerSubscription> = {}; const pripojeni: Record<string, PlayerSubscription> = {};
@ -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 if (prev === false) return leave(guild.id); // Nebyl jsem ve vojsu vůbec
joinVoice(prev, guild); // Byl jsem jinde 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") };
}