From 717a38d6b7cd20d2d7b9904dfeea9b29302900aa Mon Sep 17 00:00:00 2001
From: Indrajith K L
Date: Wed, 26 May 2021 01:46:01 +0530
Subject: :sparkles: Add New Command `gt` - Game of Thrones Random Quotes

---
 .vscode/launch.json              | 17 +++++++++++++++++
 src/commands/gt.js               | 28 ++++++++++++++++++++++++++++
 src/configs/commands.config.json |  5 +++++
 3 files changed, 50 insertions(+)
 create mode 100644 .vscode/launch.json
 create mode 100644 src/commands/gt.js

diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..77165f9
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,17 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "pwa-node",
+            "request": "launch",
+            "name": "Launch Program",
+            "skipFiles": [
+                "<node_internals>/**"
+            ],
+            "program": "${workspaceFolder}\\src\\main.js"
+        }
+    ]
+}
\ No newline at end of file
diff --git a/src/commands/gt.js b/src/commands/gt.js
new file mode 100644
index 0000000..512e76b
--- /dev/null
+++ b/src/commands/gt.js
@@ -0,0 +1,28 @@
+const axios = require('axios').default;
+const {MessageEmbed} = require('discord.js'); 
+const instance = axios.create({
+    baseURL: 'https://game-of-thrones-quotes.herokuapp.com/v1'
+  });
+
+async function getRandomQuotes(message, args) {
+    const randomQuotesUrl = "/random";
+    try {
+        const result = await instance.get(randomQuotesUrl);
+        const {sentence, character: {name, house: {name:houseName}}} = result.data;
+        const randomQuoteMessage = new MessageEmbed()
+                                            .setDescription(sentence)
+                                            .setFooter(`${name}, ${houseName}`);
+        message.channel.send(randomQuoteMessage);
+    } catch(error) {
+        const errorMessage = new MessageEmbed()
+        .setTitle("Something went wrong: Error getting quotes from Arya Stark")
+        .setColor("RED");
+        message.channel.send(errorMessage);
+    }
+}
+
+module.exports = {
+    execute(client, message, args) {
+        getRandomQuotes(message, args);
+    }
+}
\ No newline at end of file
diff --git a/src/configs/commands.config.json b/src/configs/commands.config.json
index 282de6e..268d889 100644
--- a/src/configs/commands.config.json
+++ b/src/configs/commands.config.json
@@ -24,6 +24,11 @@
             "name": "vaccine",
             "description": "Get Vaccine Availability by Pincode",
             "file": "./commands/vaccine.js"
+        },
+        {
+            "name": "gt",
+            "description": "Game of Thrones Quotes",
+            "file": "./commands/gt.js"
         }
     ]
 }
\ No newline at end of file
-- 
cgit v1.2.3