Add !admin greet command

This commit is contained in:
eleksir
2022-03-06 00:08:34 +03:00
parent 7e5fbba0d0
commit de2106b16b
3 changed files with 118 additions and 5 deletions

View File

@@ -15,10 +15,11 @@ use Data::Dumper qw (Dumper);
use BotLib::Conf qw (LoadConf); use BotLib::Conf qw (LoadConf);
use BotLib::Admin qw (@ForbiddenMessageTypes GetForbiddenTypes AddForbiddenType use BotLib::Admin qw (@ForbiddenMessageTypes GetForbiddenTypes AddForbiddenType
DelForbiddenType ListForbidden FortuneToggle FortuneStatus DelForbiddenType ListForbidden FortuneToggle FortuneStatus
PluginToggle PluginStatus PluginEnabled ChanMsgToggle ChanMsgStatus); PluginToggle PluginStatus PluginEnabled ChanMsgToggle ChanMsgStatus
GreetMsgToggle GreetMsgStatus);
use BotLib::Util qw (trim); use BotLib::Util qw (trim);
use version; our $VERSION = qw (1.0); use version; our $VERSION = qw (1.1);
use Exporter qw (import); use Exporter qw (import);
our @EXPORT_OK = qw (Command Highlight BotSleep IsCensored); our @EXPORT_OK = qw (Command Highlight BotSleep IsCensored);
@@ -197,6 +198,10 @@ ${csign}admin fortune # - где 1 - вкл, 0 - выкл фортунку
${csign}admin фортунка # - где 1 - вкл, 0 - выкл фортунку с утра ${csign}admin фортунка # - где 1 - вкл, 0 - выкл фортунку с утра
${csign}admin fortune - показываем ли с утра фортунку для чата ${csign}admin fortune - показываем ли с утра фортунку для чата
${csign}admin фортунка - показываем ли с утра фортунку для чата ${csign}admin фортунка - показываем ли с утра фортунку для чата
${csign}admin greet # - где 1 - вкл, 0 - выкл приветствия новых участников чата
${csign}admin приветствие # - где 1 - вкл, 0 - выкл приветствия новых участников чата
${csign}admin greet - приветствуем ли новых участников чата
${csign}admin приветствие - приветствуем ли новых участников чата
${csign}admin oboobs # - где 1 - вкл, 0 - выкл плагина oboobs ${csign}admin oboobs # - где 1 - вкл, 0 - выкл плагина oboobs
${csign}admin oboobs - показываем ли сисечки по просьбе участников чата (команды ${csign}tits, ${csign}tities, ${csign}boobs, ${csign}boobies, ${csign}сиси, ${csign}сисечки) ${csign}admin oboobs - показываем ли сисечки по просьбе участников чата (команды ${csign}tits, ${csign}tities, ${csign}boobs, ${csign}boobies, ${csign}сиси, ${csign}сисечки)
${csign}admin obutts # - где 1 - вкл, 0 - выкл плагина obutts ${csign}admin obutts # - где 1 - вкл, 0 - выкл плагина obutts
@@ -272,6 +277,17 @@ MYADMIN
} else { } else {
$reply = ChanMsgStatus ($chatid); $reply = ChanMsgStatus ($chatid);
} }
# Приветствуем ли мы новых участников чата
} elsif ($cmd eq 'greet' || $cmd eq 'приветствие') {
if (defined $args) {
if ($args == 1) {
$reply = GreetMsgToggle ($chatid, 1);
} elsif ($args == 0) {
$reply = GreetMsgToggle ($chatid, 0);
}
} else {
$reply = GreetMsgStatus ($chatid);
}
# Работает ли плагин oboobs в чатике # Работает ли плагин oboobs в чатике
} elsif ($cmd eq 'oboobs') { } elsif ($cmd eq 'oboobs') {
if (defined $args) { if (defined $args) {

View File

@@ -11,13 +11,14 @@ use CHI::Driver::BerkeleyDB ();
use BotLib::Conf qw (LoadConf); use BotLib::Conf qw (LoadConf);
use BotLib::Util qw (utf2sha1); use BotLib::Util qw (utf2sha1);
use version; our $VERSION = qw (1.0); use version; our $VERSION = qw (1.1);
use Exporter qw (import); use Exporter qw (import);
# to export array we need @ISA here # to export array we need @ISA here
our @ISA = qw / Exporter /; ## no critic (ClassHierarchies::ProhibitExplicitISA) our @ISA = qw / Exporter /; ## no critic (ClassHierarchies::ProhibitExplicitISA)
our @EXPORT_OK = qw (@ForbiddenMessageTypes @PluginList GetForbiddenTypes AddForbiddenType DelForbiddenType our @EXPORT_OK = qw (@ForbiddenMessageTypes @PluginList GetForbiddenTypes AddForbiddenType DelForbiddenType
ListForbidden FortuneToggle FortuneToggleList FortuneStatus PluginToggle PluginStatus ListForbidden FortuneToggle FortuneToggleList FortuneStatus PluginToggle PluginStatus
PluginEnabled ChanMsgToggle ChanMsgStatus ChanMsgEnabled); PluginEnabled ChanMsgToggle ChanMsgStatus ChanMsgEnabled GreetMsgToggle GreetMsgStatus
GreetMsgEnabled);
my $c = LoadConf (); my $c = LoadConf ();
my $cachedir = $c->{cachedir}; my $cachedir = $c->{cachedir};
@@ -276,6 +277,97 @@ sub ChanMsgToggleList () {
return $cache->get_keys (); return $cache->get_keys ();
} }
sub GreetMsgToggle (@) {
my $chatid = shift;
my $action = shift // undef;
my $phrase = 'Приветствия новых участников чата ';
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'greet_msg',
);
my $state = $cache->get ($chatid);
if (defined $action) {
if ($action) {
$cache->set ($chatid, 1, 'never');
$phrase .= 'включены.';
} else {
if (defined $state && $state) {
$cache->set ($chatid, 0, 'never');
$phrase .= 'выключены.';
} else {
$cache->set ($chatid, 1, 'never');
$phrase .= 'включены.';
}
}
} else {
if (defined $state){
if ($state) {
$cache->set ($chatid, 0, 'never');
$phrase .= 'выключены.';
} else {
$cache->set ($chatid, 1, 'never');
$phrase .= 'включены.';
}
} else {
$cache->set ($chatid, 1, 'never');
$phrase .= 'выключены.';
}
}
return $phrase;
}
sub GreetMsgStatus ($) {
my $chatid = shift;
my $phrase = 'Приветствия новых участников чата ';
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'greet_msg',
);
my $state = $cache->get ($chatid);
if (defined $state) {
if ($state) {
$phrase .= 'включены.';
} else {
$phrase .= 'выключены.';
}
} else {
$phrase .= 'включены.';
}
return $phrase;
}
sub GreetMsgEnabled ($) {
my $chatid = shift;
my $cache = CHI->new (
driver => 'BerkeleyDB',
root_dir => $cachedir,
namespace => __PACKAGE__ . '_' . 'greet_msg',
);
my $state = $cache->get ($chatid);
if (defined $state) {
if ($state) {
return 1;
} else {
return 0;
}
} else {
return 1;
}
}
sub PluginStatus (@) { sub PluginStatus (@) {
my $chatid = shift; my $chatid = shift;
my $plugin = shift; my $plugin = shift;

View File

@@ -12,7 +12,7 @@ use Log::Any qw ($log);
use Math::Random::Secure qw (irand); use Math::Random::Secure qw (irand);
use Mojo::Base 'Teapot::Bot::Brain'; use Mojo::Base 'Teapot::Bot::Brain';
use BotLib::Admin qw (FortuneToggleList ChanMsgEnabled); use BotLib::Admin qw (FortuneToggleList ChanMsgEnabled GreetMsgEnabled);
use BotLib qw (Command Highlight BotSleep IsCensored); use BotLib qw (Command Highlight BotSleep IsCensored);
use BotLib::Conf qw (LoadConf); use BotLib::Conf qw (LoadConf);
use BotLib::Util qw (trim fmatch); use BotLib::Util qw (trim fmatch);
@@ -127,6 +127,11 @@ sub __on_msg {
# Newcommer event, greet our new member and suggest to introduce themself. # Newcommer event, greet our new member and suggest to introduce themself.
if ($msg->can ('new_chat_members') && defined ($msg->new_chat_members)) { if ($msg->can ('new_chat_members') && defined ($msg->new_chat_members)) {
unless (GreetMsgEnabled ($chatid)) {
return;
}
my @members; my @members;
my @introduce = ( my @introduce = (
'Дратути', 'Дратути',