Skip to content

Commit

Permalink
Version 2.5 - Improved User-friendliness
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyWhoCode authored Apr 12, 2021
2 parents 1b4aefb + b160466 commit 33728f9
Show file tree
Hide file tree
Showing 41 changed files with 24,247 additions and 119 deletions.
116 changes: 83 additions & 33 deletions Commands/addcategory.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,100 @@
const {dbClient} = require("../mongodb.js")
const {sbAlias, dAlias, uAlias} = require("../constants.js")
const {sbAlias, dAlias, noAlias, cancelAlias} = require("../constants.js")
const globalFunctions = require("../globalfunctions.js")

var categoryEmbed = {
color: 0xffba00,
title: 'Suggestion',
description: "This is an empty section of the guide. Add some changes to this guide using!",
description: "This is an empty section of the guide.",
fields: [
{
name: '_ _',
value: "_ _",
}],
footer: {
text: 'Skycomm Guide Bot',
text: 'Skyblock Guides',
icon_url: "https://i.imgur.com/184jyne.png",
},
}

module.exports = {
name: "addcategory",
alises: ["ac", "addc", "AC", "Ac", "addC", "Addcategory", "AddCategory"],
alises: ["ac", "addc"],
execute(message, args) {
var categoryChannel = ""
var msgID = ""
var category = args[0]
let categoryName = args.slice(1, args.length).join(" ").trim()
if (args.length == 0 || category.length == 0 || categoryName.length == 0) return message.channel.send("See `g!addcategory <#Guide Channel> <Category Name>`")
//checks if there is any bad input
var categoryChannel, msgID, category, categoryName = ""
var channelConfirm = false
let guideDB = dbClient.db("skyblockGuide").collection("Guides")


if (args.length == 0) {
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 Channel to put the new Guide in: `skyblock` or `dungeons`")
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
//stops process if given no/cancel alias

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

collector.stop()
//Stops prompting the user

categoryEmbed.title = categoryName
categoryEmbed.timestamp = new Date()

if (globalFunctions.checkAliases(sbAlias, category)) {
category = "Skyblock"
categoryChannel = message.guild.channels.cache.find(ch => ch.name === "skyblock-guide")
categoryEmbed.color = 0x87d8fa
categoryEmbed.description = "This is an empty section of the guide. Add some changes to this guide using `g!sbsuggest <Suggestion>`!"

} else if (globalFunctions.checkAliases(dAlias, category)) {
category = "Dungeons"
categoryChannel = message.guild.channels.cache.find(ch => ch.name === "dungeons-guide-n-tips")
categoryEmbed.color = 0xcc0000
categoryEmbed.description = "This is an empty section of the guide. Add some changes to this guide using `g!dsuggest <Suggestion>`!"

}

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

let newEntry = globalFunctions.makeNewEntry(categoryEmbed, categoryName, msgID, category)
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.

} 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
//if a valid alias of the guide channel is given, run this portion of the code
}
})

if (!channelConfirm) return undefined
}
//**Enable the Argument helper: Prompts the user for each argument of the command to make it more user-friendly
//Exits out of the code to prevent the code below the argument parsing from returning an error

else {
category = args[0]
categoryName = args.slice(1, args.length).join(" ").trim()
if (globalFunctions.checkAliases(sbAlias, category) == false && globalFunctions.checkAliases(dAlias, category) == false) return message.channel.send("You are missing an argument! Please use the right format. `g!addcategory <#Guide Channel> <Category Name>`")
//checks if provided alias does not match list of alises

}
//**Default command.** Format: g!ac <#Guide-Channel> <Category-Name>

if (globalFunctions.checkAliases(sbAlias, category) == false && globalFunctions.checkAliases(dAlias, category) == false && globalFunctions.checkAliases(uAlias, category) == false) return message.channel.send("You are missing an argument! Please use the right format. `g!addcategory <#Guide Channel> <Category Name>`")
//checks if provided alias does not match list of alises

