Compare commits

..

2 Commits

Author SHA1 Message Date
Avril 70a2dddb6e Merge pull request 'Remove tripcodes (for now)' (#1) from Mil/doushio:no-ffi into master
2 years ago
Mil 1ae95bd4a4 Remove tripcodes (for now)
2 years ago

@ -407,13 +407,9 @@ 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,
@ -480,7 +476,18 @@ function parse_dice(frag)
{ {
return {n:1, faces:2}; return {n:1, faces:2};
} }
if (frag == '#fun' || frag == '#fcount' || frag == '#du') 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')
return {n: 1, faces: 2}; return {n: 1, faces: 2};
if (frag == '#tea') if (frag == '#tea')
return {n: 1, faces: 2}; return {n: 1, faces: 2};
@ -498,23 +505,6 @@ 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;

@ -22,9 +22,8 @@
"chart.js": "^2.7.2", "chart.js": "^2.7.2",
"diskspace": "^2.0.0", "diskspace": "^2.0.0",
"formidable": "1.0.17", "formidable": "1.0.17",
"hashloli": "git+ssh://public@flanchan.moe:hashloli.git", "hashloli": "git+ssh://git@git.flanchan.moe:flanchan/hashloli.git",
"jsoncompress": "^0.1.3", "jsoncompress": "^0.1.3",
"kana-hash": "file:../../home/avril/software/libkhash/node",
"minimist": "1.2.0", "minimist": "1.2.0",
"nan": "^2.14.0", "nan": "^2.14.0",
"recaptcha2": "^1.3.2", "recaptcha2": "^1.3.2",

@ -119,39 +119,6 @@ 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)
@ -175,7 +142,6 @@ 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;

@ -2,7 +2,7 @@ var opts = require('./opts');
if (require.main == module) opts.parse_args(); if (require.main == module) opts.parse_args();
opts.load_defaults(); opts.load_defaults();
const khash = require("kana-hash"); //const khash = require("kana-hash");
var _ = require('../lib/underscore'), var _ = require('../lib/underscore'),
amusement = require('./amusement'), amusement = require('./amusement'),
@ -23,7 +23,7 @@ var _ = require('../lib/underscore'),
render = require('./render'), render = require('./render'),
request = require('request'), request = require('request'),
STATE = require('./state'), STATE = require('./state'),
tripcode = require('../tripcode').make(),//{hash:function(a,b){return new khash.Kana(0, this.salt).once(a);}, setSalt:function(a){if(a) this.salt = new khash.Salt(a); else this.salt = khash.Salt.Default; return this.salt;}}, //require('./../tripcode/tripcode'), //tripcode = require('../tripcode').make(),//{hash:function(a,b){return new khash.Kana(0, this.salt).once(a);}, setSalt:function(a){if(a) this.salt = new khash.Salt(a); else this.salt = khash.Salt.Default; return this.salt;}}, //require('./../tripcode/tripcode'),
urlParse = require('url').parse, urlParse = require('url').parse,
web = require('./web'), web = require('./web'),
winston = require('winston'); winston = require('winston');
@ -845,12 +845,12 @@ function allocate_post(msg, client, callback) {
post.name = parsed[0]; post.name = parsed[0];
var spec = STATE.hot.SPECIAL_TRIPCODES; var spec = STATE.hot.SPECIAL_TRIPCODES;
if (spec && parsed[1] && parsed[1] in spec) { if (spec && parsed[1] && parsed[1] in spec) {
post.trip = spec[parsed[1]]; post.trip = spec[parsed[1]];
} }
else if (parsed[1] || parsed[2]) { else if (parsed[1] || parsed[2]) {
var trip = tripcode.hash(parsed[1], parsed[2]); var trip = "Can this just be a string?"; //tripcode.hash(parsed[1], parsed[2]);
if (trip) if (trip)
post.trip = trip; post.trip = trip;
} }
} }
if (msg.email) { if (msg.email) {
@ -1245,8 +1245,8 @@ function non_daemon_pid_setup() {
if (require.main == module) { if (require.main == module) {
if (!process.getuid()) if (!process.getuid())
throw new Error("Refusing to run as root."); throw new Error("Refusing to run as root.");
if (!tripcode.setSalt(config.SECURE_SALT)) // if (!tripcode.setSalt(config.SECURE_SALT))
throw "Bad SECURE_SALT"; // throw "Bad SECURE_SALT";
async.series([ async.series([
imager.make_media_dirs, imager.make_media_dirs,
setup_imager_relay, setup_imager_relay,

Loading…
Cancel
Save