telegram inbital working
This commit is contained in:
parent
e656821fb1
commit
cc6d42c512
15
game.js
15
game.js
|
@ -4,6 +4,8 @@ const { Telegraf } = require('telegraf')
|
||||||
if(process.platform !== 'darwin') var gpio = require('rpi-gpio');
|
if(process.platform !== 'darwin') var gpio = require('rpi-gpio');
|
||||||
|
|
||||||
const telegramBotToken = '5472909337:AAGH269wNGa9u99ekJqHqXEHfi0knpV7IFU';
|
const telegramBotToken = '5472909337:AAGH269wNGa9u99ekJqHqXEHfi0knpV7IFU';
|
||||||
|
//const groupid='@HotSoup';
|
||||||
|
const groupid='-1001703800044';
|
||||||
const GlobalLog = QLog.scope('Global');
|
const GlobalLog = QLog.scope('Global');
|
||||||
const TelLog = QLog.scope('Telegram');
|
const TelLog = QLog.scope('Telegram');
|
||||||
|
|
||||||
|
@ -72,6 +74,16 @@ var GAME = {};
|
||||||
|
|
||||||
var botCTX;
|
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) {
|
async function sendBotMsg(msg) {
|
||||||
if(botCTX) {
|
if(botCTX) {
|
||||||
botCTX.reply(msg);
|
botCTX.reply(msg);
|
||||||
|
@ -208,12 +220,14 @@ async function finish(value) {
|
||||||
GlobalLog.debug('Finish');
|
GlobalLog.debug('Finish');
|
||||||
if(STATE === STATES.STARTED) {
|
if(STATE === STATES.STARTED) {
|
||||||
GlobalLog.note('You made it in', GAME.runTime, 'seconds');
|
GlobalLog.note('You made it in', GAME.runTime, 'seconds');
|
||||||
|
GlobalLog.note(GAME);
|
||||||
playSound(GAME.finish);
|
playSound(GAME.finish);
|
||||||
STATE = STATES.FINISH;
|
STATE = STATES.FINISH;
|
||||||
clearInterval(GAME.countTimer)
|
clearInterval(GAME.countTimer)
|
||||||
GAME.events = [];
|
GAME.events = [];
|
||||||
await sendBotImg('/tmp/img.png');
|
await sendBotImg('/tmp/img.png');
|
||||||
await sendBotMsg(`Gewinner in nur ${GAME.runTime} Sekunden!`);
|
await sendBotMsg(`Gewinner in nur ${GAME.runTime} Sekunden!`);
|
||||||
|
await sendBotGroupImg(groupid, `Gewinner in nur ${GAME.runTime} Sekunden!`, '/tmp/img.png');
|
||||||
if(MODE === GROWN) {
|
if(MODE === GROWN) {
|
||||||
if(GAME.runTime < best.grown) {
|
if(GAME.runTime < best.grown) {
|
||||||
await sendBotMsg(`Neue Bestzeit bei den Erwachsenen!`);
|
await sendBotMsg(`Neue Bestzeit bei den Erwachsenen!`);
|
||||||
|
@ -261,6 +275,7 @@ function toggle(value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function playSound(file){
|
function playSound(file){
|
||||||
|
if(!file) { GlobalLog.error('Sound not defined.'); return; }
|
||||||
GlobalLog.info("Play sound : ", file);
|
GlobalLog.info("Play sound : ", file);
|
||||||
if(GAME.playing) {
|
if(GAME.playing) {
|
||||||
GlobalLog.debug("Stopping old soundfile", GAME.playing);
|
GlobalLog.debug("Stopping old soundfile", GAME.playing);
|
||||||
|
|
Loading…
Reference in New Issue