-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mike Zrimsek
committed
Oct 29, 2020
0 parents
commit 8b0b1d9
Showing
9 changed files
with
3,987 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Publish Docker image | ||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
jobs: | ||
push_to_registry: | ||
name: Push Docker image to GitHub Packages | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
- name: Push to GitHub Packages | ||
uses: docker/build-push-action@v1 | ||
with: | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
registry: docker.pkg.github.com | ||
repository: mzrimsek/twitch-bastulos-bot/bastulos-bot | ||
tag_with_ref: true |
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,2 @@ | ||
node_modules | ||
.env* |
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,11 @@ | ||
FROM node:latest | ||
|
||
RUN mkdir -p /usr/src/bot | ||
WORKDIR /usr/src/bot | ||
|
||
COPY package.json /usr/src/bot | ||
RUN npm install | ||
|
||
COPY . /usr/src/bot | ||
|
||
CMD ["npm", "run", "forever"] |
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,22 @@ | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 Mike Zrimsek | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,6 @@ | ||
const config = { | ||
address: process.env.OBS_URL, | ||
password: process.env.OBS_PASSWORD | ||
}; | ||
|
||
module.exports = config; |
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,15 @@ | ||
const config = { | ||
options: { | ||
debug: true | ||
}, | ||
connection: { | ||
reconnect: true | ||
}, | ||
identity: { | ||
username: 'bastulosbot', | ||
password: `oauth:${process.env.TMI_TOKEN}` | ||
}, | ||
channels: ['bastulos'] | ||
}; | ||
|
||
module.exports = config; |
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,154 @@ | ||
require('dotenv').config(); | ||
|
||
const tmi = require('tmi.js'); | ||
const OBSWebSocket = require('obs-websocket-js'); | ||
|
||
const tmiConfig = require('./config/tmi'); | ||
const obsConfig = require('./config/obs'); | ||
|
||
const client = new tmi.client(tmiConfig); | ||
const obs = new OBSWebSocket(); | ||
|
||
client.connect(); | ||
obs.connect(obsConfig); | ||
|
||
const COMMAND_PREFACE = '!'; | ||
const ADMIN_USER = 'bastulos'; | ||
const ADMIN_COMMANDS = { | ||
TOGGLE_COMMANDS_ACTIVE: 'active', | ||
RECONNECT_OBS: 'obs' | ||
}; | ||
const COMMANDS = { | ||
COMMAND_LIST: 'help', | ||
RESET: 'reset', | ||
TOGGLE_CAM: 'cam', | ||
TOGGLE_MUTE_MIC: 'mic', | ||
CHANGE_OVERLAY_COLOR: 'color', | ||
TOGGLE_AQUA: 'aqua', | ||
HELLO: 'hello', | ||
HEART: 'heart' | ||
}; | ||
const SOURCES = { | ||
WEBCAM: 'Webcam', | ||
MIC: 'Desktop Mic', | ||
AQUA: 'Aqua' | ||
}; | ||
|
||
let active = true; | ||
|
||
client.on('chat', async (channel, userInfo, message, self) => { | ||
if (self) return; // ignore messages from the bot | ||
|
||
if (message[0] !== COMMAND_PREFACE) return; // ignore non command messages | ||
|
||
const normalizedMessage = message.toLowerCase(); | ||
const messageParts = normalizedMessage.split(' '); | ||
const command = messageParts[0]; | ||
|
||
if (userInfo.username === ADMIN_USER) { | ||
switch (command) { | ||
case `${COMMAND_PREFACE}${ADMIN_COMMANDS.TOGGLE_COMMANDS_ACTIVE}`: { | ||
if (active) { | ||
client.say(channel, `Bot commands are disabled!`); | ||
active = false; | ||
} | ||
else { | ||
client.say(channel, `Bot commands are enabled!`); | ||
active = true; | ||
} | ||
break; | ||
} | ||
case `${COMMAND_PREFACE}${ADMIN_COMMANDS.RECONNECT_OBS}`: { | ||
obs.connect(obsConfig); | ||
break; | ||
} | ||
default: { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (!active) return; | ||
|
||
switch (command) { | ||
case `${COMMAND_PREFACE}${COMMANDS.RESET}`: { | ||
obs.send('SetSourceFilterVisibility', { | ||
sourceName: SOURCES.WEBCAM, | ||
filterName: 'Color Correction', | ||
filterEnabled: false | ||
}); | ||
obs.send('SetSceneItemRender', { source: SOURCES.WEBCAM, render: true }); | ||
obs.send('SetMute', { source: SOURCES.MIC, mute: false }); | ||
break; | ||
} | ||
case `${COMMAND_PREFACE}${COMMANDS.HEART}`: | ||
case `${COMMAND_PREFACE}${COMMANDS.HELLO}`: { | ||
client.say(channel, `@${userInfo.username}, may your heart be your guiding key`); | ||
break; | ||
} | ||
case `${COMMAND_PREFACE}${COMMANDS.COMMAND_LIST}`: { | ||
const commands = Object.keys(COMMANDS); | ||
const commandList = commands.map(commandKey => `${COMMAND_PREFACE}${COMMANDS[commandKey]}`).join(', '); | ||
client.say(channel, `Here are the available commands: \n${commandList}`); | ||
break; | ||
} | ||
case `${COMMAND_PREFACE}${COMMANDS.TOGGLE_CAM}`: { | ||
const properties = await obs.send('GetSceneItemProperties', { item: { name: SOURCES.WEBCAM } }); | ||
const { visible } = properties; | ||
obs.send('SetSceneItemRender', { source: SOURCES.WEBCAM, render: !visible }); | ||
break; | ||
} | ||
case `${COMMAND_PREFACE}${COMMANDS.TOGGLE_MUTE_MIC}`: { | ||
obs.send('ToggleMute', { source: SOURCES.MIC }); | ||
break; | ||
} | ||
case `${COMMAND_PREFACE}${COMMANDS.CHANGE_OVERLAY_COLOR}`: { | ||
let numTimes = messageParts[1] ? parseInt(messageParts[1]) : 1; | ||
|
||
if (numTimes < 0) { | ||
numTimes = Math.abs(numTimes); | ||
} | ||
|
||
if (numTimes > 1000) { | ||
numTimes = 1000; | ||
} | ||
|
||
obs.send('SetSourceFilterVisibility', { | ||
sourceName: SOURCES.WEBCAM, | ||
filterName: 'Color Correction', | ||
filterEnabled: true | ||
}); | ||
|
||
const setColorCorrectionToRandomColor = () => { | ||
const randomColor = getRandomColor(); | ||
obs.send('SetSourceFilterSettings', { | ||
sourceName: SOURCES.WEBCAM, | ||
filterName: 'Color Correction', | ||
filterSettings: { | ||
color: randomColor | ||
} | ||
}); | ||
}; | ||
|
||
const rate = 1000 / numTimes; | ||
for (let i = 0; i < numTimes; i++) { | ||
setTimeout(setColorCorrectionToRandomColor, rate * i); | ||
} | ||
|
||
break; | ||
} | ||
case `${COMMAND_PREFACE}${COMMANDS.TOGGLE_AQUA}`: { | ||
const properties = await obs.send('GetSceneItemProperties', { item: { name: SOURCES.AQUA } }); | ||
const { visible } = properties; | ||
obs.send('SetSceneItemRender', { source: SOURCES.AQUA, render: !visible }); | ||
break; | ||
} | ||
default: { | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
function getRandomColor() { | ||
return (Math.random() * 4294967296) >>> 0; | ||
} |
Oops, something went wrong.