aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord.js
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-10-12 20:27:37 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-10-12 20:27:37 -0400
commitba2d7b7db0a627234ed08de9d6bec8cb675404a7 (patch)
tree9ade9ed549b52eac3f2966a5cee5478267eca7c4 /src/lib/extensions/discord.js
parentcac6abf3efd563b83f8f0ce70ce4bcfa5ada1a27 (diff)
downloadtanzanite-ba2d7b7db0a627234ed08de9d6bec8cb675404a7.tar.gz
tanzanite-ba2d7b7db0a627234ed08de9d6bec8cb675404a7.tar.bz2
tanzanite-ba2d7b7db0a627234ed08de9d6bec8cb675404a7.zip
revamp automod, refactoring, fixes
Diffstat (limited to 'src/lib/extensions/discord.js')
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts22
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts25
2 files changed, 30 insertions, 17 deletions
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts
index 256b9dc..3a2ae51 100644
--- a/src/lib/extensions/discord.js/BushGuild.ts
+++ b/src/lib/extensions/discord.js/BushGuild.ts
@@ -1,5 +1,6 @@
-import { Guild, UserResolvable } from 'discord.js';
+import { Guild, MessageOptions, UserResolvable } from 'discord.js';
import { RawGuildData } from 'discord.js/typings/rawDataTypes';
+import { Moderation } from '../../common/moderation';
import { Guild as GuildDB, GuildFeatures, GuildLogType, GuildModel } from '../../models/Guild';
import { ModLogType } from '../../models/ModLog';
import { BushClient, BushUserResolvable } from '../discord-akairo/BushClient';
@@ -96,7 +97,7 @@ export class BushGuild extends Guild {
if (!banSuccess) return 'error banning';
// add modlog entry
- const { log: modlog } = await util.createModLogEntry({
+ const { log: modlog } = await Moderation.createModLogEntry({
type: options.duration ? ModLogType.TEMP_BAN : ModLogType.PERM_BAN,
user: user,
moderator: moderator.id,
@@ -108,7 +109,7 @@ export class BushGuild extends Guild {
caseID = modlog.id;
// add punishment entry so they can be unbanned later
- const punishmentEntrySuccess = await util.createPunishmentEntry({
+ const punishmentEntrySuccess = await Moderation.createPunishmentEntry({
type: 'ban',
user: user,
guild: this,
@@ -161,7 +162,7 @@ export class BushGuild extends Guild {
if (!unbanSuccess) return 'error unbanning';
// add modlog entry
- const { log: modlog } = await util.createModLogEntry({
+ const { log: modlog } = await Moderation.createModLogEntry({
type: ModLogType.UNBAN,
user: user.id,
moderator: moderator.id,
@@ -172,7 +173,7 @@ export class BushGuild extends Guild {
caseID = modlog.id;
// remove punishment entry
- const removePunishmentEntrySuccess = await util.removePunishmentEntry({
+ const removePunishmentEntrySuccess = await Moderation.removePunishmentEntry({
type: 'ban',
user: user.id,
guild: this
@@ -192,4 +193,15 @@ export class BushGuild extends Guild {
client.emit('bushUnban', user, moderator, this, options.reason ?? undefined, caseID!, dmSuccessEvent!);
return ret;
}
+
+ /**
+ * Sends a message to the guild's specified logging channel.
+ */
+ public async sendLogChannel(logType: GuildLogType, message: MessageOptions) {
+ const logChannel = await this.getLogChannel(logType);
+ if (!logChannel || logChannel.type !== 'GUILD_TEXT') return;
+ if (!logChannel.permissionsFor(this.me!.id)?.has(['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'])) return;
+
+ return await logChannel.send(message).catch(() => null);
+ }
}
diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts
index 8e855f7..b4c136c 100644
--- a/src/lib/extensions/discord.js/BushGuildMember.ts
+++ b/src/lib/extensions/discord.js/BushGuildMember.ts
@@ -1,5 +1,6 @@
import { GuildMember, MessageEmbed, Partialize, Role } from 'discord.js';
import { RawGuildMemberData } from 'discord.js/typings/rawDataTypes';
+import { Moderation } from '../../common/moderation';
import { ModLogType } from '../../models/ModLog';
import { BushClient } from '../discord-akairo/BushClient';
import { BushGuild } from './BushGuild';
@@ -111,7 +112,7 @@ export class BushGuildMember extends GuildMember {
const ret = await (async () => {
// add modlog entry
- const result = await util.createModLogEntry(
+ const result = await Moderation.createModLogEntry(
{
type: ModLogType.WARN,
user: this,
@@ -145,7 +146,7 @@ export class BushGuildMember extends GuildMember {
const ret = await (async () => {
if (options.addToModlog || options.duration) {
- const { log: modlog } = await util.createModLogEntry({
+ const { log: modlog } = await Moderation.createModLogEntry({
type: options.duration ? ModLogType.TEMP_PUNISHMENT_ROLE : ModLogType.PERM_PUNISHMENT_ROLE,
guild: this.guild,
moderator: moderator.id,
@@ -158,7 +159,7 @@ export class BushGuildMember extends GuildMember {
caseID = modlog.id;
if (options.addToModlog || options.duration) {
- const punishmentEntrySuccess = await util.createPunishmentEntry({
+ const punishmentEntrySuccess = await Moderation.createPunishmentEntry({
type: 'role',
user: this,
guild: this.guild,
@@ -198,7 +199,7 @@ export class BushGuildMember extends GuildMember {
const ret = await (async () => {
if (options.addToModlog) {
- const { log: modlog } = await util.createModLogEntry({
+ const { log: modlog } = await Moderation.createModLogEntry({
type: ModLogType.REMOVE_PUNISHMENT_ROLE,
guild: this.guild,
moderator: moderator.id,
@@ -209,7 +210,7 @@ export class BushGuildMember extends GuildMember {
if (!modlog) return 'error creating modlog entry';
caseID = modlog.id;
- const punishmentEntrySuccess = await util.removePunishmentEntry({
+ const punishmentEntrySuccess = await Moderation.removePunishmentEntry({
type: 'role',
user: this,
guild: this.guild,
@@ -281,7 +282,7 @@ export class BushGuildMember extends GuildMember {
if (!muteSuccess) return 'error giving mute role';
// add modlog entry
- const { log: modlog } = await util.createModLogEntry({
+ const { log: modlog } = await Moderation.createModLogEntry({
type: options.duration ? ModLogType.TEMP_MUTE : ModLogType.PERM_MUTE,
user: this,
moderator: moderator.id,
@@ -294,7 +295,7 @@ export class BushGuildMember extends GuildMember {
caseID = modlog.id;
// add punishment entry so they can be unmuted later
- const punishmentEntrySuccess = await util.createPunishmentEntry({
+ const punishmentEntrySuccess = await Moderation.createPunishmentEntry({
type: 'mute',
user: this,
guild: this.guild,
@@ -351,7 +352,7 @@ export class BushGuildMember extends GuildMember {
if (!muteSuccess) return 'error removing mute role';
//remove modlog entry
- const { log: modlog } = await util.createModLogEntry({
+ const { log: modlog } = await Moderation.createModLogEntry({
type: ModLogType.UNMUTE,
user: this,
moderator: moderator.id,
@@ -363,7 +364,7 @@ export class BushGuildMember extends GuildMember {
caseID = modlog.id;
// remove mute entry
- const removePunishmentEntrySuccess = await util.removePunishmentEntry({
+ const removePunishmentEntrySuccess = await Moderation.removePunishmentEntry({
type: 'mute',
user: this,
guild: this.guild
@@ -402,7 +403,7 @@ export class BushGuildMember extends GuildMember {
if (!kickSuccess) return 'error kicking';
// add modlog entry
- const { log: modlog } = await util.createModLogEntry({
+ const { log: modlog } = await Moderation.createModLogEntry({
type: ModLogType.KICK,
user: this,
moderator: moderator.id,
@@ -439,7 +440,7 @@ export class BushGuildMember extends GuildMember {
if (!banSuccess) return 'error banning';
// add modlog entry
- const { log: modlog } = await util.createModLogEntry({
+ const { log: modlog } = await Moderation.createModLogEntry({
type: options.duration ? ModLogType.TEMP_BAN : ModLogType.PERM_BAN,
user: this,
moderator: moderator.id,
@@ -451,7 +452,7 @@ export class BushGuildMember extends GuildMember {
caseID = modlog.id;
// add punishment entry so they can be unbanned later
- const punishmentEntrySuccess = await util.createPunishmentEntry({
+ const punishmentEntrySuccess = await Moderation.createPunishmentEntry({
type: 'ban',
user: this,
guild: this.guild,