Browse Source

Add random comic generator

ghorsington 6 years ago
parent
commit
1857982a24
1 changed files with 31 additions and 0 deletions
  1. 31 0
      commands/rcg.js

+ 31 - 0
commands/rcg.js

@@ -0,0 +1,31 @@
+const request = require("request-promise-native");
+
+const rcgRe = /<input id="rcg_image".+value="([^"]+)".*\/>/i;
+
+const documentation = {
+    "random comic": {
+        auth: false,
+        description: "Generates a comic just for you!"
+    }
+};
+
+async function randomComic(msg) {
+    let result = await request("http://explosm.net/rcg/view/");
+    
+    let regexResult = rcgRe.exec(result);
+
+    msg.channel.send(`${msg.author.toString()} I find this very funny:`, {
+        files: [ regexResult[1].trim() ]
+    });
+}
+
+const commands = {
+    "random comic": msg => {
+        randomComic(msg);
+    }
+};
+
+module.exports = {
+    commands: commands,
+    documentation: documentation
+};