Commit df5d27f1 authored by Guillaume Lebigot's avatar Guillaume Lebigot

Send poll winner to twitch chat

parent 8288c8c2
......@@ -14,6 +14,7 @@ import { PollResults, PollItem } from '../types/poll';
import { on } from '../lib/utils/pubsub';
import { State } from '../types/state';
import i18n from 'i18next';
import { sayTwitch } from '../utils/twitch';
const sleep = promisify(setTimeout);
let poll: PollItem[] = [];
......@@ -75,7 +76,11 @@ export async function timerPoll() {
export async function endPoll() {
if (poll.length > 0) {
const winner = await getPollResults();
if (getConfig().Karaoke.StreamerMode.Enabled && getState().status !== 'play') displayPoll(winner.index);
const streamConfig = getConfig().Karaoke.StreamerMode;
if (streamConfig.Enabled) {
if (getState().status !== 'play') displayPoll(winner.index);
if (streamConfig.Twitch.Channel) sayTwitch(`Poll winner : ${winner.kara} (${winner.votes} votes)`);
}
pollEnding = true;
logger.debug(`[Poll] Ending poll with ${JSON.stringify(winner)}`);
emitWS('songPollResult', winner);
......
......@@ -28,6 +28,14 @@ export async function initTwitch() {
}
}
export function sayTwitch(message: string) {
if (client) try {
client.say(getConfig().Karaoke.StreamerMode.Twitch.Channel, message);
} catch(err) {
logger.warn(`[Twitch] Unable to say to channel : ${err}`);
}
}
function listenVoteEvents(chat: any) {
chat.on('message', (target: string, context: ChatUserstate, msg: string, self: boolean) => {
if (self) return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment