accept user fluxer implementation
This commit is contained in:
@@ -20,11 +20,9 @@ export class MessagesService
|
||||
async sendToUser(userInput: User, message: MessagePayload): Promise<void> {
|
||||
const user = await client.users.fetch(userInput.id);
|
||||
|
||||
if (user) {
|
||||
await user.send(message);
|
||||
} else {
|
||||
this.logger.error(`User with ID ${userInput.id} not found.`);
|
||||
}
|
||||
if (!user) this.logger.error(`User with ID ${userInput.id} not found.`);
|
||||
this.logger.info(`sending message to user with ID ${userInput.id}.`);
|
||||
await user.send(message);
|
||||
}
|
||||
|
||||
async logMessage(message: Message): Promise<void> {
|
||||
@@ -38,7 +36,6 @@ export class MessagesService
|
||||
|
||||
recipient = channel.recipient;
|
||||
}
|
||||
|
||||
let logMessage: string;
|
||||
|
||||
if (recipient) {
|
||||
@@ -57,7 +54,16 @@ export class MessagesService
|
||||
const fetchedChannel = await client.channels.fetch(channel.id);
|
||||
|
||||
if (fetchedChannel?.isTextBased() && fetchedChannel.isSendable()) {
|
||||
await fetchedChannel.send(createMessageInput);
|
||||
this.logger.info(`sending message to channel with ID ${channel.id}.`);
|
||||
const success = await fetchedChannel.send(createMessageInput);
|
||||
if (success)
|
||||
this.logger.info(
|
||||
`sending message to channel with ID ${channel.id} SUCCESS.`,
|
||||
);
|
||||
else
|
||||
this.logger.error(
|
||||
`sending message to channel with ID ${channel.id} FAILED.`,
|
||||
);
|
||||
} else {
|
||||
this.logger.error(
|
||||
`Channel with ID ${channel.id} not found or is not text-based.`,
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
import { i18nService } from "@avocadi/bot-core/lib/i18n";
|
||||
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("guildMemberAdd", async (member) => {
|
||||
if (member.user.bot) {
|
||||
// Don't send a welcome message for bots (sorry tom)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
greetingService.sendGreeting(member.user, member.user.username);
|
||||
logChannelService.sendLogMessage(
|
||||
`Neues Mitglied: <@${member.user.id}> (${member.user.tag}) ist dem Server beigetreten.`,
|
||||
const channel = await member.guild.channels.fetch(
|
||||
config.channelMapping.text.welcome,
|
||||
);
|
||||
|
||||
if (!channel) return;
|
||||
|
||||
greetingService.sendGreeting(member.user.id, channel);
|
||||
greetingService.sendDmGreeting(member.user);
|
||||
|
||||
// logChannelService.sendLogMessage(await i18nService.t("greeting1", "de", "greeting"), TODO
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ client.on("messageReactionAdd", async (reaction, user) => {
|
||||
|
||||
await acceptUserService.sendDmAcceptUser(messageAuthor_User);
|
||||
await logChannelService.sendLogMessage(
|
||||
`introduction of <@${messageAuthor_User.id}> (${messageAuthor_User.username}) got accepted`,
|
||||
`introduction of <@${messageAuthor_User.id}> got accepted`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ const configInput: z.input<typeof ConfigSchema> = {
|
||||
feedback: "1475069278198489089",
|
||||
help: "",
|
||||
introduction: "1473060169972367394",
|
||||
news: "",
|
||||
news: "1474477662908567694",
|
||||
log: "1473380467480031548",
|
||||
general: "1473029758951358491",
|
||||
rules: "1473070476174811195",
|
||||
testing: "",
|
||||
testing: "1479976182517571597",
|
||||
welcome: "1473270114214928440",
|
||||
pomodoro: "",
|
||||
},
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import { createLogger } from "@avocadi/bot-core/lib/logger";
|
||||
import { Events, type MessageReaction, type User } from "@fluxerjs/core";
|
||||
import { config } from "config";
|
||||
import { RolesService } from "entities/roles/roles.service";
|
||||
import { acceptUserService } from "features/accept-user/accept-user.service";
|
||||
import { logChannelService } from "features/log-channel/log-channel.service";
|
||||
import client from "lib/client";
|
||||
|
||||
const logger = createLogger("ReactionsListener");
|
||||
|
||||
client.on(
|
||||
Events.MessageReactionAdd,
|
||||
async (reaction: MessageReaction, user: User) => {
|
||||
const guild = reaction.guild;
|
||||
if (!guild) {
|
||||
logger.error(`Guild not found for message ${reaction.messageId}.`);
|
||||
return;
|
||||
}
|
||||
logger.info(`Guild found for message ${reaction.messageId}.`);
|
||||
|
||||
const channelIntroduction = await client.channels.fetch(
|
||||
config.channelMapping.text.introduction,
|
||||
);
|
||||
|
||||
const message = await reaction.fetchMessage();
|
||||
|
||||
// check if valid channel
|
||||
if (message.guild?.id && message.channel?.id === channelIntroduction?.id) {
|
||||
logger.info("valid channel");
|
||||
|
||||
const member = guild?.members.get(user.id);
|
||||
|
||||
// check if member who reacted has role MOD
|
||||
if (member?.roles.includes(config.roleMapping.mod)) {
|
||||
const messageAuthor_User = message.author;
|
||||
|
||||
if (messageAuthor_User) {
|
||||
const roleMemberId = config.roleMapping.people;
|
||||
|
||||
const messageAuthor_GuildMember = await guild?.fetchMember(
|
||||
messageAuthor_User.id,
|
||||
);
|
||||
if (
|
||||
!messageAuthor_GuildMember?.roles.find((r) => r === roleMemberId)
|
||||
) {
|
||||
logger.info(`accepting ${messageAuthor_User?.username}...`);
|
||||
|
||||
const rolesService = new RolesService();
|
||||
rolesService.assignRole(messageAuthor_GuildMember, roleMemberId);
|
||||
|
||||
await acceptUserService.sendDmAcceptUser(messageAuthor_User);
|
||||
await logChannelService.sendLogMessage(
|
||||
`introduction of <@${messageAuthor_User.id}> (${messageAuthor_User.username}) got accepted`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -21,6 +21,6 @@ client.on(Events.GuildMemberAdd, async (member: GuildMember) => {
|
||||
await logChannelService.sendLogMessage(
|
||||
`new member: <@${member.user.id}> (${member.user.username}) joined the server.`,
|
||||
);
|
||||
await greetingService.sendGreeting(member.user.username, channel);
|
||||
await greetingService.sendDmGreeting(member.user, member.user.username);
|
||||
await greetingService.sendGreeting(member.user.id, channel);
|
||||
await greetingService.sendDmGreeting(member.user);
|
||||
});
|
||||
|
||||
@@ -1,58 +1,60 @@
|
||||
import { createLogger } from "@avocadi/bot-core/lib/logger";
|
||||
import { Events } from "@fluxerjs/core";
|
||||
import { Events, type MessageReaction, type User } from "@fluxerjs/core";
|
||||
import { config } from "config";
|
||||
import { RolesService } from "entities/roles/roles.service";
|
||||
import { acceptUserService } from "features/accept-user/accept-user.service";
|
||||
import { logChannelService } from "features/log-channel/log-channel.service";
|
||||
import client from "lib/client";
|
||||
|
||||
const logger = createLogger("ReactionsListener");
|
||||
//const logger = createLogger("ReactionsListener");
|
||||
|
||||
client.on(Events.MessageReactionAdd, async (reaction, user) => {
|
||||
const guild = reaction.message.guild;
|
||||
if (!guild) {
|
||||
logger.error(`Guild not found for message ${reaction.message.id}.`);
|
||||
return;
|
||||
}
|
||||
logger.info(`Guild found for message ${reaction.message.id}.`);
|
||||
client.on(
|
||||
Events.MessageReactionAdd,
|
||||
async (
|
||||
reaction: MessageReaction,
|
||||
_user: User,
|
||||
_messageId: string,
|
||||
channelId: string,
|
||||
_emoji: string,
|
||||
userId: string,
|
||||
) => {
|
||||
const message = await reaction.fetchMessage();
|
||||
|
||||
const channelIntroduction = await client.channels.fetch(
|
||||
config.channelMapping.text.introduction,
|
||||
);
|
||||
if (!message || !reaction.guildId) return;
|
||||
|
||||
const message = await reaction.message.fetch();
|
||||
const guild = client.guilds.get(reaction.guildId);
|
||||
if (!guild) return;
|
||||
|
||||
// check if valid channel
|
||||
if (message.guild?.id && message.channel?.id === channelIntroduction?.id) {
|
||||
logger.info("valid channel");
|
||||
const channelIntroduction = await client.channels.fetch(
|
||||
config.channelMapping.text.introduction,
|
||||
);
|
||||
if (guild.id && channelId === channelIntroduction?.id) {
|
||||
const reactionUser =
|
||||
guild.members.get(userId) ?? (await guild.fetchMember(userId));
|
||||
|
||||
const member = guild?.members.cache.get(user.id);
|
||||
if (reactionUser?.roles.find((r) => r === config.roleMapping.mod)) {
|
||||
const messageUser = message.author;
|
||||
|
||||
// check if member who reacted has role MOD
|
||||
if (member?.roles.cache.get(config.roleMapping.mod)) {
|
||||
const messageAuthor_User = await message.author.fetch();
|
||||
if (!messageUser) return;
|
||||
|
||||
if (messageAuthor_User) {
|
||||
const roleMemberId = config.roleMapping.people;
|
||||
|
||||
const messageAuthor_GuildMember = await guild?.members.fetch(
|
||||
messageAuthor_User.id,
|
||||
);
|
||||
if (
|
||||
!messageAuthor_GuildMember?.roles.cache.find(
|
||||
(r) => r.id === roleMemberId,
|
||||
)
|
||||
) {
|
||||
logger.info(`accepting ${messageAuthor_User?.username}...`);
|
||||
const messageAuthor_GuildMember =
|
||||
guild.members.get(messageUser.id) ??
|
||||
(await guild.fetchMember(messageUser.id));
|
||||
|
||||
if (!messageAuthor_GuildMember.roles.find((r) => r === roleMemberId)) {
|
||||
const rolesService = new RolesService();
|
||||
rolesService.assignRole(messageAuthor_GuildMember, roleMemberId);
|
||||
await rolesService.assignRole(
|
||||
messageAuthor_GuildMember,
|
||||
roleMemberId,
|
||||
);
|
||||
|
||||
await acceptUserService.sendDmAcceptUser(messageAuthor_User);
|
||||
await acceptUserService.sendDmAcceptUser(messageUser);
|
||||
await logChannelService.sendLogMessage(
|
||||
`introduction of <@${messageAuthor_User.id}> (${messageAuthor_User.username}) got accepted`,
|
||||
`introduction of <@${messageUser.id}> got accepted`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user