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