Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ObsWebSocket from 'obs-websocket-js';
- import {BotModule} from '../BotModule';
- import {ChatUserstate} from 'tmi.js';
- import {SocketMessagePayload} from '../../../shared/socket-message-payload.interface';
- import {SocketMessageType} from '../../../shared/socket-message-type.interface';
- import {SocketMessage} from '../../../shared/socket-message.interface';
- import {twitchModule} from './TwitchModule';
- class OBSModule extends BotModule
- {
- moduleName = 'OBSModule';
- private client: ObsWebSocket;
- private obsAddress: string;
- private obsPort: number | string;
- private obsPassword: string;
- constructor()
- {
- super();
- this.obsAddress = process.env.OBS_ADDRESS || 'localhost';
- this.obsPort = process.env.OBS_PORT || 4444;
- this.obsPassword = process.env.OBS_PASSWORD;
- this.client = new ObsWebSocket();
- this.client.on('Exiting', () => {
- console.log('OBS Exited');
- this.client.disconnect();
- setTimeout(() => this.connect(), 10000);
- });
- this.client.on('SwitchScenes', scene => {
- this.onSceneSwitch(scene);
- });
- this.connect();
- }
- private connect(): void
- {
- this.client.connect({address: this.obsAddress + ':' + this.obsPort, password: atob(this.obsPassword)})
- .then(() => console.log('OBS API initialized'))
- .catch(() => setTimeout(() => this.connect(), 30000));
- }
- init(): void
- {
- twitchModule.subscribeTwitchEvent('channel.channel_points_custom_reward_redemption.add', event => {
- const username = event.user_name;
- const rewardId = event.reward.id;
- console.log(`${username} redeemed ${rewardId} (${event.reward.title}): ${event.user_input}`);
- if (rewardId === '1f8cea96-ec9a-4518-91a6-4c0029d1a90c')
- {
- this.toggleSnapCam(true);
- setTimeout(() => this.toggleSnapCam(false), 60000);
- }
- });
- }
- onCommand(channel: string, userState: ChatUserstate, command: string, args: string[]): void
- {
- }
- onSocketMessage(data: SocketMessage<SocketMessageType, SocketMessagePayload>): void
- {
- }
- onTMIMessage(channel: string, userState: ChatUserstate, message: string): void
- {
- }
- private toggleSnapCam(state: boolean): void
- {
- this.client.send('SetSceneItemProperties', {
- item: {
- name: 'SnapCam',
- },
- visible: state,
- position: {},
- bounds: {},
- scale: {},
- crop: {}
- });
- }
- private onSceneSwitch(scene: any)
- {
- // if (scene['scene-name'] === 'Just chatting')
- // {
- // twitchModule.updateCustomReward({is_enabled: true});
- // }
- // else
- // {
- // twitchModule.updateCustomReward({is_enabled: false});
- // }
- }
- }
- export const obsModule = new OBSModule();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement