Skip to content

Commit

Permalink
Merge pull request #542 from aternosorg/bw-dm
Browse files Browse the repository at this point in the history
fix bad words using the dm punishment
  • Loading branch information
JulianVennen authored Nov 24, 2022
2 parents d77160c + a40b801 commit ee5d726
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 72 deletions.
69 changes: 1 addition & 68 deletions src/database/BadWord.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ChatTriggeredFeature from './ChatTriggeredFeature.js';
import TypeChecker from '../settings/TypeChecker.js';
import {channelMention} from 'discord.js';
import * as util from 'util';
import Punishment from './Punishment.js';
import {yesNo} from '../util/format.js';
import {EMBED_FIELD_LIMIT} from '../util/apiLimits.js';
Expand Down Expand Up @@ -41,7 +40,7 @@ export default class BadWord extends ChatTriggeredFeature {
if (json) {
this.punishment = typeof (json.punishment) === 'string' ? JSON.parse(json.punishment) : json.punishment;
this.response = json.response;
if (this.punishment && this.punishment.action === 'dm' && this.response && this.response !== 'disabled') {
if (this.punishment?.action?.toUpperCase?.() === 'DM' && this.response && this.response !== 'disabled') {
if (this.response === 'default') {
this.punishment.message = BadWord.defaultResponse;
} else {
Expand Down Expand Up @@ -144,72 +143,6 @@ export default class BadWord extends ChatTriggeredFeature {
await badWord.save();
return {success: true, badWord, message: null};
}

/**
* edit this badword
* @param {String} option option to change
* @param {String[]} args
* @param {Guild} guild
* @returns {Promise<{success: boolean, message: String}>} response message
*/
async edit(option, args, guild) {
switch (option) {
case 'trigger': {
let trigger = this.constructor.getTrigger(args.shift(), args.join(' '));
if (!trigger.success) return {success: false, message:trigger.message};
this.trigger = trigger.trigger;
await this.save();
return {success: true, message:'Successfully changed trigger'};
}

case 'response': {
let response = args.join(' ');
if (!response) response = 'disabled';

this.response = response;
await this.save();
return {success: true, message:`Successfully ${response === 'disabled' ? 'disabled' : 'changed'} response`};
}

case 'punishment': {
let action = args.shift().toLowerCase(),
duration = args.join(' ');
if (!this.constructor.punishmentTypes.includes(action)) return {success: false, message:'Unknown punishment'};
this.punishment = {action, duration};
await this.save();
return {success: true, message:`Successfully ${action === 'none' ? 'disabled' : 'changed'} punishment`};
}

case 'priority': {
let priority = parseInt(args.shift());
if (Number.isNaN(priority)) return {success: false, message:'Invalid priority'};
this.priority = priority;
await this.save();
return {success: true, message:`Successfully changed priority to ${priority}`};
}

case 'channels': {
if (args[0].toLowerCase() === 'global') {
this.global = true;
this.channels = [];
}
else {
// TODO: update
let channels = util.channelMentions(guild, args);
if (!channels) return {success: false, message:'No valid channels specified'};
this.global = false;
this.channels = channels;
}
await this.save();
return {success: true, message: global ? 'Successfully made this badword global' : 'Successfully changed channels'};
}

default: {
return {success: false, message:'Unknown option'};
}
}
}

getOverview() {
return `[${this.id}] ${this.global ? 'global' : this.channels.map(channelMention).join(', ')} ${this.trigger.asString()}`;
}
Expand Down
8 changes: 4 additions & 4 deletions src/database/ChatTriggeredFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export default class ChatTriggeredFeature {
* @returns {Promise<?this>}
*/
static async getByID(id, guildid) {
const result = await database.query(`SELECT *FROM ${this.escapedTableName} WHERE id = ? AND guildid = ?`, id, guildid);
const result = await database.query(`SELECT * FROM ${this.escapedTableName} WHERE id = ? AND guildid = ?`, id, guildid);
if (!result) return null;
return this.fromData(result);
}
Expand Down Expand Up @@ -398,7 +398,7 @@ export default class ChatTriggeredFeature {
*/
static async getAll(guildId) {
const result = await database.queryAll(
`SELECT *FROM ${this.escapedTableName} WHERE guildid = ?`, [guildId]);
`SELECT * FROM ${this.escapedTableName} WHERE guildid = ?`, [guildId]);

const collection = new Collection();
for (const res of result) {
Expand All @@ -415,7 +415,7 @@ export default class ChatTriggeredFeature {
*/
static async refreshGuild(guildId) {
const result = await database.queryAll(
`SELECT *FROM ${this.escapedTableName} WHERE guildid = ?AND global = TRUE`, [guildId]);
`SELECT * FROM ${this.escapedTableName} WHERE guildid = ?AND global = TRUE`, [guildId]);

const newItems = new Collection();
for (const res of result) {
Expand All @@ -434,7 +434,7 @@ export default class ChatTriggeredFeature {
*/
static async refreshChannel(channelId) {
const result = await database.queryAll(
`SELECT *FROM ${this.escapedTableName} WHERE channels LIKE ?`, [`%${channelId}%`]);
`SELECT * FROM ${this.escapedTableName} WHERE channels LIKE ?`, [`%${channelId}%`]);

const newItems = new Collection();
for (const res of result) {
Expand Down

0 comments on commit ee5d726

Please sign in to comment.