accept user fluxer implementation
This commit is contained in:
@@ -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