Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cairthenn committed Aug 22, 2019
2 parents 008b76a + 17d13f4 commit c279f53
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 35 deletions.
9 changes: 5 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

});
})
Expand Down Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
{
"name": "Blink",
"version": "1.2.8",
"version": "1.2.9",
"description": "Blink",
"license": "GPL-3.0",
"main": "main.js",
Expand Down
4 changes: 4 additions & 0 deletions src/app/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
86 changes: 57 additions & 29 deletions src/app/twitch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Expand Down Expand Up @@ -106,6 +107,8 @@ export class TwitchService {

public username: string;
public usernameLower: string;
public whispers: ChatService;
public mentions: ChatService;

private authWindow;
private cheers: any = {};
Expand All @@ -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;
Expand Down Expand Up @@ -228,14 +232,15 @@ 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 => {
this.validation = validatation;
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;
Expand All @@ -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;
});
});
}

Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit c279f53

Please sign in to comment.