Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function saveGameToDb(roomToSave) {
if (roomToSave.gameStarted === true && roomToSave.finished !== true) {
if (roomToSave.savedGameRecordId === undefined) {
savedGameObj.create({ room: JSON.stringify(roomToSave) }, (err, savedGame) => {
if (err) {
console.log(err);
} else {
rooms[rooms.indexOf(roomToSave)].savedGameRecordId = savedGame.id;
// console.log("Successfully created this save game");
}
});
} else {
savedGameObj.findByIdAndUpdate(roomToSave.savedGameRecordId, { room: JSON.stringify(roomToSave) }, (err, savedGame) => {
// console.log("Successfully saved this game");
});
}
}
}
function deleteSaveGameFromDb(room) {
function saveGameToDb(roomToSave) {
if (roomToSave.gameStarted === true && roomToSave.finished !== true) {
if (roomToSave.savedGameRecordId === undefined) {
savedGameObj.create({ room: JSON.stringify(roomToSave) }, (err, savedGame) => {
if (err) {
console.log(err);
} else {
rooms[rooms.indexOf(roomToSave)].savedGameRecordId = savedGame.id;
// console.log("Successfully created this save game");
}
});
} else {
savedGameObj.findByIdAndUpdate(roomToSave.savedGameRecordId, { room: JSON.stringify(roomToSave) }, (err, savedGame) => {
// console.log("Successfully saved this game");
});
}
}
}
function deleteSaveGameFromDb(room) {
Trivia.exportGame = (file) => {
// Copy the data so we don't modify the actual game object.
var json = JSON.parse(JSON.stringify(game));
// Remove the timeout so the game can be exported.
Object.keys(json).forEach((key) => {
if(typeof json[key].timeout !== "undefined") {
delete json[key].timeout;
delete json[key].message;
}
// If there is no guild ID, the game is a DM game.
// DM games are re-assigned to make sure they show up last.
// This ensures that the first key is always a non-DM game if possible.
if(typeof json[key].guildId === "undefined") {
var replace = json[key];
delete json[key];
json[key] = replace;
}
const logPromise = (file: string, key: string, args: any[], resolvedValue: any) => {
const template = `${file} %s(${token}).then(${token})`;
console.log(template, key, stringifyArgs(args), circularJSON.stringify(resolvedValue));
};
static send(topic: string, data?: any) {
/**
* If the websocket is dead, return
*/
if (ws.readyState !== ws.OPEN) return
try {
let json = CircularJSON.stringify({
t: topic,
d: data,
})
if (injectify.info.compression) {
json = '#' + pako.deflate(json, {to: 'string'})
}
ws.send(json)
} catch (e) {
if (injectify.debug) console.error(e)
injectify.error(e.stack)
}
}
function encode (data) {
data =
typeof data === 'object'
? CircularJSON.stringify(data, null, 2)
: data.toString()
return data
.replace(/&/g, '&')
.replace(//g, '>')
}
function toValue(value: any): { json: string } {
return { json: stringify(value, null, null, true) };
}
common.stringify = function (obj, callback) {
callback = callback || function () {
};
return callback(null, stringify.stringify(obj));
};
.add('CircularJSON', () => CircularJSON.stringify(obj))
.add('json-stringify-safe', () => stringify(obj))
global.CJSONString = function(obj): string {
return cjson.stringify(obj);
}