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

Cleanup + improvements #1

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
Prev Previous commit
Next Next commit
...
  • Loading branch information
Elara-Discord-Bots committed Apr 15, 2024
commit 371f8fd3dcc01e2b751020e1166aadfda58e4c85
14 changes: 7 additions & 7 deletions src/bot/commands/eval.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
const util = require('util')
const { inspect } = require('util')

module.exports = {
func: async (message, suffix) => {
try { // This eval command is from https://github.com/TheSharks/WildBeast/ because I really like their method
const returned = eval(suffix)
let str = util.inspect(returned, {
let str = inspect(returned, {
depth: 1
})
if (str.length > 1900) {
str = `${str.substr(0, 1897)}...`
str = `${str.substring(0, 1897)}...`
}
str = str.replace(new RegExp(process.env.BOT_TOKEN, 'gi'), '( ͡° ͜ʖ ͡°)')
message.channel.createMessage('```xl\n' + str + '\n```').then(ms => {
if (returned !== undefined && returned !== null && typeof returned.then === 'function') {
returned.then(() => {
str = util.inspect(returned, {
str = inspect(returned, {
depth: 1
})
if (str.length > 1900) {
str = str.substr(0, 1897)
str = str.substring(0, 1897)
str = str + '...'
}
ms.edit('```xl\n' + str + '\n```')
}, e => {
str = util.inspect(e, {
str = inspect(e, {
depth: 1
})
if (str.length > 1900) {
str = str.substr(0, 1897)
str = str.substring(0, 1897)
str = str + '...'
}
ms.edit('```xl\n' + str + '\n```')
Expand Down
3 changes: 1 addition & 2 deletions src/bot/commands/logbots.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module.exports = {
author: {
name: displayUser(message.author),
icon_url: message.author.avatarURL
},
fields: []
}
}]
})
},
Expand Down
10 changes: 1 addition & 9 deletions src/bot/events/channelCreate.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
const send = require('../modules/webhooksender')
const { displayUser } = require('../utils/constants')
const CHANNEL_TYPE_MAP = {
0: 'Text channel',
2: 'Voice channel',
4: 'Category channel',
5: 'Announcement channel',
13: 'Stage channel',
15: 'Forum channel'
}
const { displayUser, CHANNEL_TYPE_MAP } = require('../utils/constants')

module.exports = {
name: 'channelCreate',
Expand Down
11 changes: 1 addition & 10 deletions src/bot/events/channelDelete.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
const send = require('../modules/webhooksender')
const { displayUser } = require('../utils/constants')
const CHANNEL_TYPE_MAP = {
0: 'Text channel',
2: 'Voice channel',
4: 'Category',
5: 'Announcement',
13: 'Stage Channel',
15: 'Forum channel'
}

const { displayUser, CHANNEL_TYPE_MAP } = require('../utils/constants')
module.exports = {
name: 'channelDelete',
type: 'on',
Expand Down
12 changes: 2 additions & 10 deletions src/bot/events/channelUpdate.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
const send = require('../modules/webhooksender')
const escape = require('markdown-escape')
const { displayUser } = require('../utils/constants')
const CHANNEL_TYPE_MAP = {
0: 'Text channel',
2: 'Voice channel',
4: 'Category channel',
5: 'Announcement channel',
13: 'Stage channel',
15: 'Forum channel'
}
const { displayUser, CHANNEL_TYPE_MAP } = require('../utils/constants')

const canUseExternal = guild => {
const logChannelID = global.bot.guildSettingsCache[guild.id].event_logs.channelUpdate
Expand Down Expand Up @@ -220,7 +212,7 @@ module.exports = {
}

function toTitleCase (str) {
return str.replace(/_/g, ' ').replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase() })
return str.replace(/_/g, ' ').replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase() })
}

function getDifference (array1, array2) {
Expand Down
2 changes: 1 addition & 1 deletion src/bot/events/guildRoleUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function intToHex (num) {
}

function toTitleCase (str) {
return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase() })
return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase() })
}

function rgbToHex (r, g, b) { // bitwise math is black magic
Expand Down
2 changes: 1 addition & 1 deletion src/bot/modules/commandhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = async message => {
if (message.author.bot || !message.member || message.channel instanceof Eris.TextVoiceChannel) return
if (message.content.startsWith(process.env.GLOBAL_BOT_PREFIX)) {
const cmd = message.content.substring(process.env.GLOBAL_BOT_PREFIX.length).split(' ')[0].toLowerCase()
const splitSuffix = message.content.substr(process.env.GLOBAL_BOT_PREFIX).split(' ')
const splitSuffix = message.content.substring(process.env.GLOBAL_BOT_PREFIX).split(' ')
const suffix = splitSuffix.slice(1, splitSuffix.length).join(' ')
processCommand(message, cmd, suffix)
}
Expand Down
20 changes: 19 additions & 1 deletion src/bot/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,22 @@ exports.chunkify = (toChunk, maxCharacters = 1000) => {
* @param {import("eris").Member | import("eris").User}) user
* @returns {string}
*/
exports.displayUser = (user) => `${user.username}${user.discriminator !== "0" ? `#${user.discriminator}` : ""}`;
exports.displayUser = (user) => `${user.username}${user.discriminator !== "0" ? `#${user.discriminator}` : ""}`;

// All channel types from: https://discord.com/developers/docs/resources/channel#channel-object-channel-types
// Used for the channel* events.
exports.CHANNEL_TYPE_MAP = {
0: 'Text channel',
1: 'DM channel',
2: 'Voice channel',
3: 'Group DM channel',
4: 'Category channel',
5: 'Announcement channel',
10: 'Announcement thread channel',
11: 'Public Thread channel',
12: 'Private Thread channel',
13: 'Stage channel',
14: 'Directory channel',
15: 'Forum channel',
16: 'Media channel'
}