server/amusement.js: Pseudo-code on how `#<` **might** be able to work.. Eh. I can"t be bothered with this anymore right now.

Fortune for doushio's current commit: Blessing − 吉
hash-command-arbitrary
Avril 3 years ago
parent 6d5460ece6
commit 3e31b30338
Signed by untrusted user: flanchan
GPG Key ID: 284488987C31F630

@ -407,9 +407,13 @@ OS.karada = function (body) {
return output; return output;
} }
var dice_re = /(#tea|#dame|#tutturu|#muri|#flip|#when|#du|#fun|#fcount|#test|#sleep|#janken|#8ball|#imfey|#\?(?:\[(?:\w,*)+\])?|#\d{0,2}d\d{1,4}(?:[+-]\d{1,4})?)/i; var dice_re = /(#tea|#dame|#tutturu|#muri|#flip|#when|#du|#fun|#fcount|#test|#sleep|#janken|#8ball|#imfey|#<(.*)|#\?(?:\[(?:\w,*)+\])?|#\d{0,2}d\d{1,4}(?:[+-]\d{1,4})?)/i;
exports.dice_re = dice_re; exports.dice_re = dice_re;
//TODO: XXX: Does this need to be exposed to the client? I don't think it does.
const ARBITRARY = config.ARBITRARY || {};
exports.lookup_arbitrary = ARBITRARY;
var WHEN = [ var WHEN = [
'Now', null, null, null, null, 'Now', null, null, null, null,
'Later', null, null, null, null, 'Later', null, null, null, null,
@ -476,17 +480,6 @@ function parse_dice(frag)
{ {
return {n:1, faces:2}; return {n:1, faces:2};
} }
if (/^#\?/.test(frag))
{
var l = frag.slice(2).split(/(\[|\]|,)/);
var j =0;
for(var i=0;i<l.length;i++)
{
if(/(\[|\]|,)/.test(l[i])) continue;
if(l[i].length>0) j+=1;
}
return {n:1, faces: j};
}
if (frag == '#fun' || frag == '#fcount' || frag == '#du') if (frag == '#fun' || frag == '#fcount' || frag == '#du')
return {n: 1, faces: 2}; return {n: 1, faces: 2};
if (frag == '#tea') if (frag == '#tea')
@ -505,6 +498,23 @@ function parse_dice(frag)
return {n: 1, faces: 2}; return {n: 1, faces: 2};
if (frag == '#janken') if (frag == '#janken')
return {n: 1, faces: 3}; return {n: 1, faces: 3};
if (/^#\?/.test(frag))
{
var l = frag.slice(2).split(/(\[|\]|,)/);
var j =0;
for(var i=0;i<l.length;i++)
{
if(/(\[|\]|,)/.test(l[i])) continue;
if(l[i].length>0) j+=1;
}
return {n:1, faces: j};
}
if (/^#</.test(frag)) {
const rest = frag.slice(2);
if (rest.length)
return {n: 1, faces: 3};
else return {n: 0, faces: 3};
}
var m = frag.match(/^#(\d*)d(\d+)([+-]\d+)?$/i); var m = frag.match(/^#(\d*)d(\d+)([+-]\d+)?$/i);
if (!m) if (!m)
return false; return false;

@ -119,6 +119,39 @@ exports.roll_dice = function (frag, post, extra) {
else if(ms[i] == '#fcount') { else if(ms[i] == '#fcount') {
dice.push([pyu]); dice.push([pyu]);
} }
else if(ms[i].startsWith('#<'))
{
//TODO: Stupid hack on how to make this work with `async () =>` results... (pseudo-code, maybe come back to this when I can be bothered to write the needed utils, figure out how node capture groups works, and all the other bs needed...)
/* XXX: [[psuedo-code]]
const frag = ms[i].slice(2);
const lookup_result = match_regexes_in_object_keys(config.ARBITRARY, frag); // { lookup: <value>, key: <regex>, matches: <regex match groups> };
const lookup = lookup_result.lookup;
// XXX: Sets the extra.new_dice, and appends post.dice one value: `result`.
const set_dice = (result) => {
const dice = result ? [result] : [];
extra.new_dice = dice;
dice = post.dice ? post.dice.concat(dice) : dice;
post.dice = dice;
return dice;
};
if(!lookup) ;// XXX: no match
else if(is_function(lookup))
{ let string = lookup(frag, lookup_result.matches || {}, lookup_result.key);
dice.push([string]); }
else if(is_string(lookup)) dice.push([string]);
else if(is_promise(lookup) {
// We need to insert this via `attachToPost`. So we'll set `extra.new_dice` to be sure it's hit.
//set_dice("..."); //XXX: TODO: Won't this just mean the next result is *appeneded*, and treated as a result for the next command? So, we won't set an intermidiate, we'll just wait on `lookup().then(...)`
// When async lambda completes, we'll set `extra.new_dice()` and append `post.dice()` again.
lookup(frag, lookup_result.matches || {}, lookup_result.key).then(set_dice).catch((err) => {
set_dice("Error: " + (err || "(unbound)"));
});
return; // XXX: Important to return here so we don't hit the below `if(dice.length)`
} else ; //XXX no match
*/
}
else { else {
var info = common.parse_dice(ms[i]); var info = common.parse_dice(ms[i]);
if (!info) if (!info)
@ -142,6 +175,7 @@ exports.roll_dice = function (frag, post, extra) {
if (dice.length + exist > rollLimit) if (dice.length + exist > rollLimit)
dice = dice.slice(0, Math.max(0, rollLimit - exist)); dice = dice.slice(0, Math.max(0, rollLimit - exist));
if (dice.length) { if (dice.length) {
// TODO: for `#<` to work: The key to hitting `attachToPost` at all is in `extra.new_dice` vs `post.dice`
extra.new_dice = dice; extra.new_dice = dice;
dice = post.dice ? post.dice.concat(dice) : dice; dice = post.dice ? post.dice.concat(dice) : dice;
post.dice = dice; post.dice = dice;

Loading…
Cancel
Save