From 092c22eb95f7d47d626d490f2dee17dfb5a8e5c4 Mon Sep 17 00:00:00 2001
From: Claudio Giordano <claudio.giordano@autistici.org>
Date: Tue, 2 Apr 2019 19:52:21 +0200
Subject: [PATCH 1/3] Add sample alias command

---
 commands/alias.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 help/alias.yml    | 11 ++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 commands/alias.js
 create mode 100644 help/alias.yml

diff --git a/commands/alias.js b/commands/alias.js
new file mode 100644
index 0000000..f7d5989
--- /dev/null
+++ b/commands/alias.js
@@ -0,0 +1,66 @@
+"use strict";
+
+const { Broadcast: B, Logger } = require("ranvier");
+const sprintf = require("sprintf-js").sprintf;
+
+module.exports = {
+  usage: "alias [word] [command]",
+  command: state => (args, player, arg0) => {
+    let aliases = player.getMeta("alias") || {};
+
+    args = args
+      .toString()
+      .trim()
+      .toLowerCase();
+    const [alias, ...commandArgs] = args.split(" ");
+
+    if (!alias && commandArgs.length === 0) {
+      /**
+       * prints defined alias list
+       */
+      B.sayAt(
+        player,
+        sprintf("<cyan>%-20s</cyan> | <cyan>%-57s</cyan>", "Alias", "Command")
+      );
+      B.sayAt(player, B.line(20) + "-+-" + B.line(57));
+
+      if (!aliases || Object.entries(aliases).length === 0) {
+        return B.sayAt(player, "No aliases defined yet!");
+      }
+
+      for (let [key, value] of Object.entries(aliases)) {
+        B.sayAt(player, sprintf("%-20s | %-57s", key, value));
+      }
+    }
+
+    if (alias && commandArgs.length === 0) {
+      /**
+       * drop alias
+       */
+      if (aliases && aliases[alias]) {
+        delete aliases[alias];
+        player.setMeta("alias", aliases);
+        player.save();
+
+        return B.sayAt(player, `Alias '${alias}' deleted!`);
+      }
+
+      return B.sayAt(player, `Alias '${alias}' not found!`);
+    }
+
+    if (alias && commandArgs.length > 0) {
+      /**
+       * Add or update alias with args
+       */
+      if (aliases && aliases[alias]) {
+        return B.sayAt(player, `Alias '${alias}' updated!`);
+      }
+
+      aliases[alias] = commandArgs.join(" ");
+      player.setMeta("alias", aliases);
+      player.save();
+
+      return B.sayAt(player, `Alias '${alias}' added!`);
+    }
+  }
+};
diff --git a/help/alias.yml b/help/alias.yml
new file mode 100644
index 0000000..60099d3
--- /dev/null
+++ b/help/alias.yml
@@ -0,0 +1,11 @@
+---
+command: alias
+body: |
+  Alias allows you to set shortcuts for commands or long strings of text.
+
+  - alias - print all defined aliases
+  - alias <word> - delete matching defined alias
+  - alias <word> <command> - define or update an alias
+
+keywords:
+- aliases
\ No newline at end of file

From e4739f675a6413244c864b1cee44bc995411cfd8 Mon Sep 17 00:00:00 2001
From: Claudio Giordano <claudio.giordano@autistici.org>
Date: Sat, 21 Mar 2020 02:27:26 +0100
Subject: [PATCH 2/3] Fix alias update command

---
 commands/alias.js | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/commands/alias.js b/commands/alias.js
index f7d5989..93dfd44 100644
--- a/commands/alias.js
+++ b/commands/alias.js
@@ -53,6 +53,8 @@ module.exports = {
        * Add or update alias with args
        */
       if (aliases && aliases[alias]) {
+        aliases[alias] = commandArgs.join(" ");
+        player.setMeta("alias", aliases);
         return B.sayAt(player, `Alias '${alias}' updated!`);
       }
 

From c99b74edf795db4c3cc7ca7ab50a82ff61a3404c Mon Sep 17 00:00:00 2001
From: Claudio Giordano <claudio.giordano@autistici.org>
Date: Fri, 4 Dec 2020 01:30:45 +0100
Subject: [PATCH 3/3] Update dependencies

---
 package-lock.json | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 7a071f0..e5b4af7 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5,9 +5,9 @@
   "requires": true,
   "dependencies": {
     "humanize-duration": {
-      "version": "3.14.0",
-      "resolved": "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.14.0.tgz",
-      "integrity": "sha512-ebqI6Aaw64T7e7bZoFeoHkvlyy7mpVDqXCPm9gLFi9S42QWD3PWQ1FMwDKJo0y8/sXcfZ9hughSadLwTfmafmw=="
+      "version": "3.24.0",
+      "resolved": "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.24.0.tgz",
+      "integrity": "sha512-B3udnqisaDeRsvUSb+5n2hjxhABI9jotB+i1IEhgHhguTeM5LxIUKoVIu7UpeyaPOygr/Fnv7UhOi45kYYG+tg=="
     }
   }
 }