Skip to content

Commit

Permalink
rps fixes and more
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Apr 21, 2021
1 parent 6888841 commit 6efe0c7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to oneplace-chat will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.1] -

### Fixed
- RPS Matching fixes
- Return correct menu when game limit reached
- security fixes

## [1.0.0] -

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "onePlace Faucet Telegram Bot Module",
"type": "oneplace-module",
"license": "BSD-3-Clause",
"version": "1.0.0",
"version": "1.0.1",
"keywords": [
"laminas",
"mvc",
Expand Down
52 changes: 44 additions & 8 deletions src/Controller/TelegramController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Where;
use Laminas\Db\TableGateway\TableGateway;
use MongoDB\Driver\Server;
use OnePlace\User\Model\UserTable;
use OnePlace\Faucet\RPSServer\Controller\ServerController;

Expand Down Expand Up @@ -112,7 +113,7 @@ private function castTelegramRPSVote($iVote,$iChatID,$sEmote = '') {
if($oPlcUserCheck) {
$oGamePrepared = ServerController::getPreparedRPSGame($oPlcUserCheck);
if($oGamePrepared) {
$aGameInfo = ServerController::startRPSGame($iVote,(float)$oGamePrepared->amount_bet,$oPlcUserCheck);
$aGameInfo = ServerController::startRPSGame($iVote,(float)$oGamePrepared->amount_bet,$oPlcUserCheck,'telegram');
if($aGameInfo['state'] == 'success') {
$keyboard = [
'keyboard' => [
Expand All @@ -136,8 +137,24 @@ private function castTelegramRPSVote($iVote,$iChatID,$sEmote = '') {
];
$aMsgData['reply'] = $aContent['text'];
} else {
$keyboard = [
'keyboard' => [
[
['text' => '☑️️️ New Game'],
['text' => '👁‍️️ My Games'],
],
[
['text' => '👁‍️️ Look for Games'],
],
[
['text' => '🏠‍️️ Back to Menu']
]
]
];
$encodedKeyboard = json_encode($keyboard);
$aContent = [
'chat_id' => $iChatID,
'reply_markup' => $encodedKeyboard,
'text' => "Error while creating game: ".$aGameInfo['message'],
];
$aMsgData['reply'] = $aContent['text'];
Expand Down Expand Up @@ -185,7 +202,7 @@ public function tgbhookAction()
'user_idfs' => 1,
'chat_id' => $iChatID,
'date' => date('Y-m-d H:i:s', time()),
'message' => utf8_decode($oUpdate->message->text),
'message' => utf8_decode((isset($oUpdate->message->text)) ? $oUpdate->message->text : ''),
'parse_next' => 0,
'reply' => 'no reply',
];
Expand All @@ -212,8 +229,19 @@ public function tgbhookAction()
$aMsgData['reply'] = $iGameID;
$aMsgData['parse_next'] = 1;
$aMsgData['parse_type'] = 'rpsvote';
ServerController::joinRPSGame($iGameID, $oPlcUserCheck->getID());
TelegramController::sendTelegramMessage($aContent);
$oGame = ServerController::loadRPSGame($iGameID, 'client');
if($oGame->amount_bet > $oPlcUserCheck->token_balance) {
$aContent = [
'chat_id' => $iChatID,
'text' => "Your balance is too low to join this game",
];
$aMsgData['parse_next'] = 0;
$aMsgData['reply'] = $aContent['text'];
TelegramController::sendTelegramMessage($aContent);
} else {
ServerController::joinRPSGame($iGameID, $oPlcUserCheck->getID());
TelegramController::sendTelegramMessage($aContent);
}
} else {
$aContent = [
'chat_id' => $iChatID,
Expand Down Expand Up @@ -297,8 +325,13 @@ public function tgbhookAction()
}
$aGamesKB[] = [['text' => '#'.$oGame->Match_ID.': '.$sEmote.' - '.TelegramController::timeElapsedString($oGame->date_created).' - '.$oGame->amount_bet.' Coins - Cancel']];
}
$iGames = count($aGamesKB);
} else {
$aGamesKB[] = [['text' => 'No Open Games']];
$iGames = (count($aGamesKB)-3);
}
if($iGames < 0) {
$iGames = 0;
}
$aGamesKB[] = [['text' => '✊️️ Rock, Paper, Scissors']];
$aGamesKB[] = [['text' => '🏠‍️️ Back to Menu']];
Expand All @@ -309,7 +342,7 @@ public function tgbhookAction()
$aContent = [
'chat_id' => $iChatID,
'reply_markup' => $encodedKeyboard,
'text' => "You have ".(count($aGamesKB)-2).' open Games',
'text' => "You have ".$iGames.' open Games',
];
$aMsgData['reply'] = $aContent['text'];

Expand Down Expand Up @@ -821,8 +854,8 @@ public function tgbhookAction()
'parse_next' => 0,
],'Message_ID = '.$oReplyCheck->Message_ID);

if(ServerController::joinRPSGame($iGameID, $oPlcUserCheck->getID(), $iVote)) {
$aGameInfo = ServerController::matchRPSGame($iGameID, $iVote);
if(ServerController::joinRPSGame($iGameID, $oPlcUserCheck->getID(), $iVote, 'telegram')) {
$aGameInfo = ServerController::matchRPSGame($iGameID, $iVote, 0, 'telegram');
}
$aMsgData['reply'] = $aContent['text'];
}
Expand Down Expand Up @@ -1057,6 +1090,9 @@ public function tgbhookAction()
'chat_id' => $iChatID,
'text' => "There is already an account with that e-mail. please use /login",
];
$oMsgTbl->update([
'parse_next' => 0,
],'Message_ID = '.$oReplyCheck->Message_ID);
TelegramController::sendTelegramMessage($aContent);
} else {
$aContent = [
Expand All @@ -1073,7 +1109,7 @@ public function tgbhookAction()

break;
case 'username':
$sUserCheck = $oUpdate->message->text;
$sUserCheck = (isset($oUpdate->message->text)) ? $oUpdate->message->text : '';
$bIsEmail = stripos($sUserCheck,'@');
$oPlcUserCheck = false;
if($bIsEmail === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Module {
*
* @since 1.0.0
*/
const VERSION = '1.0.0';
const VERSION = '1.0.1';

/**
* Load module config file
Expand Down

0 comments on commit 6efe0c7

Please sign in to comment.