Skip to content

Instantly share code, notes, and snippets.

@ILiekTofu
Last active June 15, 2021 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ILiekTofu/3958622e66b500a535122e666936339c to your computer and use it in GitHub Desktop.
Save ILiekTofu/3958622e66b500a535122e666936339c to your computer and use it in GitHub Desktop.
GMNotes
on("chat:message", function(msg) {
if(msg.type == "api" && ((msg.content.indexOf('!livehandout') == 0) || (msg.content.indexOf('!livehandoutid') == 0))) {
let args = msg.content.split(/\s+--/);
let handout;
if (args[0] == '!livehandout') {
handout = findObjs({
type: 'handout',
name: args[1]
}, {caseinsensitve:true})[0];
} else if (args[0] == '!livehandoutid') {
handout = findObjs({
type: 'handout',
_id: args[1]
}, {caseinsensitve:true})[0];
}
if(handout){
let x = handout.get('gmnotes', function(text){
let split = ('^' + args[2] + 'split' + '^');
if (text.search(args[2] + 'split') == -1) {
sendChat('Live Handouts', '/w gm There is no tag "' + args[2] + '" currently set');
} else if ((args[2].search('-GM')==!-1) && !playerIsGM(msg.playerid)) {
return;
} else {
let chars = text.split(split);
if (chars.length == 3){
handout.set('notes', chars[1]);
} else {
sendChat('Live Handouts', '/w gm There may be a tag that is too close to ' + args[2] + ', consider renaming it.');
}
}
});
}
}
});
on("chat:message", function(msg) {
if(msg.type == "api" && ((msg.content.indexOf('!sethandout') == 0) || (msg.content.indexOf('!sethandoutid') == 0)) && playerIsGM(msg.playerid)) {
let args = msg.content.split(/\s+--/);
let handout;
if (args[0] == '!sethandout') {
handout = findObjs({
type: 'handout',
name: args[1]
}, {caseinsensitve:true})[0];
} else if (args[0] == '!sethandoutid') {
handout = findObjs({
type: 'handout',
_id: args[1]
}, {caseinsensitve:true})[0];
}
if(handout){
let x = handout.get('notes', function(text){
let split = ('^' + args[2] + 'split' + '^');
let notes = split + text + split;
y = handout.get('gmnotes', function(text1){
if (text1.search(split) !== -1){
sendChat('Live Handouts', '/w gm The "' + args[2] + '" tag is already taken.');
} else {
notes1 = text1 + notes;
setTimeout(()=>handout.set('gmnotes', notes1), 0);
sendChat('Live Handouts', '/w gm The "' + args[2] + '" tag has been set.');
}
});
});
}
}
});
on("chat:message", function(msg) {
if(msg.type == "api" && ((msg.content.indexOf('!replacehandout') == 0) || (msg.content.indexOf('!replacehandoutid') == 0)) && playerIsGM(msg.playerid)) {
let args = msg.content.split(/\s+--/);
let handout;
if (args[0] == '!replacehandout') {
handout = findObjs({
type: 'handout',
name: args[1]
}, {caseinsensitve:true})[0];
} else if (args[0] == '!replacehandoutid') {
handout = findObjs({
type: 'handout',
_id: args[1]
}, {caseinsensitve:true})[0];
}
if(handout){
let x = handout.get('gmnotes', function(text){
let split = ('^' + args[2] + 'split' + '^');
if (text.search(args[2] + 'split') == -1) {
sendChat('Live Handouts', '/w gm There is no tag "' + args[2] + '" currently set');
} else {
var chars = text.split(split);
if (chars.length == 3){
let y = handout.get('notes', function(text2){
let body = chars[0] + split + text2 + split + chars[2];
setTimeout(()=>handout.set('gmnotes', body), 0);
sendChat('Live Handouts', '/w gm The "' + args[2] + '" tag has been replaced.');
});
} else {
sendChat('Live Handouts', '/w gm There may be a tag that is too close to ' + args[2] + ', consider renaming it.');
}
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment