Skip to content

Commit

Permalink
Bug fixes on different raid poll scenarios
Browse files Browse the repository at this point in the history
- Fixed hitting caption cap causing spam of new polls on chat
- Raid info polls are now posted as normal image with caption even though auto_extend is set to true
  • Loading branch information
Ninjasoturi committed Aug 22, 2021
1 parent 426f47b commit 396f8f4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.234.2
2.1.234.3
2 changes: 1 addition & 1 deletion config/config.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"VERSION":"2.1.234.2",
"VERSION":"2.1.234.3",
"DB_HOST":"localhost",
"DB_NAME":"your_database_name",
"DB_USER":"your_database_user",
Expand Down
17 changes: 16 additions & 1 deletion logic/send_raid_poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ function send_raid_poll($raid_id, $raid = false, $chats, $tg_json = false) {
$text = show_raid_poll($raid);
$keys = keys_vote($raid);

$post_text = false;
if(array_key_exists('short', $text)) {
$msg_short_len = strlen(utf8_decode($text['short']));
debug_log($msg_short_len, 'Raid poll short message length:');
// Message short enough?
if($msg_short_len >= 1024) {
// Use full text and reset text to true regardless of prior value
$post_text = true;
}
} else {
// Use full text and reset text to true regardless of prior value
$post_text = true;
}

// Telegram JSON array.
if($tg_json == false) $tg_json = [];

Expand All @@ -30,6 +44,7 @@ function send_raid_poll($raid_id, $raid = false, $chats, $tg_json = false) {
// Send the message.
$raid_picture_hide_level = explode(",",$config->RAID_PICTURE_HIDE_LEVEL);
$raid_picture_hide_pokemon = explode(",",$config->RAID_PICTURE_HIDE_POKEMON);
$raid_poll_hide_buttons_levels = explode(",",$config->RAID_POLL_HIDE_BUTTONS_RAID_LEVEL);

$raid_pokemon_id = $raid['pokemon'];
$raid_level = $raid['level'];
Expand All @@ -47,7 +62,7 @@ function send_raid_poll($raid_id, $raid = false, $chats, $tg_json = false) {
send_message($chat_id, $text['full'], $keys, ['disable_web_page_preview' => 'true'], false, $raid_id);
}else {
if($config->RAID_PICTURE && $raid['event_hide_raid_picture'] == 0 && !in_array($raid_level, $raid_picture_hide_level) && !in_array($raid_pokemon, $raid_picture_hide_pokemon) && !in_array($raid_pokemon_id, $raid_picture_hide_pokemon)) {
if($config->RAID_PICTURE_AUTOEXTEND) {
if(($config->RAID_PICTURE_AUTOEXTEND && !in_array($raid['level'], $raid_poll_hide_buttons_levels)) or $post_text) {
send_photo($chat_id, $picture_url, '', [], [], false, $raid_id);
send_message($chat_id, $text['short'], $keys, ['disable_web_page_preview' => 'true'], false, $raid_id);
} else {
Expand Down
18 changes: 11 additions & 7 deletions logic/update_raid_poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ function update_raid_poll($raid_id, $raid = false, $update = false, $tg_json = f

// Telegram JSON array.
if($tg_json == false) $tg_json = [];
if($config->RAID_PICTURE) {
$time_now = utcnow();
if($time_now > $raid['end_time'] ) {
$raid['pokemon'] = 'ended';
}
require_once(LOGIC_PATH . '/raid_picture.php');
$picture_url = raid_picture_url($raid);
}

foreach($chat_and_message as $chat_id_msg_id) {
$chat = $chat_id_msg_id['chat_id'];
Expand All @@ -76,18 +84,14 @@ function update_raid_poll($raid_id, $raid = false, $update = false, $tg_json = f
if($post_text == true) {
// Delete raid picture and caption.
$tg_json[] = delete_message($chat, $message, true);
my_query("DELETE FROM cleanup WHERE chat_id = '{$chat}' AND message_id = '{$message}'");

// Resend raid poll as text message.
$tg_json[] = send_message($chat, $text['full'], $keys, ['disable_web_page_preview' => 'true'], true);
send_photo($chat, $picture_url, '', [], [], false, $raid_id);
send_message($chat, $text['full'], $keys, ['disable_web_page_preview' => 'true'], false, $raid_id);
} else {
// Edit the picture and caption
if(!$skip_picture_update) {
$time_now = utcnow();
if($time_now > $raid['end_time'] ) {
$raid['pokemon'] = 'ended';
}
require_once(LOGIC_PATH . '/raid_picture.php');
$picture_url = raid_picture_url($raid);
$tg_json[] = editMessageMedia($message, $text['short'], $keys, $chat, ['disable_web_page_preview' => 'true'], true, $picture_url);
}else {
// Edit the caption.
Expand Down

0 comments on commit 396f8f4

Please sign in to comment.