Skip to content

Commit

Permalink
feat: linting, set up webhooks during tracking, add necralisk
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Oct 31, 2020
1 parent c86dca1 commit f287db5
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/CommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const trackableEvents = {
syndicates,
conclave,
deals,
cambion: ['cambion.fass', 'cambion.vome'],
cambion: ['cambion.fass', 'cambion.vome', 'necralisk'],
cetus: ['cetus.day', 'cetus.night'],
ostrons: ['cetus.day', 'cetus.night', 'syndicate.ostrons'],
earth: ['earth.day', 'earth.night'],
Expand Down
34 changes: 33 additions & 1 deletion src/commands/Tracking/Track.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
setupPages,
constructItemEmbeds,
constructTypeEmbeds,
emojify,
} = require('../../CommonFunctions');

/**
Expand Down Expand Up @@ -59,6 +60,37 @@ class Track extends Command {
await this.notifyCurrent(channel, message);
}
this.messageManager.notifySettingsChange(message, true, true);

if (!ctx.webhook) {
if (message.channel.permissionsFor(this.bot.client.user).has('MANAGE_WEBHOOKS')) {
let webhook;
try {
await message.channel.send('Setting up webhook...');
const existingWebhooks = (await message.channel.fetchWebhooks())
.filter(w => w.type === 'Incoming');
if (existingWebhooks.size) {
const temp = existingWebhooks.first();
webhook = {
id: temp.id,
token: temp.token,
name: this.settings.defaults.username,
avatar: this.settings.defaults.avatar,
};
} else {
webhook = await message.channel.createWebhook(this.settings.defaults.username, {
avatar: this.settings.defaults.avatar,
reason: 'Automated Webhook setup for Notifications',
});
}
this.bot.settings.setChannelWebhook(message.channel, webhook);
await message.channel.send(`${emojify('green_tick')} Webhook setup complete.`);
} catch (e) {
await message.channel.send(`${emojify('red_tick')} Cannot set up webhooks: failed to look up.`);
}
} else {
await message.channel.send(`${emojify('red_tick')} Cannot set up webhooks: missing permissions.`);
}
}
return this.messageManager.statuses.SUCCESS;
}

Expand All @@ -73,7 +105,7 @@ class Track extends Command {
if (pages.length) {
return setupPages(pages, { message, settings: this.settings, mm: this.messageManager });
}
return this.messageManager.send(message, { content: 'Nothing Tracked', deleteOriginal: true, deleteResponse: true });
return message.channel.send('Nothing Tracked');
}

async failure(message, prefix) {
Expand Down
10 changes: 5 additions & 5 deletions src/notifications/Broadcaster.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const logger = require('../Logger');
const bs = require('byte-size');
const logger = require('../Logger');

function byteFmt () {
function byteFmt() {
return `${this.value}${this.unit}`;
}

Expand All @@ -15,12 +15,12 @@ const clean = (channelId, index) => {
const before = v8.getHeapStatistics();
global.gc();
const after = v8.getHeapStatistics();

const entry = {
b: { u: bs(before.used_heap_size, byteFmt), l: bs(before.heap_size_limit, byteFmt) },
a: { u: bs(after.used_heap_size, byteFmt), l: bs(after.heap_size_limit, byteFmt) },
};

logger.silly(`${channelId} ======> ${String(entry.b.u).padEnd(7)} || ${String(entry.a.u).padEnd(7)}`);
} catch (e) {
logger.info(e);
Expand All @@ -44,7 +44,7 @@ class Broadcaster {
this.webhook = messageManager.webhook;
this.shards = process.env.SHARDS;
}

wrap(embed, ctx) {
return this.wraps([embed], ctx);
}
Expand Down
6 changes: 4 additions & 2 deletions src/notifications/Notifier.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

/* eslint-disable no-unused-vars */

const Wikia = require('node-wikia');
const util = require('util');

Expand Down Expand Up @@ -303,7 +305,7 @@ class Notifier {
await this.broadcaster.broadcast(new embeds.Acolyte(
{ logger },
[acolyte], platform,
), platform, `enemies${a.isDiscovered ? '' : '.departed'}`)
), platform, `enemies${acolyte.isDiscovered ? '' : '.departed'}`);
}
return true;
}
Expand Down Expand Up @@ -351,7 +353,7 @@ class Notifier {
const pages = createGroupedArray(embed.fields, 15);
for (const page of pages) {
const tembed = { ...embed };
tembed.fields = pageFields;
tembed.fields = page;
await this.broadcaster.broadcast(tembed, platform, 'baro');
}
} else {
Expand Down
9 changes: 5 additions & 4 deletions src/notifications/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ class Worker {
deps.messageManager = this.messageManager;

this.notifier = new Notifier(deps);
// this.feedNotifier = new FeedsNotifier(deps);
// this.twitchNotifier = new TwitchNotifier(deps);
this.feedNotifier = new FeedsNotifier(deps);
this.twitchNotifier = new TwitchNotifier(deps);

this.feedNotifier.start();
this.twitchNotifier.start();

// this.feedNotifier.start();
await this.notifier.start();
// await this.twitchNotifier.start();

const body = {
embeds: [{
Expand Down
7 changes: 7 additions & 0 deletions src/resources/syndicates.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@
"timeout": 86400000,
"notifiable": true
},
{
"key": "necralisk",
"display": "Entrati",
"prefix": false,
"timeout": 0,
"notifiable": true
},
{
"key": "all",
"display": "all",
Expand Down
4 changes: 3 additions & 1 deletion src/resources/trackables.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"syndicate.meridian",
"syndicate.ostrons",
"syndicate.assassins",
"necralisk",
"updates",
"primeaccess",
"streams",
Expand Down Expand Up @@ -110,7 +111,8 @@
"syndicate.meridian",
"syndicate.ostrons",
"syndicate.assassins",
"solaris"
"solaris",
"necralisk"
],
"conclave": [
"conclave.weeklies",
Expand Down
2 changes: 1 addition & 1 deletion src/settings/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class Database {
'defaultNoText', 'defaultShown', 'createPrivateChannel', 'tempCategory',
'lfgChannel', 'settings.cc.ping', 'language', 'respond_to_settings',
'lfgChannel.swi', 'lfgChannel.ps4', 'lfgChannel.xb1', 'delete_after_respond']);

if (platforms.length > 4) {
platforms.forEach((platform, index) => {
if (index > 3) {
Expand Down
10 changes: 4 additions & 6 deletions src/settings/DatabaseQueries/PingsQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ class PingsQueries {
if (!guild) {
return undefined;
}
if (guild['channels']) {
delete guild['channels'];
guild.id = guild['id'];

if (guild.channels) {
delete guild.channels;
guild.id = guild['id']; // eslint-disable-line no-self-assign, dot-notation
}

if (!guild.id) {
console.log(JSON.stringify(Object.keys(guild)));
console.log(JSON.stringify(guild['id']));
guild = { id: guild };
}
const query = SQL`SELECT text FROM pings WHERE guild_id=${guild.id} AND item_or_type in (${itemsOrTypes})`;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/RESTWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RESTWrapper {
}

async init() {
this.user = /*await this.client.get('/users/@me');*/ { username: 'Genesis' };
this.user = /* await this.client.get('/users/@me'); */ { username: 'Genesis' };
}

/**
Expand Down

0 comments on commit f287db5

Please sign in to comment.