Compare commits
10 commits
96dabb6693
...
dde334bdfa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dde334bdfa | ||
|
|
5c22f2dd25 | ||
|
|
d121765e88 | ||
|
|
d90746b07c | ||
|
|
cabef748b0 | ||
|
|
2c09ecf9c3 | ||
|
|
6b2876e514 | ||
|
|
0afccf3735 | ||
|
|
031055e09c | ||
|
|
9cf864f56e |
9 changed files with 362 additions and 16 deletions
|
|
@ -42,6 +42,11 @@ export default {
|
||||||
|
|
||||||
const category = categoryOption as CategoryChannel;
|
const category = categoryOption as CategoryChannel;
|
||||||
|
|
||||||
|
await interaction.reply({
|
||||||
|
content: `${emoji.answer.loading} | Starting the deletion of **${category.name}**.`,
|
||||||
|
flags: MessageFlags.Ephemeral,
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (const channel of category.children.cache.values()) {
|
for (const channel of category.children.cache.values()) {
|
||||||
await channel.delete(
|
await channel.delete(
|
||||||
|
|
@ -53,11 +58,12 @@ export default {
|
||||||
`Deleted ${category.name} (requested by ${interaction.user.username})`,
|
`Deleted ${category.name} (requested by ${interaction.user.username})`,
|
||||||
);
|
);
|
||||||
|
|
||||||
await interaction.reply({
|
if (interaction.channel) {
|
||||||
|
await interaction.editReply({
|
||||||
content: `${emoji.answer.yes} | Deleted category **${category.name}** and its channels.`,
|
content: `${emoji.answer.yes} | Deleted category **${category.name}** and its channels.`,
|
||||||
flags: MessageFlags.Ephemeral,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (err: unknown) {
|
catch (err: unknown) {
|
||||||
log.error(err, 'Cannot delete category or its channels');
|
log.error(err, 'Cannot delete category or its channels');
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import {
|
||||||
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
import emoji from '../../../assets/emoji.json' assert { type: 'json' };
|
||||||
import { Guild as GuildPrisma, User as UserPrisma } from '@prisma/client';
|
import { Guild as GuildPrisma, User as UserPrisma } from '@prisma/client';
|
||||||
import { log } from '@lib/log';
|
import { log } from '@lib/log';
|
||||||
import { isOwner } from '@lib/perm.js';
|
import { isOwner } from '@lib/perm';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
|
@ -32,10 +32,6 @@ export default {
|
||||||
name: 'Show',
|
name: 'Show',
|
||||||
value: 'logs_show',
|
value: 'logs_show',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'Auto-configuration',
|
|
||||||
value: 'logs_auto',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'Configuration',
|
name: 'Configuration',
|
||||||
value: 'logs_config',
|
value: 'logs_config',
|
||||||
|
|
@ -143,7 +139,7 @@ export default {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case 'logs_auto': {
|
case 'logs_config': {
|
||||||
if (!await isOwner(interaction.user.id)) {
|
if (!await isOwner(interaction.user.id)) {
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: `${emoji.answer.no} | This command is only for owner`,
|
content: `${emoji.answer.no} | This command is only for owner`,
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ export default {
|
||||||
});
|
});
|
||||||
await new Promise((res) => setTimeout(res, 1000));
|
await new Promise((res) => setTimeout(res, 1000));
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch {
|
||||||
log.info(`Not able to fetch user ${buyer.id}`);
|
log.info(`Not able to fetch user ${buyer.id}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
64
src/events/guild/guildBanAdd.ts
Normal file
64
src/events/guild/guildBanAdd.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import {
|
||||||
|
AuditLogEvent,
|
||||||
|
Channel,
|
||||||
|
EmbedBuilder,
|
||||||
|
Events,
|
||||||
|
Guild,
|
||||||
|
GuildAuditLogs,
|
||||||
|
GuildBan,
|
||||||
|
User,
|
||||||
|
} from 'discord.js';
|
||||||
|
import { Guild as GuildPrisma } from '@prisma/client';
|
||||||
|
import { prisma } from '@lib/prisma';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: Events.GuildBanAdd,
|
||||||
|
async execute(ban: GuildBan) {
|
||||||
|
const guild: Guild = ban.guild;
|
||||||
|
const banned_user: User = ban.user;
|
||||||
|
const fetchedLogs: GuildAuditLogs<AuditLogEvent.MemberBanAdd> = await guild.fetchAuditLogs({
|
||||||
|
limit: 5,
|
||||||
|
type: AuditLogEvent.MemberBanAdd,
|
||||||
|
});
|
||||||
|
const banLog = fetchedLogs.entries.find(
|
||||||
|
(entry) => entry.target?.id === banned_user.id,
|
||||||
|
);
|
||||||
|
const executor: string = banLog.executor.username ?? 'Unknown executor';
|
||||||
|
const reason: string = ban.reason ?? banLog.reason ?? 'No reason provided';
|
||||||
|
const guildData: GuildPrisma = await prisma.guild.findUnique({
|
||||||
|
where: {
|
||||||
|
id: guild.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const toSend: EmbedBuilder = new EmbedBuilder()
|
||||||
|
.setTitle('🔨 | Member banned')
|
||||||
|
.setAuthor({
|
||||||
|
name: `${banned_user.username} (${banned_user.id})`,
|
||||||
|
iconURL: banned_user.displayAvatarURL({
|
||||||
|
size: 2048,
|
||||||
|
extension: 'png',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.setColor(guildData.color)
|
||||||
|
.setFooter({
|
||||||
|
text: guildData.footer,
|
||||||
|
})
|
||||||
|
.setTimestamp().setDescription(`
|
||||||
|
**Banned by:**
|
||||||
|
${executor}
|
||||||
|
**Reason:**
|
||||||
|
${reason}
|
||||||
|
`);
|
||||||
|
if (guildData.logMod) {
|
||||||
|
const logChannel: Channel | null = await guild.client.channels.fetch(
|
||||||
|
guildData.logMod,
|
||||||
|
);
|
||||||
|
if (logChannel) {
|
||||||
|
logChannel.send({
|
||||||
|
embeds: [toSend],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
98
src/events/guild/guildBanRemove.ts
Normal file
98
src/events/guild/guildBanRemove.ts
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
import {
|
||||||
|
AuditLogEvent,
|
||||||
|
Channel,
|
||||||
|
EmbedBuilder,
|
||||||
|
Events,
|
||||||
|
Guild,
|
||||||
|
GuildAuditLogs,
|
||||||
|
GuildBan,
|
||||||
|
User,
|
||||||
|
} from 'discord.js';
|
||||||
|
import { Guild as GuildPrisma } from '@prisma/client';
|
||||||
|
import { prisma } from '@lib/prisma';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: Events.GuildBanRemove,
|
||||||
|
async execute(ban: GuildBan) {
|
||||||
|
const guild: Guild = ban.guild;
|
||||||
|
const banned_user: User = ban.user;
|
||||||
|
const banFetchLog: GuildAuditLogs<AuditLogEvent.MemberBanAdd> =
|
||||||
|
await guild.fetchAuditLogs({
|
||||||
|
limit: 99,
|
||||||
|
type: AuditLogEvent.MemberBanAdd,
|
||||||
|
});
|
||||||
|
const banLog = banFetchLog.entries.find(
|
||||||
|
(entry) => entry.target?.id === banned_user.id,
|
||||||
|
);
|
||||||
|
const unbanFetchLog: GuildAuditLogs<AuditLogEvent.MemberBanRemove> =
|
||||||
|
await guild.fetchAuditLogs({
|
||||||
|
limit: 99,
|
||||||
|
type: AuditLogEvent.MemberBanRemove,
|
||||||
|
});
|
||||||
|
const unbanLog = unbanFetchLog.entries.find(
|
||||||
|
(entry) => entry.target?.id === banned_user.id,
|
||||||
|
);
|
||||||
|
const executor: string = banLog.executor.username ?? 'Unknown executor';
|
||||||
|
const reason: string = ban.reason ?? banLog.reason ?? 'No reason provided';
|
||||||
|
const bannedAt: number | undefined = banLog?.createdTimestamp;
|
||||||
|
const unbannedAt: number | undefined = unbanLog?.createdTimestamp;
|
||||||
|
let durationFormatted: string | null = null;
|
||||||
|
if (unbannedAt && bannedAt) {
|
||||||
|
const durationMs: number = unbannedAt - bannedAt;
|
||||||
|
const durationTotalSeconds: number = Math.max(0, Math.floor(durationMs / 1000));
|
||||||
|
const durationHours: number = Math.floor(durationTotalSeconds / 3600);
|
||||||
|
const durationMinutes: number = Math.floor((durationTotalSeconds % 3600) / 60);
|
||||||
|
const durationSeconds: number = durationTotalSeconds % 60;
|
||||||
|
const durationParts: string[] = [];
|
||||||
|
if (durationHours > 0) {
|
||||||
|
durationParts.push(`${durationHours}h`);
|
||||||
|
}
|
||||||
|
if (durationMinutes > 0) {
|
||||||
|
durationParts.push(`${durationMinutes}m`);
|
||||||
|
}
|
||||||
|
if (durationSeconds > 0 || durationParts.length === 0) {
|
||||||
|
durationParts.push(`${durationSeconds}s`);
|
||||||
|
}
|
||||||
|
durationFormatted = durationParts.join(' ');
|
||||||
|
}
|
||||||
|
const guildData: GuildPrisma = await prisma.guild.findUnique({
|
||||||
|
where: {
|
||||||
|
id: guild.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const toSend: EmbedBuilder = new EmbedBuilder()
|
||||||
|
.setTitle('🔨 | Member Unbanned')
|
||||||
|
.setAuthor({
|
||||||
|
name: `${banned_user.username} (${banned_user.id})`,
|
||||||
|
iconURL: banned_user.displayAvatarURL({
|
||||||
|
size: 2048,
|
||||||
|
extension: 'png',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.setColor(guildData.color)
|
||||||
|
.setFooter({
|
||||||
|
text: guildData.footer,
|
||||||
|
})
|
||||||
|
.setTimestamp().setDescription(`
|
||||||
|
**Banned by:**
|
||||||
|
${executor}
|
||||||
|
**Banned the:**
|
||||||
|
${bannedAt ? `<t:${Math.floor(bannedAt / 1000)}:D> (<t:${Math.floor(bannedAt / 1000)}:R>)` : 'No date found'}
|
||||||
|
**Ban Duration:**
|
||||||
|
${durationFormatted ?? 'Cannot calculate the ban duration'}
|
||||||
|
**Reason:**
|
||||||
|
${reason}
|
||||||
|
`);
|
||||||
|
if (guildData.logMod) {
|
||||||
|
const logChannel: Channel | null = await guild.client.channels.fetch(
|
||||||
|
guildData.logMod,
|
||||||
|
);
|
||||||
|
if (logChannel) {
|
||||||
|
logChannel.send({
|
||||||
|
embeds: [toSend],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
84
src/events/guild/guildMemberAdd.ts
Normal file
84
src/events/guild/guildMemberAdd.ts
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
import { Channel, EmbedBuilder, Events, GuildMember } from 'discord.js';
|
||||||
|
import { Guild as GuildPrisma } from '@prisma/client';
|
||||||
|
import { prisma } from '@lib/prisma';
|
||||||
|
import { placeholder } from '@lib/placeholder';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: Events.GuildMemberAdd,
|
||||||
|
async execute(member: GuildMember) {
|
||||||
|
const memberId: string = member.id;
|
||||||
|
const guildId: string = member.guild.id;
|
||||||
|
const guildData: GuildPrisma = await prisma.guild.findUnique({
|
||||||
|
where: {
|
||||||
|
id: guildId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (guildData.joinEnabled) {
|
||||||
|
const fetchedChannel: Channel | null = await member.client.channels.fetch(guildData.joinChannel as string);
|
||||||
|
if (fetchedChannel) {
|
||||||
|
fetchedChannel.send({
|
||||||
|
content: placeholder(guildData.joinMessage, member),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (guildData.logMember) {
|
||||||
|
const toSend: EmbedBuilder = new EmbedBuilder()
|
||||||
|
.setTitle('🛬 | Member just joined')
|
||||||
|
.setAuthor({
|
||||||
|
name: `${member.user.username} (${member.user.id})`,
|
||||||
|
iconURL: member.displayAvatarURL({
|
||||||
|
size: 2048,
|
||||||
|
extension: 'png',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.setColor(guildData.color)
|
||||||
|
.setFooter({
|
||||||
|
text: guildData.footer,
|
||||||
|
})
|
||||||
|
.setTimestamp()
|
||||||
|
.setDescription(`
|
||||||
|
**Acount Creation:**
|
||||||
|
<t:${Math.floor(member.user.createdTimestamp / 1000)}:D> (<t:${Math.floor(member.user.createdTimestamp / 1000)}:R>)
|
||||||
|
**JoinDate:**
|
||||||
|
<t:${Math.floor(member.joinedTimestamp / 1000)}:D> (<t:${Math.floor(member.joinedTimestamp / 1000)}:R>)
|
||||||
|
`);
|
||||||
|
const fetchedChannel: Channel | null = await member.client.channels.fetch(guildData.logMember as string);
|
||||||
|
if (fetchedChannel) {
|
||||||
|
fetchedChannel.send({
|
||||||
|
embeds: [toSend],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await prisma.user.upsert({
|
||||||
|
where: {
|
||||||
|
id: memberId,
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
id: memberId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await prisma.guildUser.upsert({
|
||||||
|
where: {
|
||||||
|
userId_guildId: {
|
||||||
|
userId: memberId,
|
||||||
|
guildId: guildId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
user: {
|
||||||
|
connect:
|
||||||
|
{
|
||||||
|
id: memberId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
guild: {
|
||||||
|
connect: {
|
||||||
|
id: guildId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
92
src/events/guild/guildMemberRemove.ts
Normal file
92
src/events/guild/guildMemberRemove.ts
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
import { Channel, EmbedBuilder, Events, GuildMember } from 'discord.js';
|
||||||
|
import { Guild as GuildPrisma } from '@prisma/client';
|
||||||
|
import { prisma } from '@lib/prisma';
|
||||||
|
import { placeholder } from '@lib/placeholder';
|
||||||
|
import { getUserRoles } from '@lib/roles.js';
|
||||||
|
import { client } from '@lib/client.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: Events.GuildMemberRemove,
|
||||||
|
async execute(member: GuildMember) {
|
||||||
|
if (member.id === client.user.id) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
const memberId: string = member.id;
|
||||||
|
const guildId: string = member.guild.id;
|
||||||
|
const guildData: GuildPrisma = await prisma.guild.findUnique({
|
||||||
|
where: {
|
||||||
|
id: guildId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (guildData.leaveEnabled) {
|
||||||
|
const fetchedChannel: Channel | null = await member.client.channels.fetch(guildData.leaveChannel as string);
|
||||||
|
if (fetchedChannel) {
|
||||||
|
fetchedChannel.send({
|
||||||
|
content: placeholder(guildData.leaveMessage, member),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (guildData.logMember) {
|
||||||
|
const toSend: EmbedBuilder = new EmbedBuilder()
|
||||||
|
.setTitle('🛫 | Member just left')
|
||||||
|
.setAuthor({
|
||||||
|
name: `${member.user.username} (${member.user.id})`,
|
||||||
|
iconURL: member.displayAvatarURL({
|
||||||
|
size: 2048,
|
||||||
|
extension: 'png',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.setColor(guildData.color)
|
||||||
|
.setFooter({
|
||||||
|
text: guildData.footer,
|
||||||
|
})
|
||||||
|
.setTimestamp()
|
||||||
|
.setDescription(`
|
||||||
|
**Roles:**
|
||||||
|
${getUserRoles(member)}
|
||||||
|
|
||||||
|
**Acount Creation:**
|
||||||
|
<t:${Math.floor(member.user.createdTimestamp / 1000)}:D> <t:${Math.floor(member.user.createdTimestamp / 1000)}:R>
|
||||||
|
**JoinDate:**
|
||||||
|
<t:${Math.floor(member.joinedTimestamp / 1000)}:D> <t:${Math.floor(member.joinedTimestamp / 1000)}:R>
|
||||||
|
`);
|
||||||
|
const fetchedChannel: Channel | null = await member.client.channels.fetch(guildData.logMember as string);
|
||||||
|
if (fetchedChannel) {
|
||||||
|
fetchedChannel.send({
|
||||||
|
embeds: [toSend],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await prisma.user.upsert({
|
||||||
|
where: {
|
||||||
|
id: memberId,
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
id: memberId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await prisma.guildUser.upsert({
|
||||||
|
where: {
|
||||||
|
userId_guildId: {
|
||||||
|
userId: memberId,
|
||||||
|
guildId: guildId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
user: {
|
||||||
|
connect:
|
||||||
|
{
|
||||||
|
id: memberId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
guild: {
|
||||||
|
connect: {
|
||||||
|
id: guildId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
@ -65,6 +65,7 @@ export default {
|
||||||
}
|
}
|
||||||
const toRep = new EmbedBuilder()
|
const toRep = new EmbedBuilder()
|
||||||
.setColor(guildData.color)
|
.setColor(guildData.color)
|
||||||
|
.setTimestamp()
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: guildData.footer,
|
text: guildData.footer,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
import {
|
import { Client, GatewayIntentBits } from 'discord.js';
|
||||||
Client,
|
|
||||||
GatewayIntentBits,
|
|
||||||
} from 'discord.js';
|
|
||||||
|
|
||||||
export const client: Client = new Client({
|
export const client: Client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.Guilds,
|
GatewayIntentBits.Guilds,
|
||||||
|
GatewayIntentBits.GuildModeration,
|
||||||
|
GatewayIntentBits.GuildMembers,
|
||||||
GatewayIntentBits.GuildMessages,
|
GatewayIntentBits.GuildMessages,
|
||||||
GatewayIntentBits.MessageContent,
|
GatewayIntentBits.MessageContent,
|
||||||
GatewayIntentBits.GuildMembers,
|
GatewayIntentBits.GuildMessageReactions,
|
||||||
|
GatewayIntentBits.GuildMessageTyping,
|
||||||
|
GatewayIntentBits.GuildVoiceStates,
|
||||||
|
GatewayIntentBits.DirectMessages,
|
||||||
|
GatewayIntentBits.DirectMessageReactions,
|
||||||
|
GatewayIntentBits.AutoModerationConfiguration,
|
||||||
|
GatewayIntentBits.AutoModerationExecution,
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue