From cc6d42c51287f39be3f39f82db4a214762b4dd69 Mon Sep 17 00:00:00 2001 From: Kai Mosebach Date: Thu, 11 Aug 2022 22:33:24 +0100 Subject: [PATCH] telegram inbital working --- game.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/game.js b/game.js index 86abdb7..2354e82 100644 --- a/game.js +++ b/game.js @@ -4,6 +4,8 @@ const { Telegraf } = require('telegraf') if(process.platform !== 'darwin') var gpio = require('rpi-gpio'); const telegramBotToken = '5472909337:AAGH269wNGa9u99ekJqHqXEHfi0knpV7IFU'; +//const groupid='@HotSoup'; +const groupid='-1001703800044'; const GlobalLog = QLog.scope('Global'); const TelLog = QLog.scope('Telegram'); @@ -72,6 +74,16 @@ var GAME = {}; var botCTX; +async function sendBotGroupMsg(id,msg) { + if(botCTX) { + botCTX.telegram.sendMessage(id,msg); + } +} +async function sendBotGroupImg(chat_id, caption, photo) { + if(botCTX) { + botCTX.telegram.sendPhoto( chat_id, photo, caption ); + } +} async function sendBotMsg(msg) { if(botCTX) { botCTX.reply(msg); @@ -208,12 +220,14 @@ async function finish(value) { GlobalLog.debug('Finish'); if(STATE === STATES.STARTED) { GlobalLog.note('You made it in', GAME.runTime, 'seconds'); + GlobalLog.note(GAME); playSound(GAME.finish); STATE = STATES.FINISH; clearInterval(GAME.countTimer) GAME.events = []; await sendBotImg('/tmp/img.png'); await sendBotMsg(`Gewinner in nur ${GAME.runTime} Sekunden!`); + await sendBotGroupImg(groupid, `Gewinner in nur ${GAME.runTime} Sekunden!`, '/tmp/img.png'); if(MODE === GROWN) { if(GAME.runTime < best.grown) { await sendBotMsg(`Neue Bestzeit bei den Erwachsenen!`); @@ -261,6 +275,7 @@ function toggle(value) { } function playSound(file){ + if(!file) { GlobalLog.error('Sound not defined.'); return; } GlobalLog.info("Play sound : ", file); if(GAME.playing) { GlobalLog.debug("Stopping old soundfile", GAME.playing);