forked from Suggester/Suggester
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fa4e175
Showing
58 changed files
with
8,066 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = { | ||
"env": { | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
}, | ||
"rules": { | ||
"eqeqeq": [ | ||
"error", | ||
"smart" | ||
], | ||
"indent": [ | ||
"error", | ||
"tab" | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"double" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
], | ||
"no-var": [ | ||
"error" | ||
] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file and config files | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and *not* Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Other stuff | ||
data/ | ||
.data/ | ||
.config/ | ||
.bash_history | ||
.idea/ | ||
config.json | ||
build/ | ||
commands/test.js | ||
utils/testSchemas.js | ||
/persistent.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
const Discord = require("discord.js"); | ||
const fs = require("fs"); | ||
|
||
const client = new Discord.Client(); | ||
const core = require("./coreFunctions.js"); | ||
const { connect, connection } = require("mongoose"); | ||
const autoIncrement = require("mongoose-sequence"); | ||
|
||
connect(process.env.MONGO, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true | ||
}) | ||
.catch((err) => { | ||
throw new Error(err); | ||
}); | ||
|
||
autoIncrement(connection); | ||
|
||
connection.on("open", () => { | ||
console.log("Connected to MongoDB!"); | ||
}); | ||
connection.on("error", (err) => { | ||
console.error("Connection error: ", err); | ||
}); | ||
/* | ||
const DBL = require("dblapi.js"); | ||
const dbl = new DBL(process.env.DBL_TOKEN, client); | ||
// Optional events | ||
dbl.on("posted", () => { | ||
core.coreLog(":hash: **Server Count Posted to Discord Bot List (.org)**", client); | ||
}); | ||
dbl.on("error", e => { | ||
core.coreLog(`:rotating_light: **DBL (.org) ERROR** \n\`\`\`${e}\`\`\``, client); | ||
}); | ||
*/ | ||
/* | ||
const Enmap = require("enmap"); | ||
if (!client.suggestions) { | ||
client.suggestions = new Enmap({ | ||
name: "suggestions" | ||
}); | ||
} | ||
if (!client.servers) { | ||
client.servers = new Enmap({ | ||
name: "servers" | ||
}); | ||
} | ||
if (!client.core) { | ||
client.core = new Enmap({ | ||
name: "core" | ||
}); | ||
} | ||
*/ | ||
fs.readdir("./events/", (err, files) => { | ||
files.forEach(file => { | ||
const eventHandler = require(`./events/${file}`); | ||
const eventName = file.split(".")[0]; | ||
|
||
client.on(eventName, (...args) => { | ||
try { | ||
eventHandler(Discord, client, ...args); | ||
} catch (err) { | ||
core.errorLog(err, "Event Handler", `Event: ${eventName}`); | ||
} | ||
|
||
}); | ||
}); | ||
}); | ||
|
||
client.login(process.env.TOKEN) | ||
.catch((err) => { | ||
throw new Error(err); | ||
}); | ||
|
||
// core.errorLog(err, type, footer) | ||
client.on("error", (err) => { | ||
core.errorLog(err, "error", "something happened and idk what"); | ||
}); | ||
client.on("warn", (warning) => { | ||
console.warn(warning); | ||
}); | ||
process.on("unhandledRejection", (err) => { // this catches unhandledPromiserejectionWarning and other unhandled rejections | ||
core.errorLog(err, "unhandledRejection", "oof something is broken x.x"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { emoji } = require("../config.json"); | ||
const { dbModifyId, dbQuery } = require("../coreFunctions"); | ||
module.exports = { | ||
controls: { | ||
permission: 1, | ||
usage: "acknowledgement <user> (new acknowledgement)", | ||
aliases: ["ack", "setack", "setacknowledgement", "addack"], | ||
description: "Sets a verify acknowledgement for a user", | ||
enabled: true, | ||
docs: "", | ||
permissions: ["VIEW_CHANNEL", "SEND_MESSAGES", "USE_EXTERNAL_EMOJIS"] | ||
}, | ||
do: async (message, client, args) => { | ||
let user = client.users.find((user) => user.id === args[0]) || message.mentions.members.first(); | ||
if (!user || !args[1]) { | ||
if (!user) user = message.author; | ||
let dbUser = await dbQuery("User", { id: user.id }); | ||
let ack = dbUser ? dbUser.ack : "No Acknowledgement Set"; | ||
return message.channel.send(`\`${user.tag || user.user.tag}\`'s acknowledgement is: \`${ack || "no acknowledgement set"}\``); | ||
} | ||
|
||
let ack = args.slice(1).join(" "); | ||
if (ack.toLowerCase() === "reset") { | ||
await dbModifyId("User", user.id, { ack: undefined }); | ||
return message.channel.send(`<:${emoji.check}> \`${user.user.tag}\`'s acknowledgement has been reset.`); | ||
} | ||
await dbModifyId("User", user.id, { ack: ack }); | ||
return message.channel.send(`<:${emoji.check}> Set \`${user.tag || user.user.tag}\`'s acknowledgement to **${ack}**`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
const config = require("../config.json"); | ||
const core = require("../coreFunctions.js"); | ||
module.exports = { | ||
controls: { | ||
permission: 3, | ||
aliases: ["anonymouscomment"], | ||
usage: "acomment <suggestion id> <comment>", | ||
description: "Adds a comment to an approved suggestion anonymously", | ||
enabled: true, | ||
docs: "staff/acomment", | ||
permissions: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS", "USE_EXTERNAL_EMOJIS"] | ||
}, | ||
do: (message, client, args, Discord) => { | ||
|
||
let missingConfigs = []; | ||
if (!client.servers.get(message.guild.id)) return message.channel.send(`<:${config.emoji.x}> You must configure your server to use this command. Please use the \`config\` command.\n:rotating_light: The database was recently lost due to an accident, which means that all configuration settings and suggestions were lost. Please join the support server for more information.`); | ||
if (!client.servers.get(message.guild.id, "admin_roles") || client.servers.get(message.guild.id, "admin_roles").length < 1) missingConfigs.push("Server Admin Roles"); | ||
if (!client.servers.get(message.guild.id, "staff_roles") || client.servers.get(message.guild.id, "staff_roles").length < 1) missingConfigs.push("Server Staff Roles"); | ||
if (!client.servers.get(message.guild.id, "channels.suggestions") || !client.channels.get(client.servers.get(message.guild.id, "channels.suggestions"))) missingConfigs.push("Approved Suggestions Channel"); | ||
if (client.servers.get(message.guild.id, "mode") === "review" && (!client.servers.get(message.guild.id, "channels.staff") || !client.channels.get(client.servers.get(message.guild.id, "channels.staff")))) missingConfigs.push("Suggestion Review Channel"); | ||
|
||
if (missingConfigs.length > 1) { | ||
let embed = new Discord.RichEmbed() | ||
.setDescription(`This command cannot be run because some server configuration elements are missing. A server manager can fix this by using the \`${client.servers.get(message.guild.id, "prefix")}config\` command.`) | ||
.addField("Missing Elements", `<:${config.emoji.x}> ${missingConfigs.join(`\n<:${config.emoji.x}> `)}`) | ||
.setColor("#e74c3c"); | ||
return message.channel.send(embed); | ||
} | ||
|
||
if (client.channels.get(client.servers.get(message.guild.id, "channels.suggestions"))) { | ||
let perms = core.channelPermissions(client.channels.get(client.servers.get(message.guild.id, "channels.suggestions")).memberPermissions(client.user.id), "suggestions", client); | ||
if (perms.length > 0) { | ||
let embed = new Discord.RichEmbed() | ||
.setDescription(`This command cannot be run because some permissions are missing. ${client.user.username} needs the following permissions in the <#${client.servers.get(message.guild.id, "channels.suggestions")}> channel:`) | ||
.addField("Missing Elements", `<:${config.emoji.x}> ${perms.join(`\n<:${config.emoji.x}> `)}`) | ||
.addField("How to Fix", `In the channel settings for <#${client.servers.get(message.guild.id, "channels.suggestions")}>, make sure that **${client.user.username}** has a <:${config.emoji.check}> for the above permissions.`) | ||
.setColor("#e74c3c"); | ||
return message.channel.send(embed); | ||
} | ||
} else { | ||
return message.channel.send(`<:${config.emoji.x}> Could not find your suggestions channel! Please make sure you have configured a suggestion channel.`); | ||
} | ||
|
||
if (!args[0] || !client.suggestions.find(s => s.id.toString() === args[0] && s.guild === message.guild.id)) return message.channel.send(`<:${config.emoji.x}> Please provide a valid suggestion id!`); | ||
|
||
let suggestion = client.suggestions.find(s => s.id.toString() === args[0] && s.guild === message.guild.id); | ||
let id = suggestion.id.toString(); | ||
|
||
if (suggestion.status !== "approved") return message.channel.send(`<:${config.emoji.x}> Comments can only be added to approved suggestions!`); | ||
|
||
if (!args[1]) return message.channel.send(`<:${config.emoji.x}> Please provide a comment!`); | ||
|
||
if (suggestion.comments && suggestion.comments.filter(c => !c.deleted).length + 1 > 23) return message.channel.send(`<:${config.emoji.x}> Suggestions can only have up to 23 comments.`); | ||
|
||
let comment = args.splice(1).join(" "); | ||
|
||
if (!client.suggestions.get(id, "comments")) client.suggestions.set(id, [], "comments"); | ||
|
||
client.suggestions.push(id, { | ||
"comment": comment, | ||
"author": 0, | ||
"id": client.suggestions.get(id, "comments").length + 1 | ||
}, "comments"); | ||
|
||
let suggester; | ||
if (client.users.get(client.suggestions.get(id, "suggester"))) { | ||
suggester = client.users.get(client.suggestions.get(id, "suggester")); | ||
} else { | ||
let found = false; | ||
let sent = false; | ||
client.fetchUser(client.users.get(client.suggestions.get(id, "suggester")), true).then(user => { | ||
suggester = user; | ||
found = true; | ||
}).catch(() => { | ||
found = false; | ||
sent = true; | ||
return message.channel.send(`${config.emoji.x} The suggesting user could not be fetched, please try again. If the issue persists, please contact our support team.`); | ||
}); | ||
|
||
if (!suggester && !found && !sent) return message.channel.send(`${config.emoji.x} The suggesting user could not be fetched, please try again. If the issue persists, please contact our support team.`); | ||
|
||
} | ||
|
||
let replyEmbed = new Discord.RichEmbed() | ||
.setTitle("Anonymous Comment Added") | ||
.setDescription(`${suggestion.suggestion}\n[Suggestions Feed Post](https://discordapp.com/channels/${client.suggestions.get(id, "guild")}/${client.servers.get(client.suggestions.get(id, "guild"), "channels.suggestions")}/${client.suggestions.get(id, "messageid")})`) | ||
.addField("Official Comment", comment) | ||
.setColor("#3498db") | ||
.setFooter(`Suggestion ID: ${id.toString()}`); | ||
message.channel.send(replyEmbed); | ||
|
||
if (client.servers.get(message.guild.id, "notify") && client.servers.get(message.guild.id, "notify") === true) { | ||
let dmEmbed = new Discord.RichEmbed() | ||
.setTitle("A comment was added to your suggestion!") | ||
.setDescription(`${suggestion.suggestion}\n[Suggestions Feed Post](https://discordapp.com/channels/${client.suggestions.get(id, "guild")}/${client.servers.get(client.suggestions.get(id, "guild"), "channels.suggestions")}/${client.suggestions.get(id, "messageid")})`) | ||
.addField("Official Comment", comment) | ||
.setColor("#3498db") | ||
.setFooter(`Suggestion ID: ${id.toString()}`); | ||
suggester.send(dmEmbed); | ||
} | ||
client.channels.get(client.servers.get(client.suggestions.get(id, "guild"), "channels.suggestions")).fetchMessage(client.suggestions.get(id, "messageid")).then(f => f.edit(core.suggestionEmbed(client.suggestions.get(id), client))); | ||
|
||
if (client.servers.get(message.guild.id, "channels.log")) { | ||
let logEmbed = new Discord.RichEmbed() | ||
.setAuthor(`${message.author.tag} added an anonymous comment to #${id.toString()}`, message.author.displayAvatarURL) | ||
.addField("Suggestion", suggestion.suggestion) | ||
.addField("Comment", comment) | ||
.setFooter(`Suggestion ID: ${id.toString()} | Commenter ID: ${message.author.id}`) | ||
.setTimestamp() | ||
.setColor("#3498db"); | ||
core.serverLog(logEmbed, message.guild.id, client); | ||
} | ||
|
||
} | ||
}; |
Oops, something went wrong.