Some channel logging (W.I.P)
Signed-off-by: loicbersier <loic.bersier1@gmail.com>
This commit is contained in:
parent
b8105f2f1d
commit
320ac3a3f0
6 changed files with 195 additions and 0 deletions
50
commands/admin/log.js
Normal file
50
commands/admin/log.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
const { Command } = require('discord-akairo');
|
||||
const LogStats = require('../../models').LogStats;
|
||||
|
||||
class logCommand extends Command {
|
||||
constructor() {
|
||||
super('log', {
|
||||
aliases: ['log', 'logging'],
|
||||
category: 'admin',
|
||||
userPermissions: ['MANAGE_MESSAGES'],
|
||||
channel: 'guild',
|
||||
description: {
|
||||
content: 'Setup logging in current channel (W.I.P)',
|
||||
usage: '',
|
||||
examples: ['']
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async exec(message, args) {
|
||||
const logStats = await LogStats.findOne({where: {guild: message.guild.id}});
|
||||
const ownerID = this.client.ownerID;
|
||||
|
||||
if (!logStats) {
|
||||
const body = {guild: message.guild.id, channel: message.channel.id};
|
||||
await LogStats.create(body);
|
||||
return message.channel.send('Logging has been enabled on this channel');
|
||||
} else if (logStats.get('ownerID') == message.author.id || message.member.hasPermission('ADMINISTRATOR') || message.author.id == ownerID) {
|
||||
message.channel.send('The log channel is already setup, do you want to delete it? y/n');
|
||||
const filter = m => m.content && m.author.id == message.author.id;
|
||||
message.channel.awaitMessages(filter, {time: 5000, max: 1, errors: ['time'] })
|
||||
.then(async messages => {
|
||||
let messageContent = messages.map(messages => messages.content.toLowerCase());
|
||||
if (messageContent == 'y' || messageContent == 'yes') {
|
||||
await LogStats.destroy({where: {guild: message.guild.id}});
|
||||
return message.channel.send('Log channel has been disabled!');
|
||||
} else {
|
||||
return message.channel.send('Not updating.');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return message.channel.send('Took too long to answer. didin\'t change anything.');
|
||||
});
|
||||
} else {
|
||||
return message.channel.send(`You are not the owner of this tag, if you think it is problematic ask an admin to remove it by doing ${this.client.commandHandler.prefix[0]}tag ${args.trigger} --remove`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = logCommand;
|
27
event/listeners/log/channelCreate.js
Normal file
27
event/listeners/log/channelCreate.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
const { Listener } = require('discord-akairo');
|
||||
const LogStats = require('../../../models/').LogStats;
|
||||
|
||||
class channelCreateListener extends Listener {
|
||||
constructor() {
|
||||
super('channelCreate', {
|
||||
emitter: 'client',
|
||||
event: 'channelCreate'
|
||||
});
|
||||
}
|
||||
|
||||
async exec(GuildChannel) {
|
||||
const logStats = await LogStats.findOne({where: {guild: GuildChannel.guild.id}});
|
||||
if (logStats) {
|
||||
const channel = this.client.channels.resolve(await logStats.get('channel'));
|
||||
let Embed = this.client.util.embed()
|
||||
.setColor('NAVY')
|
||||
.setTitle('Channel created!')
|
||||
.setDescription(`${GuildChannel.type} channel ${GuildChannel} got created!`)
|
||||
.setFooter(`Channel ID: ${GuildChannel.id}`)
|
||||
.setTimestamp();
|
||||
|
||||
channel.send(Embed);
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = channelCreateListener;
|
27
event/listeners/log/channelDelete.js
Normal file
27
event/listeners/log/channelDelete.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
const { Listener } = require('discord-akairo');
|
||||
const LogStats = require('../../../models/').LogStats;
|
||||
|
||||
class channelDeleteListener extends Listener {
|
||||
constructor() {
|
||||
super('channelDelete', {
|
||||
emitter: 'client',
|
||||
event: 'channelDelete'
|
||||
});
|
||||
}
|
||||
|
||||
async exec(GuildChannel) {
|
||||
const logStats = await LogStats.findOne({where: {guild: GuildChannel.guild.id}});
|
||||
if (logStats) {
|
||||
console.log(GuildChannel);
|
||||
const channel = this.client.channels.resolve(await logStats.get('channel'));
|
||||
let Embed = this.client.util.embed()
|
||||
.setColor('NAVY')
|
||||
.setTitle('Channel created!')
|
||||
.setDescription(`${GuildChannel.type} channel ${GuildChannel.name} got deleted!`)
|
||||
.setTimestamp();
|
||||
|
||||
channel.send(Embed);
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = channelDeleteListener;
|
50
event/listeners/log/channelUpdate.js
Normal file
50
event/listeners/log/channelUpdate.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
const { Listener } = require('discord-akairo');
|
||||
const LogStats = require('../../../models/').LogStats;
|
||||
|
||||
class channelUpdateListener extends Listener {
|
||||
constructor() {
|
||||
super('channelUpdate', {
|
||||
emitter: 'client',
|
||||
event: 'channelUpdate'
|
||||
});
|
||||
}
|
||||
|
||||
async exec(oldChannel, newChannel) {
|
||||
const logStats = await LogStats.findOne({where: {guild: newChannel.guild.id}});
|
||||
|
||||
if (logStats) {
|
||||
const channel = this.client.channels.resolve(await logStats.get('channel'));
|
||||
let Embed = this.client.util.embed()
|
||||
.setColor('NAVY')
|
||||
.setTitle(`${newChannel.type} channel updated!`)
|
||||
.setTimestamp();
|
||||
|
||||
if (oldChannel.name !== newChannel.name) {
|
||||
Embed.addField('', '')
|
||||
.addField('Previous channel', oldChannel.name, true)
|
||||
.addField('New channel', newChannel.name, true);
|
||||
}
|
||||
|
||||
if (oldChannel.topic !== newChannel.topic) {
|
||||
Embed.addField('', '')
|
||||
.addField('Previous channel topic', oldChannel.topic, true)
|
||||
.addField('New channel topic', newChannel.topic, true);
|
||||
}
|
||||
|
||||
if (oldChannel.nsfw !== newChannel.nsfw) {
|
||||
Embed.addField('', '')
|
||||
.addField('Previous channel nsfw', oldChannel.nsfw, true)
|
||||
.addField('New channel nsfw', newChannel.nsfw, true);
|
||||
}
|
||||
|
||||
if (oldChannel.rateLimitPerUser !== newChannel.rateLimitPerUser) {
|
||||
Embed.addField('', '')
|
||||
.addField('Previous channel slowmode', `${oldChannel.rateLimitPerUser} seconds`, true)
|
||||
.addField('New channel slowmode', `${newChannel.rateLimitPerUser} seconds`, true);
|
||||
}
|
||||
|
||||
channel.send(Embed);
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = channelUpdateListener;
|
30
migrations/20200430005935-create-log-stats.js
Normal file
30
migrations/20200430005935-create-log-stats.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('LogStats', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
guild: {
|
||||
type: Sequelize.BIGINT
|
||||
},
|
||||
channel: {
|
||||
type: Sequelize.BIGINT
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('LogStats');
|
||||
}
|
||||
};
|
11
models/logstats.js
Normal file
11
models/logstats.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const LogStats = sequelize.define('LogStats', {
|
||||
guild: DataTypes.BIGINT,
|
||||
channel: DataTypes.BIGINT
|
||||
}, {});
|
||||
LogStats.associate = function(models) {
|
||||
// associations can be defined here
|
||||
};
|
||||
return LogStats;
|
||||
};
|
Loading…
Reference in a new issue