73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import config from "config";
|
|
import client from "lib/client";
|
|
import { getRandomInt } from "lib/utils";
|
|
import { dmWelcomeContent, dmAcceptedContent } from "./dm.components.ts";
|
|
import {
|
|
Client,
|
|
EmbedBuilder,
|
|
type Message,
|
|
type CacheType,
|
|
type GuildMember,
|
|
type Interaction,
|
|
type OmitPartialGroupDMChannel,
|
|
} from "discord.js";
|
|
|
|
export class DmService {
|
|
async handleInteraction(interaction: Interaction<CacheType>) {
|
|
// todo
|
|
}
|
|
|
|
async welcomePrivate(member: GuildMember) {
|
|
console.log("welcome private");
|
|
try {
|
|
await client.users.send(member, dmWelcomeContent);
|
|
} catch (error) {
|
|
console.error("error while sending a welcome msg:", error);
|
|
}
|
|
}
|
|
|
|
async welcomePrivateTest() {
|
|
console.log("test welcome private");
|
|
try {
|
|
await client.users.send(config.discord.myId, dmWelcomeContent);
|
|
} catch (error) {
|
|
console.error("error while sending a welcome msg:", error);
|
|
}
|
|
}
|
|
|
|
async forward(message: OmitPartialGroupDMChannel<Message<boolean>>) {
|
|
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.channelIdNotification);
|
|
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) {
|
|
console.error("error while sending a accept msg:", error);
|
|
}
|
|
}
|
|
}
|