telegram inbital working

This commit is contained in:
Kai Mosebach 2022-08-11 22:33:24 +01:00
parent e656821fb1
commit cc6d42c512
1 changed files with 15 additions and 0 deletions

15
game.js
View File

@ -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);