diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-19 12:02:21 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-19 12:02:21 +0200 |
| commit | 65da4cba0053bc6ee6f5442a45022bf5b4198e70 (patch) | |
| tree | 009923749461351b397cf26672b00b663bef0f63 | |
| parent | a0cb47ddcfcafc8a254de6b7574838d61a593bdd (diff) | |
| download | discordbot-65da4cba0053bc6ee6f5442a45022bf5b4198e70.tar.gz discordbot-65da4cba0053bc6ee6f5442a45022bf5b4198e70.zip | |
rotate IGNs in playing status
| -rw-r--r-- | api.js | 9 | ||||
| -rw-r--r-- | bot.js | 2 | ||||
| -rw-r--r-- | responses.js | 13 |
3 files changed, 22 insertions, 2 deletions
@@ -74,13 +74,20 @@ async function getMappings() { } ); return mapping; - }); + }, { ttl: 60 * 30 }); } module.exports.mapGameMode = async function(id) { return (await getMappings())["gamemode"][id]; } +// return a set of IGN of supporters +module.exports.getGamers = async function() { + return await cache.wrap("gamers", async () => { + return (await getFE("/gamer")).map((gamer) => gamer.name); + }, { ttl: 60 * 30 }); +} + // be an async iterator // next() returns promises that are awaited until there is an update module.exports.subscribeUpdates = function(name, timeout=UPDATE_TIMEOUT) { @@ -25,7 +25,7 @@ client .on("debug", console.log) .on("ready", () => { console.log(`Client ready; logged in as ${client.user.username}#${client.user.discriminator} (${client.user.id})`); - client.user.setGame("?v shutterfly | vainsocial.com"); + responses.rotateGameStatus(client); }) .on('disconnect', () => { console.warn('Disconnected!'); }) .on('reconnecting', () => { console.warn('Reconnecting...'); }) diff --git a/responses.js b/responses.js index d1284e5..39369ed 100644 --- a/responses.js +++ b/responses.js @@ -12,6 +12,7 @@ const Commando = require("discord.js-commando"), const PREVIEW = process.env.PREVIEW || true, MATCH_HISTORY_LEN = parseInt(process.env.MATCH_HISTORY_LEN) || 3, + IGN_ROTATE_TIMEOUT = parseInt(process.env.IGN_ROTATE_TIMEOUT) || 300, REACTION_TIMEOUT = parseInt(process.env.REACTION_TIMEOUT) || 60; // s const reactionsPipe = new Channel(); @@ -108,6 +109,18 @@ ${picks} `; } +module.exports.rotateGameStatus = (client) => { + (async function rotate() { + const gamers = await api.getGamers(), + idx = Math.floor(Math.random() * (gamers.length - 1)) + 1; + if (PREVIEW) await client.user.setGame( + `?v ${gamers[idx]} | preview.vainsocial.com`); + else await client.user.setGame( + `!v ${gamers[idx]} | vainsocial.com`); + setTimeout(rotate, IGN_ROTATE_TIMEOUT * 1000); + })(); +} + // reaction -> pipe ->>> consumers // handle new reaction event module.exports.onNewReaction = (reaction) => { |
