From 22d911aaaac9c682401f95e9023794b16a73d22b Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 20 Nov 2017 22:38:40 +0100 Subject: [PATCH] moar trigger --- src/inc/trigger/coins.js | 58 +++++++++++++++++++++++ src/inc/trigger/drugs.js | 79 ++++++++++++++++++++++++++++++++ src/inc/trigger/kernel.js | 26 +++++++++++ src/inc/trigger/lachs.js | 11 +++++ src/inc/trigger/notschlachten.js | 14 ++++++ src/inc/trigger/sandbox.js | 3 +- 6 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 src/inc/trigger/coins.js create mode 100644 src/inc/trigger/drugs.js create mode 100644 src/inc/trigger/kernel.js create mode 100644 src/inc/trigger/lachs.js create mode 100644 src/inc/trigger/notschlachten.js diff --git a/src/inc/trigger/coins.js b/src/inc/trigger/coins.js new file mode 100644 index 0000000..7007609 --- /dev/null +++ b/src/inc/trigger/coins.js @@ -0,0 +1,58 @@ +const https = require("https"); + +const api_url = ({ market, crypto, currency }) => `https://api.cryptowat.ch/markets/${market}/${crypto}${currency}/summary`; +const currencies = { + usd: ({ val }) => `\$${val}`, + eur: ({ val }) => `${val}€`, + eth: ({ val }) => `${val}Ξ`, + btc: ({ val }) => `${val}฿`, + xmr: ({ val }) => `${val} xmr` +}; +const markets = { + btc: "coinbase", + eth: "coinbase", + xmr: "bitfinex" +}; + +module.exports = bot => { + bot._trigger.set("coins", { + call: /^(.|\/)(btc|eth|xmr)/i, + level: 0, + active: true, + clients: ["irc", "tg"], + f: e => { + let args = e.message.trim().substr(1).toLowerCase().split(" "); + cryptowat_summary(args[0], markets[args[0]], args[0] !== "xmr" ? args[1] : "usd").then( + resolve => e.reply(resolve), + reject => e.reply(reject) + ); + } + }); +}; + +const cryptowat_summary = (crypto, market, currency) => { + return new Promise((resolve, reject) => { + if (!currency) + currency = "eur"; + if (!Object.keys(currencies).includes(currency) || crypto === currency) + reject(`Can't convert or invalid currency: ${currency}`); + https.get([{ market: market, crypto: crypto, currency: currency }].map(api_url).join``, res => { + let content = ""; + res.on('data', chunk => content += chunk.toString()); + res.on('end', () => { + if(content.length === 0) + reject("No data received"); + const result = JSON.parse(content).result; + const data = { + last: [{ val: result.price.last }].map(currencies[currency]).join``, + high: [{ val: result.price.high }].map(currencies[currency]).join``, + low: [{ val: result.price.low }].map(currencies[currency]).join``, + change: (result.price.change.percentage * 100).toFixed(2), + volume: result.volume + }; + + resolve(`Current: ${data.last} - High: ${data.high} - Low: ${data.low} - Change: ${data.change}% - Volume: ${data.volume}`); + }); + }); + }); +}; \ No newline at end of file diff --git a/src/inc/trigger/drugs.js b/src/inc/trigger/drugs.js new file mode 100644 index 0000000..0f76d7d --- /dev/null +++ b/src/inc/trigger/drugs.js @@ -0,0 +1,79 @@ +const strains = { + 'sativa': [ + 'Sour Diesel', 'Green Crack', 'Jack Herer', 'Durban Poison', + 'Lemon Haze', 'Strawberry Cough', 'Super Silver Haze', + 'Alaskan Thunder Fuck', 'Super Lemon Haze', 'Amnesia Haze', + 'Maui Wowie', 'Chocolope', 'Harlequin' + ], + 'indica': [ + 'Granddaddy Purple', 'Bubba Kush', 'Northern Lights', + 'Blue Cheese', 'Purple Kush', 'Blueberry', 'Grape Ape', + 'Blackberry Kush', 'Master Kush', 'God\'s Gift', + 'LA Confidential', 'Death Star', 'Purple Urkle', + 'Afghan Kush', 'Skywalker', 'White Rhino', 'Hindu Kush' + ], + 'hybrid': [ + 'Blue Dream', 'Girl Scout Cookies', 'OG Kush', 'White Widow', + 'Gorilla Glue #4', 'Pineapple Express', 'Trainwreck', + 'AK-47', 'Headband', 'Chemdawg', 'Cheese', 'Cherry Pie', + 'Skywalker OG', 'Tahoe OG Kush', 'Lemon Kush', + 'Platinum Girl Scout Cookies', 'Golden Goat', 'Agent Orange' + ] +}; +const actions = { + 'joint': [ + ['passes', 'to'], + ['rolls', 'for'], + ['lights', 'for'] + ], + 'bong': [ + ['passes', 'to'], + ['preps', 'for'], + ['lights', 'for'] + ], + 'vape': [ + ['passes', 'to'] + ], + 'blunt': [ + ['passes', 'to'], + ['rolls', 'for'], + ['lights', 'for'] + ] +}; +const strain_types = Object.keys(strains); +const action_types = Object.keys(actions); + +module.exports = bot => { + bot._trigger.set("dope", { + call: /^(.|\/)dope/i, + level: 0, + active: true, + clients: ["irc", "tg"], + f: e => { + let args = e.message.trim().split(" "); + args.shift(); + args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0]; + + const strain_type = strain_types[~~(Math.random() * strain_types.length)] + , consume_type = action_types[~~(Math.random() * action_types.length)] + , action = actions[consume_type][~~(Math.random() * actions[consume_type].length)] + , strain = strains[strain_type][~~(Math.random() * strains[strain_type].length)]; + + e.replyAction(`${action[0]} a ${consume_type} of the finest ${strain_type} "${strain}" ${action[1]} ${args[0]}`); + } + }); + + bot._trigger.set("meth", { + call: /^(.|\/)meth/i, + level: 0, + active: true, + clients: ["irc", "tg"], + f: e => { + let args = e.message.trim().split(" "); + args.shift(); + args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0]; + + e.replyAction(`legt ${args[0]} eine dicke Line Meth \\________`); + } + }); +}; \ No newline at end of file diff --git a/src/inc/trigger/kernel.js b/src/inc/trigger/kernel.js new file mode 100644 index 0000000..1c922de --- /dev/null +++ b/src/inc/trigger/kernel.js @@ -0,0 +1,26 @@ +const https = require("https"); + +const feed = "https://www.kernel.org/releases.json"; + +module.exports = bot => { + bot._trigger.set("kernel", { + call: /^(.|\/)kernel/i, + level: 0, + active: true, + clients: ["irc", "tg"], + f: e => { + https.get(feed, res => { + let content = ""; + res.on('data', chunk => content += chunk.toString()); + res.on('end', () => { + const releases = JSON.parse(content).releases; + const out = []; + for (let entry in releases) + out.push(`${releases[entry].version} (${releases[entry].moniker}${releases[entry].iseol ? `, EOL` : ""})`); + e.reply(out.join(", ")); + }); + }); + + } + }); +}; diff --git a/src/inc/trigger/lachs.js b/src/inc/trigger/lachs.js new file mode 100644 index 0000000..44b92bb --- /dev/null +++ b/src/inc/trigger/lachs.js @@ -0,0 +1,11 @@ +module.exports = bot => { + bot._trigger.set("lachs", { + call: /^(.|\/)lachs/i, + level: 0, + active: true, + clients: ["irc", "tg"], + f: e => { + e.reply("öhöhöhöhöhöhö"); + } + }); +}; \ No newline at end of file diff --git a/src/inc/trigger/notschlachten.js b/src/inc/trigger/notschlachten.js new file mode 100644 index 0000000..14db2eb --- /dev/null +++ b/src/inc/trigger/notschlachten.js @@ -0,0 +1,14 @@ +module.exports = bot => { + bot._trigger.set("notschlachten", { + call: /^(.|\/)notschlachten/i, + level: 0, + active: true, + clients: ["irc", "tg"], + f: e => { + let args = e.message.trim().split(" "); + args.shift(); + args[0] = (args[0] == String.empty || typeof args[0] === "undefined" || args[0] == "") ? e.user.nick : args[0]; + e.replyAction(`notschlachtet ${args[0]} und entsorgt die Leiche im Biomüll`); + } + }); +}; \ No newline at end of file diff --git a/src/inc/trigger/sandbox.js b/src/inc/trigger/sandbox.js index 3da2d9a..59009df 100644 --- a/src/inc/trigger/sandbox.js +++ b/src/inc/trigger/sandbox.js @@ -9,8 +9,7 @@ module.exports = bot => { f: e => { const args = e.message.substring(3); const context = { - e: e, - b: bot + e: e }; try { let output = vm.runInNewContext(args, context);