Compare commits
No commits in common. "62b3eb070bc1c648b175b485cbb6220677f707ef" and "94d2fc40e66b9388d82d50044c122fe2356e7801" have entirely different histories.
62b3eb070b
...
94d2fc40e6
3
.gitignore
vendored
3
.gitignore
vendored
@ -173,6 +173,3 @@ dist
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
|
||||
# DB
|
||||
avocadis_diary.sqlite
|
||||
|
BIN
mydb.sqlite
BIN
mydb.sqlite
Binary file not shown.
@ -14,7 +14,7 @@ import {
|
||||
|
||||
export class DmService {
|
||||
async handleInteraction(interaction: Interaction<CacheType>) {
|
||||
// todo
|
||||
// todo ?
|
||||
}
|
||||
|
||||
async welcomePrivate(member: GuildMember) {
|
||||
@ -41,19 +41,7 @@ export class DmService {
|
||||
const context = `<@${message.author.id}> hat geschrieben: " ${message.content} "`;
|
||||
|
||||
console.log(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);
|
||||
client.users.send(config.discord.myId, context);
|
||||
}
|
||||
|
||||
async acceptDm(member: GuildMember) {
|
||||
|
@ -1,30 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,26 @@
|
||||
import config from "config";
|
||||
import { EmbedBuilder } 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 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 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;
|
||||
}
|
@ -2,8 +2,10 @@ import config from "config";
|
||||
import client from "lib/client";
|
||||
import { getRandomInt } from "lib/utils";
|
||||
import {
|
||||
customContent,
|
||||
greetContent,
|
||||
sleepContent,
|
||||
createEmbed,
|
||||
} from "./greeting.components.ts";
|
||||
import {
|
||||
type ChatInputCommandInteraction,
|
||||
@ -14,7 +16,6 @@ import {
|
||||
type Interaction,
|
||||
} from "discord.js";
|
||||
import { DmService } from "actions/dm/dm.service.ts";
|
||||
import { Commands, type CommandsType } from "commands/index.ts";
|
||||
|
||||
export class GreetingService {
|
||||
dmService: DmService;
|
||||
@ -26,26 +27,17 @@ export class GreetingService {
|
||||
async handleInteraction(
|
||||
interaction: Interaction<CacheType>
|
||||
) {
|
||||
console.log("accept");
|
||||
|
||||
if (interaction.isChatInputCommand()) {
|
||||
await this.handleChatInputCommand(interaction);
|
||||
return;
|
||||
await this.acceptUser(interaction);
|
||||
}
|
||||
|
||||
}
|
||||
async handleChatInputCommand(interaction: ChatInputCommandInteraction<CacheType>) {
|
||||
console.log("accept");
|
||||
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;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
async custom() {
|
||||
console.log("custom message");
|
||||
|
||||
client.users.send(config.discord.myId, "hat funktioniert :)");
|
||||
}
|
||||
|
||||
async welcome(member: GuildMember) {
|
||||
@ -190,83 +182,4 @@ export class GreetingService {
|
||||
}
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { SlashCommandBuilder, userMention } from "discord.js";
|
||||
import { z } from "zod";
|
||||
|
||||
export const Commands = z.enum(["giessen", "medikamente", "hilfe", "accept", "welcome", "embed"]);
|
||||
export const Commands = z.enum(["giessen", "medikamente", "hilfe", "accept"]);
|
||||
|
||||
export const CommandsMeta: Record<z.output<typeof Commands>, { description: string }> = {
|
||||
giessen: {
|
||||
@ -15,12 +15,6 @@ export const CommandsMeta: Record<z.output<typeof Commands>, { description: stri
|
||||
},
|
||||
accept: {
|
||||
description: "admin use only"
|
||||
},
|
||||
welcome: {
|
||||
description: "admin use only"
|
||||
},
|
||||
embed: {
|
||||
description: "admin use only"
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,29 +38,6 @@ export default function getCommands() {
|
||||
option.setName('input')
|
||||
.setDescription('input for bot')
|
||||
.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());
|
||||
|
||||
return commands;
|
||||
|
@ -2,19 +2,15 @@ export default {
|
||||
discord: {
|
||||
// test
|
||||
testChannel: process.env.DISCORD_TEST_CHANNEL_ID || "",
|
||||
channelIdBot: process.env.DISCORD_CHANNEL_ID_BOT || "",
|
||||
|
||||
// avocadi
|
||||
serverID: process.env.DISCORD_SERVER_ID || "",
|
||||
channelIdBot: process.env.DISCORD_CHANNEL_ID_BOT || "",
|
||||
channelIdNotification: process.env.DISCORD_CHANNEL_ID_NOTIFICATION || "",
|
||||
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 || "",
|
||||
channelIdFeedback: process.env.DISCORD_CHANNEL_ID_FEEDBACK || "",
|
||||
channelIdHelp: process.env.DISCORD_CHANNEL_ID_HELP || "",
|
||||
channelIdIntroduction: process.env.DISCORD_CHANNEL_ID_INTRODUCTION || "",
|
||||
channelIdWelcome: process.env.DISCORD_CHANNEL_ID_WELCOME || "",
|
||||
channelIdOffTopic: process.env.DISCORD_CHANNEL_ID_OFF_TOPIC || "",
|
||||
roleStudy: process.env.PEOPLE || "",
|
||||
|
||||
// other
|
||||
|
@ -17,10 +17,10 @@ import config from "config";
|
||||
import { WaterMeService } from "actions/waterMe/waterMe.service";
|
||||
import { MedicationService } from "actions/medication/medication.service";
|
||||
import { HelpService } from "actions/help/help.service";
|
||||
import { custom } from "zod";
|
||||
import { GreetingService } from "actions/greeting/greeting.service";
|
||||
import { ActivityService } from "actions/activity/activity.service";
|
||||
import { DmService } from "actions/dm/dm.service";
|
||||
import { EmbedService } from "actions/embed/embed.service";
|
||||
|
||||
export default class DiscordController extends EventEmitter {
|
||||
private discordService!: DiscordService;
|
||||
@ -30,7 +30,6 @@ export default class DiscordController extends EventEmitter {
|
||||
helpService: HelpService;
|
||||
activityService: ActivityService;
|
||||
dmService: DmService;
|
||||
embedService: EmbedService;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@ -41,7 +40,6 @@ export default class DiscordController extends EventEmitter {
|
||||
this.helpService = new HelpService();
|
||||
this.activityService = new ActivityService();
|
||||
this.dmService = new DmService();
|
||||
this.embedService = new EmbedService();
|
||||
// log when running
|
||||
client.once("ready", async () => {
|
||||
await this.setActivity();
|
||||
@ -126,12 +124,6 @@ export default class DiscordController extends EventEmitter {
|
||||
case Commands.Enum.accept:
|
||||
await this.greetingService.handleInteraction(interaction);
|
||||
return;
|
||||
case Commands.Enum.welcome:
|
||||
await this.greetingService.handleInteraction(interaction);
|
||||
return;
|
||||
case Commands.Enum.embed:
|
||||
await this.embedService.handleInteraction(interaction);
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user