require_once(__DIR__ . '/config.php');
require_once(AUTOLOAD_PATH);
-use Telegram\Bot\Api;
+use Telegram\Bot\Api as TelegramAPI;
+use Telegram\Bot\Objects\Update as TelegramUpdate;
-function getTelegram(): \Telegram\Bot\Api {
+function getTelegram(): TelegramAPI {
STATIC $tg;
- return $tg = $tg ?? new \Telegram\Bot\Api(BOT_TOKEN);
+ return $tg = $tg ?? new TelegramAPI(BOT_TOKEN);
}
-function splitBill($amount) {
+function splitBill(float $amount) : float {
return floor($amount/2);
}
}
const notEmpty = 'notEmpty';
-function notEmpty($value) {
+function notEmpty($value) : bool {
return !empty($value);
}
-function getMessageSender($update) {
+function getMessageSender(TelegramUpdate $update) : string {
return PARTICIPANT_IDS[getMessageSenderId($update)];
}
-function getMessageSenderId($update) {
+function getMessageSenderId(TelegramUpdate $update) : int {
return $update->get('message')->get('from')->get('id');
}
-function getMessageSenderDisplayName($update) {
+function getMessageSenderDisplayName(TelegramUpdate $update) : int {
return $update->get('message')->get('from')->get('first_name');
}
-function canChatWith($update) {
+function canChatWith(TelegramUpdate $update) : bool {
return in_array($update->get('message')->get('from')->get('id'), array_keys(PARTICIPANT_IDS));
}
-function debug($whatever) {
- echo '<pre>';
- print_r($whatever);
- echo '</pre>';
-}
-
-function partition(int $numPartitions, $array) {
+function partition(int $numPartitions, array $array) : array {
$partitionSize = (int)ceil(count($array) / $numPartitions);
- return
- array_values(filter(notEmpty)(
- map(function($p) use ($array, $partitionSize) {
- return array_slice($array, $p*$partitionSize, $partitionSize);
- })(range(0, $numPartitions-1))
- ));
+ return array_values(filter(notEmpty)(
+ map(function($p) use ($array, $partitionSize) {
+ return array_slice($array, $p*$partitionSize, $partitionSize);
+ })(range(0, $numPartitions-1))
+ ));
}
-function getInbox($inbox) {
+function getInbox(string $inbox) {
STATIC $inboxes;
if (!isset($inboxes[$inbox])) {
}
function getSeason(int $monthNum) {
- return ['summer', 'autumn', 'winter', 'spring'][floor(($monthNum%12)/3)];
+ return ['summer', 'autumn', 'winter', 'spring'][(int)floor(($monthNum%12)/3)];
}
function getMonthName($monthNum) {