diff --git a/main.js b/main.js index 1074307..d32c66d 100644 --- a/main.js +++ b/main.js @@ -42,7 +42,7 @@ function autoUpdate() { autoUpdater.on('error', err => { const errorLog = `${process.execPath}/error.log`; - fs.writeFile(errorLog, `There was a problem updating the application: ${err}`, 'a+', (err) => { + fs.appendFile(errorLog, `There was a problem updating the application: ${err}`, (err) => { }); }) @@ -98,9 +98,10 @@ function launchApplication() { window.show(); }); - // if(process.env.NODE_ENV == 'dev') { - // window.webContents.toggleDevTools(); - // } + if(process.env.NODE_ENV == 'dev') { + window.webContents.toggleDevTools(); + } + window.loadFile('./dist/index.html'); if(!firstRun && process.env.NODE_ENV != 'dev' && process.platform == 'win32') { diff --git a/package-lock.json b/package-lock.json index 48c5f44..f0ef520 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "Blink", - "version": "1.2.8", + "version": "1.2.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8678ca6..d52177f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Blink", - "version": "1.2.8", + "version": "1.2.9", "description": "Blink", "license": "GPL-3.0", "main": "main.js", diff --git a/src/app/chat.service.ts b/src/app/chat.service.ts index 66706ff..671c6e0 100644 --- a/src/app/chat.service.ts +++ b/src/app/chat.service.ts @@ -449,6 +449,10 @@ export class ChatService { const message = Message.fromIncoming(original, params, this.emotes, this.cheers, this.settings, this.usernameLower); + if(message.ignore) { + return; + } + if (message.highlight && !this.active) { this.mentions++; if (this.settings.flash) { diff --git a/src/app/twitch.service.ts b/src/app/twitch.service.ts index beea04d..f970faa 100644 --- a/src/app/twitch.service.ts +++ b/src/app/twitch.service.ts @@ -4,13 +4,14 @@ import { IrcService } from './irc.service'; import CryptoJS from 'crypto-js'; import * as qs from 'querystring'; import { Web } from './web'; +import { ChatService } from './chat.service'; const authBase = 'https://id.twitch.tv/oauth2'; const authUrl = `${authBase}/authorize`; const validateUrl = `${authBase}/validate`; const revokeUrl = `${authBase}/revoke`; const redirect = 'https://cairthenn.com'; -const scopes = 'chat:edit chat:read whispers:edit whispers:read channel:moderate user_subscriptions'; +const scopes = 'chat:edit chat:read whispers:edit whispers:read channel:moderate user_subscriptions channel_editor'; const clientId = 'ut8pnp247zcvfj7gga2lxo8kp2d9lz'; const badgeChannelUrl = 'https://badges.twitch.tv/v1/badges/channels/'; @@ -106,6 +107,8 @@ export class TwitchService { public username: string; public usernameLower: string; + public whispers: ChatService; + public mentions: ChatService; private authWindow; private cheers: any = {}; @@ -115,6 +118,7 @@ export class TwitchService { private emotes: any = {}; private setNames: any = {}; private validation: any = {}; + private userIdMap: any = {}; private enckey: string; private loggedIn: boolean; private emoteCheck: number; @@ -228,6 +232,7 @@ export class TwitchService { return promise.then((auth: any) => { return Web.get(validateUrl, { headers: { + Accept: 'application/vnd.twitchtv.v5+json', Authorization : `OAuth ${auth.access_token}` } }).then(validatation => { @@ -235,7 +240,7 @@ export class TwitchService { this.usernameLower = validatation.login; this.enckey = CryptoJS.AES.encrypt(auth.access_token, validatation.login); this.loggedIn = true; - + const displayNamePromise = this.getChannel(validatation.login).then(channel => { this.username = channel.display_name; return true; @@ -247,47 +252,69 @@ export class TwitchService { const ircPromise = this.irc.connect(validatation.login, auth.access_token).then(() => true).catch(err => false); const emotePromise = this.getEmotes().then(() => true).catch(err => false); return Promise.all([displayNamePromise, ircPromise, emotePromise]).then(results => { - console.log(results); return results.every(x => x); }).catch(err => { console.log(`Error fetching channel info: ${err}`); return false; }); }); }).catch(err => { console.log(`Error fetching channel info: ${err}`); return false; }); } - public getStream(id: string, update?: boolean) { - const fetch = update || this.streams[id] ? this.needsUpdate(this.streams[id][1], 'streams') : true; - if (!fetch) { - return Promise.resolve(this.streams[id][0]); - } - - return Web.get(`${twitchApi}/${apiVersion}/${streamEp}/${id}`, { - headers: { - Authorization : `OAuth ${this.key}` + public getStream(name: string, update?: boolean) { + + return this.getChannelID(name).then(id => { + const fetch = update || this.streams[id] ? this.needsUpdate(this.streams[id][1], 'streams') : true; + if (!fetch) { + return Promise.resolve(this.streams[id][0]); } - }).then(stream => { - const info = stream.stream || {}; - info.live = info.stream_type === 'live'; - info.vod = info.stream_type === 'playlist'; - this.streams[id] = [ info, Date.now() ]; - return info; + + return Web.get(`${twitchApi}/${apiVersion}/${streamEp}/${id}`, { + headers: { + Accept: 'application/vnd.twitchtv.v5+json', + Authorization : `OAuth ${this.key}` + } + }).then(stream => { + const info = stream.stream || {}; + info.live = info.stream_type === 'live'; + info.vod = info.stream_type === 'playlist'; + this.streams[id] = [ info, Date.now() ]; + return info; + }); }); } - public getChannel(id: string, update?: boolean) { + private getChannelID(name: string) { - const fetch = update || this.channels[id] ? this.needsUpdate(this.channels[id][1], 'channels') : true; - if (!fetch) { - return Promise.resolve(this.channels[id][0]); + if (name in this.userIdMap) { + return Promise.resolve(this.userIdMap[name]); } - return Web.get(`${twitchApi}/${apiVersion}/${channelEp}/${id}`, { + return Web.get(`${twitchApi}/helix/users?login=${name}`, { headers: { - Authorization : `OAuth ${this.key}` + Authorization : `Bearer ${this.key}` + } + }).then(response => { + return this.userIdMap[name] = response.data[0].id; + }) + + } + + public getChannel(name: string, update?: boolean) { + + return this.getChannelID(name).then(id => { + const fetch = update || this.channels[id] ? this.needsUpdate(this.channels[id][1], 'channels') : true; + if (!fetch) { + return Promise.resolve(this.channels[id][0]); } - }).then(channel => { - channel.signup = new Date(channel.created_at).toDateString(); - this.channels[id] = [ channel, Date.now() ]; - return channel; + + return Web.get(`${twitchApi}/${apiVersion}/${channelEp}/${id}`, { + headers: { + Accept: 'application/vnd.twitchtv.v5+json', + Authorization : `OAuth ${this.key}` + } + }).then(channel => { + channel.signup = new Date(channel.created_at).toDateString(); + this.channels[id] = [ channel, Date.now() ]; + return channel; + }); }); } @@ -336,8 +363,9 @@ export class TwitchService { return Promise.resolve(this.emotes); } - return Web.get(`${twitchApi}/${apiVersion}/users/${this.usernameLower}/emotes`, { + return Web.get(`${twitchApi}/${apiVersion}/users/${this.validation.user_id}/emotes`, { headers: { + Accept: 'application/vnd.twitchtv.v5+json', Authorization : `OAuth ${this.key}` } }).then(emotes => {