Started work on character log for rolls to be stored

This commit is contained in:
Stefan Zermatten
2020-09-29 22:34:30 +02:00
parent 75ab43da00
commit a6a96fc19f
12 changed files with 190 additions and 45 deletions

View File

@@ -0,0 +1,54 @@
import SimpleSchema from 'simpl-schema';
if (Meteor.isServer){
var sendWebhookAsCreature = require('/imports/server/discord/sendWebhook.js').sendWebhookAsCreature;
}
let CreatureLogs = new Mongo.Collection('creatureLogs');
let CreatureLogSchema = new SimpleSchema({
text: {
type: String,
},
type: {
type: String,
allowedValues: ['roll', 'change', 'damage', 'info'],
defaultValue: 'info',
},
// The real-world date that it occured, usually sorted by date
date: {
type: Date,
autoValue: function() {
// If the date isn't set, set it to now
if (!this.isSet) {
return new Date();
}
},
index: 1,
},
creatureId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
index: 1,
},
});
CreatureLogs.attachSchema(CreatureLogSchema);
// This function should only be called by trusted code. No permission checks
const insertCreatureLog = function({log, creature}){
if (typeof log === 'string'){
log = {text: log};
}
log.creatureId = creature._id;
let id = CreatureLogs.insert(log);
if (Meteor.isServer){
sendWebhookAsCreature({
creature,
content: log.text,
});
}
return id;
};
export default CreatureLogs;
export { CreatureLogSchema, insertCreatureLog};