Skip to content

Commit

Permalink
feat: twitch notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Feb 23, 2021
1 parent dc006da commit 0cfa18e
Show file tree
Hide file tree
Showing 16 changed files with 696 additions and 255 deletions.
156 changes: 56 additions & 100 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"zlib-sync": "^0.1.7"
},
"devDependencies": {
"@babel/core": "^7.11.0",
"@babel/core": "^7.12.13",
"@babel/eslint-parser": "^7.12.13",
"@babel/plugin-proposal-class-properties": "^7.12.13",
"@babel/plugin-proposal-private-methods": "^7.12.13",
Expand Down
5 changes: 3 additions & 2 deletions src/CommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const welcomes = require('./resources/welcomes.json');

const {
eventTypes, rewardTypes, opts, fissures, syndicates, twitter, conclave, deals, clantech,
resources, nightwave, twitch,
resources, nightwave, twitch
} = require('./resources/trackables.json');

const rssFeeds = require('./resources/rssFeeds');
Expand Down Expand Up @@ -379,7 +379,7 @@ const chunkify = ({
if (checkTitle) {
// strip the last title if it starts with a title
if (string.endsWith('**')) {
const endTitle = string.matches(/\*\*(.*)\*\*\s*$/g)[1];
const endTitle = (string.match(/\*\*(.*)\*\*\s*$/g)[1] || '');
string = string.replace(/\*\*(.*)\*\*\s*$/g, ''); // eslint-disable-line no-param-reassign
breakIndex -= endTitle.length;
}
Expand Down Expand Up @@ -411,6 +411,7 @@ const markdinate = htmlString => htmlString
.replace(/<\/li>\s*<li>/gm, '</li>\n<li>') // clean up breaks between list items
.replace(/<li\s?(?:class=".*")?\s?(?:dir=".*")?>\n/gm, '- ') // strip list items to bullets, replace later with emoji
.replace(/ipsnoembed="false" /gm, '') // manually replace ipsnoembed, it causes issues given location
.replace(/ipsnoembed="true" /gm, '') // manually replace ipsnoembed, it causes issues given location
.replace(/<a href="(.*)" rel="external nofollow(?: noopener)?"\s?(?:target="_blank")?>(.*)<\/a>/gm, '[$2]($1)')
.replace(/&amp;/gm, '&') // replace ampersand entity... it looks weird with some titles
.replace(/<\/li>/gm, '') // strip li end tags
Expand Down
7 changes: 5 additions & 2 deletions src/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const levels = {
SILLY: 'grey',
DEBUG: 'brightYellow',
INFO: 'blue',
WARN: 'orange',
WARN: 'brightRed',
ERROR: 'red',
FATAL: 'magenta',
};
Expand All @@ -40,6 +40,8 @@ const contexts = {
TWITCH: 'magenta',
WS: 'cyan',
DB: 'blue',
TwitchApi: 'magenta',
TM: 'yellow',
};

/**
Expand Down Expand Up @@ -79,12 +81,13 @@ Object.keys(levels).forEach((level) => {
if (Sentry) {
Sentry.captureException(message);
}
if (errorHook) {
if (errorHook && !l.logLevel === 'DEBUG') {
// filter out api errors, they're largely unhelpful and unrecoverable
if (message.stack && message.stack.startsWith('DiscordAPIError')) return;
errorHook.send(new ErrorEmbed(message));
} else {
console.error(simple);
console.error(message);
}
}
};
Expand Down
16 changes: 16 additions & 0 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

const { Client, WebhookClient } = require('discord.js');

// const Feeder = require('rss-feed-emitter');

const WorldStateClient = require('./resources/WorldStateClient');
const CommandManager = require('./CommandManager');
const EventHandler = require('./EventHandler');
Expand All @@ -11,6 +13,8 @@ const MessageManager = require('./settings/MessageManager');
const Database = require('./settings/Database');
const logger = require('./Logger');

// const feeds = require('./resources/rssFeeds');

const unlog = ['WS_CONNECTION_TIMEOUT'];

/**
Expand Down Expand Up @@ -150,6 +154,8 @@ class Genesis {
this.clusterId = process.env.CLUSTER_ID || 0;
// this.tracker = new Tracker(this);

// this.feeder; // for debugging

if (process.env.CONTROL_WH_ID) {
this.controlHook = new WebhookClient(process.env.CONTROL_WH_ID, process.env.CONTROL_WH_TOKEN);
}
Expand Down Expand Up @@ -203,6 +209,16 @@ class Genesis {
try {
await this.client.login(this.token);
this.logger.debug('Logged in with token.');

/* For Debugging:
this.feeder = new Feeder({
userAgent: `RSS Feed Emitter | ${this.client.user.username}`,
skipFirstLoad: true,
});
feeds.forEach((feed) => {
this.feeder.add({ url: feed.url, refresh: 900000 });
});
*/
} catch (err) {
const type = ((err && err.toString()) || '').replace(/Error \[(.*)\]: .*/ig, '$1');
if (!unlog.includes(type)) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/GetRSSUpdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GetRSSUpdates extends Command {

async run(message, ctx) {
const feedUrl = feeds.filter(f => f.key === `forum.updates.${ctx.platform}`)[0].url;
const matchingFeeds = this.bot.feedNotifier.feeder.list.filter(f => f.url === feedUrl);
const matchingFeeds = this.bot.feeder.list.filter(f => f.url === feedUrl);
const updates = matchingFeeds && matchingFeeds[0]
&& matchingFeeds[0].items && matchingFeeds[0].items[0]
? [...matchingFeeds[0].items]
Expand Down

0 comments on commit 0cfa18e

Please sign in to comment.