categoryEmbed.title = categoryName
categoryEmbed.title = categoryName
categoryEmbed.timestamp = new Date()

if (globalFunctions.checkAliases(sbAlias, category)) {
Expand All @@ -45,27 +108,14 @@ module.exports = {
categoryChannel = message.guild.channels.cache.find(ch => ch.name === "dungeons-guide-n-tips")
categoryEmbed.color = 0xcc0000
categoryEmbed.description = "This is an empty section of the guide. Add some changes to this guide using `g!dsuggest <Suggestion>`!"

} else if (globalFunctions.checkAliases(uAlias, category)) {
category = "Update Tips"
categoryChannel = message.guild.channels.cache.find(ch => ch.name === "update-tips")
categoryEmbed.color = 0xffba00
categoryEmbed.description = "This is an empty section of the guide. Add some changes to this guide using `g!update <Update Tip>`!"
}

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

}

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

let database = dbClient.db("skyblockGuide")
let guideDB = database.collection("Guides")
let updateDB = database.collection("Update Tips")
let newEntry = globalFunctions.makeNewEntry(categoryEmbed, categoryName, msgID, category)
if (category == "Update Tips") {
updateDB.insertOne(newEntry)
updateDB.updateOne({"identifier": category}, {$set: {"identifier": category, "currentMsgId": msgID, "msgObject": categoryEmbed}})
} else {
guideDB.insertOne(newEntry)
}
guideDB.insertOne(newEntry)

message.channel.send("Your category has been created!")
}
message.channel.send("Your category has been created!")
}
}
88 changes: 79 additions & 9 deletions Commands/addsection.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,94 @@
const {dbClient} = require("../mongodb.js")
const globalFunction = require("../globalfunctions.js")
const {noAlias, cancelAlias} = require("../constants.js")
const globalfunctions = require("../globalfunctions.js")
const entrySchema = {
"name": "_ _",
"value": "_ _"
}

module.exports = {
name: "addsection",
alises: ["as", "Addsection", "Adds", "AddSection", "As"],
alises: ["as", "adds"],
async execute(message, args) {
let sectionName = args.slice(1, args.length).join(" ").trim()
if (args.length == 0 || args[0] == undefined || sectionName.length == 0) return message.channel.send("See `g!addsection <Category-Name> <Section Name>`")
//checks if there is any bad input
var categoryName = globalFunction.translateCategoryName(args[0])

var sectionName, categoryName, categoryMsg = ""
let guideCollection = dbClient.db("skyblockGuide").collection("Guides")
let 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 the provided category does not exist in the database, give the user an error saying so.
var categoryConfirm = false

if (args.length == 0) {
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.")
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
//stops process if given no/cancel alias

} else if (categoryConfirm) {
sectionName = globalFunctions.translateCategoryName(msg.content.trim())

collector.stop()
//Stops prompting the user

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
msgEmbed.fields.push(newEntry)

delete msgEmbed.description
let channelName = categoryMsg[0].category
guideCollection.updateOne({"categoryTitle": { $regex: new RegExp(categoryName, "i") }}, {$set: {"category": channelName, "messageID": categoryMsg[0].messageID, "categoryTitle": categoryMsg[0].categoryTitle, "embedMessage": msgEmbed}})

var guideChannel = ""
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})
.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()
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
//if a valid alias of the guide channel is given, run this portion of the code
}
})

if (!categoryConfirm) return undefined
}
//**Enable the Argument helper: Prompts the user for each argument of the command to make it more user-friendly
//Exits out of the code to prevent the code below the argument parsing from returning an error


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

categoryName = globalFunction.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 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>


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

1 comment on commit 33728f9

@GuyWhoCode
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noteworthy changes:

  • Implemented improved search capabilities through Jaro-Winkler and Fuzzy searching algorithms.
  • Added Example command usage through message embeds
  • Added Argument helpers that prompt the user for every argument of a command. Makes replacing spaces with hyphens a format for advanced users.
  • Completely removed support for Update Tips

Please sign in to comment.