Merge branch 'master' of ssh://numinibsd/git/base/enigma-bbs
This commit is contained in:
commit
9a71674840
|
@ -13,7 +13,7 @@ exports.getModuleAsset = getModuleAsset;
|
|||
exports.resolveConfigAsset = resolveConfigAsset;
|
||||
exports.getViewPropertyAsset = getViewPropertyAsset;
|
||||
|
||||
var ALL_ASSETS = [
|
||||
const ALL_ASSETS = [
|
||||
'art',
|
||||
'menu',
|
||||
'method',
|
||||
|
|
|
@ -169,6 +169,10 @@ function initialize(cb) {
|
|||
},
|
||||
function readyMessageNetworkSupport(callback) {
|
||||
require('./msg_network.js').startup(callback);
|
||||
},
|
||||
function readyEventScheduler(callback) {
|
||||
const EventSchedulerModule = require('./event_scheduler.js').EventSchedulerModule;
|
||||
EventSchedulerModule.loadAndStart(callback);
|
||||
}
|
||||
],
|
||||
function onComplete(err) {
|
||||
|
|
|
@ -211,15 +211,24 @@ function getDefaultConfig() {
|
|||
|
||||
archivers : {
|
||||
zip : {
|
||||
sig : "504b0304",
|
||||
sig : '504b0304',
|
||||
offset : 0,
|
||||
compressCmd : "7z",
|
||||
compressArgs : [ "a", "-tzip", "{archivePath}", "{fileList}" ],
|
||||
decompressCmd : "7z",
|
||||
decompressArgs : [ "e", "-o{extractPath}", "{archivePath}" ]
|
||||
compressCmd : '7z',
|
||||
compressArgs : [ 'a', '-tzip', '{archivePath}', '{fileList}' ],
|
||||
decompressCmd : '7z',
|
||||
decompressArgs : [ 'e', '-o{extractPath}', '{archivePath}' ]
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
messageAreaDefaults : {
|
||||
//
|
||||
// The following can be override per-area as well
|
||||
//
|
||||
maxMessages : 1024, // 0 = unlimited
|
||||
maxAgeDays : 0, // 0 = unlimited
|
||||
},
|
||||
|
||||
messageConferences : {
|
||||
system_internal : {
|
||||
name : 'System Internal',
|
||||
|
@ -257,6 +266,25 @@ function getDefaultConfig() {
|
|||
}
|
||||
},
|
||||
|
||||
eventScheduler : {
|
||||
|
||||
|
||||
events : {
|
||||
trimMessageAreas : {
|
||||
// may optionally use [or ]@watch:/path/to/file
|
||||
schedule : 'every 24 hours after 3:30 am',
|
||||
|
||||
// action:
|
||||
// - @method:path/to/module.js:theMethodName
|
||||
// (path is relative to engima base dir)
|
||||
//
|
||||
// - @execute:/path/to/something/executable.sh
|
||||
//
|
||||
action : '@method:core/message_area.js:trimMessageAreasScheduledEvent', // see method for avail args
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
misc : {
|
||||
idleLogoutSeconds : 60 * 6, // 6m
|
||||
},
|
||||
|
|
|
@ -169,17 +169,19 @@ function createMessageBaseTables() {
|
|||
'END;'
|
||||
);
|
||||
|
||||
// :TODO: need SQL to ensure cleaned up if delete from message?
|
||||
dbs.message.run(
|
||||
'CREATE TABLE IF NOT EXISTS message_meta (' +
|
||||
' message_id INTEGER NOT NULL,' +
|
||||
' meta_category INTEGER NOT NULL,' +
|
||||
' meta_name VARCHAR NOT NULL,' +
|
||||
' meta_value VARCHAR NOT NULL,' +
|
||||
' UNIQUE(message_id, meta_category, meta_name, meta_value),' + // why unique here?
|
||||
' UNIQUE(message_id, meta_category, meta_name, meta_value),' + // :TODO:why unique here?
|
||||
' FOREIGN KEY(message_id) REFERENCES message(message_id)' +
|
||||
');'
|
||||
);
|
||||
|
||||
// :TODO: need SQL to ensure cleaned up if delete from message?
|
||||
dbs.message.run(
|
||||
'CREATE TABLE IF NOT EXISTS hash_tag (' +
|
||||
' hash_tag_id INTEGER PRIMARY KEY,' +
|
||||
|
@ -188,6 +190,7 @@ function createMessageBaseTables() {
|
|||
');'
|
||||
);
|
||||
|
||||
// :TODO: need SQL to ensure cleaned up if delete from message?
|
||||
dbs.message.run(
|
||||
'CREATE TABLE IF NOT EXISTS message_hash_tag (' +
|
||||
' hash_tag_id INTEGER NOT NULL,' +
|
||||
|
|
114
core/door.js
114
core/door.js
|
@ -1,24 +1,24 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var spawn = require('child_process').spawn;
|
||||
var events = require('events');
|
||||
const events = require('events');
|
||||
|
||||
var _ = require('lodash');
|
||||
var pty = require('ptyw.js');
|
||||
var decode = require('iconv-lite').decode;
|
||||
var net = require('net');
|
||||
var async = require('async');
|
||||
const _ = require('lodash');
|
||||
const pty = require('ptyw.js');
|
||||
const decode = require('iconv-lite').decode;
|
||||
const createServer = require('net').createServer;
|
||||
|
||||
exports.Door = Door;
|
||||
|
||||
function Door(client, exeInfo) {
|
||||
events.EventEmitter.call(this);
|
||||
|
||||
const self = this;
|
||||
this.client = client;
|
||||
this.exeInfo = exeInfo;
|
||||
|
||||
this.exeInfo.encoding = this.exeInfo.encoding || 'cp437';
|
||||
this.exeInfo.encoding = this.exeInfo.encoding.toLowerCase();
|
||||
let restored = false;
|
||||
|
||||
//
|
||||
// Members of exeInfo:
|
||||
|
@ -32,24 +32,16 @@ function Door(client, exeInfo) {
|
|||
// node
|
||||
// inhSocket
|
||||
//
|
||||
}
|
||||
|
||||
require('util').inherits(Door, events.EventEmitter);
|
||||
|
||||
|
||||
|
||||
Door.prototype.run = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
var doorData = function(data) {
|
||||
// :TODO: skip decoding if we have a match, e.g. cp437 === cp437
|
||||
this.doorDataHandler = function(data) {
|
||||
if(self.client.term.outputEncoding === self.exeInfo.encoding) {
|
||||
self.client.term.rawWrite(data);
|
||||
} else {
|
||||
self.client.term.write(decode(data, self.exeInfo.encoding));
|
||||
}
|
||||
};
|
||||
|
||||
var restored = false;
|
||||
|
||||
var restore = function(piped) {
|
||||
this.restoreIo = function(piped) {
|
||||
if(!restored && self.client.term.output) {
|
||||
self.client.term.output.unpipe(piped);
|
||||
self.client.term.output.resume();
|
||||
|
@ -57,56 +49,63 @@ Door.prototype.run = function() {
|
|||
}
|
||||
};
|
||||
|
||||
var sockServer;
|
||||
|
||||
async.series(
|
||||
[
|
||||
function prepareServer(callback) {
|
||||
this.prepareSocketIoServer = function(cb) {
|
||||
if('socket' === self.exeInfo.io) {
|
||||
sockServer = net.createServer(function connected(conn) {
|
||||
const sockServer = createServer(conn => {
|
||||
|
||||
sockServer.getConnections(function connCount(err, count) {
|
||||
sockServer.getConnections( (err, count) => {
|
||||
|
||||
// We expect only one connection from our DOOR/emulator/etc.
|
||||
if(!err && count <= 1) {
|
||||
self.client.term.output.pipe(conn);
|
||||
|
||||
conn.on('data', doorData);
|
||||
conn.on('data', self.doorDataHandler);
|
||||
|
||||
conn.on('end', function ended() {
|
||||
restore(conn);
|
||||
conn.once('end', () => {
|
||||
return self.restoreIo(conn);
|
||||
});
|
||||
|
||||
conn.on('error', function error(err) {
|
||||
self.client.log.info('Door socket server connection error: ' + err.message);
|
||||
restore(conn);
|
||||
conn.once('error', err => {
|
||||
self.client.log.info( { error : err.toString() }, 'Door socket server connection');
|
||||
return self.restoreIo(conn);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
sockServer.listen(0, function listening() {
|
||||
callback(null);
|
||||
sockServer.listen(0, () => {
|
||||
return cb(null, sockServer);
|
||||
});
|
||||
} else {
|
||||
callback(null);
|
||||
return cb(null);
|
||||
}
|
||||
},
|
||||
function launch(callback) {
|
||||
// Expand arg strings, e.g. {dropFile} -> DOOR32.SYS
|
||||
var args = _.clone(self.exeInfo.args); // we need a copy so the original is not modified
|
||||
};
|
||||
}
|
||||
|
||||
for(var i = 0; i < args.length; ++i) {
|
||||
require('util').inherits(Door, events.EventEmitter);
|
||||
|
||||
Door.prototype.run = function() {
|
||||
const self = this;
|
||||
|
||||
this.prepareSocketIoServer( (err, sockServer) => {
|
||||
if(err) {
|
||||
this.client.log.warn( { error : err.toString() }, 'Failed executing door');
|
||||
return self.emit('finished');
|
||||
}
|
||||
|
||||
// Expand arg strings, e.g. {dropFile} -> DOOR32.SYS
|
||||
let args = _.clone(self.exeInfo.args); // we need a copy so the original is not modified
|
||||
|
||||
for(let i = 0; i < args.length; ++i) {
|
||||
args[i] = self.exeInfo.args[i].format({
|
||||
dropFile : self.exeInfo.dropFile,
|
||||
node : self.exeInfo.node.toString(),
|
||||
//inhSocket : self.exeInfo.inhSocket.toString(),
|
||||
srvPort : sockServer ? sockServer.address().port.toString() : '-1',
|
||||
userId : self.client.user.userId.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
var door = pty.spawn(self.exeInfo.cmd, args, {
|
||||
const door = pty.spawn(self.exeInfo.cmd, args, {
|
||||
cols : self.client.term.termWidth,
|
||||
rows : self.client.term.termHeight,
|
||||
// :TODO: cwd
|
||||
|
@ -118,19 +117,17 @@ Door.prototype.run = function() {
|
|||
|
||||
self.client.term.output.pipe(door);
|
||||
|
||||
door.on('data', doorData);
|
||||
door.on('data', self.doorDataHandler);
|
||||
|
||||
door.on('close', function closed() {
|
||||
restore(door);
|
||||
door.once('close', () => {
|
||||
return self.restoreIo(door);
|
||||
});
|
||||
} else if('socket' === self.exeInfo.io) {
|
||||
self.client.log.debug(
|
||||
{ port : sockServer.address().port },
|
||||
'Using temporary socket server for door I/O');
|
||||
self.client.log.debug( { port : sockServer.address().port }, 'Using temporary socket server for door I/O');
|
||||
}
|
||||
|
||||
door.on('exit', function exited(code) {
|
||||
self.client.log.info( { code : code }, 'Door exited');
|
||||
door.once('exit', exitCode => {
|
||||
self.client.log.info( { exitCode : exitCode }, 'Door exited');
|
||||
|
||||
if(sockServer) {
|
||||
sockServer.close();
|
||||
|
@ -138,19 +135,12 @@ Door.prototype.run = function() {
|
|||
|
||||
// we may not get a close
|
||||
if('stdio' === self.exeInfo.io) {
|
||||
restore(door);
|
||||
return self.restoreIo(door);
|
||||
}
|
||||
|
||||
door.removeAllListeners();
|
||||
|
||||
self.emit('finished');
|
||||
});
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
if(err) {
|
||||
self.client.log.warn( { error : err.toString() }, 'Failed executing door');
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
|
@ -0,0 +1,202 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
const PluginModule = require('./plugin_module.js').PluginModule;
|
||||
const Config = require('./config.js').config;
|
||||
const Log = require('./logger.js').log;
|
||||
|
||||
const _ = require('lodash');
|
||||
const later = require('later');
|
||||
const path = require('path');
|
||||
|
||||
exports.getModule = EventSchedulerModule;
|
||||
exports.EventSchedulerModule = EventSchedulerModule; // allow for loadAndStart
|
||||
|
||||
exports.moduleInfo = {
|
||||
name : 'Event Scheduler',
|
||||
desc : 'Support for scheduling arbritary events',
|
||||
author : 'NuSkooler',
|
||||
};
|
||||
|
||||
const SCHEDULE_REGEXP = /(?:^|or )?(@watch\:)([^\0]+)?$/;
|
||||
const ACTION_REGEXP = /\@(method|execute)\:([^\0]+)?$/;
|
||||
|
||||
class ScheduledEvent {
|
||||
constructor(events, name) {
|
||||
this.name = name;
|
||||
this.schedule = this.parseScheduleString(events[name].schedule);
|
||||
this.action = this.parseActionSpec(events[name].action);
|
||||
if(this.action) {
|
||||
this.action.args = events[name].args;
|
||||
}
|
||||
}
|
||||
|
||||
get isValid() {
|
||||
if((!this.schedule || (!this.schedule.sched && !this.schedule.watchFile)) || !this.action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if('method' === this.action.type && !this.action.location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
parseScheduleString(schedStr) {
|
||||
if(!schedStr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let schedule = {};
|
||||
|
||||
const m = SCHEDULE_REGEXP.exec(schedStr);
|
||||
if(m) {
|
||||
schedStr = schedStr.substr(0, m.index).trim();
|
||||
|
||||
if('@watch:' === m[1]) {
|
||||
schedule.watchFile = m[2];
|
||||
}
|
||||
}
|
||||
|
||||
if(schedStr.length > 0) {
|
||||
const sched = later.parse.text(schedStr);
|
||||
if(-1 === sched.error) {
|
||||
schedule.sched = sched;
|
||||
}
|
||||
}
|
||||
|
||||
// return undefined if we couldn't parse out anything useful
|
||||
if(!_.isEmpty(schedule)) {
|
||||
return schedule;
|
||||
}
|
||||
}
|
||||
|
||||
parseActionSpec(actionSpec) {
|
||||
if(actionSpec) {
|
||||
if('@' === actionSpec[0]) {
|
||||
const m = ACTION_REGEXP.exec(actionSpec);
|
||||
if(m) {
|
||||
if(m[2].indexOf(':') > -1) {
|
||||
const parts = m[2].split(':');
|
||||
return {
|
||||
type : m[1],
|
||||
location : parts[0],
|
||||
what : parts[1],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
type : m[1],
|
||||
what : m[2],
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
type : 'execute',
|
||||
what : actionSpec,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function EventSchedulerModule(options) {
|
||||
PluginModule.call(this, options);
|
||||
|
||||
if(_.has(Config, 'eventScheduler')) {
|
||||
this.moduleConfig = Config.eventScheduler;
|
||||
}
|
||||
|
||||
const self = this;
|
||||
this.runningActions = new Set();
|
||||
|
||||
this.performAction = function(schedEvent) {
|
||||
if(self.runningActions.has(schedEvent.name)) {
|
||||
return; // already running
|
||||
}
|
||||
|
||||
self.runningActions.add(schedEvent.name);
|
||||
|
||||
if('method' === schedEvent.action.type) {
|
||||
const modulePath = path.join(__dirname, '../', schedEvent.action.location); // enigma-bbs base + supplied location (path/file.js')
|
||||
try {
|
||||
const methodModule = require(modulePath);
|
||||
methodModule[schedEvent.action.what](schedEvent.action.args, err => {
|
||||
if(err) {
|
||||
Log.debug(
|
||||
{ error : err.toString(), eventName : schedEvent.name, action : schedEvent.action },
|
||||
'Error while performing scheduled event action');
|
||||
}
|
||||
|
||||
self.runningActions.delete(schedEvent.name);
|
||||
});
|
||||
} catch(e) {
|
||||
Log.warn(
|
||||
{ error : e.toString(), eventName : schedEvent.name, action : schedEvent.action },
|
||||
'Failed to perform scheduled event action');
|
||||
|
||||
self.runningActions.delete(schedEvent.name);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// convienence static method for direct load + start
|
||||
EventSchedulerModule.loadAndStart = function(cb) {
|
||||
const loadModuleEx = require('./module_util.js').loadModuleEx;
|
||||
|
||||
const loadOpts = {
|
||||
name : path.basename(__filename, '.js'),
|
||||
path : __dirname,
|
||||
};
|
||||
|
||||
loadModuleEx(loadOpts, (err, mod) => {
|
||||
if(err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
const modInst = new mod.getModule();
|
||||
modInst.startup( err => {
|
||||
return cb(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
EventSchedulerModule.prototype.startup = function(cb) {
|
||||
|
||||
this.eventTimers = [];
|
||||
const self = this;
|
||||
|
||||
if(this.moduleConfig && _.has(this.moduleConfig, 'events')) {
|
||||
const events = Object.keys(this.moduleConfig.events).map( name => {
|
||||
return new ScheduledEvent(this.moduleConfig.events, name);
|
||||
});
|
||||
|
||||
events.forEach( schedEvent => {
|
||||
if(!schedEvent.isValid) {
|
||||
Log.warn( { eventName : schedEvent.name }, 'Invalid scheduled event entry');
|
||||
return;
|
||||
}
|
||||
|
||||
if(schedEvent.schedule.sched) {
|
||||
this.eventTimers.push(later.setInterval( () => {
|
||||
self.performAction(schedEvent);
|
||||
}, schedEvent.schedule.sched));
|
||||
}
|
||||
|
||||
// :TODO: handle watchfile -> performAction
|
||||
});
|
||||
}
|
||||
|
||||
cb(null);
|
||||
};
|
||||
|
||||
EventSchedulerModule.prototype.shutdown = function(cb) {
|
||||
if(this.eventTimers) {
|
||||
this.eventTimers.forEach( et => et.clear() );
|
||||
}
|
||||
|
||||
cb(null);
|
||||
};
|
|
@ -132,6 +132,7 @@ function MenuModule(options) {
|
|||
if(err) {
|
||||
console.log(err)
|
||||
// :TODO: what to do exactly?????
|
||||
return self.prevMenu();
|
||||
}
|
||||
|
||||
self.finishedLoading();
|
||||
|
|
|
@ -243,7 +243,14 @@ Message.prototype.load = function(options, cb) {
|
|||
'WHERE message_uuid=? ' +
|
||||
'LIMIT 1;',
|
||||
[ options.uuid ],
|
||||
function row(err, msgRow) {
|
||||
(err, msgRow) => {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
if(!msgRow) {
|
||||
return callback(new Error('Message (no longer) available'));
|
||||
}
|
||||
|
||||
self.messageId = msgRow.message_id;
|
||||
self.areaTag = msgRow.area_tag;
|
||||
self.messageUuid = msgRow.message_uuid;
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
let msgDb = require('./database.js').dbs.message;
|
||||
let Config = require('./config.js').config;
|
||||
let Message = require('./message.js');
|
||||
let Log = require('./logger.js').log;
|
||||
let checkAcs = require('./acs_util.js').checkAcs;
|
||||
let msgNetRecord = require('./msg_network.js').recordMessage;
|
||||
const msgDb = require('./database.js').dbs.message;
|
||||
const Config = require('./config.js').config;
|
||||
const Message = require('./message.js');
|
||||
const Log = require('./logger.js').log;
|
||||
const checkAcs = require('./acs_util.js').checkAcs;
|
||||
const msgNetRecord = require('./msg_network.js').recordMessage;
|
||||
|
||||
let async = require('async');
|
||||
let _ = require('lodash');
|
||||
let assert = require('assert');
|
||||
const async = require('async');
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
const moment = require('moment');
|
||||
|
||||
exports.getAvailableMessageConferences = getAvailableMessageConferences;
|
||||
exports.getSortedAvailMessageConferences = getSortedAvailMessageConferences;
|
||||
|
@ -27,6 +28,7 @@ exports.getNewMessagesInAreaForUser = getNewMessagesInAreaForUser;
|
|||
exports.getMessageAreaLastReadId = getMessageAreaLastReadId;
|
||||
exports.updateMessageAreaLastReadId = updateMessageAreaLastReadId;
|
||||
exports.persistMessage = persistMessage;
|
||||
exports.trimMessageAreasScheduledEvent = trimMessageAreasScheduledEvent;
|
||||
|
||||
const CONF_AREA_RW_ACS_DEFAULT = 'GM[users]';
|
||||
const AREA_MANAGE_ACS_DEFAULT = 'GM[sysops]';
|
||||
|
@ -182,7 +184,7 @@ function getMessageAreaByTag(areaTag, optionalConfTag) {
|
|||
// No confTag to work with - we'll have to search through them all
|
||||
//
|
||||
var area;
|
||||
_.forEach(confs, (v, k) => {
|
||||
_.forEach(confs, (v) => {
|
||||
if(_.has(v, [ 'areas', areaTag ])) {
|
||||
area = v.areas[areaTag];
|
||||
return false; // stop iteration
|
||||
|
@ -464,3 +466,126 @@ function persistMessage(message, cb) {
|
|||
cb
|
||||
);
|
||||
}
|
||||
|
||||
// method exposed for event scheduler
|
||||
function trimMessageAreasScheduledEvent(args, cb) {
|
||||
|
||||
function trimMessageAreaByMaxMessages(areaInfo, cb) {
|
||||
if(0 === areaInfo.maxMessages) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
msgDb.run(
|
||||
`DELETE FROM message
|
||||
WHERE message_id IN
|
||||
(SELECT message_id
|
||||
FROM message
|
||||
WHERE area_tag = ?
|
||||
ORDER BY message_id
|
||||
LIMIT (MAX(0, (SELECT COUNT()
|
||||
FROM message
|
||||
WHERE area_tag = ?) - ${areaInfo.maxMessages}
|
||||
))
|
||||
);`,
|
||||
[ areaInfo.areaTag, areaInfo.areaTag],
|
||||
err => {
|
||||
if(err) {
|
||||
Log.warn( { areaInfo : areaInfo, error : err.toString(), type : 'maxMessages' }, 'Error trimming message area');
|
||||
} else {
|
||||
Log.debug( { areaInfo : areaInfo, type : 'maxMessages' }, 'Area trimmed successfully');
|
||||
}
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function trimMessageAreaByMaxAgeDays(areaInfo, cb) {
|
||||
if(0 === areaInfo.maxAgeDays) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
msgDb.run(
|
||||
`DELETE FROM message
|
||||
WHERE area_tag = ? AND modified_timestamp < date('now', '-${areaInfo.maxAgeDays} days');`,
|
||||
[ areaInfo.areaTag ],
|
||||
err => {
|
||||
if(err) {
|
||||
Log.warn( { areaInfo : areaInfo, error : err.toString(), type : 'maxAgeDays' }, 'Error trimming message area');
|
||||
} else {
|
||||
Log.debug( { areaInfo : areaInfo, type : 'maxAgeDays' }, 'Area trimmed successfully');
|
||||
}
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async.waterfall(
|
||||
[
|
||||
function getAreaTags(callback) {
|
||||
let areaTags = [];
|
||||
msgDb.each(
|
||||
`SELECT DISTINCT area_tag
|
||||
FROM message;`,
|
||||
(err, row) => {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
areaTags.push(row.area_tag);
|
||||
},
|
||||
err => {
|
||||
return callback(err, areaTags);
|
||||
}
|
||||
);
|
||||
},
|
||||
function prepareAreaInfo(areaTags, callback) {
|
||||
let areaInfos = [];
|
||||
|
||||
// determine maxMessages & maxAgeDays per area
|
||||
areaTags.forEach(areaTag => {
|
||||
|
||||
let maxMessages = Config.messageAreaDefaults.maxMessages;
|
||||
let maxAgeDays = Config.messageAreaDefaults.maxAgeDays;
|
||||
|
||||
const area = getMessageAreaByTag(areaTag); // note: we don't know the conf here
|
||||
if(area) {
|
||||
if(area.maxMessages) {
|
||||
maxMessages = area.maxMessages;
|
||||
}
|
||||
if(area.maxAgeDays) {
|
||||
maxAgeDays = area.maxAgeDays;
|
||||
}
|
||||
}
|
||||
|
||||
areaInfos.push( {
|
||||
areaTag : areaTag,
|
||||
maxMessages : maxMessages,
|
||||
maxAgeDays : maxAgeDays,
|
||||
} );
|
||||
});
|
||||
|
||||
return callback(null, areaInfos);
|
||||
},
|
||||
function trimAreas(areaInfos, callback) {
|
||||
async.each(
|
||||
areaInfos,
|
||||
(areaInfo, next) => {
|
||||
trimMessageAreaByMaxMessages(areaInfo, err => {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
trimMessageAreaByMaxAgeDays(areaInfo, err => {
|
||||
return next(err);
|
||||
});
|
||||
});
|
||||
},
|
||||
callback
|
||||
);
|
||||
}
|
||||
],
|
||||
err => {
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
|
@ -1140,6 +1140,8 @@ function FTNMessageScanTossModule() {
|
|||
|
||||
require('util').inherits(FTNMessageScanTossModule, MessageScanTossModule);
|
||||
|
||||
// :TODO: *scheduled* portion of this stuff should probably use event_scheduler - @immediate would still use record().
|
||||
|
||||
FTNMessageScanTossModule.prototype.startup = function(cb) {
|
||||
Log.info(`${exports.moduleInfo.name} Scanner/Tosser starting up`);
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ function AbracadabraModule(options) {
|
|||
|
||||
const doorInstance = new door.Door(self.client, exeInfo);
|
||||
|
||||
doorInstance.on('finished', () => {
|
||||
doorInstance.once('finished', () => {
|
||||
self.prevMenu();
|
||||
});
|
||||
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var MenuModule = require('../core/menu_module.js').MenuModule;
|
||||
var Log = require('../core/logger.js').log;
|
||||
var resetScreen = require('../core/ansi_term.js').resetScreen;
|
||||
const MenuModule = require('../core/menu_module.js').MenuModule;
|
||||
const resetScreen = require('../core/ansi_term.js').resetScreen;
|
||||
|
||||
var async = require('async');
|
||||
var _ = require('lodash');
|
||||
var http = require('http');
|
||||
var net = require('net');
|
||||
var crypto = require('crypto');
|
||||
var buffers = require('buffers');
|
||||
const async = require('async');
|
||||
const _ = require('lodash');
|
||||
const http = require('http');
|
||||
const net = require('net');
|
||||
const crypto = require('crypto');
|
||||
|
||||
var packageJson = require('../package.json');
|
||||
const packageJson = require('../package.json');
|
||||
|
||||
/*
|
||||
Expected configuration block:
|
||||
|
|
|
@ -939,6 +939,10 @@
|
|||
value: { command: "DL" }
|
||||
action: @menu:doorDarkLands
|
||||
}
|
||||
{
|
||||
value: { command: "DP" }
|
||||
action: @menu:doorParty
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -1006,6 +1010,16 @@
|
|||
door: tw
|
||||
}
|
||||
}
|
||||
|
||||
doorParty: {
|
||||
desc: Using DoorParty!
|
||||
module: @systemModule:door_party
|
||||
config: {
|
||||
username: XXXXXXXX
|
||||
password: XXXXXXXX
|
||||
bbsTag: XX
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Message Area Menu
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -133,7 +133,7 @@ MessageListModule.prototype.mciReady = function(mciData, cb) {
|
|||
callback(0 === self.messageList.length ? new Error('No messages in area') : null);
|
||||
} else {
|
||||
messageArea.getMessageListForArea( { client : self.client }, self.messageAreaTag, function msgs(err, msgList) {
|
||||
if(msgList && 0 === msgList.length) {
|
||||
if(!msgList || 0 === msgList.length) {
|
||||
callback(new Error('No messages in area'));
|
||||
} else {
|
||||
self.messageList = msgList;
|
||||
|
@ -210,6 +210,7 @@ MessageListModule.prototype.mciReady = function(mciData, cb) {
|
|||
function complete(err) {
|
||||
if(err) {
|
||||
self.client.log.error( { error : err.toString() }, 'Error loading message list');
|
||||
|
||||
}
|
||||
cb(err);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue