3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

Progress on refactoring and polishing everything

This commit is contained in:
Pragmatic Software 2021-06-22 13:37:01 -07:00
parent b6c6100de1
commit 883a62920d
6 changed files with 48 additions and 25 deletions

View File

@ -45,15 +45,15 @@ sub initialize {
sub stdin_reader { sub stdin_reader {
my ($self, $input) = @_; my ($self, $input) = @_;
# make sure we're in the foreground first
$self->{foreground} = (tcgetpgrp($self->{tty_fd}) == getpgrp()) ? 1 : 0;
return if not $self->{foreground};
# decode STDIN input from utf8 # decode STDIN input from utf8
$input = decode('UTF-8', $input); $input = decode('UTF-8', $input);
chomp $input; chomp $input;
# make sure we're in the foreground first
$self->{foreground} = (tcgetpgrp($self->{tty_fd}) == getpgrp()) ? 1 : 0;
return if not $self->{foreground};
$self->{pbot}->{logger}->log("---------------------------------------------\n"); $self->{pbot}->{logger}->log("---------------------------------------------\n");
$self->{pbot}->{logger}->log("Got STDIN: $input\n"); $self->{pbot}->{logger}->log("Got STDIN: $input\n");

View File

@ -1,8 +1,10 @@
# File: Indefinite.pm
#
# Purpose: Implements a/an inflexion for nouns.
package PBot::Utils::Indefinite; package PBot::Utils::Indefinite;
use 5.010; use warnings; use PBot::Imports;
use feature 'unicode_strings';
require Exporter; require Exporter;
our @ISA = qw/Exporter/; our @ISA = qw/Exporter/;

View File

@ -1,10 +1,17 @@
package PBot::Utils::LWPUserAgentCached; # File: LWPUserAgentCached.pm
use strict; #
# Purpose: variant of LWP::UserAgent::WithCache. Instead of depending on # Purpose: variant of LWP::UserAgent::WithCache. Instead of depending on
# the 'expires' or 'Last-Modified' attributes, we always cache for the # the 'expires' or 'Last-Modified' attributes, we always cache for the
# specified duration. # specified duration.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::Utils::LWPUserAgentCached;
use PBot::Imports;
use base qw/LWP::UserAgent/; use base qw/LWP::UserAgent/;
use Cache::FileCache; use Cache::FileCache;
use File::HomeDir; use File::HomeDir;

View File

@ -1,16 +1,16 @@
#!/usr/bin/env perl # File: ParseDate.pm
#
# Purpose: Intelligently parses strings like "3pm", "5 minutes", "next week",
# etc, into seconds.
# This Source Code Form is subject to the terms of the Mozilla Public # This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;
use feature 'unicode_strings';
package PBot::Utils::ParseDate; package PBot::Utils::ParseDate;
use PBot::Imports;
use DateTime; use DateTime;
use DateTime::Format::Flexible; use DateTime::Format::Flexible;
use DateTime::Format::Duration; use DateTime::Format::Duration;

View File

@ -1,14 +1,22 @@
# File: SafeFilename.pm
#
# Purpose: for strings containing filenames, translates potentially unsafe
# characters into safe expansions; e.g. "foo/bar" becomes "foo&fslash;bar".
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::Utils::SafeFilename; package PBot::Utils::SafeFilename;
use 5.010; use warnings; use PBot::Imports;
use feature 'unicode_strings';
require Exporter; require Exporter;
our @ISA = qw/Exporter/; our @ISA = qw/Exporter/;
our @EXPORT = qw/safe_filename/; our @EXPORT = qw/safe_filename/;
sub safe_filename { sub safe_filename {
my $name = shift; my ($name) = @_;
my $safe = ''; my $safe = '';
while ($name =~ m/(.)/gms) { while ($name =~ m/(.)/gms) {

View File

@ -1,12 +1,18 @@
# File: ValidateString.pm
#
# Purpose: ensures that a given string conforms to PBot's limitations
# for internal strings. This means ensuring the string is not too long,
# does not have undesired characters, etc.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
package PBot::Utils::ValidateString; package PBot::Utils::ValidateString;
use warnings; use PBot::Imports;
use strict;
use feature 'unicode_strings'; # export validate_string subroutine
use utf8;
# export validate_string() subroutine
require Exporter; require Exporter;
our @ISA = qw/Exporter/; our @ISA = qw/Exporter/;
our @EXPORT = qw/validate_string/; our @EXPORT = qw/validate_string/;