parent
5da56dfa60
commit
45b97bfb7e
@ -0,0 +1,9 @@ |
||||
const mongoose = require('mongoose'); |
||||
|
||||
const ResponseSchema = new mongoose.Schema({ |
||||
gid: {type: String, unique: true}, |
||||
responses: {type: Map, default: new Map()}, |
||||
bindings: {type: Map, default: new Map()} |
||||
}); |
||||
|
||||
module.exports = mongoose.model('responses', ResponseSchema); |
@ -0,0 +1,9 @@ |
||||
const Responses = require('../../models/responses'); |
||||
|
||||
module.exports = async (message, name) => { |
||||
let tr = await Responses.findOne({gid: message.guild.id}); |
||||
if (!tr) {message.reply("This server does not have any responses saved!"); return null;} |
||||
if (!tr.responses.has(name.toLowerCase())) {message.reply("I don't have that response saved here."); return null;} |
||||
message.delete(); |
||||
return tr.responses.get(name.toLowerCase()); |
||||
}; |
@ -0,0 +1,15 @@ |
||||
const Responses = require('../../models/responses'); |
||||
|
||||
module.exports = async (options, message) => { |
||||
try { |
||||
if (!options) {return null;} |
||||
if (!options.name || !options.name.length) {message.reply("You need to have a name in order to save a response."); return null;} |
||||
let sr = await Responses.findOne({gid: message.guild.id}) ? await Responses.findOne({gid: message.guild.id}) : new Responses({gid: message.guild.id}); |
||||
if (sr.responses.has(options.name)) {message.reply("You already have a response with that name. Use `edit` instead."); return null;} |
||||
sr.responses.set(options.name, options); |
||||
sr.save(); |
||||
message.channel.send("Response added!"); |
||||
} catch {message.reply("There seems to have been an error in saving your response. If this persists, please contact the developers or join the support sever."); return null;} |
||||
|
||||
return options; |
||||
}; |
Loading…
Reference in new issue