Added lovely quotes for certain users.
This commit is contained in:
55
F1DataBot.pm
55
F1DataBot.pm
@@ -47,7 +47,7 @@ sub new {
|
||||
return $Self;
|
||||
}
|
||||
|
||||
=head1 Greet
|
||||
=head1 greet
|
||||
|
||||
Merely a dummy routine to test the bot's functionallity. Maybe using it for easter eggs or some kind of fun later.
|
||||
|
||||
@@ -292,6 +292,38 @@ sub statistics {
|
||||
|
||||
}
|
||||
|
||||
=head1 replyLoveQuote
|
||||
|
||||
Reply with lovely text to special user id.
|
||||
|
||||
=cut
|
||||
|
||||
sub replyLoveQuote {
|
||||
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
return unless $Self->{Whitelist}->{$Param{Message}->{from}->{id}} eq 'Sarah' || $Self->{Whitelist}->{$Param{Message}->{from}->{id}} eq 'Stefan';
|
||||
|
||||
my $LoveQuotes = YAML::LoadFile("$FindBin::Bin/lovely_quotes.yml");
|
||||
|
||||
my %MessageData;
|
||||
if ( ref $LoveQuotes eq 'ARRAY' ) {
|
||||
|
||||
my $QuoteID = int( rand( $#{ $LoveQuotes } ) );
|
||||
|
||||
my $Message = $LoveQuotes->[$QuoteID]->{Text};
|
||||
$Message .= "\n\n - <i>$LoveQuotes->[$QuoteID]->{Source}</i>";
|
||||
|
||||
%MessageData = (
|
||||
text => $Message,
|
||||
parse_mode => 'HTML',
|
||||
);
|
||||
}
|
||||
|
||||
return \%MessageData;
|
||||
|
||||
}
|
||||
|
||||
=head1 processMessage
|
||||
|
||||
Function which receives a single message and decides what to to based on message content and attributes.
|
||||
@@ -338,12 +370,19 @@ sub processMessage {
|
||||
else {
|
||||
$Self->{LogObject}
|
||||
->debug( 'Command not recognized. Data: ' . $Param{Message}->{message}->{text} );
|
||||
$ResponseData->{text} =
|
||||
"I'm sorry, "
|
||||
. ( $Param{Message}->{message}->{chat}->{first_name}
|
||||
? $Param{Message}->{message}->{chat}->{first_name}
|
||||
: $Param{Message}->{message}->{chat}->{username} )
|
||||
. ", I couldn't understand your request. Currently I can process the commands:\n\n\t\/greet\n\t\/statistics driver standings\n\t\/statistics constructor standings";
|
||||
if ( $Self->{Whitelist}->{$Param{Message}->{message}->{from}->{id}} eq 'Sarah'
|
||||
|| $Self->{Whitelist}->{$Param{Message}->{message}->{from}->{id}} eq 'Stefan' ) {
|
||||
$ResponseData = $Self->replyLoveQuote( Message => $Param{Message}->{message} );
|
||||
}
|
||||
else {
|
||||
$ResponseData->{text} =
|
||||
"I'm sorry, "
|
||||
. ( $Param{Message}->{message}->{chat}->{first_name}
|
||||
? $Param{Message}->{message}->{chat}->{first_name}
|
||||
: $Param{Message}->{message}->{chat}->{username} )
|
||||
. ", I couldn't understand your request. Currently I can process the commands:\n\n\t\/greet\n\t\/statistics driver standings\n\t\/statistics constructor standings";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
my $ResponseResult = plain POST(
|
||||
@@ -392,7 +431,7 @@ sub fetchMessages {
|
||||
|
||||
MESSAGE:
|
||||
for my $Message (@Messages) {
|
||||
if ( $Self->{Whitelist}{$Message->{message}{from}{id}} ) {
|
||||
if ( !$Self->{Whitelist}{$Message->{message}{from}{id}} ) {
|
||||
$Self->{LogObject}
|
||||
->info( 'fetchMessages: User not whitelisted, skipping message ' . Dumper($MessageDataRaw) );
|
||||
next MESSAGE;
|
||||
|
||||
Reference in New Issue
Block a user