1 |
import { roleMention } from '@discordjs/builders'; |
import { roleMention } from '@discordjs/builders'; |
2 |
import { GuildBan, GuildMember, Message, MessageEmbed, TextChannel, User } from 'discord.js'; |
import { CommandInteraction, FileOptions, GuildBan, GuildMember, Message, MessageEmbed, TextChannel, User } from 'discord.js'; |
3 |
import DiscordClient from '../client/Client'; |
import DiscordClient from '../client/Client'; |
4 |
import { timeProcess, timeSince } from '../utils/util'; |
import { timeProcess, timeSince } from '../utils/util'; |
5 |
|
|
10 |
this.client = client; |
this.client = client; |
11 |
} |
} |
12 |
|
|
13 |
channel(callback: (channel: TextChannel) => any, msg: Message | GuildBan) { |
channel(callback: (channel: TextChannel) => any, msg: any) { |
14 |
let channelID = this.client.config.props[msg.guild!.id].logging_channel; |
let channelID = this.client.config.props[msg.guild!.id].logging_channel; |
15 |
let channel = msg.guild!.channels.cache.find(c => c.id === channelID) as TextChannel; |
let channel = msg.guild!.channels.cache.find((c: any) => c.id === channelID) as TextChannel; |
16 |
|
|
17 |
if (channel) { |
if (channel) { |
18 |
return callback(channel); |
return callback(channel); |
19 |
} |
} |
20 |
} |
} |
21 |
|
|
22 |
channelJoinLeft(callback: (channel: TextChannel) => any, msg: Message | GuildBan) { |
channelJoinLeft(callback: (channel: TextChannel) => any, msg: any) { |
23 |
let channelID = this.client.config.props[msg.guild!.id].logging_channel_join_leave; |
let channelID = this.client.config.props[msg.guild!.id].logging_channel_join_leave; |
24 |
let channel = msg.guild!.channels.cache.find(c => c.id === channelID) as TextChannel; |
let channel = msg.guild!.channels.cache.find((c: any) => c.id === channelID) as TextChannel; |
25 |
|
|
26 |
if (channel) { |
if (channel) { |
27 |
return callback(channel); |
return callback(channel); |
65 |
text: "Deleted", |
text: "Deleted", |
66 |
}) |
}) |
67 |
.setTimestamp(); |
.setTimestamp(); |
68 |
|
|
69 |
|
const files: FileOptions[] = []; |
70 |
|
|
71 |
if (msg.attachments.size > 0) { |
if (msg.attachments.size > 0) { |
72 |
let str = ''; |
let str = ''; |
73 |
|
|
74 |
msg.attachments.forEach(a => { |
msg.attachments.forEach(a => { |
75 |
str += `**${a.name}** ${a.url}\n`; |
str += `${a.name}\n`; |
76 |
|
files.push({ |
77 |
|
name: a.name!, |
78 |
|
attachment: a.proxyURL |
79 |
|
}); |
80 |
}); |
}); |
81 |
|
|
82 |
embed.addField('Attachments', str); |
embed.addField('Attachments (top)', str); |
83 |
} |
} |
84 |
|
|
85 |
await channel.send({ |
await channel.send({ |
86 |
embeds: [ |
embeds: [ |
87 |
embed |
embed |
88 |
] |
], |
89 |
|
files |
90 |
}); |
}); |
91 |
}, msg); |
}, msg); |
92 |
} |
} |
95 |
this.channel(async (channel) => { |
this.channel(async (channel) => { |
96 |
let r = '*No reason provided*'; |
let r = '*No reason provided*'; |
97 |
|
|
98 |
|
const auditLog = (await ban.guild.fetchAuditLogs({ |
99 |
|
limit: 1, |
100 |
|
type: 'MEMBER_BAN_ADD', |
101 |
|
})).entries.first(); |
102 |
|
|
103 |
|
|
104 |
if (ban.reason) { |
if (ban.reason) { |
105 |
r = ban.reason; |
r = ban.reason; |
106 |
} |
} |
107 |
|
else if (auditLog) { |
108 |
|
console.log(auditLog); |
109 |
|
const { target, reason } = await auditLog; |
110 |
|
|
111 |
|
if (target!.id === ban.user.id && reason) { |
112 |
|
r = await reason; |
113 |
|
} |
114 |
|
} |
115 |
|
|
116 |
await channel.send({ |
await channel.send({ |
117 |
embeds: [ |
embeds: [ |
274 |
}, member); |
}, member); |
275 |
} |
} |
276 |
|
|
277 |
logWarn(msg: Message, member: GuildMember | User, d: User, reason: string, id: number | string) { |
logWarn(msg: Message | CommandInteraction, member: GuildMember | User, d: User, reason: string | undefined, id: number | string) { |
278 |
if ((member as GuildMember).user) |
if ((member as GuildMember).user) |
279 |
member = (member as GuildMember).user; |
member = (member as GuildMember).user; |
280 |
|
|
288 |
name: (member as User).tag, |
name: (member as User).tag, |
289 |
iconURL: member.displayAvatarURL(), |
iconURL: member.displayAvatarURL(), |
290 |
}) |
}) |
291 |
.addField('Reason', reason) |
.addField('Reason', reason ?? '*No reason provided*') |
292 |
.addField('Warned by', d.tag) |
.addField('Warned by', d.tag) |
293 |
.addField('User ID', member.id) |
.addField('User ID', member.id) |
294 |
.addField('Warning ID', id + '') |
.addField('Case ID', id + '') |
295 |
.setFooter({ |
.setFooter({ |
296 |
text: "Warned", |
text: "Warned", |
297 |
}) |
}) |