Skip to content

Commit 6efe0c7

Browse files
author
Praesidiarius
committed
rps fixes and more
1 parent 6888841 commit 6efe0c7

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to oneplace-chat will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.1] -
9+
10+
### Fixed
11+
- RPS Matching fixes
12+
- Return correct menu when game limit reached
13+
- security fixes
14+
815
## [1.0.0] -
916

1017
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "onePlace Faucet Telegram Bot Module",
44
"type": "oneplace-module",
55
"license": "BSD-3-Clause",
6-
"version": "1.0.0",
6+
"version": "1.0.1",
77
"keywords": [
88
"laminas",
99
"mvc",

src/Controller/TelegramController.php

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Laminas\Db\Sql\Select;
2525
use Laminas\Db\Sql\Where;
2626
use Laminas\Db\TableGateway\TableGateway;
27+
use MongoDB\Driver\Server;
2728
use OnePlace\User\Model\UserTable;
2829
use 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) {

src/Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Module {
2828
*
2929
* @since 1.0.0
3030
*/
31-
const VERSION = '1.0.0';
31+
const VERSION = '1.0.1';
3232

3333
/**
3434
* Load module config file

0 commit comments

Comments
 (0)