Compare commits

..

2 Commits

Author SHA1 Message Date
62b3eb070b added createEmbed 2025-01-07 00:31:01 +01:00
78a65511c2 not much 2025-01-06 15:17:51 +01:00
10 changed files with 269 additions and 38 deletions

3
.gitignore vendored
View File

@ -173,3 +173,6 @@ dist
# Finder (MacOS) folder config # Finder (MacOS) folder config
.DS_Store .DS_Store
# DB
avocadis_diary.sqlite

Binary file not shown.

View File

@ -14,7 +14,7 @@ import {
export class DmService { export class DmService {
async handleInteraction(interaction: Interaction<CacheType>) { async handleInteraction(interaction: Interaction<CacheType>) {
// todo ? // todo
} }
async welcomePrivate(member: GuildMember) { async welcomePrivate(member: GuildMember) {
@ -41,7 +41,19 @@ export class DmService {
const context = `<@${message.author.id}> hat geschrieben: " ${message.content} "`; const context = `<@${message.author.id}> hat geschrieben: " ${message.content} "`;
console.log(context); console.log(context);
client.users.send(config.discord.myId, context);
try {
const channels = client.channels;
const channel = channels.cache.get(config.discord.channelIdNotification);
if (channel?.isTextBased() && channel?.isSendable()) {
await channel.send(context);
}
} catch (error) {
console.error("error while forwarding a welcome msg:", error);
}
//client.users.send(config.discord.myId, context);
} }
async acceptDm(member: GuildMember) { async acceptDm(member: GuildMember) {

View File

@ -0,0 +1,30 @@
import config from "config";
import { EmbedBuilder } from "discord.js";
export const customContent = `hey <@&${config.discord.roleStudy}>! meine [eigene website](https://avocadi.unom.io) ist endlich on :3\ngebe mir gerne rueckmeldung unter <#${config.discord.channelIdFeedback}>! <3`;
export function createEmbed(title: string, description: string, timestamp?: boolean) {
// ({ embeds: [exampleEmbed] })
console.log("createEmbed()");
const customEmbed = (timestamp === true) ? new EmbedBuilder()
.setColor(0x004400)
.setAuthor({
name: title,
iconURL:
"https://media.discordapp.net/attachments/1321933410188656693/1323447010380222474/mo_Avocadi_Avatar_Closeup_2.png?ex=67748b93&is=67733a13&hm=f48efb3523bca5f50e79144c7b41a127c94670e693e3da3dc2e6ffe62ad8a769&=&format=webp&quality=lossless&width=1524&height=1524",
url: "https://avocadi.unom.io",
})
.setDescription(description)
.setTimestamp() :
new EmbedBuilder()
.setColor(0x004400)
.setAuthor({
name: title,
iconURL:
"https://media.discordapp.net/attachments/1321933410188656693/1323447010380222474/mo_Avocadi_Avatar_Closeup_2.png?ex=67748b93&is=67733a13&hm=f48efb3523bca5f50e79144c7b41a127c94670e693e3da3dc2e6ffe62ad8a769&=&format=webp&quality=lossless&width=1524&height=1524",
url: "https://avocadi.unom.io",
})
.setDescription(description);
//.setFooter({ text: 'Some footer text here', iconURL: 'https://i.imgur.com/AfFp7pu.png' });
return customEmbed;
}

View File

@ -0,0 +1,78 @@
import config from "config";
import client from "lib/client";
import { getRandomInt } from "lib/utils";
import { customContent, createEmbed } from "./embed.components.ts";
import {
Client,
EmbedBuilder,
type Message,
type CacheType,
type GuildMember,
type Interaction,
type OmitPartialGroupDMChannel,
type ChatInputCommandInteraction,
} from "discord.js";
import { type CommandsType, Commands } from "commands/index.ts";
import { time } from "drizzle-orm/mysql-core";
export class EmbedService {
async handleInteraction(interaction: Interaction<CacheType>) {
if (interaction.isChatInputCommand()) {
await this.handleChatInputCommand(interaction);
return;
}
}
async handleChatInputCommand(
interaction: ChatInputCommandInteraction<CacheType>,
) {
console.log("accept");
const commandName = interaction.commandName as CommandsType;
switch (commandName) {
case Commands.Enum.embed:
await this.customEmbed(interaction);
return;
default:
break;
}
}
async customEmbed(interaction: ChatInputCommandInteraction<CacheType>) {
const title = interaction.options.getString("title") || " ";
const description = interaction.options.getString("description") || " ";
const timestamp = interaction.options.getBoolean("timestamp") || false;
// return the value
console.log(title, description, timestamp);
// permission check
const userIdCommand = interaction.user.id;
if (userIdCommand !== config.discord.myId) {
await interaction.reply({
content: "you have no permission for that command",
ephemeral: true,
});
return;
}
try {
// get user id from mentioning
const guild = interaction.guild;
if (!guild) {
await interaction.reply({
content: "command can only be used on a server",
ephemeral: true,
});
return;
}
await interaction.reply({
embeds: [createEmbed(title, description, timestamp)],
});
} 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,
});
}
}
}

View File

@ -1,26 +1,6 @@
import config from "config"; import config from "config";
import { EmbedBuilder } from "discord.js";
export const greetContent = ["HALLOOOO", "guten morgen! ich hoffe es geht euch gut <3"]; 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 sleepContent = ["gute nacht! ich muss jetzt schlafen gehen :c", "zzzzZZ..", "*schnarch*"];
export const customContent = `hey <@&${config.discord.roleStudy}>! meine [eigene website](https://avocadi.unom.io) ist endlich on :3\ngebe mir gerne rueckmeldung unter <#${config.discord.channelIdFeedback}>! <3`;
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 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 const dmAcceptedContent = `huhu! du wurdest als lernende:r akzeptiert :3\nsag gerne hallo: <#${config.discord.channelIdOffTopic}> <:avocadi_cute:1321893797138923602>`;
export function createEmbed() {
// ({ embeds: [exampleEmbed] })
console.log("createEmbed()");
const exampleEmbed = new EmbedBuilder()
.setColor(0x004400)
.setAuthor({
name: "avocadi - neuigkeiten",
iconURL:
"https://media.discordapp.net/attachments/1321933410188656693/1323447010380222474/mo_Avocadi_Avatar_Closeup_2.png?ex=67748b93&is=67733a13&hm=f48efb3523bca5f50e79144c7b41a127c94670e693e3da3dc2e6ffe62ad8a769&=&format=webp&quality=lossless&width=1524&height=1524",
url: "https://avocadi.unom.io",
})
.setDescription(customContent)
.setTimestamp();
//.setFooter({ text: 'Some footer text here', iconURL: 'https://i.imgur.com/AfFp7pu.png' });
return exampleEmbed;
}

View File

@ -2,10 +2,8 @@ import config from "config";
import client from "lib/client"; import client from "lib/client";
import { getRandomInt } from "lib/utils"; import { getRandomInt } from "lib/utils";
import { import {
customContent,
greetContent, greetContent,
sleepContent, sleepContent,
createEmbed,
} from "./greeting.components.ts"; } from "./greeting.components.ts";
import { import {
type ChatInputCommandInteraction, type ChatInputCommandInteraction,
@ -16,6 +14,7 @@ import {
type Interaction, type Interaction,
} from "discord.js"; } from "discord.js";
import { DmService } from "actions/dm/dm.service.ts"; import { DmService } from "actions/dm/dm.service.ts";
import { Commands, type CommandsType } from "commands/index.ts";
export class GreetingService { export class GreetingService {
dmService: DmService; dmService: DmService;
@ -27,19 +26,28 @@ export class GreetingService {
async handleInteraction( async handleInteraction(
interaction: Interaction<CacheType> interaction: Interaction<CacheType>
) { ) {
console.log("accept");
if (interaction.isChatInputCommand()) { if (interaction.isChatInputCommand()) {
await this.handleChatInputCommand(interaction);
return;
}
}
async handleChatInputCommand(interaction: ChatInputCommandInteraction<CacheType>) {
console.log("accept");
const commandName = interaction.commandName as CommandsType;
switch (commandName) {
case Commands.Enum.accept:
await this.acceptUser(interaction); await this.acceptUser(interaction);
return;
case Commands.Enum.welcome:
await this.welcomeCommand(interaction);
return;
default:
break;
} }
} }
async custom() {
console.log("custom message");
client.users.send(config.discord.myId, "hat funktioniert :)");
}
async welcome(member: GuildMember) { async welcome(member: GuildMember) {
console.log("welcome msg"); console.log("welcome msg");
@ -182,4 +190,83 @@ export class GreetingService {
} }
return greetContent[getRandomInt(0, greetContent.length - 1)]; return greetContent[getRandomInt(0, greetContent.length - 1)];
} }
async welcomeCommand(
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
const userIdCommand = interaction.user.id;
if (userIdCommand !== config.discord.myId) {
await interaction.reply({
content: "you have no permission for that command",
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 username = (await guild.members.fetch(userId)).user.username;
console.log(username);
// get member from id
const member = await guild.members.fetch(userId);
const welcomeContents = [
`willkommen auf dem server, ${member}! 💕`,
`hey ${member}! schoen, dass du hier bist! 😊`,
`hi ${member}, willkommen! viel spass hier! 💖`,
`willkommen, ${member}! schoen, dass du da bist! 🥳`,
`moin ${member}! viel spass im server! c:`,
`hey ${member}, herzlich willkommen! fuehl dich wie zu hause! <3`,
`hi ${member}! cool, dass du da bist! 👏`,
`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! ✨`,
];
const welcomeContent =
welcomeContents[Math.floor(Math.random() * welcomeContents.length)];
try {
const channels = client.channels;
const channel = channels.cache.get(config.discord.channelIdWelcome);
if (channel?.isTextBased() && channel?.isSendable()) {
await channel.send(welcomeContent);
}
} 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,
});
}
}
} }

View File

@ -1,7 +1,7 @@
import { SlashCommandBuilder, userMention } from "discord.js"; import { SlashCommandBuilder, userMention } from "discord.js";
import { z } from "zod"; import { z } from "zod";
export const Commands = z.enum(["giessen", "medikamente", "hilfe", "accept"]); export const Commands = z.enum(["giessen", "medikamente", "hilfe", "accept", "welcome", "embed"]);
export const CommandsMeta: Record<z.output<typeof Commands>, { description: string }> = { export const CommandsMeta: Record<z.output<typeof Commands>, { description: string }> = {
giessen: { giessen: {
@ -15,6 +15,12 @@ export const CommandsMeta: Record<z.output<typeof Commands>, { description: stri
}, },
accept: { accept: {
description: "admin use only" description: "admin use only"
},
welcome: {
description: "admin use only"
},
embed: {
description: "admin use only"
} }
} }
@ -38,6 +44,29 @@ export default function getCommands() {
option.setName('input') option.setName('input')
.setDescription('input for bot') .setDescription('input for bot')
.setRequired(true)), .setRequired(true)),
new SlashCommandBuilder()
.setName(Commands.Enum.welcome)
.setDescription(CommandsMeta.welcome.description)
.addStringOption(option =>
option.setName('input')
.setDescription('input for bot')
.setRequired(true)),
new SlashCommandBuilder()
.setName(Commands.Enum.embed)
.setDescription(CommandsMeta.embed.description)
.addStringOption(option =>
option.setName('title')
.setDescription('title')
.setRequired(true))
.addStringOption(option =>
option.setName('description')
.setDescription('description')
.setRequired(true))
.addBooleanOption(option =>
option.setName('timestamp')
.setDescription('timestamp bool')
.setRequired(false)),
].map((command) => command.toJSON()); ].map((command) => command.toJSON());
return commands; return commands;

View File

@ -2,15 +2,19 @@ export default {
discord: { discord: {
// test // test
testChannel: process.env.DISCORD_TEST_CHANNEL_ID || "", testChannel: process.env.DISCORD_TEST_CHANNEL_ID || "",
channelIdBot: process.env.DISCORD_CHANNEL_ID_BOT || "",
// avocadi // avocadi
serverID: process.env.DISCORD_SERVER_ID || "", serverID: process.env.DISCORD_SERVER_ID || "",
channelIdNews: process.env.DISCORD_CHANNEL_ID_NEWS || "", channelIdBot: process.env.DISCORD_CHANNEL_ID_BOT || "",
channelIdFeedback: process.env.DISCORD_CHANNEL_ID_FEEDBACK || "", channelIdNotification: process.env.DISCORD_CHANNEL_ID_NOTIFICATION || "",
channelIdIntroduction: process.env.DISCORD_CHANNEL_ID_INTRODUCTION || "",
channelIdWelcome: process.env.DISCORD_CHANNEL_ID_WELCOME || "", channelIdWelcome: process.env.DISCORD_CHANNEL_ID_WELCOME || "",
channelIdRules: process.env.DISCORD_CHANNEL_ID_RULE || "",
channelIdNews: process.env.DISCORD_CHANNEL_ID_NEWS || "",
channelIdIntroduction: process.env.DISCORD_CHANNEL_ID_INTRODUCTION || "",
channelIdOffTopic: process.env.DISCORD_CHANNEL_ID_OFF_TOPIC || "", channelIdOffTopic: process.env.DISCORD_CHANNEL_ID_OFF_TOPIC || "",
channelIdFeedback: process.env.DISCORD_CHANNEL_ID_FEEDBACK || "",
channelIdHelp: process.env.DISCORD_CHANNEL_ID_HELP || "",
roleStudy: process.env.PEOPLE || "", roleStudy: process.env.PEOPLE || "",
// other // other

View File

@ -17,10 +17,10 @@ import config from "config";
import { WaterMeService } from "actions/waterMe/waterMe.service"; import { WaterMeService } from "actions/waterMe/waterMe.service";
import { MedicationService } from "actions/medication/medication.service"; import { MedicationService } from "actions/medication/medication.service";
import { HelpService } from "actions/help/help.service"; import { HelpService } from "actions/help/help.service";
import { custom } from "zod";
import { GreetingService } from "actions/greeting/greeting.service"; import { GreetingService } from "actions/greeting/greeting.service";
import { ActivityService } from "actions/activity/activity.service"; import { ActivityService } from "actions/activity/activity.service";
import { DmService } from "actions/dm/dm.service"; import { DmService } from "actions/dm/dm.service";
import { EmbedService } from "actions/embed/embed.service";
export default class DiscordController extends EventEmitter { export default class DiscordController extends EventEmitter {
private discordService!: DiscordService; private discordService!: DiscordService;
@ -30,6 +30,7 @@ export default class DiscordController extends EventEmitter {
helpService: HelpService; helpService: HelpService;
activityService: ActivityService; activityService: ActivityService;
dmService: DmService; dmService: DmService;
embedService: EmbedService;
constructor() { constructor() {
super(); super();
@ -40,6 +41,7 @@ export default class DiscordController extends EventEmitter {
this.helpService = new HelpService(); this.helpService = new HelpService();
this.activityService = new ActivityService(); this.activityService = new ActivityService();
this.dmService = new DmService(); this.dmService = new DmService();
this.embedService = new EmbedService();
// log when running // log when running
client.once("ready", async () => { client.once("ready", async () => {
await this.setActivity(); await this.setActivity();
@ -124,6 +126,12 @@ export default class DiscordController extends EventEmitter {
case Commands.Enum.accept: case Commands.Enum.accept:
await this.greetingService.handleInteraction(interaction); await this.greetingService.handleInteraction(interaction);
return; return;
case Commands.Enum.welcome:
await this.greetingService.handleInteraction(interaction);
return;
case Commands.Enum.embed:
await this.embedService.handleInteraction(interaction);
return;
default: default:
break; break;
} }