From b84f8bb24504cac9febb095723a5f19a5130a013 Mon Sep 17 00:00:00 2001 From: eleksir Date: Mon, 12 Dec 2022 17:26:50 +0300 Subject: [PATCH] Move IsCensored to Admin.pm --- lib/BotLib/Admin.pm | 24 +++++++++++++++++++++++- lib/BotLib/Util.pm | 23 +---------------------- lib/TelegramBot.pm | 5 +++-- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/BotLib/Admin.pm b/lib/BotLib/Admin.pm index b6ce9f5..e75be94 100644 --- a/lib/BotLib/Admin.pm +++ b/lib/BotLib/Admin.pm @@ -18,7 +18,8 @@ our @ISA = qw / Exporter /; ## no critic (ClassHierarchies::ProhibitExplicitI our @EXPORT_OK = qw (@ForbiddenMessageTypes @PluginList GetForbiddenTypes AddForbiddenType DelForbiddenType ListForbidden FortuneToggle FortuneToggleList FortuneStatus PluginToggle PluginStatus PluginEnabled ChanMsgToggle ChanMsgStatus ChanMsgEnabled GreetMsgToggle GreetMsgStatus - GreetMsgEnabled GoodbyeMsgToggle GoodbyeMsgStatus GoodbyeMsgEnabled MigrateSettingsToNewChatID); + GreetMsgEnabled GoodbyeMsgToggle GoodbyeMsgStatus GoodbyeMsgEnabled MigrateSettingsToNewChatID + IsCensored); my $c = LoadConf (); my $cachedir = $c->{cachedir}; @@ -606,6 +607,27 @@ sub MigrateSettingsToNewChatID { return; } +sub IsCensored { + my $msg = shift; + + my $forbidden = GetForbiddenTypes ($msg->chat->id); + + # voice messages are special + if (defined ($msg->voice) && defined ($msg->voice->duration) && ($msg->voice->duration > 0)) { + if ($forbidden->{'voice'}) { + return 1; + } + } + + foreach (keys %{$forbidden}) { + if ($forbidden->{$_} && (defined $msg->{$_})) { + return 1; + } + } + + return 0; +} + 1; # vim: set ft=perl noet ai ts=4 sw=4 sts=4: diff --git a/lib/BotLib/Util.pm b/lib/BotLib/Util.pm index 43a7e04..6461dbf 100644 --- a/lib/BotLib/Util.pm +++ b/lib/BotLib/Util.pm @@ -15,7 +15,7 @@ use URI::URL qw (url); use version; our $VERSION = qw (1.0); use Exporter qw (import); -our @EXPORT_OK = qw (trim urlencode fmatch utf2b64 utf2sha1 BotSleep Highlight IsCensored RandomCommonPhrase); +our @EXPORT_OK = qw (trim urlencode fmatch utf2b64 utf2sha1 BotSleep Highlight RandomCommonPhrase); sub trim { my $str = shift; @@ -124,27 +124,6 @@ sub Highlight { return ($userid, $username, $fullname, $highlight, $visavi); } -sub IsCensored { - my $msg = shift; - - my $forbidden = GetForbiddenTypes ($msg->chat->id); - - # voice messages are special - if (defined ($msg->voice) && defined ($msg->voice->duration) && ($msg->voice->duration > 0)) { - if ($forbidden->{'voice'}) { - return 1; - } - } - - foreach (keys %{$forbidden}) { - if ($forbidden->{$_} && (defined $msg->{$_})) { - return 1; - } - } - - return 0; -} - sub RandomCommonPhrase { my @myphrase = ( 'Так, блядь...', diff --git a/lib/TelegramBot.pm b/lib/TelegramBot.pm index 12eaa72..b10b2fa 100644 --- a/lib/TelegramBot.pm +++ b/lib/TelegramBot.pm @@ -14,10 +14,11 @@ use Log::Any qw ($log); use Math::Random::Secure qw (irand); use Mojo::Base 'Teapot::Bot::Brain'; -use BotLib::Admin qw (FortuneToggleList ChanMsgEnabled GreetMsgEnabled GoodbyeMsgEnabled MigrateSettingsToNewChatID); +use BotLib::Admin qw (FortuneToggleList ChanMsgEnabled GreetMsgEnabled GoodbyeMsgEnabled MigrateSettingsToNewChatID + IsCensored); use BotLib qw (Command); use BotLib::Conf qw (LoadConf); -use BotLib::Util qw (trim fmatch BotSleep Highlight IsCensored RandomCommonPhrase); +use BotLib::Util qw (trim fmatch BotSleep Highlight RandomCommonPhrase); use RedisLib qw (redis_events_listener); use version; our $VERSION = qw (1.0);