import config from "config"; import { type CacheType, Client, EmbedBuilder, type GuildMember, type Interaction, type Message, type OmitPartialGroupDMChannel, } from "discord.js"; import client from "lib/client"; import { getRandomInt } from "lib/utils"; import { dmAcceptedContent, dmWelcomeContent } from "./dm.components.ts"; export class DmService { async handleInteraction(interaction: Interaction) { // todo } async reminderPrivate(member: GuildMember) { console.log("reminder"); try { const content = `hey, kleine erinnerung :)\nbitte stelle dich auf <#${config.discord.channelIdIntroduction}> vor, damit du alle kanaele ansehen und nutzen kannst! <3`; await client.users.send(member, content); } catch (error) { const channels = client.channels; const channel = channels.cache.get(config.discord.channelIdLog); if (channel?.isTextBased() && channel?.isSendable()) { await channel.send( `konnte keine private nachricht an <@${member.user.id}> senden`, ); } console.error("error while sending a welcome msg:", error); } } async welcomePrivate(member: GuildMember) { console.log("welcome private"); try { await client.users.send(member, dmWelcomeContent); } catch (error) { const channels = client.channels; const channel = channels.cache.get(config.discord.channelIdLog); if (channel?.isTextBased() && channel?.isSendable()) { await channel.send( `konnte keine private nachricht an <@${member.user.id}> senden`, ); } console.error("error while sending a welcome msg:", error); } } async forward(message: OmitPartialGroupDMChannel>) { if (message.channel.isDMBased()) { const author = message.author.id; const recipient = message.channel.recipient?.id; console.log("forward message"); let context = ""; if (message.author.bot) { context = `<@${author}> hat an <@${recipient}> geschrieben:\n"${message.content}"`; } else { context = `<@${author}> hat geschrieben:\n"${message.content}"`; } try { const channels = client.channels; const channel = channels.cache.get(config.discord.channelIdLog); if (channel?.isTextBased() && channel?.isSendable()) { await channel.send(context); } } catch (error) { console.error("error while forwarding a msg:", error); } } } async acceptDm(member: GuildMember) { console.log("accept dm"); try { await client.users.send(member, dmAcceptedContent); } catch (error) { const channels = client.channels; const channel = channels.cache.get(config.discord.channelIdLog); if (channel?.isTextBased() && channel?.isSendable()) { await channel.send( `konnte keine private nachricht an <@${member.user.id}> senden`, ); } console.error("error while sending a accept msg:", error); } } async roleMentionDm(member: GuildMember, add: boolean) { console.log("rolementionadd dm"); try { const contentRoleMentionDm = `du hast die rolle **streber:in** erfolgreich ** *${add ? "zugeteilt" : "entfernt"}* ** bekommen :3 <#${config.discord.channelIdOffTopic}> <:avocadi_cute:1321893797138923602>`; client.users.send(member, contentRoleMentionDm); } catch (error) { const channels = client.channels; const channel = channels.cache.get(config.discord.channelIdLog); if (channel?.isTextBased() && channel?.isSendable()) { await channel.send( `konnte keine private nachricht an <@${member.user.id}> senden`, ); } console.error("error while sending a accept msg:", error); } } }