Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event cleanup #31

Merged
merged 9 commits into from
Jul 7, 2018
3 changes: 1 addition & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ const config = require('./config.json')
const gotkicked = require('./gotkicked.json')
const joinmessages = require('./joinmessages.json')

// Since the events are moved to seperate files, need to smuggle these in through the config argument
config.colors = {
red: 0x781706,
orange: 0xBA430D,
green: 0x037800
}

// Since the events are moved to seperate files, need to smuggle these in through the config argument
config.gotkicked = gotkicked
config.joinmessages = joinmessages

Expand Down
102 changes: 25 additions & 77 deletions events/message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// message.js

const extra = require('./../modules/extraneous')

var checkusers = {}
var messages = []

Expand Down Expand Up @@ -92,7 +94,7 @@ module.exports = async (config, client, influx, message) => {
.then(connection => {
connection.playFile('./Roblox_Death_Sound_Effect.mp3')
})
await sleep(3000)
await extra.sleep(3000)
console.log('Disconnecting from voice channel')
message.member.voiceChannel.leave()
}
Expand Down Expand Up @@ -133,7 +135,7 @@ module.exports = async (config, client, influx, message) => {
database: 'nixnest'
})
message.channel.send('Setting messages for user')
await sleep(2000)
await extra.sleep(2000)
influx.writePoints([
{
measurement: 'message',
Expand Down Expand Up @@ -278,14 +280,14 @@ module.exports = async (config, client, influx, message) => {
default: {
if (config.plugins.hasOwnProperty(command)) {
if (config.plugins[command].nsfw && !message.channel.nsfw) {
message.channel.send('Tisk tisk, '.join(message.author.username, '. Don\'t be naughty here.'))
message.channel.send('Tisk tisk, '.join(message.author.username), '. Don\'t be naughty here.')
break
}
arg.shift()
arg.shift()
arg.unshift(message.author.id)
var argb = message.content.split(' ')
argb.shift()
argb.unshift(message.author.id)
const { execFile } = require('child_process')
execFile(config.plugins[command].path, arg, (error, stdout, stderr) => {
execFile(config.plugins[command].path, argb, (error, stdout, stderr) => {
if (error) {
throw error
}
Expand All @@ -299,76 +301,22 @@ module.exports = async (config, client, influx, message) => {
}
}
};
if (message.guild.id.toString().includes(config.logserver)) {
var embedFields = fieldGenerator(message.cleanContent, 'Command')
console.log(embedFields)
client.channels.get(config.logchannel).send({embed: {
color: config.colors.green,
author: {
name: message.author.username,
icon_url: message.author.displayAvatarURL
},
url: urlGenerator(message),
title: 'Command ran in #' + message.channel.name,
fields: embedFields,
timestamp: new Date(),
footer: {
icon_url: client.user.displayAvatarURL,
text: 'User ID: ' + message.author.id
}
}})
}
}

const embedLength = 1020

function lengthSplit (message, length) {
var splitCount = Math.floor(message.length / length) + 1
var splits = []

for (var n = 0; n < splitCount; n++) {
splits.push(message.substr(0 + (n * length), length))
}

if (!splits[splits.length - 1]) {
splits.pop()
}
console.log(splits)
return splits
};

function fieldGenerator (message, msgTitle) {
console.log(msgTitle)
console.log(message)
var splits = lengthSplit(message, embedLength)
var fields = []

if (splits.length === 1) {
fields = [{
name: msgTitle,
value: '` ' + splits[0] + ' `'
}]
} else {
for (var n = 0; n < splits.length; n++) {
fields.push({
name: msgTitle + ' (' + n + ')',
value: '` ' + splits[n] + ' `'
})
var embedFields = extra.fieldGenerator(message.cleanContent, 'Command')
console.log(embedFields)
client.channels.get(config.logchannel).send({embed: {
color: config.colors.green,
author: {
name: message.author.username,
icon_url: message.author.displayAvatarURL
},
url: extra.urlGenerator(message),
title: 'Command ran in #' + message.channel.name,
fields: embedFields,
timestamp: new Date(),
footer: {
icon_url: client.user.displayAvatarURL,
text: 'User ID: ' + message.author.id
}
}
console.log(fields)
return fields
};

function urlGenerator (msgObj) {
var url = `https://discordapp.com/channels/${msgObj.guild.id}/${msgObj.channel.id}/${msgObj.id}`
return url
}

async function sleep (ms = 0) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, ms)
})
}})
}
51 changes: 4 additions & 47 deletions events/messageDelete.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// messageDelete.js

const extra = require('./../modules/extraneous')

module.exports = async (config, client, influx, message) => {
var embedFields = fieldGenerator(message.cleanContent, 'Message')
var embedFields = extra.fieldGenerator(message.cleanContent, 'Message')
console.log(embedFields)
client.channels.get(config.logchannel).send({embed: {
color: config.colors.red,
author: {
name: message.author.username,
icon_url: message.author.displayAvatarURL
},
url: urlGenerator(message),
url: extra.urlGenerator(message),
title: 'Message ID#' + message.id + ' deleted in #' + message.channel.name,
description: 'The following message was deleted:',
fields: embedFields,
Expand All @@ -21,48 +23,3 @@ module.exports = async (config, client, influx, message) => {

}})
}

const embedLength = 1020

function lengthSplit (message, length) {
var splitCount = Math.floor(message.length / length) + 1
var splits = []

for (var n = 0; n < splitCount; n++) {
splits.push(message.substr(0 + (n * length), length))
}

if (!splits[splits.length - 1]) {
splits.pop()
}
console.log(splits)
return splits
};

function fieldGenerator (message, msgTitle) {
console.log(msgTitle)
console.log(message)
var splits = lengthSplit(message, embedLength)
var fields = []

if (splits.length === 1) {
fields = [{
name: msgTitle,
value: '` ' + splits[0] + ' `'
}]
} else {
for (var n = 0; n < splits.length; n++) {
fields.push({
name: msgTitle + ' (' + n + ')',
value: '` ' + splits[n] + ' `'
})
}
}
console.log(fields)
return fields
};

function urlGenerator (msgObj) {
var url = `https://discordapp.com/channels/${msgObj.guild.id}/${msgObj.channel.id}/${msgObj.id}`
return url
}
53 changes: 5 additions & 48 deletions events/messageUpdate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// messageUpdate.js

const extra = require('./../modules/extraneous')

module.exports = async (config, client, influx, oldmsg, newmsg) => {
if (oldmsg.cleanContent !== newmsg.cleanContent) {
var oldFields = fieldGenerator(oldmsg.cleanContent, 'Old message')
var newFields = fieldGenerator(newmsg.cleanContent, 'New message')
var oldFields = extra.fieldGenerator(oldmsg.cleanContent, 'Old message')
var newFields = extra.fieldGenerator(newmsg.cleanContent, 'New message')
var embedFields = oldFields.concat(newFields)
console.log(embedFields)
client.channels.get(config.logchannel).send({embed: {
Expand All @@ -12,7 +14,7 @@ module.exports = async (config, client, influx, oldmsg, newmsg) => {
name: newmsg.author.username,
icon_url: newmsg.author.displayAvatarURL
},
url: urlGenerator(newmsg),
url: extra.urlGenerator(newmsg),
title: 'Message ID#' + newmsg.id + ' modified in #' + newmsg.channel.name,
description: 'The following message was modified:',
fields: embedFields,
Expand All @@ -24,48 +26,3 @@ module.exports = async (config, client, influx, oldmsg, newmsg) => {
}})
}
}

const embedLength = 1020

function lengthSplit (message, length) {
var splitCount = Math.floor(message.length / length) + 1
var splits = []

for (var n = 0; n < splitCount; n++) {
splits.push(message.substr(0 + (n * length), length))
}

if (!splits[splits.length - 1]) {
splits.pop()
}
console.log(splits)
return splits
};

function fieldGenerator (message, msgTitle) {
console.log(msgTitle)
console.log(message)
var splits = lengthSplit(message, embedLength)
var fields = []

if (splits.length === 1) {
fields = [{
name: msgTitle,
value: '` ' + splits[0] + ' `'
}]
} else {
for (var n = 0; n < splits.length; n++) {
fields.push({
name: msgTitle + ' (' + n + ')',
value: '` ' + splits[n] + ' `'
})
}
}
console.log(fields)
return fields
};

function urlGenerator (msgObj) {
var url = `https://discordapp.com/channels/${msgObj.guild.id}/${msgObj.channel.id}/${msgObj.id}`
return url
}
5 changes: 5 additions & 0 deletions modules/extraneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ module.exports = {
urlGenerator: (msgObj) => {
var url = `https://discordapp.com/channels/${msgObj.guild.id}/${msgObj.channel.id}/${msgObj.id}`
return url
},
sleep (ms = 0) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms)
})
}
}
3 changes: 2 additions & 1 deletion plugins/remember.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import sys

if len(sys.argv) < 3:
reply = "Missing parameters"
arg = sys.argv[1]
reply = "*<@{}> will remember that*".format(arg)
else:
args = sys.argv
args.pop(0)
Expand Down