diff --git a/mods/menu.hjson b/mods/menu.hjson index eaed5f0a..2356a937 100644 --- a/mods/menu.hjson +++ b/mods/menu.hjson @@ -135,7 +135,7 @@ } TM2: { argName: addOrExit - items: [ "hell yeah!", "nah" ] + items: [ "yeah!", "nah" ] submit: true focus: true } @@ -152,18 +152,22 @@ } ] } + actionKeys: [ + { + keys: [ "escape" ] + action: @systemMethod:nextMenu + } + ] }, 1: { mci: { ET1: { focus: true - // :TODO: fix this length - maxLength: 30 - width: 30 + maxLength: 70 argName: oneliner } TL2: { - width: 20 + width: 60 } TM3: { argName: addOrCancel @@ -184,6 +188,12 @@ } ] } + actionKeys: [ + { + keys: [ "escape" ] + action: @method:cancelAdd + } + ] } } } diff --git a/mods/onelinerz.js b/mods/onelinerz.js index a6036c61..74d912cf 100644 --- a/mods/onelinerz.js +++ b/mods/onelinerz.js @@ -112,9 +112,14 @@ function OnelinerzModule(options) { let entries = []; self.db.each( - `SELECT user_id, user_name, oneliner, timestamp - FROM onelinerz - LIMIT ${limit};`, + `SELECT * + FROM ( + SELECT * + FROM onelinerz + ORDER BY timestamp DESC + LIMIT ${limit} + ) + ORDER BY timestamp ASC;`, (err, row) => { if(!err) { row.timestamp = moment(row.timestamp); // convert -> moment @@ -127,19 +132,15 @@ function OnelinerzModule(options) { ); }, function populateEntries(entriesView, entries, callback) { - const listFormat = config.listFormat || '{username}: {oneliner}'; - - // :TODO: remove meh: - //entries = [ - // { user_id : 1, user_name : 'NuSkooler', oneliner : 'Boojahhhh!!!', timestamp : '2016-06-04' } - //] + const listFormat = config.listFormat || '{username}@{ts}: {oneliner}';// :TODO: should be userName to be consistent + const tsFormat = config.timestampFormat || 'ddd h:mma'; entriesView.setItems(entries.map( e => { return listFormat.format( { userId : e.user_id, username : e.user_name, oneliner : e.oneliner, - ts : e.timestamp.toString(), // :TODO: allow custom TS formatting - see e.g. last_callers.js + ts : e.timestamp.format(tsFormat), } ); })); @@ -221,6 +222,10 @@ function OnelinerzModule(options) { const oneliner = formData.value.oneliner.trim(); // remove any trailing ws self.storeNewOneliner(oneliner, err => { + if(err) { + self.client.log.warn( { error : err.message }, 'Failed saving oneliner'); + } + self.clearAddForm(); self.displayViewScreen(true); // true=cls }); @@ -268,16 +273,32 @@ function OnelinerzModule(options) { this.storeNewOneliner = function(oneliner, cb) { const ts = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZ'); - // :TODO: Keep max of N (e.g. 25) & change retrieval to show most recent N (height) - - self.db.run( - `INSERT INTO onelinerz (user_id, user_name, oneliner, timestamp) - VALUES (?, ?, ?, ?);`, - [ self.client.user.userId, self.client.user.username, oneliner, ts ], - err => { - return cb(err); - } - ); + async.series( + [ + function addRec(callback) { + self.db.run( + `INSERT INTO onelinerz (user_id, user_name, oneliner, timestamp) + VALUES (?, ?, ?, ?);`, + [ self.client.user.userId, self.client.user.username, oneliner, ts ], + callback + ); + }, + function removeOld(callback) { + // keep 25 max most recent items - remove the older ones + self.db.run( + `DELETE FROM onelinerz + WHERE id IN ( + SELECT id + FROM onelinerz + ORDER BY id DESC + LIMIT -1 OFFSET 25 + );`, + callback + ); + } + ], + cb + ); }; } diff --git a/mods/themes/luciano_blocktronics/ONELINER.ANS b/mods/themes/luciano_blocktronics/ONELINER.ANS new file mode 100644 index 00000000..b494dc7b Binary files /dev/null and b/mods/themes/luciano_blocktronics/ONELINER.ANS differ diff --git a/mods/themes/luciano_blocktronics/theme.hjson b/mods/themes/luciano_blocktronics/theme.hjson index b6d98b9a..98f16cb4 100644 --- a/mods/themes/luciano_blocktronics/theme.hjson +++ b/mods/themes/luciano_blocktronics/theme.hjson @@ -84,6 +84,29 @@ } } + loginOnelinerz: { + config: { + listFormat: "|00|11{username:<12}|08: |03{oneliner:<59.58}" + } + 0: { + mci: { + VM1: { height: 10 } + TM2: { + focusTextStyle: first lower + } + } + } + 1: { + mci: { + ET1: { width: 60 } + TL2: { width: 60 } + TM3: { + focusTextStyle: first lower + } + } + } + } + mainMenuUserStats: { mci: { UN1: { width: 17 } @@ -336,6 +359,12 @@ } } } + + ercClient: { + config: { + //chatEntryFormat: "|00|08[|03{bbsTag}|08] |10{userName}|08: |02{message}" + } + } } } } \ No newline at end of file