2424use Laminas \Db \Sql \Select ;
2525use Laminas \Db \Sql \Where ;
2626use Laminas \Db \TableGateway \TableGateway ;
27+ use MongoDB \Driver \Server ;
2728use OnePlace \User \Model \UserTable ;
2829use OnePlace \Faucet \RPSServer \Controller \ServerController ;
2930
@@ -112,7 +113,7 @@ private function castTelegramRPSVote($iVote,$iChatID,$sEmote = '') {
112113 if ($ oPlcUserCheck ) {
113114 $ oGamePrepared = ServerController::getPreparedRPSGame ($ oPlcUserCheck );
114115 if ($ oGamePrepared ) {
115- $ aGameInfo = ServerController::startRPSGame ($ iVote ,(float )$ oGamePrepared ->amount_bet ,$ oPlcUserCheck );
116+ $ aGameInfo = ServerController::startRPSGame ($ iVote ,(float )$ oGamePrepared ->amount_bet ,$ oPlcUserCheck, ' telegram ' );
116117 if ($ aGameInfo ['state ' ] == 'success ' ) {
117118 $ keyboard = [
118119 'keyboard ' => [
@@ -136,8 +137,24 @@ private function castTelegramRPSVote($iVote,$iChatID,$sEmote = '') {
136137 ];
137138 $ aMsgData ['reply ' ] = $ aContent ['text ' ];
138139 } else {
140+ $ keyboard = [
141+ 'keyboard ' => [
142+ [
143+ ['text ' => '☑️️️ New Game ' ],
144+ ['text ' => '👁️️ My Games ' ],
145+ ],
146+ [
147+ ['text ' => '👁️️ Look for Games ' ],
148+ ],
149+ [
150+ ['text ' => '🏠️️ Back to Menu ' ]
151+ ]
152+ ]
153+ ];
154+ $ encodedKeyboard = json_encode ($ keyboard );
139155 $ aContent = [
140156 'chat_id ' => $ iChatID ,
157+ 'reply_markup ' => $ encodedKeyboard ,
141158 'text ' => "Error while creating game: " .$ aGameInfo ['message ' ],
142159 ];
143160 $ aMsgData ['reply ' ] = $ aContent ['text ' ];
@@ -185,7 +202,7 @@ public function tgbhookAction()
185202 'user_idfs ' => 1 ,
186203 'chat_id ' => $ iChatID ,
187204 'date ' => date ('Y-m-d H:i:s ' , time ()),
188- 'message ' => utf8_decode ($ oUpdate ->message ->text ),
205+ 'message ' => utf8_decode (( isset ( $ oUpdate ->message ->text )) ? $ oUpdate -> message -> text : '' ),
189206 'parse_next ' => 0 ,
190207 'reply ' => 'no reply ' ,
191208 ];
@@ -212,8 +229,19 @@ public function tgbhookAction()
212229 $ aMsgData ['reply ' ] = $ iGameID ;
213230 $ aMsgData ['parse_next ' ] = 1 ;
214231 $ aMsgData ['parse_type ' ] = 'rpsvote ' ;
215- ServerController::joinRPSGame ($ iGameID , $ oPlcUserCheck ->getID ());
216- TelegramController::sendTelegramMessage ($ aContent );
232+ $ oGame = ServerController::loadRPSGame ($ iGameID , 'client ' );
233+ if ($ oGame ->amount_bet > $ oPlcUserCheck ->token_balance ) {
234+ $ aContent = [
235+ 'chat_id ' => $ iChatID ,
236+ 'text ' => "Your balance is too low to join this game " ,
237+ ];
238+ $ aMsgData ['parse_next ' ] = 0 ;
239+ $ aMsgData ['reply ' ] = $ aContent ['text ' ];
240+ TelegramController::sendTelegramMessage ($ aContent );
241+ } else {
242+ ServerController::joinRPSGame ($ iGameID , $ oPlcUserCheck ->getID ());
243+ TelegramController::sendTelegramMessage ($ aContent );
244+ }
217245 } else {
218246 $ aContent = [
219247 'chat_id ' => $ iChatID ,
@@ -297,8 +325,13 @@ public function tgbhookAction()
297325 }
298326 $ aGamesKB [] = [['text ' => '# ' .$ oGame ->Match_ID .': ' .$ sEmote .' - ' .TelegramController::timeElapsedString ($ oGame ->date_created ).' - ' .$ oGame ->amount_bet .' Coins - Cancel ' ]];
299327 }
328+ $ iGames = count ($ aGamesKB );
300329 } else {
301330 $ aGamesKB [] = [['text ' => 'No Open Games ' ]];
331+ $ iGames = (count ($ aGamesKB )-3 );
332+ }
333+ if ($ iGames < 0 ) {
334+ $ iGames = 0 ;
302335 }
303336 $ aGamesKB [] = [['text ' => '✊️️ Rock, Paper, Scissors ' ]];
304337 $ aGamesKB [] = [['text ' => '🏠️️ Back to Menu ' ]];
@@ -309,7 +342,7 @@ public function tgbhookAction()
309342 $ aContent = [
310343 'chat_id ' => $ iChatID ,
311344 'reply_markup ' => $ encodedKeyboard ,
312- 'text ' => "You have " .( count ( $ aGamesKB )- 2 ) .' open Games ' ,
345+ 'text ' => "You have " .$ iGames .' open Games ' ,
313346 ];
314347 $ aMsgData ['reply ' ] = $ aContent ['text ' ];
315348
@@ -821,8 +854,8 @@ public function tgbhookAction()
821854 'parse_next ' => 0 ,
822855 ],'Message_ID = ' .$ oReplyCheck ->Message_ID );
823856
824- if (ServerController::joinRPSGame ($ iGameID , $ oPlcUserCheck ->getID (), $ iVote )) {
825- $ aGameInfo = ServerController::matchRPSGame ($ iGameID , $ iVote );
857+ if (ServerController::joinRPSGame ($ iGameID , $ oPlcUserCheck ->getID (), $ iVote, ' telegram ' )) {
858+ $ aGameInfo = ServerController::matchRPSGame ($ iGameID , $ iVote, 0 , ' telegram ' );
826859 }
827860 $ aMsgData ['reply ' ] = $ aContent ['text ' ];
828861 }
@@ -1057,6 +1090,9 @@ public function tgbhookAction()
10571090 'chat_id ' => $ iChatID ,
10581091 'text ' => "There is already an account with that e-mail. please use /login " ,
10591092 ];
1093+ $ oMsgTbl ->update ([
1094+ 'parse_next ' => 0 ,
1095+ ],'Message_ID = ' .$ oReplyCheck ->Message_ID );
10601096 TelegramController::sendTelegramMessage ($ aContent );
10611097 } else {
10621098 $ aContent = [
@@ -1073,7 +1109,7 @@ public function tgbhookAction()
10731109
10741110 break ;
10751111 case 'username ' :
1076- $ sUserCheck = $ oUpdate ->message ->text ;
1112+ $ sUserCheck = ( isset ( $ oUpdate ->message ->text )) ? $ oUpdate -> message -> text : '' ;
10771113 $ bIsEmail = stripos ($ sUserCheck ,'@ ' );
10781114 $ oPlcUserCheck = false ;
10791115 if ($ bIsEmail === false ) {
0 commit comments