Skip to content

Commit

Permalink
Drop getConfig() for bot context
Browse files Browse the repository at this point in the history
  • Loading branch information
holzmaster committed Mar 26, 2024
1 parent 2bb625e commit 5976dd3
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 52 deletions.
9 changes: 3 additions & 6 deletions src/commands/bonk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import type { Client, GuildMember } from "discord.js";
import type { CommandResult, MessageCommand } from "./command.js";
import type { ProcessableMessage } from "../handler/cmdHandler.js";
import log from "../utils/logger.js";
import { getConfig } from "../utils/configHandler.js";

const config = getConfig();

const createBonkMeme = async (author: GuildMember): Promise<Buffer> => {
const bonk = await fs.readFile("assets/bonk.png");
Expand All @@ -30,9 +27,9 @@ export class BonkCommand implements MessageCommand {
name = "bonk";
aliases = ["bong"];
description = `Bonkt einen Nutzer und ersetzt den rechten gelben Hund mit dem Avatar des Nutzers.
Usage: ${config.bot_settings.prefix.command_prefix}bonk
${config.bot_settings.prefix.command_prefix}bonk @ShadowByte#1337
Oder auf eine Nachricht mit ${config.bot_settings.prefix.command_prefix}bonk antworten.`;
Usage: $COMMAND_PREFIX$bonk
$COMMAND_PREFIX$bonk @ShadowByte#1337
Oder auf eine Nachricht mit $COMMAND_PREFIX$bonk antworten.`;

async handleMessage(
message: ProcessableMessage,
Expand Down
5 changes: 1 addition & 4 deletions src/commands/extend.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { type APIEmbedField, EmbedBuilder, type Message } from "discord.js";

import log from "../utils/logger.js";
import { getConfig } from "../utils/configHandler.js";
import * as poll from "./poll.js";
import type { CommandFunction } from "../types.js";

const config = getConfig();

const isPollField = (field: APIEmbedField): boolean =>
!field.inline && poll.LETTERS.some(l => field.name.startsWith(l));

Expand Down Expand Up @@ -132,4 +129,4 @@ export const run: CommandFunction = async (client, message, args, context) => {
await message.delete();
};

export const description = `Nutzbar als Reply auf eine mit --extendable erstellte Umfrage, um eine/mehrere Antwortmöglichkeit/en hinzuzüfgen. Die Anzahl der bestehenden und neuen Antwortmöglichkeiten darf ${poll.OPTION_LIMIT} nicht übersteigen.\nUsage: ${config.bot_settings.prefix.command_prefix}extend [Antwort 1] ; [...]`;
export const description = `Nutzbar als Reply auf eine mit --extendable erstellte Umfrage, um eine/mehrere Antwortmöglichkeit/en hinzuzüfgen. Die Anzahl der bestehenden und neuen Antwortmöglichkeiten darf ${poll.OPTION_LIMIT} nicht übersteigen.\nUsage: $COMMAND_PREFIX$extend [Antwort 1] ; [...]`;
6 changes: 2 additions & 4 deletions src/commands/min.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { getConfig } from "../utils/configHandler.js";
import type { CommandFunction } from "../types.js";

const config = getConfig();

const getAdvice = (age: number) => {
if (age <= 13) {
return "Nicht mit vertretbarer rechtlicher Komplexität durchbutterbar";
Expand Down Expand Up @@ -41,4 +38,5 @@ export const run: CommandFunction = async (_client, message, args) => {
await message.channel.send(advice);
};

export const description = `Gibt dir die Moralisch vertretbare Altersgrenze für den Geschlechtsakt basierend auf deinem Alter zurück. \nUsage: ${config.bot_settings.prefix.command_prefix}min [dein Alter]`;
export const description =
"Gibt dir die Moralisch vertretbare Altersgrenze für den Geschlechtsakt basierend auf deinem Alter zurück. \nUsage: $COMMAND_PREFIX$min [dein Alter]";
6 changes: 2 additions & 4 deletions src/commands/modcommands/assigner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { CommandFunction } from "../../types.js";
import log from "../../utils/logger.js";
import { getConfig } from "../../utils/configHandler.js";

const config = getConfig();

/**
* Creates an assigner message
Expand All @@ -28,4 +25,5 @@ export const run: CommandFunction = async (_client, message, args) => {
await Promise.all(validRoles.map(drawRole));
};

export const description = `Startet den assigner mit gegebenen Rollen \nBenutzung: ${config.bot_settings.prefix.mod_prefix}assigner [rolle 1] [rolle 2] [...]`;
export const description =
"Startet den assigner mit gegebenen Rollen \nBenutzung: $MOD_COMMAND_PREFIX$assigner [rolle 1] [rolle 2] [...]";
5 changes: 1 addition & 4 deletions src/commands/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ import {

import log from "../utils/logger.js";
import * as additionalMessageData from "../storage/additionalMessageData.js";
import { getConfig } from "../utils/configHandler.js";
import type { BotContext } from "../context.js";
import type { CommandFunction } from "../types.js";

const config = getConfig();

export const LETTERS = [
":regional_indicator_a:",
":regional_indicator_b:",
Expand Down Expand Up @@ -379,7 +376,7 @@ export const processPolls = async (context: BotContext) => {
};

export const description = `Erstellt eine Umfrage mit mehreren Antwortmöglichkeiten (standardmäßig mit Mehrfachauswahl) (maximal ${OPTION_LIMIT}).
Usage: ${config.bot_settings.prefix.command_prefix}poll [Optionen?] [Hier die Frage] ; [Antwort 1] ; [Antwort 2] ; [...]
Usage: $COMMAND_PREFIX$poll [Optionen?] [Hier die Frage] ; [Antwort 1] ; [Antwort 2] ; [...]
Optionen:
\t-c, --channel
\t\t\tSendet die Umfrage in den Umfragenchannel, um den Slowmode zu umgehen
Expand Down
5 changes: 1 addition & 4 deletions src/commands/roll.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { type APIEmbed, cleanContent } from "discord.js";

import { getConfig } from "../utils/configHandler.js";
import type { CommandFunction } from "../types.js";

const config = getConfig();

/**
* Creates a pseudo randomly generated number
* @param {number} min
Expand Down Expand Up @@ -122,6 +119,6 @@ export const run: CommandFunction = async (_client, message, args) => {

export const description = `
Wirft x beliebig viele Würfel mit y vielen Seiten.
Usage: ${config.bot_settings.prefix.command_prefix}roll xdy
Usage: $COMMAND_PREFIX$roll xdy
Mit x als die Anzahl der Würfel (<11) und y als die Menge der Seiten der Würfel (<=100)
`.trim();
8 changes: 3 additions & 5 deletions src/commands/selfban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import moment from "moment";

import type { CommandFunction } from "../types.js";
import * as banService from "../storage/ban.js";
import { getConfig } from "../utils/configHandler.js";
import * as ban from "./modcommands/ban.js";

const config = getConfig();

export const run: CommandFunction = async (client, message, args, context) => {
let input = args?.[0]?.trim() ?? "8";
const tilt = input === "tilt";
Expand Down Expand Up @@ -86,9 +83,10 @@ export const run: CommandFunction = async (client, message, args, context) => {

await message.author.send(`Du hast dich selber von der Coding Shitpost Zentrale gebannt!
Du wirst entbannt in: ${durationHumanized}
Falls du doch vorzeitig entbannt entbannt werden möchtest, kannst du dich im <#${config.ids.banned_channel_id}> Channel melden.
Falls du doch vorzeitig entbannt entbannt werden möchtest, kannst du dich im ${context.textChannels.banned} Channel melden.
Haddi & xD™`);
};

export const description = `Bannt den ausführenden User indem er ihn von allen Channels ausschließt.\nBenutzung: ${config.bot_settings.prefix.command_prefix}selfban [Dauer in Stunden = 8; tilt; 0 = manuelle Entbannung durch Moderader nötig]`;
export const description =
"Bannt den ausführenden User indem er ihn von allen Channels ausschließt.\nBenutzung: $COMMAND_PREFIX$selfban [Dauer in Stunden = 8; tilt; 0 = manuelle Entbannung durch Moderader nötig]";
5 changes: 1 addition & 4 deletions src/commands/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import parseOptions from "minimist";
import { cleanContent } from "discord.js";

import type { CommandFunction } from "../types.js";
import { getConfig } from "../utils/configHandler.js";

const config = getConfig();

/**
* Creates a new poll (vote; yes/no)
Expand Down Expand Up @@ -53,7 +50,7 @@ export const run: CommandFunction = async (_client, message, args, context) => {
};

export const description = `Erstellt eine Umfrage (ja/nein).
Usage: ${config.bot_settings.prefix.command_prefix}vote [Optionen?] [Hier die Frage]
Usage: $COMMAND_PREFIX$vote [Optionen?] [Hier die Frage]
Optionen:
\t-c, --channel
\t\t\tSendet die Umfrage in den Umfragenchannel, um den Slowmode zu umgehen`;
1 change: 0 additions & 1 deletion src/handler/cmdHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { Client, Guild, GuildMember, Message } from "discord.js";

import type { CommandFunction, CommandResult } from "../types.js";
import log from "../utils/logger.js";
import { getConfig } from "../utils/configHandler.js";
import * as ban from "../commands/modcommands/ban.js";
import { hasBotDenyRole } from "../utils/userUtils.js";
import { isMessageInBotSpam } from "../utils/channelUtils.js";
Expand Down
13 changes: 3 additions & 10 deletions src/handler/messageDeleteHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { Client, Message } from "discord.js";

import { getConfig } from "../utils/configHandler.js";
import type { BotContext } from "../context.js";

const config = getConfig();

const deleteInlineRepliesFromBot = (
messageRef: Message<true>,
client: Client,
Expand All @@ -22,17 +19,13 @@ const deleteInlineRepliesFromBot = (
export default async function (
message: Message<true>,
client: Client,
_context: BotContext,
context: BotContext,
) {
if (message.author && message.author.id !== client.user?.id) {
if (message.content) {
const isNormalCommand =
message.content.startsWith(
config.bot_settings.prefix.command_prefix,
) ||
message.content.startsWith(
config.bot_settings.prefix.mod_prefix,
);
message.content.startsWith(context.prefix.command) ||
message.content.startsWith(context.prefix.modCommand);

if (isNormalCommand) {
await deleteInlineRepliesFromBot(message, client);
Expand Down
11 changes: 5 additions & 6 deletions src/handler/voiceStateUpdateHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { VoiceState } from "discord.js";
import type { BotContext } from "../context.js";
import { getConfig } from "../utils/configHandler.js";
import log from "../utils/logger.js";

const config = getConfig();

export interface VoiceUpdateEvent {
oldState: VoiceState;
newState: VoiceState;
Expand All @@ -18,15 +15,17 @@ export const woisData = {
export async function checkVoiceUpdate(
oldState: VoiceState,
newState: VoiceState,
_botContext: BotContext,
context: BotContext,
): Promise<void> {
log.debug(
`Voice update detected: ${oldState.channelId} -> ${newState.channelId}`,
);

const mainVoiceId = context.voiceChannels.haupt_woischat.id;

// User joined Channel
if (oldState.channel === null && newState.channel !== null) {
if (newState.channelId === config.ids.haupt_woischat) {
if (newState.channelId === mainVoiceId) {
woisData.latestEvents.push({
oldState,
newState,
Expand All @@ -37,7 +36,7 @@ export async function checkVoiceUpdate(

// user left channel
if (oldState.channel !== null && newState.channel === null) {
if (newState.channelId === config.ids.haupt_woischat) {
if (newState.channelId === mainVoiceId) {
// Add to latest events
woisData.latestEvents.push({
oldState,
Expand Down

0 comments on commit 5976dd3

Please sign in to comment.