More strict check of redis message json format

This commit is contained in:
eleksir
2022-04-18 23:19:19 +03:00
parent 391b9889cf
commit 33ab2a368d
3 changed files with 12 additions and 2 deletions

View File

@@ -16,7 +16,7 @@ use BotLib::Conf qw (LoadConf);
use BotLib::Admin qw (@ForbiddenMessageTypes GetForbiddenTypes AddForbiddenType
DelForbiddenType ListForbidden FortuneToggle FortuneStatus
PluginToggle PluginStatus PluginEnabled ChanMsgToggle ChanMsgStatus
GreetMsgToggle GreetMsgStatus GoodbyeMsgToggle GoodbyeMsgStatus);
GreetMsgToggle GreetMsgStatus GoodbyeMsgToggle GoodbyeMsgStatus);
use BotLib::Util qw (trim);
use version; our $VERSION = qw (1.1);

View File

@@ -37,7 +37,13 @@ sub redis_parse_message {
$message->{parse_mode} = 'Markdown';
}
$message->{chat_id} = 0 + $m->{chatid};
$message->{chat_id} = eval { 0 + $m->{chatid}; };
unless (defined $message->{chat_id}) {
log->error ('Incoming redis message is incorrect: chat id must be numeric value!');
return;
}
$message->{text} = "$m->{message}";
my $can_talk = Teapot::Bot::Object::ChatPermissions->canTalk ($main::TGM, 0 + $m->{chatid});

View File

@@ -71,6 +71,10 @@ sub __cron {
if ($hour == 8 && ($min >= 0 && $min <= 14)) {
foreach my $enabledfortunechat (FortuneToggleList ()) {
# Set it to strings, explicitly
next unless (defined $enabledfortunechat);
next if ("$enabledfortunechat" eq '');
next if ("$enabledfortunechat" eq '0');
$rmsg->{userid} = "$enabledfortunechat";
$rmsg->{chatid} = "$enabledfortunechat";