$cbq = getTelegram()->getWebHookUpdates()->getCallbackQuery();
// handling for paginating shit
$data = $cbq->getData(); // that's gonna have the data attached to the button
+
if ($data) {
+ list($whatever, $who, $page) = explode('_', $data);
+
+ $chunky = getChunkyScores($who);
+ $pranks = $chunky[$page - 1];
+ $numE = count($pranks);
+ $pranks[$numE-1] .= "\n——————————————";
+
+ $extra = count($chunky) > 1 ? " (page $page of " . count($chunky) . ")" : '';
+
+ $buttons = array_merge(
+ $page != 1 ? [['text' => '« Previous page', 'callback_data' => 'scores_' . $who . '_' . ($page - 1)]] : [],
+ $page != count($chunky) ? [['text' => 'Next page »', 'callback_data' => 'scores_' . $who . '_' . ($page + 1)]] : []
+ );
+
$keyboard = [
- 'inline_keyboard' => [[['text' => $data == 'jeff' ? 'chef' : 'jeff', 'callback_data' => $data == 'jeff' ? 'chef' : 'jeff']]],
+ 'inline_keyboard' => [
+ $buttons
+ ],
];
$markup = json_encode($keyboard);
getTelegram()->editMessageText([
'chat_id' => getTelegram()->getWebHookUpdates()->getChat()->getId(),
'message_id' => $cbq->getMessage()->getMessageId(),
- 'text' => 'my name is ' . $data,
+ 'parse_mode' => 'Markdown',
+ 'text' => "High scores for $who"."$extra ...\n\n```\n" . unlines($pranks) . "\n```",
'reply_markup' => $markup
]);
}
$extra = count($chunky) > 1 ? " (page $page of " . count($chunky) . ")" : '';
+ $buttons = array_merge(
+ $page != 1 ? [['text' => '« Previous page', 'callback_data' => 'scores_' . $hsname . '_' . ($page - 1)]] : [],
+ $page != count($chunky) ? [['text' => 'Next page »', 'callback_data' => 'scores_' . $hsname . '_' . ($page + 1)]] : []
+ );
+
+ $keyboard = [
+ 'inline_keyboard' => [
+ $buttons
+ ],
+ ];
+
$chatid = getTelegram()->getWebhookUpdates()->get('message')->get('chat')->get('id');
getTelegram()->sendMessage(
[
'chat_id' => $chatid,
'parse_mode' => 'Markdown',
- 'text' => "High scores for $hsname"."$extra ...\n\n```\n" . unlines($pranks) . "```"
+ 'text' => "High scores for $hsname"."$extra ...\n\n```\n" . unlines($pranks) . "\n```",
+ 'reply_markup' => $buttons ? json_encode($keyboard) : []
]
);
}