-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Messages won't be shown more than once - Improved system and quality
- Loading branch information
Showing
2 changed files
with
50 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const rp = require('request-promise-native'); | ||
class AlertHandler { | ||
constructor() { | ||
|
||
} | ||
|
||
async load() { | ||
return await this._check(Mana.version); | ||
} | ||
|
||
async login() { | ||
return await this._check(Mana.version, Mana.user.getSummonerId()); | ||
} | ||
|
||
async stop() { | ||
|
||
} | ||
|
||
async _check(version = Mana.version, summonerId) { | ||
const alerts = Mana.getStore().get('alerts', []); | ||
|
||
try { | ||
let messages = await rp({ uri: `https://manaflux-server.herokuapp.com/api/alerts/v2?v=${this.version}${summonerId ? '&summoner=' + summonerId : ''}`, json: true }); | ||
console.dir(messages); | ||
|
||
messages.filter(x => !alerts.includes(x._id)).forEach(x => { | ||
this._alert(x.message); | ||
alerts.push(x._id); | ||
}); | ||
|
||
Mana.getStore().set('alerts', alerts); | ||
} | ||
catch(err) { | ||
console.error(err); | ||
} | ||
} | ||
|
||
_alert(message) { | ||
alertify.warning(message); | ||
} | ||
} | ||
|
||
module.exports = AlertHandler; |