Skip to content

Commit

Permalink
feat: reenable pings (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Mar 19, 2021
1 parent fde50be commit 67d1815
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/notifications/Broadcaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Broadcaster {
}

try {
const prepend = ''; // await this.settings.getPing(guild, (items || []).concat([type]));
const prepend = this.workerCache.getKey('pings')[`${guild.id}:${[type].concat(items || [])}`] || ''; // await this.settings.getPing(guild, (items || []).concat([type]));
if (!embed.embeds) {
await this.webhook(ctx, { text: prepend, embed: this.wrap(embed, ctx) });
} else {
Expand Down
18 changes: 17 additions & 1 deletion src/notifications/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ class Worker {
});
}
}

/* eslint-disable-next-line class-methods-use-this */
async hydratePings() {
const sDate = Date.now();
const pings = await db.getAllPings();
if (pings) {
deps.workerCache.setKey('pings', pings);
deps.workerCache.save(true);
}
const eDate = Date.now();
logger.info(`ping hydration took ${String(eDate - sDate).red}ms`, 'DB');
}

async hydrateGuilds() {
const sDate = Date.now();
const guilds = await db.getGuilds();
Expand All @@ -58,6 +69,8 @@ class Worker {
}
const eDate = Date.now();
logger.info(`guild hydration took ${String(eDate - sDate).red}ms`, 'DB');

await this.hydratePings();
}

