add help command

This commit is contained in:
Cynthia Foxwell 2022-08-27 18:49:02 -06:00
parent a13afe9395
commit b6a4e5edff
3 changed files with 92 additions and 6 deletions

30
.eslintrc.js Normal file
View File

@ -0,0 +1,30 @@
const OFF = 0;
// const WARN = 1;
const ERROR = 2;
module.exports = {
extends: ["eslint:recommended"],
parserOptions: {
ecmaVersion: 2020,
},
env: {
es6: true,
node: true,
},
rules: {
indent: OFF,
semi: ERROR,
quotes: [ERROR, "double", {avoidEscape: true, allowTemplateLiterals: true}],
"no-empty": ERROR,
"array-callback-return": ERROR,
"consistent-return": ERROR,
eqeqeq: OFF,
"prefer-const": ERROR,
"no-unused-vars": [ERROR, {args: "none", varsIgnorePattern: "^_"}],
"no-console": OFF,
"no-debugger": OFF,
"require-atomic-updates": OFF,
},
globals: {
},
};

5
.prettierrc Normal file
View File

@ -0,0 +1,5 @@
{
"semi": true,
"bracketSpacing": false,
"endOfLine": "lf"
}

View File

@ -1,6 +1,5 @@
const Eris = require("eris"); const Eris = require("eris");
const chalk = require("chalk"); const chalk = require("chalk");
const {inspect} = require("util");
const token = process.argv[2]; const token = process.argv[2];
const stdin = process.stdin; const stdin = process.stdin;
@ -17,6 +16,21 @@ let currentGuild,
const messageQueue = []; const messageQueue = [];
const commands = {
q: "quit comcord",
e: "emote",
g: "goto a channel",
G: "goto a guild",
l: "list channels",
L: "list guilds",
w: "who is in guild",
f: "finger",
r: "channel history",
R: "extended channel history",
h: "command help",
c: "clear",
};
const client = new Eris("Bot " + token, { const client = new Eris("Bot " + token, {
defaultImageFormat: "png", defaultImageFormat: "png",
defaultImageSize: 1024, defaultImageSize: 1024,
@ -44,8 +58,9 @@ function processMessage({name, content, bot}) {
} else { } else {
// TODO: markdown // TODO: markdown
console.log( console.log(
chalk.bold.cyan(`[${name}]` + " ".rep(nameLength - (name.length + 2))) + chalk.bold.cyan(
chalk.reset(" " + content) `[${name}]` + " ".repeat(nameLength - (name.length + 2))
) + chalk.reset(" " + content)
); );
} }
} }
@ -102,7 +117,9 @@ function setupSendMode() {
toSend = ""; toSend = "";
const name = `[${client.user.username}]`; const name = `[${client.user.username}]`;
stdout.write( stdout.write(
chalk.bold.cyan(name) + " ".rep(nameLength - name.length) + chalk.reset(" ") chalk.bold.cyan(name) +
" ".repeat(nameLength - name.length) +
chalk.reset(" ")
); );
} }
function sendMessage() { function sendMessage() {
@ -116,6 +133,32 @@ function sendMessage() {
processQueue(); processQueue();
} }
function showHelp() {
console.log("\nCOMcord (c)left 2022\n");
const keys = Object.keys(commands);
keys.sort();
let index = 0;
for (const key of keys) {
const desc = commands[key];
const length = ` ${key} - ${desc}`.length;
stdout.write(
" " +
chalk.bold.yellow(key) +
chalk.reset(" - " + desc) +
" ".repeat(Math.abs(25 - length))
);
index++;
if (index % 3 == 0) stdout.write("\n");
}
if (index % 3 != 0) stdout.write("\n");
console.log("\nTo begin TALK MODE, press [SPACE]\n");
}
stdin.on("data", function (key) { stdin.on("data", function (key) {
if (inSendMode) { if (inSendMode) {
if (key === "\r") { if (key === "\r") {
@ -136,15 +179,20 @@ stdin.on("data", function (key) {
} else { } else {
switch (key) { switch (key) {
case "\u0003": case "\u0003":
case "q": case "q": {
client.disconnect(false); client.disconnect(false);
process.exit(0); process.exit(0);
break; break;
}
case "h": {
showHelp();
break;
}
case " ": case " ":
case "\r": case "\r":
default: { default: {
if (currentChannel == null) { if (currentChannel == null) {
console.log("not in a channel"); console.log("<not in a channel>");
break; break;
} }
setupSendMode(); setupSendMode();
@ -155,3 +203,6 @@ stdin.on("data", function (key) {
}); });
client.connect(); client.connect();
console.log("COMcord (c)left 2022");
console.log("Type 'h' for Commands");