-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from aternosorg/log
Split message and moderation logs
- Loading branch information
Showing
10 changed files
with
201 additions
and
66 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const Command = require('../../Command'); | ||
const util = require('../../util.js'); | ||
const Discord = require('discord.js'); | ||
|
||
class LogChannelCommand extends Command { | ||
|
||
static description = 'Configure the channel that moderations will be logged in'; | ||
|
||
static usage = '<#channel|id>|off|status'; | ||
|
||
static names = ['log','logchannel']; | ||
|
||
static userPerms = ['MANAGE_GUILD']; | ||
|
||
async execute() { | ||
if (this.args.length !== 1) { | ||
await this.sendUsage(); | ||
return; | ||
} | ||
|
||
switch (this.args[0].toLowerCase()) { | ||
case "off": | ||
this.guildConfig.logChannel = null; | ||
await this.guildConfig.save(); | ||
await this.message.channel.send(new Discord.MessageEmbed() | ||
.setDescription("Disabled moderation logs") | ||
.setFooter("You can configure message logs with the 'messagelogs' command.") | ||
.setColor(util.color.red) | ||
); | ||
break; | ||
case "status": | ||
await this.message.channel.send(new Discord.MessageEmbed() | ||
.setDescription(`Moderations are currently ${this.guildConfig.logChannel ? `logged to <#${this.guildConfig.logChannel}>` : | ||
`not logged.\n Use \`${this.prefix}log ${LogChannelCommand.usage}\` to change this`}.`) | ||
.setFooter(`You can configure message logs with ${this.prefix}messagelogs`) | ||
.setColor(this.guildConfig.logChannel ? util.color.green : util.color.red) | ||
); | ||
break; | ||
default: | ||
const channel = util.channelMentionToId(this.args[0]); | ||
if (channel === null || !await util.isChannel(this.message.guild, channel)) return this.sendUsage(); | ||
if (!this.message.guild.channels.resolve(/** @type {Snowflake} */channel).permissionsFor(this.bot.user).has(['SEND_MESSAGES', 'VIEW_CHANNEL'])){ | ||
return this.message.channel.send('I am missing the required permissions to send messages to that channel!'); | ||
} | ||
|
||
this.guildConfig.logChannel = channel; | ||
await this.guildConfig.save(); | ||
await this.message.channel.send(new Discord.MessageEmbed() | ||
.setDescription(`Set moderation log channel to <#${channel}>.`) | ||
.setFooter("You can configure message logs with the 'messagelogs' command.") | ||
.setColor(util.color.green) | ||
); | ||
} | ||
} | ||
} | ||
|
||
module.exports = LogChannelCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const Command = require('../../Command'); | ||
const util = require('../../util.js'); | ||
const Discord = require('discord.js'); | ||
|
||
class MessageLogChannelCommand extends Command { | ||
|
||
static description = 'Configure the channel that messages will be logged in'; | ||
|
||
static usage = '<#channel|id>|off|status'; | ||
|
||
static names = ['messagelog','messagelogchannel']; | ||
|
||
static userPerms = ['MANAGE_GUILD']; | ||
|
||
async execute() { | ||
if (this.args.length !== 1) { | ||
await this.sendUsage(); | ||
return; | ||
} | ||
|
||
switch (this.args[0].toLowerCase()) { | ||
case "off": | ||
this.guildConfig.messageLogChannel = null; | ||
await this.guildConfig.save(); | ||
await this.message.channel.send(new Discord.MessageEmbed() | ||
.setDescription("Disabled message logs") | ||
.setColor(util.color.red) | ||
); | ||
break; | ||
case "status": | ||
await this.message.channel.send(new Discord.MessageEmbed() | ||
.setDescription(`Messages are currently ${this.guildConfig.messageLogChannel ? `logged to <#${this.guildConfig.messageLogChannel}>` : | ||
`not logged.\n Use \`${this.prefix}messagelog ${MessageLogChannelCommand.usage}\` to change this`}.`) | ||
.setColor(this.guildConfig.messageLogChannel ? util.color.green : util.color.red) | ||
); | ||
break; | ||
default: | ||
const channel = util.channelMentionToId(this.args[0]); | ||
if (channel === null || !await util.isChannel(this.message.guild, channel)) return this.sendUsage(); | ||
if (!this.message.guild.channels.resolve(/** @type {Snowflake} */channel).permissionsFor(this.bot.user).has(['SEND_MESSAGES', 'VIEW_CHANNEL'])){ | ||
return this.message.channel.send('I am missing the required permissions to send messages to that channel!'); | ||
} | ||
|
||
this.guildConfig.messageLogChannel = channel; | ||
await this.guildConfig.save(); | ||
await this.message.channel.send(new Discord.MessageEmbed() | ||
.setDescription(`Set message log channel to <#${channel}>.`) | ||
.setColor(util.color.green) | ||
); | ||
} | ||
} | ||
} | ||
|
||
module.exports = MessageLogChannelCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const Database = require('../src/Database'); | ||
const config = require('../config.json'); | ||
const database = new Database(config.db); | ||
const GuildConfig = require('../src/GuildConfig'); | ||
|
||
async function update() { | ||
console.log('Starting update to v0.4.0'); | ||
|
||
console.log('Updating guild log channels') | ||
await database.waitForConnection(); | ||
const guilds = await database.queryAll('SELECT id, config FROM guilds'); | ||
let updated = 0; | ||
|
||
for (const guild of guilds) { | ||
const gc = new GuildConfig(guild.id, guild.config); | ||
if (gc.logChannel) { | ||
gc.messageLogChannel = gc.logChannel; | ||
await gc.save(); | ||
updated ++; | ||
} | ||
} | ||
|
||
console.log(`Done! Added message log to ${updated} of ${guilds.length} guilds!`); | ||
|
||
process.exit(0); | ||
} | ||
|
||
update().catch(e => { | ||
console.error(e); | ||
process.exit(1); | ||
}); |