Skip to content

Commit

Permalink
Update to version 0.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
vaverix committed Dec 23, 2020
1 parent 3fd1509 commit 89e8f49
Show file tree
Hide file tree
Showing 11 changed files with 4,521 additions and 4,729 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
"no-unreachable": "warn",
"no-unused-vars": "off",
"constructor-super": "warn",
"valid-typeof": "warn"
"valid-typeof": "warn",
"vue/experimental-script-setup-vars": "off"
}
};
4,851 changes: 2,225 additions & 2,626 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"name": "vaverix-twitch-bot",
"description": "Desktop application that allows you to log-in into multiple Twitch.tv channels at once. It also notifies you when someone mentions you in any channel you choose and has couple of other extra features.",
"author": "vaverix",
"version": "0.0.12",
"version": "0.0.13",
"license": "MIT",
"scripts": {
"build": "yarn compile",
"dev": "electron-webpack dev",
"compile": "electron-webpack",
"dist": "yarn compile && electron-builder",
Expand All @@ -28,14 +29,21 @@
"win": {
"target": "NSIS",
"icon": "static/icon.ico"
},
"nsis": {
"artifactName": "${productName}-Setup-${version}.${ext}"
}
},
"dependencies": {
"auto-launch": "^5.0.5",
"axios": "^0.21.1",
"css-loader": "^3.5.3",
"discord.js": "^12.2.0",
"electron-log": "^4.1.1",
"electron-store": "^5.1.1",
"electron-updater": "^4.2.5",
"marked": "^1.2.7",
"moment": "^2.29.1",
"node-fetch": "^2.6.1",
"source-map-support": "^0.5.19",
"tmi.js": "^1.5.0",
Expand Down
4 changes: 4 additions & 0 deletions src/main/appData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let appData = {}
appData.isDevelopment = process.env.NODE_ENV !== 'production'
appData.isMac = process.platform === 'darwin'
appData.store = new Store()
appData.version = require('../../package.json').version

// global reference to mainWindow (necessary to prevent window from being garbage collected)
appData.mainWindow
Expand All @@ -18,6 +19,7 @@ appData.channelImages = appData.store.get('channelImages', {
'https://static-cdn.jtvnw.net/jtv_user_pictures/f2ca9fc6-5867-493b-9e94-079fd34822bb-profile_image-70x70.jpeg',
})
appData.optionsDefaults = {
__autostart: false,
__autoscroll: true,
__autohide: false,
__notifications: true,
Expand All @@ -26,7 +28,9 @@ appData.optionsDefaults = {
__messagesLimit: 100,
__streampreview: false,
__streampreviewmode: 'docked',
__twitchBonusCollector: false,
__keywords: '',
__changelog: '0.0.0',
}
appData.options = appData.store.get('options', appData.optionsDefaults)
appData.twitchData = appData.store.get('twitchData', {
Expand Down
22 changes: 20 additions & 2 deletions src/main/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ const formQuerystring = (qs = {}) => {
const request = ({
base = '',
endpoint = '',
qs,
qs = {},
headers = {},
method = 'get',
body = '',
}) => {
let opts = {
method,
headers,
}
if (body && body.length > 0) {
opts.body = body
}
return fetch(base + endpoint + '?' + formQuerystring(qs), opts).then((res) =>
res.json()
)
Expand All @@ -33,6 +37,20 @@ const kraken = (opts) => {
return request(Object.assign(defaults, opts))
}

const gql = (clientId, oAuth, opts) => {
let defaults = {
base: 'https://gql.twitch.tv/gql',
headers: {
Authorization: oAuth || 'OAuth vjee4wlzxs9btbg3jqyx4f3md9tknp',
'Client-ID': clientId || 'kimne78kx3ncx6brgo4mv6wki5h1ko',
'Content-Type': 'text/plain;charset=UTF-8',
},
method: 'post',
body: '',
}
return request(Object.assign(defaults, opts))
}

const twitchNameToUser = (username) => {
return kraken({
endpoint: 'users',
Expand All @@ -51,4 +69,4 @@ const nonce = (length) => {
return text
}

export { formQuerystring, request, kraken, twitchNameToUser, nonce }
export { formQuerystring, request, kraken, gql, twitchNameToUser, nonce }
6 changes: 2 additions & 4 deletions src/main/twitch/floatingWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ const floatingWindow = (channel, appData) => {
} else {
window.loadURL(
formatUrl({
pathname: path.join(
__dirname,
`index.html?floatingWindow=${encodeURIComponent(channel)}`
),
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true,
search: `?floatingWindow=${encodeURIComponent(channel)}`,
})
)
}
Expand Down
26 changes: 24 additions & 2 deletions src/main/twitch/twitch.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { ipcMain } from 'electron'
import underscore from 'underscore'
import AutoLaunch from 'auto-launch'
import tmi from 'tmi.js'
//import discord from 'discord.js'
import { request, kraken, twitchNameToUser } from '../functions'
import { startTwitchBonusCollector } from './twitchBonusCollector'
import { floatingWindow } from './floatingWindow'

const autoLauncher = new AutoLaunch({
name: require('../../../package.json').name,
})
const startTwitchApp = (appData) => {
const getChannels = () => {
let temp = []
Expand Down Expand Up @@ -75,6 +79,19 @@ const startTwitchApp = (appData) => {
})
}

const toggleAutoStart = (opts) => {
if (appData && appData.isDevelopment) return
autoLauncher
.isEnabled()
.then(function (isEnabled) {
if (opts && opts['__autostart']) autoLauncher.enable()
else autoLauncher.disable()
})
.catch(function (err) {
throw err
})
}

// Main app
ipcMain.on('app:ready', () => {
if (appData.twitch && appData.twitch.disconnect) {
Expand Down Expand Up @@ -105,7 +122,7 @@ const startTwitchApp = (appData) => {
(appData.twitch.readyState && appData.twitch.readyState() != 'OPEN')
) {
appData.twitch = new tmi.Client({
options: { debug: appData.isDevelopment },
//options: { debug: appData.isDevelopment },
connection: {
reconnect: true,
secure: true,
Expand Down Expand Up @@ -179,7 +196,11 @@ const startTwitchApp = (appData) => {
}
lookFor.forEach((val) => {
let searchFor = String(val).toLowerCase().trim()
if (message.toLowerCase().indexOf(searchFor) != -1) notify = true
if (
searchFor.length > 0 &&
message.toLowerCase().indexOf(searchFor) != -1
)
notify = true
})
if (notify) {
appData.mainWindow.webContents.send('channel:notification', msg)
Expand Down Expand Up @@ -283,6 +304,7 @@ const startTwitchApp = (appData) => {
appData.options = underscore.defaults(data, appData.optionsDefaults)
appData.mainWindow.webContents.send('options:list', appData.options)
appData.store.set('options', appData.options)
toggleAutoStart(appData.options)
})
ipcMain.on('extra:floatingWindow', (e, channel) => {
floatingWindow(channel, appData)
Expand Down
Loading

0 comments on commit 89e8f49

Please sign in to comment.