add greeting
add locales
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { config } from "config";
|
import { config } from "config";
|
||||||
import { Routes } from "discord.js";
|
import { Routes } from "discord.js";
|
||||||
import getCommands from "entitites/commands";
|
import getCommands from "entities/commands";
|
||||||
import { logger } from "lib/common-logger";
|
import { logger } from "lib/common-logger";
|
||||||
import { discordRestClient } from "lib/rest-client";
|
import { discordRestClient } from "lib/rest-client";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { VoiceChannels } from "@avocadi/bot-core/entities/channels/channels.schema";
|
import { VoiceChannels } from "@avocadi/bot-core/entities/channels/channels.schema";
|
||||||
import { DynamicVoiceChannelsService } from "@avocadi/bot-core/features/dynamic-voice-channels/dynamic-voice-channels.service";
|
import { DynamicVoiceChannelsService } from "@avocadi/bot-core/features/dynamic-voice-channels/dynamic-voice-channels.service";
|
||||||
import { config } from "config";
|
import { config } from "config";
|
||||||
import { voiceChannelsService } from "entitites/channels/voice/voice-channels.service";
|
import { voiceChannelsService } from "entities/channels/voice/voice-channels.service";
|
||||||
|
|
||||||
export const dynamicVoiceChannelService = new DynamicVoiceChannelsService(
|
export const dynamicVoiceChannelService = new DynamicVoiceChannelsService(
|
||||||
voiceChannelsService,
|
voiceChannelsService,
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { GreetingService } from "@avocadi/bot-core/features/greeting/greeting.service";
|
||||||
|
import { i18nService } from "@avocadi/bot-core/lib/i18n";
|
||||||
|
import { messagesService } from "entities/messages/messages.service";
|
||||||
|
|
||||||
|
export const greetingService = new GreetingService(
|
||||||
|
messagesService,
|
||||||
|
i18nService,
|
||||||
|
"de",
|
||||||
|
);
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
import { GreetingService } from "@avocadi/bot-core/features/greeting/greeting.service";
|
|
||||||
import { messagesService } from "entitites/messages/messages.service";
|
|
||||||
|
|
||||||
export const greetingsService = new GreetingService(messagesService);
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { WaterMeService } from "@avocadi/bot-core/features/water-me/water-me.service";
|
import { WaterMeService } from "@avocadi/bot-core/features/water-me/water-me.service";
|
||||||
import { i18nService } from "@avocadi/bot-core/lib/i18n";
|
import { i18nService } from "@avocadi/bot-core/lib/i18n";
|
||||||
import { messagesService } from "entitites/messages/messages.service";
|
import { messagesService } from "entities/messages/messages.service";
|
||||||
|
|
||||||
export const waterMeService = new WaterMeService(
|
export const waterMeService = new WaterMeService(
|
||||||
messagesService,
|
messagesService,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { greetingsService } from "features/greeting/greetings.service";
|
import { greetingService } from "features/greeting/greeting.service";
|
||||||
import { logChannelService } from "features/log-channel/log-channel.service";
|
import { logChannelService } from "features/log-channel/log-channel.service";
|
||||||
import client from "lib/client";
|
import client from "lib/client";
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ client.on("guildMemberAdd", async (member) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
greetingsService.sendGreeting(member.user, member.user.username);
|
greetingService.sendGreeting(member.user, member.user.username);
|
||||||
logChannelService.sendLogMessage(
|
logChannelService.sendLogMessage(
|
||||||
`Neues Mitglied: <@${member.user.id}> (${member.user.tag}) ist dem Server beigetreten.`,
|
`Neues Mitglied: <@${member.user.id}> (${member.user.tag}) ist dem Server beigetreten.`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { config } from "config";
|
import { config } from "config";
|
||||||
import { messagesService } from "entitites/messages/messages.service";
|
import { messagesService } from "entities/messages/messages.service";
|
||||||
import client from "lib/client";
|
import client from "lib/client";
|
||||||
|
|
||||||
client.on("messageCreate", async (message) => {
|
client.on("messageCreate", async (message) => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { VoiceState } from "discord.js";
|
import type { VoiceState } from "discord.js";
|
||||||
import { voiceChannelsService } from "entitites/channels/voice/voice-channels.service";
|
import { voiceChannelsService } from "entities/channels/voice/voice-channels.service";
|
||||||
import { dynamicVoiceChannelService } from "features/dynamic-voice-channel/dynamic-voice-channel.service";
|
import { dynamicVoiceChannelService } from "features/dynamic-voice-channel/dynamic-voice-channel.service";
|
||||||
|
|
||||||
export const handleDynamicVoiceChannelDeletion = async (
|
export const handleDynamicVoiceChannelDeletion = async (
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { GreetingService } from "@avocadi/bot-core/features/greeting/greeting.service";
|
||||||
|
import { i18nService } from "@avocadi/bot-core/lib/i18n";
|
||||||
|
import { messagesService } from "entities/messages/messages.service";
|
||||||
|
|
||||||
|
export const greetingService = new GreetingService(
|
||||||
|
messagesService,
|
||||||
|
i18nService,
|
||||||
|
"en",
|
||||||
|
);
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { Events, type GuildMember } from "@fluxerjs/core";
|
||||||
|
import { config } from "config";
|
||||||
|
import { greetingService } from "features/greeting/greeting.service";
|
||||||
|
import { logChannelService } from "features/log-channel/log-channel.service";
|
||||||
|
import client from "lib/client";
|
||||||
|
import { logger } from "lib/common-logger";
|
||||||
|
|
||||||
|
client.on(Events.GuildMemberAdd, async (member: GuildMember) => {
|
||||||
|
logger.info(`${member.user.username} joined the server}`);
|
||||||
|
if (member.user.bot) {
|
||||||
|
// Don't send a welcome message for bots (sorry tom)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const channel = await client.channels.fetch(config.channelMapping.text.log);
|
||||||
|
|
||||||
|
await greetingService.sendGreeting(member.user.username, channel);
|
||||||
|
await logChannelService.sendLogMessage(
|
||||||
|
`new member: <@${member.user.id}> (${member.user.username}) joined the server.`,
|
||||||
|
);
|
||||||
|
await greetingService.sendDmGreeting(member.user, member.user.username);
|
||||||
|
await logChannelService.sendLogMessage(
|
||||||
|
`new member: <@${member.user.id}> (${member.user.username}) joined the server.`,
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
import "./ready.listener";
|
import "./ready.listener";
|
||||||
import "./stop.listener";
|
import "./stop.listener";
|
||||||
import "./messages/messages.listener";
|
import "./messages/messages.listener";
|
||||||
|
import "./guild-members/guild-members.listener";
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ import { logger } from "lib/common-logger";
|
|||||||
import { handleCommand } from "./handle-command";
|
import { handleCommand } from "./handle-command";
|
||||||
|
|
||||||
client.on(Events.MessageCreate, async (message: Message) => {
|
client.on(Events.MessageCreate, async (message: Message) => {
|
||||||
if (
|
// if (
|
||||||
message.channel?.id !== config.channelMapping.text.log &&
|
// message.channel?.id !== config.channelMapping.text.log &&
|
||||||
message.channel?.id !== config.channelMapping.text.bot
|
// message.channel?.id !== config.channelMapping.text.bot
|
||||||
) {
|
// ) {
|
||||||
await messagesService.logMessage(message);
|
// return;
|
||||||
}
|
// // await messagesService.logMessage(message);
|
||||||
|
// }
|
||||||
|
|
||||||
if (message.content?.startsWith(config.commandPrefix) && message.channel) {
|
if (message.content?.startsWith(config.commandPrefix) && message.channel) {
|
||||||
await messagesService.logMessage(message);
|
await messagesService.logMessage(message);
|
||||||
|
|||||||
6
bun.lock
6
bun.lock
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"configVersion": 0,
|
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"": {
|
"": {
|
||||||
"name": "avocadi-bot",
|
"name": "avocadi-bot",
|
||||||
@@ -57,6 +56,7 @@
|
|||||||
"discord.js": "^14.16.3",
|
"discord.js": "^14.16.3",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"drizzle-orm": "^0.38.3",
|
"drizzle-orm": "^0.38.3",
|
||||||
|
"i18next": "^25.8.11",
|
||||||
"tslog": "^4.10.2",
|
"tslog": "^4.10.2",
|
||||||
"zod": "catalog:",
|
"zod": "catalog:",
|
||||||
},
|
},
|
||||||
@@ -94,6 +94,8 @@
|
|||||||
|
|
||||||
"@babel/parser": ["@babel/parser@8.0.0-rc.1", "", { "dependencies": { "@babel/types": "^8.0.0-rc.1" }, "bin": "./bin/babel-parser.js" }, "sha512-6HyyU5l1yK/7h9Ki52i5h6mDAx4qJdiLQO4FdCyJNoB/gy3T3GGJdhQzzbZgvgZCugYBvwtQiWRt94QKedHnkA=="],
|
"@babel/parser": ["@babel/parser@8.0.0-rc.1", "", { "dependencies": { "@babel/types": "^8.0.0-rc.1" }, "bin": "./bin/babel-parser.js" }, "sha512-6HyyU5l1yK/7h9Ki52i5h6mDAx4qJdiLQO4FdCyJNoB/gy3T3GGJdhQzzbZgvgZCugYBvwtQiWRt94QKedHnkA=="],
|
||||||
|
|
||||||
|
"@babel/runtime": ["@babel/runtime@7.28.6", "", {}, "sha512-05WQkdpL9COIMz4LjTxGpPNCdlpyimKppYNoJ5Di5EUObifl8t4tuLuUBBZEpoLYOmfvIWrsp9fCl0HoPRVTdA=="],
|
||||||
|
|
||||||
"@babel/types": ["@babel/types@8.0.0-rc.1", "", { "dependencies": { "@babel/helper-string-parser": "^8.0.0-rc.1", "@babel/helper-validator-identifier": "^8.0.0-rc.1" } }, "sha512-ubmJ6TShyaD69VE9DQrlXcdkvJbmwWPB8qYj0H2kaJi29O7vJT9ajSdBd2W8CG34pwL9pYA74fi7RHC1qbLoVQ=="],
|
"@babel/types": ["@babel/types@8.0.0-rc.1", "", { "dependencies": { "@babel/helper-string-parser": "^8.0.0-rc.1", "@babel/helper-validator-identifier": "^8.0.0-rc.1" } }, "sha512-ubmJ6TShyaD69VE9DQrlXcdkvJbmwWPB8qYj0H2kaJi29O7vJT9ajSdBd2W8CG34pwL9pYA74fi7RHC1qbLoVQ=="],
|
||||||
|
|
||||||
"@biomejs/biome": ["@biomejs/biome@2.4.2", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.4.2", "@biomejs/cli-darwin-x64": "2.4.2", "@biomejs/cli-linux-arm64": "2.4.2", "@biomejs/cli-linux-arm64-musl": "2.4.2", "@biomejs/cli-linux-x64": "2.4.2", "@biomejs/cli-linux-x64-musl": "2.4.2", "@biomejs/cli-win32-arm64": "2.4.2", "@biomejs/cli-win32-x64": "2.4.2" }, "bin": { "biome": "bin/biome" } }, "sha512-vVE/FqLxNLbvYnFDYg3Xfrh1UdFhmPT5i+yPT9GE2nTUgI4rkqo5krw5wK19YHBd7aE7J6r91RRmb8RWwkjy6w=="],
|
"@biomejs/biome": ["@biomejs/biome@2.4.2", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.4.2", "@biomejs/cli-darwin-x64": "2.4.2", "@biomejs/cli-linux-arm64": "2.4.2", "@biomejs/cli-linux-arm64-musl": "2.4.2", "@biomejs/cli-linux-x64": "2.4.2", "@biomejs/cli-linux-x64-musl": "2.4.2", "@biomejs/cli-win32-arm64": "2.4.2", "@biomejs/cli-win32-x64": "2.4.2" }, "bin": { "biome": "bin/biome" } }, "sha512-vVE/FqLxNLbvYnFDYg3Xfrh1UdFhmPT5i+yPT9GE2nTUgI4rkqo5krw5wK19YHBd7aE7J6r91RRmb8RWwkjy6w=="],
|
||||||
@@ -344,6 +346,8 @@
|
|||||||
|
|
||||||
"hookable": ["hookable@6.0.1", "", {}, "sha512-uKGyY8BuzN/a5gvzvA+3FVWo0+wUjgtfSdnmjtrOVwQCZPHpHDH2WRO3VZSOeluYrHoDCiXFffZXs8Dj1ULWtw=="],
|
"hookable": ["hookable@6.0.1", "", {}, "sha512-uKGyY8BuzN/a5gvzvA+3FVWo0+wUjgtfSdnmjtrOVwQCZPHpHDH2WRO3VZSOeluYrHoDCiXFffZXs8Dj1ULWtw=="],
|
||||||
|
|
||||||
|
"i18next": ["i18next@25.8.11", "", { "dependencies": { "@babel/runtime": "^7.28.4" }, "peerDependencies": { "typescript": "^5" }, "optionalPeers": ["typescript"] }, "sha512-LZ32llTLGludnddjLoijHV7TbmVubU5eJnsWf8taiuM3jmSfUuvBLuyDeubJKS1yBjLBgb7As124M4KWNcBvpw=="],
|
||||||
|
|
||||||
"ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="],
|
"ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="],
|
||||||
|
|
||||||
"import-without-cache": ["import-without-cache@0.2.5", "", {}, "sha512-B6Lc2s6yApwnD2/pMzFh/d5AVjdsDXjgkeJ766FmFuJELIGHNycKRj+l3A39yZPM4CchqNCB4RITEAYB1KUM6A=="],
|
"import-without-cache": ["import-without-cache@0.2.5", "", {}, "sha512-B6Lc2s6yApwnD2/pMzFh/d5AVjdsDXjgkeJ766FmFuJELIGHNycKRj+l3A39yZPM4CchqNCB4RITEAYB1KUM6A=="],
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import config from "config";
|
|
||||||
import type { GuildMember } from "discord.js";
|
|
||||||
|
|
||||||
export const greetContent = ["HALLOOOO", "guten morgen! ich hoffe es geht euch gut <3"];
|
|
||||||
export const sleepContent = ["gute nacht! ich muss jetzt schlafen gehen :c", "zzzzZZ..", "*schnarch*"];
|
|
||||||
export const dmWelcomeContent = `hey! ich bin avocadi von [avocadi-study](<https://discord.gg/kkryyeXu3S>)!\n\num auf den rest des servers zugreifen zu koennen, musst du dich noch vorstellen (unter <#${config.discord.channelIdIntroduction}>)!\n\n---\nname und alter:\npronomen:\nklasse/studiengang/beruf:\nhobby:\nueber mich:\n---\n\nsobald wir deine nachricht ueberprueft haben, bekommst du die rolle **lernende:r** :)`;
|
|
||||||
export const dmAcceptedContent = `huhu! du wurdest als lernende:r akzeptiert :3\nsag gerne hallo: <#${config.discord.channelIdOffTopic}> <:avocadi_cute:1321893797138923602>`;
|
|
||||||
|
|
||||||
export function getWelcomeContent(member: GuildMember) {
|
|
||||||
const welcomeContents = [
|
|
||||||
`willkommen auf dem server, ${member}! fuehl dich wie zuhause💕`,
|
|
||||||
`hey ${member}! schoen, dass du hier bist! 😊`,
|
|
||||||
`hi ${member}, willkommen! viel spass hier! 💖`,
|
|
||||||
`willkommen, ${member}! schoen, dass du da bist! :3`,
|
|
||||||
`moin ${member}! viel spass im server! c:`,
|
|
||||||
`hey ${member}, herzlich willkommen! fuehl dich wie zu hause! <3`,
|
|
||||||
`hi ${member}! cool, dass du da bist! <3`,
|
|
||||||
`willkommen, ${member}! wir freuen uns, dass du hier bist! 💕`,
|
|
||||||
`hey ${member}! schoen, dass du bei uns bist! :3`,
|
|
||||||
`willkommen auf dem server, ${member}! viel spass hier! ✨`,
|
|
||||||
`hi ${member}, super, dass du dabei bist! :3`,
|
|
||||||
`hey ${member}, willkommen bei uns! 💖`,
|
|
||||||
`moin ${member}! schoen, dass du dabei bist! :)`,
|
|
||||||
`hi ${member}, willkommen in unserer kleinen community! ✨`,
|
|
||||||
`willkommen, ${member}! fuehl dich wie zu hause! 💕`,
|
|
||||||
`hey ${member}, schoen, dass du uns gefunden hast! <333`,
|
|
||||||
`hi ${member}, willkommen in unserer runde! c:`,
|
|
||||||
`willkommen, ${member}! schoen, dass du hier bist! 💖`,
|
|
||||||
`moin ${member}! lass uns zusammen spass haben! ✨`,
|
|
||||||
`hey ${member}, herzlich willkommen bei uns! 😊`,
|
|
||||||
`hi ${member}! schoen, dass du dabei bist! 💕`,
|
|
||||||
`willkommen auf dem server, ${member}! wir freuen uns auf dich! <3`,
|
|
||||||
`hey ${member}, schoen, dass du da bist! ✨`,
|
|
||||||
`hi ${member}, willkommen! fuehl dich wie zu hause! 💖`,
|
|
||||||
`willkommen, ${member}! lass uns gemeinsam eine tolle zeit haben! :3`,
|
|
||||||
];
|
|
||||||
return welcomeContents[Math.floor(Math.random() * welcomeContents.length)];
|
|
||||||
}
|
|
||||||
@@ -1,329 +0,0 @@
|
|||||||
import { DmService } from "actions/dm/dm.service.ts";
|
|
||||||
import { Commands, type CommandsType } from "commands/index.ts";
|
|
||||||
import config from "config";
|
|
||||||
import {
|
|
||||||
type CacheType,
|
|
||||||
type ChatInputCommandInteraction,
|
|
||||||
type GuildMember,
|
|
||||||
GuildMemberRoleManager,
|
|
||||||
type Interaction,
|
|
||||||
} from "discord.js";
|
|
||||||
import client from "lib/client";
|
|
||||||
import { getRandomInt } from "lib/utils";
|
|
||||||
import { checkPermission } from "permissions/index.ts";
|
|
||||||
import {
|
|
||||||
getWelcomeContent,
|
|
||||||
greetContent,
|
|
||||||
sleepContent,
|
|
||||||
} from "./greeting.components.ts";
|
|
||||||
|
|
||||||
export class GreetingService {
|
|
||||||
dmService: DmService;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.dmService = new DmService();
|
|
||||||
}
|
|
||||||
|
|
||||||
async handleInteraction(interaction: Interaction<CacheType>) {
|
|
||||||
if (interaction.isChatInputCommand()) {
|
|
||||||
await this.handleChatInputCommand(interaction);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async handleChatInputCommand(
|
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
|
||||||
) {
|
|
||||||
const commandName = interaction.commandName as CommandsType;
|
|
||||||
switch (commandName) {
|
|
||||||
case Commands.Enum.accept:
|
|
||||||
await this.acceptUser(interaction);
|
|
||||||
return;
|
|
||||||
case Commands.Enum.welcome:
|
|
||||||
await this.welcomeCommand(interaction);
|
|
||||||
return;
|
|
||||||
case Commands.Enum.reminder:
|
|
||||||
await this.reminderCommand(interaction);
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async welcome(member: GuildMember) {
|
|
||||||
console.log("welcome msg");
|
|
||||||
const welcomeContent = getWelcomeContent(member);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const channels = client.channels;
|
|
||||||
const channel = channels.cache.get(config.discord.channelIdWelcome);
|
|
||||||
|
|
||||||
if (channel?.isTextBased() && channel?.isSendable()) {
|
|
||||||
await channel.send(welcomeContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.dmService.welcomePrivate(member);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("error while sending a welcome msg:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async acceptUser(interaction: ChatInputCommandInteraction<CacheType>) {
|
|
||||||
console.log("accept user");
|
|
||||||
|
|
||||||
// get the string option
|
|
||||||
const input = interaction.options.getString("input") || "";
|
|
||||||
// return the value
|
|
||||||
//console.log(input);
|
|
||||||
|
|
||||||
// permission check
|
|
||||||
if ((await checkPermission(interaction.member)) !== true) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: "du hast keine rechte fuer diesen befehl",
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// get user id from mentioning
|
|
||||||
const userId = input.replace(/[<@!>]/g, "");
|
|
||||||
console.log(userId.toString());
|
|
||||||
const guild = interaction.guild;
|
|
||||||
if (!guild) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: "command can only be used on a server",
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const member = await guild.members.fetch(userId);
|
|
||||||
const username = member.user.username;
|
|
||||||
console.log(username);
|
|
||||||
|
|
||||||
if ((await this.checkRole(member)) === true) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: `${member.user.username} hat die rolle *lernende:r* schon!`,
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await member.roles.add(config.discord.roleStudy);
|
|
||||||
|
|
||||||
await interaction.reply({
|
|
||||||
content: `die rolle *lernende:r* wurde erfolgreich an ${member.user.username} vergeben`,
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.dmService.acceptDm(member);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Fehler beim Hinzufügen der Rolle:", error);
|
|
||||||
await interaction.reply({
|
|
||||||
content:
|
|
||||||
"Es gab einen Fehler beim Hinzufügen der Rolle. Stelle sicher, dass du einen gültigen User erwähnt hast.",
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// unused
|
|
||||||
async greet() {
|
|
||||||
client.user?.setActivity("guten morgen! :3", { type: 4 });
|
|
||||||
console.log("set activity: awake");
|
|
||||||
client.user?.setPresence({
|
|
||||||
status: "online",
|
|
||||||
});
|
|
||||||
|
|
||||||
const channels = client.channels;
|
|
||||||
|
|
||||||
const channel = channels.cache.get(config.discord.channelIdOffTopic);
|
|
||||||
|
|
||||||
if (channel?.isTextBased && channel?.isSendable()) {
|
|
||||||
await channel.send({ content: this.getContent(false) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// unused
|
|
||||||
async sleep() {
|
|
||||||
client.user?.setActivity("zzzzZZ..", { type: 4 });
|
|
||||||
console.log("set activity: asleep");
|
|
||||||
client.user?.setPresence({
|
|
||||||
status: "dnd",
|
|
||||||
});
|
|
||||||
|
|
||||||
const channels = client.channels;
|
|
||||||
|
|
||||||
const channel = channels.cache.get(config.discord.channelIdOffTopic);
|
|
||||||
|
|
||||||
if (channel?.isTextBased && channel?.isSendable()) {
|
|
||||||
await channel.send({ content: this.getContent(true) });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async newYear() {
|
|
||||||
client.user?.setActivity("frohes neues! :)", { type: 4 });
|
|
||||||
console.log("set activity: happy new year");
|
|
||||||
client.user?.setPresence({
|
|
||||||
status: "online",
|
|
||||||
});
|
|
||||||
|
|
||||||
// unused
|
|
||||||
/*const channels = client.channels;
|
|
||||||
|
|
||||||
const channel = channels.cache.get(config.discord.channelIdOffTopic);
|
|
||||||
|
|
||||||
if (channel?.isTextBased && channel?.isSendable()) {
|
|
||||||
await channel.send({ content: "frohes neues! @everyone" });
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
getContent(asleep: boolean) {
|
|
||||||
if (asleep) {
|
|
||||||
return sleepContent[getRandomInt(0, sleepContent.length - 1)];
|
|
||||||
}
|
|
||||||
return greetContent[getRandomInt(0, greetContent.length - 1)];
|
|
||||||
}
|
|
||||||
|
|
||||||
async reminderCommand(interaction: ChatInputCommandInteraction<CacheType>) {
|
|
||||||
console.log("remind user");
|
|
||||||
|
|
||||||
// get the string option
|
|
||||||
const input = interaction.options.getString("input") || "";
|
|
||||||
// return the value
|
|
||||||
//console.log(input);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// permission check
|
|
||||||
if ((await checkPermission(interaction.member)) !== true) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: "du hast keine rechte fuer diesen befehl",
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get user id from mentioning
|
|
||||||
const userId = input.replace(/[<@!>]/g, "");
|
|
||||||
console.log(userId.toString());
|
|
||||||
const guild = interaction.guild;
|
|
||||||
if (!guild) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: "command can only be used on a server",
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const member = await guild.members.fetch(userId);
|
|
||||||
const username = member.user.username;
|
|
||||||
console.log(username);
|
|
||||||
|
|
||||||
if ((await this.checkRole(member)) === true) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: `${member.user.username} hat die rolle *lernende:r* schon!`,
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.dmService.reminderPrivate(member);
|
|
||||||
//await member.roles.add(config.discord.roleStudy);
|
|
||||||
|
|
||||||
await interaction.reply({
|
|
||||||
content: `${member.user.username} wurde erfolgrich remindet`,
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("error while reminding:", error);
|
|
||||||
await interaction.reply({
|
|
||||||
content:
|
|
||||||
"Es gab einen Fehler beim reminden. Stelle sicher, dass du einen gültigen User erwähnt hast.",
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async welcomeCommand(interaction: ChatInputCommandInteraction<CacheType>) {
|
|
||||||
console.log("welcome user");
|
|
||||||
|
|
||||||
// get the string option
|
|
||||||
const input = interaction.options.getString("input") || "";
|
|
||||||
// return the value
|
|
||||||
//console.log(input);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// get user id from mentioning
|
|
||||||
const userId = input.replace(/[<@!>]/g, "");
|
|
||||||
console.log(userId.toString());
|
|
||||||
const guild = interaction.guild;
|
|
||||||
if (!guild) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: "command can only be used on a server",
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((await checkPermission(interaction.member)) !== true) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: "du hast keine rechte fuer diesen befehl",
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get member from id
|
|
||||||
const member = await guild.members.fetch(userId);
|
|
||||||
const username = member.user.username;
|
|
||||||
console.log(username);
|
|
||||||
|
|
||||||
const welcomeContent = getWelcomeContent(member);
|
|
||||||
|
|
||||||
if ((await this.checkRole(member)) === true) {
|
|
||||||
await interaction.reply({
|
|
||||||
content: `${member.user.username} wurde schon begruesst!`,
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const channels = client.channels;
|
|
||||||
const channel = channels.cache.get(config.discord.channelIdWelcome);
|
|
||||||
|
|
||||||
if (channel?.isTextBased() && channel?.isSendable()) {
|
|
||||||
await channel.send(welcomeContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.dmService.welcomePrivate(member);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("error while sending a welcome command msg:", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
await interaction.reply({
|
|
||||||
content: `erfolgreich welcome command: ${member.user.username}`,
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error("fehler bei welcome command", error);
|
|
||||||
await interaction.reply({
|
|
||||||
content: "fehler bei welcome command",
|
|
||||||
ephemeral: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async checkRole(member: GuildMember) {
|
|
||||||
let hasRole = false;
|
|
||||||
if (member?.roles instanceof GuildMemberRoleManager) {
|
|
||||||
if (
|
|
||||||
member.roles.cache.has(config.discord.roleAdmin) ||
|
|
||||||
member.roles.cache.has(config.discord.roleMod)
|
|
||||||
) {
|
|
||||||
console.log("user has permission");
|
|
||||||
hasRole = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hasRole;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import { CronJob } from "cron";
|
|
||||||
import { GreetingService } from "actions/greeting/greeting.service";
|
|
||||||
|
|
||||||
const greetingService = new GreetingService();
|
|
||||||
/*
|
|
||||||
new CronJob(
|
|
||||||
"0 30 6 * * *", // cronTime
|
|
||||||
async () => {
|
|
||||||
console.log("good morning");
|
|
||||||
await greetingService.greet();
|
|
||||||
}, // onTick
|
|
||||||
null, // onComplete
|
|
||||||
true, // start
|
|
||||||
"Europe/Berlin", // timeZone
|
|
||||||
);
|
|
||||||
// job.start() is optional here because of the fourth parameter set to true.
|
|
||||||
|
|
||||||
new CronJob(
|
|
||||||
"0 30 22 * * *",
|
|
||||||
async () => {
|
|
||||||
console.log("good night");
|
|
||||||
await greetingService.sleep();
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
"Europe/Berlin",
|
|
||||||
);*/
|
|
||||||
|
|
||||||
new CronJob(
|
|
||||||
"0 0 0 1 1 *",
|
|
||||||
async () => {
|
|
||||||
console.log("happy new year");
|
|
||||||
await greetingService.newYear();
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
"Europe/Berlin",
|
|
||||||
);
|
|
||||||
@@ -1,14 +1,47 @@
|
|||||||
import type { MessagesServiceInterface } from "entities/messages/messages.service";
|
import type { MessagesServiceInterface } from "entities/messages/messages.service";
|
||||||
|
import type { BaseChannel, BaseMessage, BaseUser } from "lib/common";
|
||||||
|
import type { I18nService } from "lib/i18n/i18n.service";
|
||||||
|
|
||||||
export class GreetingService<U = unknown> {
|
export class GreetingService<
|
||||||
messagesService: MessagesServiceInterface<U>;
|
U extends BaseUser = BaseUser,
|
||||||
|
M extends BaseMessage = BaseMessage,
|
||||||
|
C extends BaseChannel = BaseChannel,
|
||||||
|
> {
|
||||||
|
messagesService: MessagesServiceInterface<U, M, C>;
|
||||||
|
i18nService: I18nService;
|
||||||
|
lang: "en" | "de";
|
||||||
|
ns = "greeting";
|
||||||
|
|
||||||
constructor(messagesService: MessagesServiceInterface<U>) {
|
constructor(
|
||||||
|
messagesService: MessagesServiceInterface<U, M, C>,
|
||||||
|
i18nService: I18nService,
|
||||||
|
lang: "en" | "de",
|
||||||
|
) {
|
||||||
this.messagesService = messagesService;
|
this.messagesService = messagesService;
|
||||||
|
this.i18nService = i18nService;
|
||||||
|
this.lang = lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendGreeting(user: U, userName: string) {
|
async sendDmGreeting(user: U, _userName: string) {
|
||||||
const greetingMessage = `Hello, ${userName}! Welcome to the server!`;
|
const greetingMessage: string = await this.i18nService.t(
|
||||||
|
"dmGreeting",
|
||||||
|
this.lang,
|
||||||
|
this.ns,
|
||||||
|
);
|
||||||
|
|
||||||
await this.messagesService.sendToUser(user, greetingMessage);
|
await this.messagesService.sendToUser(user, greetingMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async sendGreeting(userName: string, channel: C) {
|
||||||
|
const greetingMessage: string =
|
||||||
|
(await this.i18nService.t("greeting1", this.lang, this.ns)) +
|
||||||
|
(await this.i18nService.t("greeting2", this.lang, this.ns, {
|
||||||
|
member: userName,
|
||||||
|
})) +
|
||||||
|
(await this.i18nService.t("greeting3", this.lang, this.ns)) +
|
||||||
|
(await this.i18nService.t("greeting4", this.lang, this.ns)) +
|
||||||
|
(await this.i18nService.t("emoji", this.lang, this.ns));
|
||||||
|
|
||||||
|
await this.messagesService.sendToChannel(channel, greetingMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import type { MessagesServiceInterface } from "entities/messages/messages.service";
|
import type { MessagesServiceInterface } from "entities/messages/messages.service";
|
||||||
import type { ParseKeys } from "i18next";
|
|
||||||
import type { I18nService } from "lib/i18n/i18n.service";
|
import type { I18nService } from "lib/i18n/i18n.service";
|
||||||
import { createLogger } from "lib/logger";
|
import { createLogger } from "lib/logger";
|
||||||
|
|
||||||
@@ -13,6 +12,7 @@ export class WaterMeService {
|
|||||||
messagesService: MessagesServiceInterface;
|
messagesService: MessagesServiceInterface;
|
||||||
i18nService: I18nService;
|
i18nService: I18nService;
|
||||||
lang: "en" | "de";
|
lang: "en" | "de";
|
||||||
|
ns = "waterMe";
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
messagesService: MessagesServiceInterface,
|
messagesService: MessagesServiceInterface,
|
||||||
@@ -26,34 +26,30 @@ export class WaterMeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getReply() {
|
async getReply() {
|
||||||
// const key = (
|
|
||||||
// this.waterLevel <= this.thirsty
|
|
||||||
// ? "water-me.needMoreWater"
|
|
||||||
// : this.waterLevel <= this.full
|
|
||||||
// ? "water-me.enoughWater"
|
|
||||||
// : "water-me.tooMuchWater"
|
|
||||||
// ) as ParseKeys;
|
|
||||||
|
|
||||||
// return await this.i18nService.t(key, this.lang);
|
|
||||||
|
|
||||||
if (this.waterLevel <= this.thirsty)
|
if (this.waterLevel <= this.thirsty)
|
||||||
return this.i18nService.t("needMoreWater", this.lang, "waterMe");
|
return this.i18nService.t("needMoreWater", this.lang, this.ns);
|
||||||
if (this.waterLevel <= this.full)
|
if (this.waterLevel <= this.full)
|
||||||
return this.i18nService.t("enoughWater", this.lang, "waterMe");
|
return this.i18nService.t("enoughWater", this.lang, this.ns);
|
||||||
return this.i18nService.t("tooMuchWater", this.lang, "waterMe");
|
return this.i18nService.t("tooMuchWater", this.lang, this.ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
async notifyIfThirsty() {
|
async notifyIfThirsty() {
|
||||||
if (this.waterLevel <= this.thirsty) {
|
if (this.waterLevel <= this.thirsty) {
|
||||||
await this.messagesService.sendToChannel(
|
await this.messagesService.sendToChannel(
|
||||||
{ id: "channelId" },
|
{ id: "channelId" },
|
||||||
{ content: await this.i18nService.t("waterMe.thirsty", this.lang) },
|
{
|
||||||
|
content: await this.i18nService.t(
|
||||||
|
"waterMe.thirsty",
|
||||||
|
this.lang,
|
||||||
|
this.ns,
|
||||||
|
),
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
waterMe() {
|
async waterMe() {
|
||||||
const reply = this.getReply();
|
const reply = await this.getReply();
|
||||||
|
|
||||||
this.waterLevel++;
|
this.waterLevel++;
|
||||||
this.logger.info(`Water level increased to ${this.waterLevel}`);
|
this.logger.info(`Water level increased to ${this.waterLevel}`);
|
||||||
@@ -64,11 +60,11 @@ export class WaterMeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleCommand(channelId: string) {
|
async handleCommand(channelId: string) {
|
||||||
const result = this.waterMe(); // muss hier await weil promise rueckgabe?
|
const result = await this.waterMe(); // muss hoer await wein promise rueckgabe?
|
||||||
|
|
||||||
this.messagesService.sendToChannel(
|
this.messagesService.sendToChannel(
|
||||||
{ id: channelId },
|
{ id: channelId },
|
||||||
{ content: await result.reply },
|
{ content: result.reply },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import i18next, { type ParseKeys } from "i18next";
|
import i18next, { type ParseKeys } from "i18next";
|
||||||
|
import greetingDe from "locales/de/greeting";
|
||||||
// import { createLogger } from "lib/logger";
|
// import { createLogger } from "lib/logger";
|
||||||
import waterMeDe from "locales/de/water-me";
|
import waterMeDe from "locales/de/water-me";
|
||||||
|
import greetingEn from "locales/en/greeting";
|
||||||
import waterMeEn from "locales/en/water-me";
|
import waterMeEn from "locales/en/water-me";
|
||||||
|
|
||||||
export class I18nService {
|
export class I18nService {
|
||||||
@@ -25,8 +27,8 @@ export class I18nService {
|
|||||||
lng: "en",
|
lng: "en",
|
||||||
fallbackLng: "en",
|
fallbackLng: "en",
|
||||||
resources: {
|
resources: {
|
||||||
en: { waterMe: waterMeEn },
|
en: { greeting: greetingEn, waterMe: waterMeEn },
|
||||||
de: { waterMe: waterMeDe },
|
de: { greeting: greetingDe, waterMe: waterMeDe },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
31
core/src/locales/de/greeting.ts
Normal file
31
core/src/locales/de/greeting.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
export default {
|
||||||
|
greeting1: ["hi ", "hey ", "willkommen "],
|
||||||
|
greeting2: ["{{member}}. ", "{{member}}, "],
|
||||||
|
greeting3: [
|
||||||
|
"cool, dass du da bist",
|
||||||
|
"fuehl dich wie zuhause",
|
||||||
|
"schoen, dass du bei uns bist",
|
||||||
|
"schoen, dass du da bist",
|
||||||
|
"schoen, dass du dabei bist",
|
||||||
|
"schoen, dass du hier bist",
|
||||||
|
"schoen, dass du uns gefunden hast",
|
||||||
|
"super, dass du dabei bist",
|
||||||
|
"lass uns zusammen spass haben",
|
||||||
|
"lass uns gemeinsam eine tolle zeit haben!",
|
||||||
|
"fuehl dich wie zu hause",
|
||||||
|
"wir freuen uns auf dich",
|
||||||
|
"wir freuen uns, dass du hier bist",
|
||||||
|
"viel spass hier",
|
||||||
|
"viel spass im server",
|
||||||
|
],
|
||||||
|
greeting4: [". ", "! "],
|
||||||
|
emoji: ["😊", "💕", "✨", "💖", ":3", ":)", "c:", "<3", "<333"],
|
||||||
|
dmAcceptedContent: `huhu! du wurdest als lernende:r>≤ akzeptiert :3
|
||||||
|
sag gerne hallo!`,
|
||||||
|
dm: `hey! ich bin avocadi von avocadi study!!
|
||||||
|
um auf den rest des servers zugreifen zu koennen, musst du dich noch vorstellen!
|
||||||
|
---
|
||||||
|
z.b.: name, alter, pronomen, klasse/studiengang/beruf, hobby, ueber mich:
|
||||||
|
---
|
||||||
|
sobald wir deine nachricht ueberprueft haben, bekommst du die rolle **lernende:r** :)`,
|
||||||
|
} as const;
|
||||||
32
core/src/locales/en/greeting.ts
Normal file
32
core/src/locales/en/greeting.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
export default {
|
||||||
|
greeting1: ["hi ", "hey ", "welcome "],
|
||||||
|
greeting2: ["{{member}}. ", "{{member}}, "],
|
||||||
|
greeting3: [
|
||||||
|
"a hearty welcome to you",
|
||||||
|
"cool that you're here",
|
||||||
|
"glad you're here",
|
||||||
|
"glad you found us",
|
||||||
|
"great to have you here",
|
||||||
|
"have fun here",
|
||||||
|
"have fun on the server",
|
||||||
|
"it is lovely to have you among us",
|
||||||
|
"let's have fun together",
|
||||||
|
"let's have a great time together",
|
||||||
|
"make yourself at home",
|
||||||
|
"nice to have you here",
|
||||||
|
"nice to have you with us",
|
||||||
|
"we hope you have a good time here",
|
||||||
|
"we look forward to having you",
|
||||||
|
"we're glad you're here",
|
||||||
|
],
|
||||||
|
greeting4: [". ", "! "],
|
||||||
|
emoji: ["😊", "💕", "✨", "💖", ":3", ":)", "c:", "<3", "<333"],
|
||||||
|
dmAcceptedContent: `hey there! you've been accepted :3
|
||||||
|
feel free to say hello!`,
|
||||||
|
dmGreeting: `hey! i'm avocadi from avocadi study!!
|
||||||
|
in order to access the rest of the server, you still need to introduce yourself!
|
||||||
|
---
|
||||||
|
e.g.: name, age, pronouns, class/degree/profession, hobbies, about me
|
||||||
|
---
|
||||||
|
once we have reviewed your message, you will be assigned the role **member** :)`,
|
||||||
|
} as const;
|
||||||
Reference in New Issue
Block a user