Skip to content

Commit

Permalink
addign tts_on/off command sorting etc...
Browse files Browse the repository at this point in the history
  • Loading branch information
Leask committed Jul 24, 2024
1 parent cf3e253 commit d4d5940
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions lib/bot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,24 @@ const newCommand = (command, description) => ({
description: trim(description).slice(0, COMMAND_DESCRIPTION_LENGTH),
});

const uptime = () => {
let resp = `${new Date().toTimeString(
).split(' ')[0].split(':').slice(0, 2).join(':')} up`;
let seconds = process.uptime();
const ss = Object.keys(sessions);
const days = Math.floor(seconds / (3600 * 24));
seconds -= days * 3600 * 24;
let hours = Math.floor(seconds / 3600);
seconds -= hours * 3600;
hours = hours.toString().padStart(2, '0');
let minutes = Math.floor(seconds / 60);
minutes = minutes.toString().padStart(2, '0');
seconds = Math.floor(seconds % 60).toString().padStart(2, '0');
days > 0 && (resp += ` ${days} day${days > 1 ? 's' : ''},`);
return `${resp} ${hours}:${minutes}:${seconds}, `
+ `${ss.length} session${ss.length > 1 ? 's' : ''}`;
};

const reply = async (ctx, md, text, extra) => {
try {
if (md) {
Expand Down Expand Up @@ -392,7 +410,10 @@ const subconscious = [{
...ctx._.cmds, ...Object.keys(ctx.session.prompts || {}).map(
command => newCommand(command, ctx.session.prompts[command])
)
].slice(0, COMMAND_LIMIT), {
].sort((x, y) =>
(ctx.session.cmds[y.command.toLowerCase()]?.touchedAt || 0)
- (ctx.session.cmds[x.command.toLowerCase()]?.touchedAt || 0)
).slice(0, COMMAND_LIMIT), {
scope: { type: 'chat', chat_id: ctx.chatId },
}), logOptions);
}
Expand Down Expand Up @@ -487,7 +508,12 @@ const subconscious = [{
break;
}
}
ctx.cmd && log(`Command: ${JSON.stringify(ctx.cmd)}`);
if (ctx.cmd) {
log(`Command: ${JSON.stringify(ctx.cmd)}`);
ctx.session.cmds || (ctx.session.cmds = {});
ctx.session.cmds[ctx.cmd.cmd]
= { args: ctx.cmd.args, touchedAt: Date.now() };
}
await next();
},
}, {
Expand All @@ -497,6 +523,9 @@ const subconscious = [{
case 'echo':
resp = json({ update: ctx.update, session: ctx.session });
break;
case 'uptime':
resp = uptime();
break;
case 'thethreelaws':
resp = lines([
`Isaac Asimov's [Three Laws of Robotics](https://en.wikipedia.org/wiki/Three_Laws_of_Robotics):`,
Expand Down Expand Up @@ -548,6 +577,7 @@ const subconscious = [{
thethreelaws: `Isaac Asimov's [Three Laws of Robotics](https://en.wikipedia.org/wiki/Three_Laws_of_Robotics)`,
ultimateanswer: '[The Answer to the Ultimate Question of Life, The Universe, and Everything](https://bit.ly/43wDhR3).',
echo: 'Show debug message.',
uptime: 'Show uptime of this bot.',
lorem: '[Lorem ipsum](https://en.wikipedia.org/wiki/Lorem_ipsum)',
},
}, {
Expand Down Expand Up @@ -737,6 +767,16 @@ const subconscious = [{
},
}, {
run: true, priority: -8840, name: 'configuration', func: async (ctx, next) => {
switch (ctx.cmd.cmd) {
case 'tts_on':
ctx.cmd.cmd = 'set';
ctx.cmd.args = '--tts on';
break;
case 'tts_off':
ctx.cmd.cmd = 'set';
ctx.cmd.args = '--tts off';
break;
}
switch (ctx.cmd.cmd) {
case 'set':
try {
Expand Down Expand Up @@ -771,6 +811,8 @@ const subconscious = [{
set: 'Usage: /set --`OPTION` `VALUE` -`SHORT`',
reset: 'Reset all configurations.',
factory: 'Factory reset all memory areas.',
tts_on: 'Alias of `/set --tts on`',
tts_off: 'Alias of `/set --tts off`',
}, args: {
chatty: {
type: 'string', short: 'c', default: ON,
Expand Down

0 comments on commit d4d5940

Please sign in to comment.