2014-05-13 12:15:52 +02:00
|
|
|
# File: MessageHistory.pm
|
|
|
|
#
|
|
|
|
# Purpose: Keeps track of who has said what and when, as well as their
|
2019-06-26 18:34:19 +02:00
|
|
|
# nickserv accounts and alter-hostmasks.
|
2014-05-13 12:15:52 +02:00
|
|
|
#
|
|
|
|
# Used in conjunction with AntiFlood and Quotegrabs for kick/ban on
|
|
|
|
# flood/ban-evasion and grabbing quotes, respectively.
|
|
|
|
|
2023-02-21 06:31:52 +01:00
|
|
|
# SPDX-FileCopyrightText: 2014-2023 Pragmatic Software <pragma78@gmail.com>
|
2021-07-11 00:00:22 +02:00
|
|
|
# SPDX-License-Identifier: MIT
|
2017-03-05 22:33:31 +01:00
|
|
|
|
2021-07-21 07:44:51 +02:00
|
|
|
package PBot::Core::MessageHistory;
|
|
|
|
use parent 'PBot::Core::Class';
|
2014-05-13 12:15:52 +02:00
|
|
|
|
2021-06-19 06:23:34 +02:00
|
|
|
use PBot::Imports;
|
2019-07-11 03:40:53 +02:00
|
|
|
|
2021-07-09 02:27:31 +02:00
|
|
|
use Time::HiRes qw(time tv_interval);
|
2014-05-13 12:15:52 +02:00
|
|
|
|
2021-07-21 07:44:51 +02:00
|
|
|
use PBot::Core::MessageHistory::Storage::SQLite;
|
2014-05-13 12:15:52 +02:00
|
|
|
|
|
|
|
sub initialize {
|
2020-02-15 23:38:32 +01:00
|
|
|
my ($self, %conf) = @_;
|
|
|
|
$self->{filename} = $conf{filename} // $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/message_history.sqlite3';
|
2014-05-13 12:15:52 +02:00
|
|
|
|
2021-07-21 07:44:51 +02:00
|
|
|
$self->{database} = PBot::Core::MessageHistory::Storage::SQLite->new(
|
2021-07-21 06:38:07 +02:00
|
|
|
pbot => $self->{pbot},
|
|
|
|
filename => $self->{filename}
|
|
|
|
);
|
|
|
|
|
2021-07-21 21:43:30 +02:00
|
|
|
$self->{database}->begin;
|
|
|
|
$self->{database}->devalidate_all_channels;
|
2014-05-13 12:15:52 +02:00
|
|
|
|
2020-02-15 23:38:32 +01:00
|
|
|
$self->{pbot}->{registry}->add_default('text', 'messagehistory', 'max_recall_time', $conf{max_recall_time} // 0);
|
2014-05-18 22:09:05 +02:00
|
|
|
|
2021-08-06 21:59:21 +02:00
|
|
|
$self->{pbot}->{atexit}->register(sub { $self->{database}->end });
|
2014-05-13 12:15:52 +02:00
|
|
|
}
|
|
|
|
|
2020-05-04 22:21:35 +02:00
|
|
|
sub get_message_account {
|
|
|
|
my ($self, $nick, $user, $host) = @_;
|
|
|
|
return $self->{database}->get_message_account($nick, $user, $host);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub add_message {
|
|
|
|
my ($self, $account, $mask, $channel, $text, $mode) = @_;
|
2021-07-09 02:27:31 +02:00
|
|
|
$self->{database}->add_message($account, $mask, $channel, { timestamp => scalar time, msg => $text, mode => $mode });
|
2020-05-04 22:21:35 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 12:15:52 +02:00
|
|
|
1;
|