/* eslint-disable-next-line class-methods-use-this */
Expand All @@ -82,6 +95,9 @@ class Worker {
// generate guild cache data if not present
const currentGuilds = deps.workerCache.getKey('guilds');
if (!currentGuilds || forceHydrate) await this.hydrateGuilds();

const currentPings = deps.workerCache.getKey('pings');
if (!(currentPings && Object.keys(currentPings).length) || forceHydrate) await this.hydratePings();

let hydrateEvents = forceHydrate;
for (const cachedEvent of cachedEvents) {
Expand Down
1 change: 1 addition & 0 deletions src/resources/pingables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["item_or_type","arbitration.corpus.arena","arbitration.corpus.defection","arbitration.corpus.defense","arbitration.corpus.disruption","arbitration.corpus.excavation","arbitration.corpus.infestedsalvage","arbitration.corpus.interception","arbitration.corpus.sanctuaryonslaught","arbitration.corpus.survival","arbitration.corrupted.arena","arbitration.corrupted.defection","arbitration.corrupted.defense","arbitration.corrupted.disruption","arbitration.corrupted.excavation","arbitration.corrupted.infestedsalvage","arbitration.corrupted.interception","arbitration.corrupted.sanctuaryonslaught","arbitration.corrupted.survival","arbitration.grineer.arena","arbitration.grineer.defection","arbitration.grineer.defense","arbitration.grineer.disruption","arbitration.grineer.excavation","arbitration.grineer.infestedsalvage","arbitration.grineer.interception","arbitration.grineer.sanctuaryonslaught","arbitration.grineer.survival","arbitration.infested.arena","arbitration.infested.defection","arbitration.infested.defense","arbitration.infested.disruption","arbitration.infested.excavation","arbitration.infested.infestedsalvage","arbitration.infested.interception","arbitration.infested.sanctuaryonslaught","arbitration.infested.survival","arbitration.orokin.arena","arbitration.orokin.defection","arbitration.orokin.defense","arbitration.orokin.disruption","arbitration.orokin.excavation","arbitration.orokin.infestedsalvage","arbitration.orokin.interception","arbitration.orokin.sanctuaryonslaught","arbitration.orokin.survival","baro","cambion.fass","cambion.vome","cetus","cetus.day","cetus.day.","cetus.day.0","cetus.day.1","cetus.day.10","cetus.day.100","cetus.day.12","cetus.day.15","cetus.day.17","cetus.day.18","cetus.day.2","cetus.day.20","cetus.day.21","cetus.day.23","cetus.day.25","cetus.day.29","cetus.day.3","cetus.day.30","cetus.day.38","cetus.day.47","cetus.day.49","cetus.day.5","cetus.day.50","cetus.day.60","cetus.day.64","cetus.day.66","cetus.day.67","cetus.day.70","cetus.day.74","cetus.day.87","cetus.day.95","cetus.night","cetus.night.","cetus.night.0","cetus.night.1","cetus.night.10","cetus.night.12","cetus.night.15","cetus.night.20","cetus.night.21","cetus.night.25","cetus.night.38","cetus.night.40","cetus.night.45","cetus.night.47","cetus.night.49","cetus.night.5","cetus.night.50","cetus.night.51","cetus.night.60","cetus.night.70","clantech","conclave.dailies","conclave.weeklies","darvo","deals.featured","deals.popular","de_rebecca.live","de_steve.live","earth.day","earth.night","enemies","enemies.departed","fissures","fissures.t1","fissures.t1.arena","fissures.t1.assassination","fissures.t1.assault","fissures.t1.capture","fissures.t1.conclave","fissures.t1.darksector","fissures.t1.defection","fissures.t1.defense","fissures.t1.disruption","fissures.t1.evacuation","fissures.t1.excavation","fissures.t1.exterminate","fissures.t1.extermination","fissures.t1.hijack","fissures.t1.hive","fissures.t1.infestedsalvage","fissures.t1.interception","fissures.t1.mobiledefense","fissures.t1.rathuum","fissures.t1.rescue","fissures.t1.sabotage","fissures.t1.sanctuaryonslaught","fissures.t1.spy","fissures.t1.survival","fissures.t2","fissures.t2.arena","fissures.t2.assassination","fissures.t2.assault","fissures.t2.capture","fissures.t2.conclave","fissures.t2.darksector","fissures.t2.defection","fissures.t2.defense","fissures.t2.disruption","fissures.t2.evacuation","fissures.t2.excavation","fissures.t2.exterminate","fissures.t2.extermination","fissures.t2.hijack","fissures.t2.hive","fissures.t2.infestedsalvage","fissures.t2.interception","fissures.t2.mobiledefense","fissures.t2.rathuum","fissures.t2.rescue","fissures.t2.sabotage","fissures.t2.sanctuaryonslaught","fissures.t2.spy","fissures.t2.survival","fissures.t3","fissures.t3.arena","fissures.t3.assassination","fissures.t3.assault","fissures.t3.capture","fissures.t3.conclave","fissures.t3.darksector","fissures.t3.defection","fissures.t3.defense","fissures.t3.disruption","fissures.t3.evacuation","fissures.t3.excavation","fissures.t3.exterminate","fissures.t3.extermination","fissures.t3.hijack","fissures.t3.hive","fissures.t3.infestedsalvage","fissures.t3.interception","fissures.t3.mobiledefense","fissures.t3.rathuum","fissures.t3.rescue","fissures.t3.sabotage","fissures.t3.sanctuaryonslaught","fissures.t3.spy","fissures.t3.survival","fissures.t4","fissures.t4.arena","fissures.t4.assassination","fissures.t4.assault","fissures.t4.capture","fissures.t4.conclave","fissures.t4.darksector","fissures.t4.defection","fissures.t4.defense","fissures.t4.disruption","fissures.t4.evacuation","fissures.t4.excavation","fissures.t4.exterminate","fissures.t4.extermination","fissures.t4.hijack","fissures.t4.hive","fissures.t4.infestedsalvage","fissures.t4.interception","fissures.t4.mobiledefense","fissures.t4.rathuum","fissures.t4.rescue","fissures.t4.sabotage","fissures.t4.sanctuaryonslaught","fissures.t4.spy","fissures.t4.survival","fissures.t5.arena","fissures.t5.assassination","fissures.t5.assault","fissures.t5.capture","fissures.t5.defection","fissures.t5.defense","fissures.t5.disruption","fissures.t5.excavation","fissures.t5.extermination","fissures.t5.hijack","fissures.t5.infestedsalvage","fissures.t5.interception","fissures.t5.mobiledefense","fissures.t5.rescue","fissures.t5.sabotage","fissures.t5.sanctuaryonslaught","fissures.t5.spy","fissures.t5.survival","forum.announcements.pc","forum.announcements.ps4","forum.announcements.switch","forum.announcements.xb1","forum.news","forum.staff.bear","forum.staff.connor","forum.staff.danielle","forum.staff.drew","forum.staff.george","forum.staff.glen","forum.staff.helen","forum.staff.marcus","forum.staff.megan","forum.staff.pablo","forum.staff.rebecca","forum.staff.saske","forum.staff.steve","forum.staff.syncrasis","forum.staff.taylor","forum.updates.pc","forum.updates.ps4","forum.updates.switch","forum.updates.xb1","forum.workshop","invasions","joeyzerotv.live","kuva.arena","kuva.assassination","kuva.assault","kuva.capture","kuva.defection","kuva.defense","kuva.disruption","kuva.excavation","kuva.extermination","kuva.hijack","kuva.infestedsalvage","kuva.interception","kuva.mobiledefense","kuva.rescue","kuva.sabotage","kuva.sanctuaryonslaught","kuva.spy","kuva.survival","necralisk","news","nightwave","nightwave.daily","nightwave.elite","nightwave.weekly","operations","outposts","players_helping_players","potato","primeaccess","resource","sherpa.live","solaris","solaris.cold","solaris.cold.10","solaris.cold.2","solaris.cold.3","solaris.cold.5","solaris.warm","solaris.warm.1","solaris.warm.10","solaris.warm.2","solaris.warm.3","solaris.warm.5","sorties","streams","syndicate.arbiters","syndicate.assassins","syndicate.loka","syndicate.meridian","syndicate.ostrons","syndicate.perrin","syndicate.suda","syndicate.veil","twitch","twitter.cameron.quote","twitter.cameron.reply","twitter.cameron.retweet","twitter.cameron.tweet","twitter.danielle.quote","twitter.danielle.reply","twitter.danielle.retweet","twitter.danielle.tweet","twitter.digitalextremes.quote","twitter.digitalextremes.reply","twitter.digitalextremes.retweet","twitter.digitalextremes.tweet","twitter.george.quote","twitter.george.reply","twitter.george.retweet","twitter.george.tweet","twitter.helen.quote","twitter.helen.reply","twitter.helen.retweet","twitter.helen.tweet","twitter.maciej.quote","twitter.maciej.reply","twitter.maciej.retweet","twitter.maciej.tweet","twitter.megan.quote","twitter.megan.reply","twitter.megan.retweet","twitter.megan.tweet","twitter.narc.quote","twitter.narc.reply","twitter.narc.retweet","twitter.narc.tweet","twitter.pablo.quote","twitter.pablo.reply","twitter.pablo.retweet","twitter.pablo.tweet","twitter.quote.cameron","twitter.quote.danielle","twitter.quote.digitalextremes","twitter.quote.helen","twitter.quote.maciej","twitter.quote.megan","twitter.quote.narc","twitter.quote.pablo","twitter.quote.rebecca","twitter.quote.sheldon","twitter.quote.steve","twitter.quote.tobiah","twitter.quote.warframe","twitter.quote.wfdiscord","twitter.rebecca.quote","twitter.rebecca.reply","twitter.rebecca.retweet","twitter.rebecca.tweet","twitter.reply.cameron","twitter.reply.danielle","twitter.reply.digitalextremes","twitter.reply.helen","twitter.reply.maciej","twitter.reply.megan","twitter.reply.narc","twitter.reply.pablo","twitter.reply.rebecca","twitter.reply.sheldon","twitter.reply.steve","twitter.reply.tobiah","twitter.reply.warframe","twitter.reply.wfdiscord","twitter.retweet.cameron","twitter.retweet.danielle","twitter.retweet.digitalextremes","twitter.retweet.helen","twitter.retweet.maciej","twitter.retweet.megan","twitter.retweet.narc","twitter.retweet.pablo","twitter.retweet.rebecca","twitter.retweet.sheldon","twitter.retweet.steve","twitter.retweet.tobiah","twitter.retweet.warframe","twitter.retweet.wfdiscord","twitter.sheldon.quote","twitter.sheldon.reply","twitter.sheldon.retweet","twitter.sheldon.tweet","twitter.steve.quote","twitter.steve.reply","twitter.steve.retweet","twitter.steve.tweet","twitter.tobiah.quote","twitter.tobiah.reply","twitter.tobiah.retweet","twitter.tobiah.tweet","twitter.tweet.cameron","twitter.tweet.danielle","twitter.tweet.digitalextremes","twitter.tweet.helen","twitter.tweet.maciej","twitter.tweet.megan","twitter.tweet.narc","twitter.tweet.pablo","twitter.tweet.rebecca","twitter.tweet.sheldon","twitter.tweet.steve","twitter.tweet.tobiah","twitter.tweet.warframe","twitter.tweet.wfdiscord","twitter.warframe.quote","twitter.warframe.reply","twitter.warframe.retweet","twitter.warframe.tweet","twitter.wfdiscord.quote","twitter.wfdiscord.reply","twitter.wfdiscord.retweet","twitter.wfdiscord.tweet","updates","warframe.devstream.live","warframe.other.live","warframe.primetime.live","alerts,vauban","alerts,vandal","alerts,wraith","alerts,skin","alerts,helmet","alerts,nitain","alerts,mutalist","alerts,weapon","alerts,fieldron","alerts,detonite","alerts,mutagen","alerts,aura","alerts,neuralSensors","alerts,orokinCell","alerts,alloyPlate","alerts,circuits","alerts,controlModule","alerts,ferrite","alerts,gallium","alerts,morphics","alerts,nanoSpores","alerts,oxium","alerts,rubedo","alerts,salvage","alerts,plastids","alerts,polymerBundle","alerts,argonCrystal","alerts,cryotic","alerts,tellurium","alerts,neurodes","alerts,nightmare","alerts,endo","alerts,reactor","alerts,catalyst","alerts,forma","alerts,synthula","alerts,exilus","alerts,riven","alerts,kavatGene","alerts,kubrowEgg","alerts,traces","alerts,other","alerts,credits","invasions,vandal,wraith","invasions,vandal,nitain","invasions,vandal,mutalist","invasions,vandal,weapon","invasions,vandal,fieldron","invasions,vandal,detonite","invasions,vandal,mutagen","invasions,vandal,reactor","invasions,vandal,catalyst","invasions,vandal,forma","invasions,vandal,other","invasions,vandal,credits","invasions,wraith,vandal","invasions,wraith,nitain","invasions,wraith,mutalist","invasions,wraith,weapon","invasions,wraith,fieldron","invasions,wraith,detonite","invasions,wraith,mutagen","invasions,wraith,reactor","invasions,wraith,catalyst","invasions,wraith,forma","invasions,wraith,other","invasions,wraith,credits","invasions,nitain,vandal","invasions,nitain,wraith","invasions,nitain,mutalist","invasions,nitain,weapon","invasions,nitain,fieldron","invasions,nitain,detonite","invasions,nitain,mutagen","invasions,nitain,reactor","invasions,nitain,catalyst","invasions,nitain,forma","invasions,nitain,other","invasions,nitain,credits","invasions,mutalist,vandal","invasions,mutalist,wraith","invasions,mutalist,nitain","invasions,mutalist,weapon","invasions,mutalist,fieldron","invasions,mutalist,detonite","invasions,mutalist,mutagen","invasions,mutalist,reactor","invasions,mutalist,catalyst","invasions,mutalist,forma","invasions,mutalist,other","invasions,mutalist,credits","invasions,weapon,vandal","invasions,weapon,wraith","invasions,weapon,nitain","invasions,weapon,mutalist","invasions,weapon,fieldron","invasions,weapon,detonite","invasions,weapon,mutagen","invasions,weapon,reactor","invasions,weapon,catalyst","invasions,weapon,forma","invasions,weapon,other","invasions,weapon,credits","invasions,fieldron,vandal","invasions,fieldron,wraith","invasions,fieldron,nitain","invasions,fieldron,mutalist","invasions,fieldron,weapon","invasions,fieldron,detonite","invasions,fieldron,mutagen","invasions,fieldron,reactor","invasions,fieldron,catalyst","invasions,fieldron,forma","invasions,fieldron,other","invasions,fieldron,credits","invasions,detonite,vandal","invasions,detonite,wraith","invasions,detonite,nitain","invasions,detonite,mutalist","invasions,detonite,weapon","invasions,detonite,fieldron","invasions,detonite,mutagen","invasions,detonite,reactor","invasions,detonite,catalyst","invasions,detonite,forma","invasions,detonite,other","invasions,detonite,credits","invasions,mutagen,vandal","invasions,mutagen,wraith","invasions,mutagen,nitain","invasions,mutagen,mutalist","invasions,mutagen,weapon","invasions,mutagen,fieldron","invasions,mutagen,detonite","invasions,mutagen,reactor","invasions,mutagen,catalyst","invasions,mutagen,forma","invasions,mutagen,other","invasions,mutagen,credits","invasions,reactor,vandal","invasions,reactor,wraith","invasions,reactor,nitain","invasions,reactor,mutalist","invasions,reactor,weapon","invasions,reactor,fieldron","invasions,reactor,detonite","invasions,reactor,mutagen","invasions,reactor,catalyst","invasions,reactor,forma","invasions,reactor,other","invasions,reactor,credits","invasions,catalyst,vandal","invasions,catalyst,wraith","invasions,catalyst,nitain","invasions,catalyst,mutalist","invasions,catalyst,weapon","invasions,catalyst,fieldron","invasions,catalyst,detonite","invasions,catalyst,mutagen","invasions,catalyst,reactor","invasions,catalyst,forma","invasions,catalyst,other","invasions,catalyst,credits","invasions,forma,vandal","invasions,forma,wraith","invasions,forma,nitain","invasions,forma,mutalist","invasions,forma,weapon","invasions,forma,fieldron","invasions,forma,detonite","invasions,forma,mutagen","invasions,forma,reactor","invasions,forma,catalyst","invasions,forma,other","invasions,forma,credits","invasions,other,vandal","invasions,other,wraith","invasions,other,nitain","invasions,other,mutalist","invasions,other,weapon","invasions,other,fieldron","invasions,other,detonite","invasions,other,mutagen","invasions,other,reactor","invasions,other,catalyst","invasions,other,forma","invasions,other,credits","invasions,credits,vandal","invasions,credits,wraith","invasions,credits,nitain","invasions,credits,mutalist","invasions,credits,weapon","invasions,credits,fieldron","invasions,credits,detonite","invasions,credits,mutagen","invasions,credits,reactor","invasions,credits,catalyst","invasions,credits,forma","invasions,credits,other"]
39 changes: 39 additions & 0 deletions src/settings/DatabaseQueries/PingsQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const SQL = require('sql-template-strings');
const logger = require('../../Logger');
const pingLists = require('../../resources/pingables.json');

class PingsQueries {
constructor(db) {
Expand Down Expand Up @@ -78,6 +79,44 @@ class PingsQueries {
return '';
}
}

async getAllPings() {
console.log(pingLists.length);

let globalPings = {};
for (const plist of pingLists) {
const plistPings = await this.getGroupPings(plist);
// console.log(JSON.stringify(plistPings));
globalPings = {
...globalPings,
...plistPings,
};
}
return globalPings;
}

async getGroupPings(plist) {
const pings = {};
// console.log(plist.split(','))
const query = SQL`SELECT guild_id, GROUP_CONCAT(text SEPARATOR ',') as ping
FROM pings
WHERE item_or_type in (${plist.split(',')})
GROUP by guild_id
ORDER by item_or_type asc`;
const res = await this.query(query);
const [rows] = res;

if (rows) {
// console.log(rows);

rows.forEach(row => {
const id = `${row.guild_id}:${plist}`;
pings[id] = row.ping;
});
}

return pings;
}

async getPingsForGuild(guild) {
if (guild) {
Expand Down

0 comments on commit 67d1815

Please sign in to comment.