moar trigger

This commit is contained in:
Flummi 2017-11-20 22:38:40 +01:00
parent 88039bbe05
commit 22d911aaaa
6 changed files with 189 additions and 2 deletions

58
src/inc/trigger/coins.js Normal file
View File

@ -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}`);
});
});
});
};

79
src/inc/trigger/drugs.js Normal file
View File

@ -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 \\________`);
}
});
};

26
src/inc/trigger/kernel.js Normal file
View File

@ -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(", "));
});
});
}
});
};

11
src/inc/trigger/lachs.js Normal file
View File

@ -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ö");
}
});
};

View File

@ -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`);
}
});
};

View File

@ -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);