Skip to content

Commit

Permalink
Version 2.6 -- Improved Multi-server support
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyWhoCode authored Jul 10, 2021
2 parents 3e698ac + ee385f6 commit b02a33e
Show file tree
Hide file tree
Showing 28 changed files with 1,071 additions and 305 deletions.
7 changes: 0 additions & 7 deletions Commands/ad.js

This file was deleted.

13 changes: 6 additions & 7 deletions Commands/addcategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var categoryEmbed = {
module.exports = {
name: "addcategory",
alises: ["ac", "addc"],
execute(message, args) {
execute(client, message, args) {
var categoryChannel, msgID, category, categoryName = ""
var channelConfirm = false
let guideDB = dbClient.db("skyblockGuide").collection("Guides")
Expand All @@ -34,12 +34,11 @@ module.exports = {
collector.on('collect', async(msg) => {
if (globalFunctions.checkAliases(noAlias, msg.content.trim()) || globalFunctions.checkAliases(cancelAlias, msg.content.trim())){
collector.stop()
message.channel.send("Process canceled.")
return undefined
return message.channel.send("Process canceled.")
//stops process if given no/cancel alias

} else if (channelConfirm) {
categoryTitle = globalFunctions.translateCategoryName(msg.content.trim())
categoryName = globalFunctions.translateCategoryName(msg.content.trim())

collector.stop()
//Stops prompting the user
Expand All @@ -63,18 +62,18 @@ module.exports = {

categoryChannel.send({ embed: categoryEmbed }).then(msg => msgID = msg.id)

let newEntry = globalFunctions.makeNewEntry(categoryEmbed, categoryName, msgID, category)
let newEntry = globalFunctions.makeNewEntry(categoryEmbed, categoryName, msgID, category, message.guild.id)
guideDB.insertOne(newEntry)
//Since Discord.js does not like exitting out of the Message collector after ending it, the same code from lines 98-118 is copied and pasted here.
return message.channel.send("Your category has been created!")

} else if (!channelConfirm) {
if (globalFunctions.checkAliases(sbAlias, msg.content.trim()) == false && globalFunctions.checkAliases(dAlias, msg.content.trim()) == false) return message.channel.send("Incorrect input. Type in a Guide Channel or its corresponding Alias.")
//checks if provided alias does not match list of alises

channelConfirm = true
category = msg.content.trim()
message.channel.send("Enter the name of the new Guide (Category).")
return undefined
return message.channel.send("Enter the name of the new Guide (Category).")
//if a valid alias of the guide channel is given, run this portion of the code
}
})
Expand Down
27 changes: 11 additions & 16 deletions Commands/addsection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {dbClient} = require("../mongodb.js")
const globalFunction = require("../globalfunctions.js")
const globalFunctions = require("../globalfunctions.js")
const {noAlias, cancelAlias} = require("../constants.js")
const globalfunctions = require("../globalfunctions.js")
const entrySchema = {
"name": "_ _",
"value": "_ _"
Expand All @@ -10,7 +9,7 @@ const entrySchema = {
module.exports = {
name: "addsection",
alises: ["as", "adds"],
async execute(message, args) {
async execute(client, message, args) {
var sectionName, categoryName, categoryMsg = ""
let guideCollection = dbClient.db("skyblockGuide").collection("Guides")
var categoryConfirm = false
Expand All @@ -19,12 +18,11 @@ module.exports = {
const filter = msg => msg.author.id === message.author.id && msg.content.length != 0
const collector = message.channel.createMessageCollector(filter, {time: globalFunctions.timeToMS("3m")})

message.channel.send("To cancel the Argument helper, type in `no` or `cancel`. Enter the Guide Category to add a new section.")
message.channel.send("To cancel the Argument helper, type in `no` or `cancel`. Enter the Guide Category (the Bold title at the top of the Guide message) to add a new section.")
collector.on('collect', async(msg) => {
if (globalFunctions.checkAliases(noAlias, msg.content.trim()) || globalFunctions.checkAliases(cancelAlias, msg.content.trim())){
collector.stop()
message.channel.send("Process canceled.")
return undefined
return message.channel.send("Process canceled.")
//stops process if given no/cancel alias

} else if (categoryConfirm) {
Expand All @@ -35,7 +33,6 @@ module.exports = {

let msgEmbed = categoryMsg[0].embedMessage
msgEmbed.timestamp = new Date()
// include edge case here to remove default value

var newEntry = Object.create(entrySchema)
newEntry.name = sectionName
Expand All @@ -49,23 +46,21 @@ module.exports = {
channelName === "Skyblock" ? guideChannel = message.guild.channels.cache.find(ch => ch.name === "skyblock-guide") : guideChannel = message.guild.channels.cache.find(ch => ch.name === "dungeons-guide-n-tips")
if (categoryMsg[0].category === "resource") guideChannel = message.guild.channels.cache.find(ch => ch.name === "skyblock-resources")

guideChannel.messages.fetch({around: categoryMsg[0].messageID, limit: 1})
guideChannel.messages.fetch({around: categoryMsg[0].messageID[message.guild.id], limit: 1})
.then(msg => {
msg.first().edit({embed: msgEmbed})
})

return message.channel.send("Your section has been added!")
//Since Discord.js does not like exitting out of the Message collector after ending it, the same code from lines 95-112 is copied and pasted here.

} else if (!categoryConfirm) {

categoryMsg = await guideCollection.find({"categoryTitle": { $regex: new RegExp(globalfunctions.translateCategoryName(msg.content.trim()), "i") } }).toArray()
categoryMsg = await guideCollection.find({"categoryTitle": { $regex: new RegExp(globalFunctions.translateCategoryName(msg.content.trim()), "i") } }).toArray()
if (categoryMsg[0] == undefined || categoryMsg.length > 1) return message.channel.send("The Category Name provided did not match anything, please enter another one.")

categoryConfirm = true
categoryName = msg.content.trim()
message.channel.send("Enter the name of the new Guide Section.")
return undefined
return message.channel.send("Enter the name of the new Guide Section.")
//if a valid alias of the guide channel is given, run this portion of the code
}
})
Expand All @@ -77,13 +72,13 @@ module.exports = {


else {
if (args[0] == undefined || sectionName.length == 0) return message.channel.send("See `g!addsection <Category-Name> <Section Name>`")
if (args[0] == undefined) return message.channel.send("See `g!addsection <Category-Name> <Section Name>`")
//checks if there is any bad input

categoryName = globalFunction.translateCategoryName(args[0])
categoryName = globalFunctions.translateCategoryName(args[0])
sectionName = args.slice(1, args.length).join(" ").trim()
categoryMsg = await guideCollection.find({"categoryTitle": { $regex: new RegExp(categoryName, "i") } }).toArray()
if (categoryMsg[0] == undefined || categoryMsg.length > 1) return message.channel.send("The Category Name provided did not match anything. Did you make sure to include hyphens?")
if (categoryMsg[0] == undefined || categoryMsg.length > 1) return message.channel.send("The Category Name provided did not match anything. Remember to separate Category titles with more than 2 words with hyphens.")
//If the provided category does not exist in the database, give the user an error saying so.
}
//**Default command.** Format: g!as <Category-Name> <Section-Name>
Expand All @@ -105,7 +100,7 @@ module.exports = {
channelName === "Skyblock" ? guideChannel = message.guild.channels.cache.find(ch => ch.name === "skyblock-guide") : guideChannel = message.guild.channels.cache.find(ch => ch.name === "dungeons-guide-n-tips")
if (categoryMsg[0].category === "resource") guideChannel = message.guild.channels.cache.find(ch => ch.name === "skyblock-resources")

guideChannel.messages.fetch({around: categoryMsg[0].messageID, limit: 1})
guideChannel.messages.fetch({around: categoryMsg[0].messageID[message.guild.id], limit: 1})
.then(msg => {
msg.first().edit({embed: msgEmbed})
})
Expand Down
23 changes: 14 additions & 9 deletions Commands/approve.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const {dbClient} = require("../mongodb.js")
const globalFunctions = require("../globalfunctions.js")
const {noAlias, cancelAlias} = require("../constants.js")
const post = require("../post.js")
const capitalizeString = str => {
return str[0].toUpperCase() + str.substring(1)
}


module.exports = {
name: 'approve',
alises: ["a"],
async execute(message, args) {
async execute(client, message, args) {
var messageID, categoryTitle, sectionTitle, suggestion, categoryMsg, embedMessage = ""
let suggestionDB = dbClient.db("skyblockGuide").collection("suggestions")
let guidesDB = dbClient.db("skyblockGuide").collection("Guides")
Expand Down Expand Up @@ -43,14 +43,15 @@ module.exports = {
//returns an error if the provided Section Name did not match anything in the Guide message
sectionTitle = globalFunctions.translateCategoryName(msg.content.trim())

collector.stop()
//Stops prompting the user

if (suggestion[0].section != categoryMsg[0].category || capitalizeString(suggestion[0].section) != categoryMsg[0].category) return message.channel.send("The suggestion that you have tried to approve does not match with the category's guide. Make sure that Skyblock Suggestions are approved for the Skyblock Guide and that Dungeon Suggestions are approved for the Dungeons Guide.")
//edge case when the suggestion trying to be approved is in the wrong section
if (globalFunctions.embedCharCount(categoryMsg[0]) >= 6000) return message.channel.send("Error. Approving the following suggestion exceeds the embed character limit (6000). Use `g!e` to shorten the embed.")
//edge case when embed exceeds limit
if (fieldError) return message.channel.send("Error. Approving the following suggestion exceeds the field character limit (1024). Use `g!e` to shorten the embed.")
//edge case when field value exceeds character limit
collector.stop()
//Stops prompting the user

let suggestionChannel = message.guild.channels.cache.find(ch => ch.name === "suggested-guide-changes")
suggestionChannel.messages.fetch({around: messageID, limit: 1})
Expand All @@ -61,13 +62,15 @@ module.exports = {
var guideChannel = ""
embedMessage.timestamp = new Date()
categoryMsg[0].category === "Skyblock" ? guideChannel = message.guild.channels.cache.find(ch => ch.name === "skyblock-guide") : guideChannel = message.guild.channels.cache.find(ch => ch.name === "dungeons-guide-n-tips")
guideChannel.messages.fetch({around: messageID, limit: 1})
guideChannel.messages.fetch({around: categoryMsg[0].messageID[message.guild.id], limit: 1})
.then(msg => {
msg.first().edit({embed: embedMessage}).then(me => {message.channel.send("ID: " + me.id)});
})

guidesDB.updateOne({"categoryTitle": { $regex: new RegExp(categoryTitle, "i") }}, {$set: {"embedMessage": embedMessage, "categoryTitle": categoryMsg[0].categoryTitle, "messageID": messageID, "category": categoryMsg[0].category}})

post.post(client, message, "", "Edit", embedMessage)
//post function

let logChannel = message.guild.channels.cache.find(ch => ch.name === "guide-log")
logChannel.send({embed: globalFunctions.logAction(message.author.username, message.author.id, 'Approve', embedMessage.fields[approveMsgIndex].value, categoryMsg[0].categoryTitle)})

Expand Down Expand Up @@ -149,6 +152,7 @@ module.exports = {
}
//**Default command.** Format: g!approve <Suggestion ID> <Category-Name> <Section-Name>


let suggestionChannel = message.guild.channels.cache.find(ch => ch.name === "suggested-guide-changes")
suggestionChannel.messages.fetch({around: messageID, limit: 1})
.then(msg => {
Expand All @@ -158,13 +162,14 @@ module.exports = {
var guideChannel = ""
embedMessage.timestamp = new Date()
categoryMsg[0].category === "Skyblock" ? guideChannel = message.guild.channels.cache.find(ch => ch.name === "skyblock-guide") : guideChannel = message.guild.channels.cache.find(ch => ch.name === "dungeons-guide-n-tips")
guideChannel.messages.fetch({around: messageID, limit: 1})
guideChannel.messages.fetch({around: categoryMsg[0].messageID[message.guild.id], limit: 1})
.then(msg => {
msg.first().edit({embed: embedMessage}).then(me => {message.channel.send("ID: " + me.id)});
})

guidesDB.updateOne({"categoryTitle": { $regex: new RegExp(categoryTitle, "i") }}, {$set: {"embedMessage": embedMessage, "categoryTitle": categoryMsg[0].categoryTitle, "messageID": messageID, "category": categoryMsg[0].category}})

guidesDB.updateOne({"categoryTitle": { $regex: new RegExp(categoryTitle, "i") }}, {$set: {"embedMessage": embedMessage, "categoryTitle": categoryMsg[0].categoryTitle, "messageID": categoryMsg[0].messageID, "category": categoryMsg[0].category}})
post.post(client, message, "", "Edit", embedMessage)
//post function
let logChannel = message.guild.channels.cache.find(ch => ch.name === "guide-log")
logChannel.send({embed: globalFunctions.logAction(message.author.username, message.author.id, 'Approve', embedMessage.fields[approveMsgIndex].value, categoryMsg[0].categoryTitle)})

Expand Down
Loading

0 comments on commit b02a33e

Please sign in to comment.