From 753cd376d775fcb27a95bd780a554808c64cd05a Mon Sep 17 00:00:00 2001 From: David Phillips Date: Mon, 27 Mar 2017 15:22:56 +1300 Subject: Rename old saxrobot/saxbot sb_config to more appropriate name --- config_file.pm | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ idalius.pl | 6 +++--- sb_config.pm | 68 ---------------------------------------------------------- 3 files changed, 71 insertions(+), 71 deletions(-) create mode 100644 config_file.pm delete mode 100644 sb_config.pm diff --git a/config_file.pm b/config_file.pm new file mode 100644 index 0000000..fe23b89 --- /dev/null +++ b/config_file.pm @@ -0,0 +1,68 @@ +#!/usr/bin/env perl + +package config_file; + +use strict; +use warnings; +use Config::Tiny; + +sub parse_config +{ + my @scalar_configs = ( + 'nick', + 'username', + 'ircname', + 'server', + 'port', + 'usessl', + 'password', + 'must_id', + 'quit_msg', + 'user', + 'group'); + my @list_configs = ( + 'channels', + 'ignore', + 'admins'); + my @optional_configs = ( + 'password'); + my $file = $_[0]; + my %built_config; + my $config = Config::Tiny->read($file); + + # FIXME catch undefined/missing config options + foreach my $option (@scalar_configs) { + my $value = $config->{_}->{$option}; + if (! defined $value && ! grep {$_ eq $option} @optional_configs) { + die "Option \"$option\" must be set in $file\n"; + } + $built_config{$option} = $config->{_}->{$option}; + } + + foreach my $option (@list_configs) { + my $vals = $config->{_}->{$option}; + $vals =~ s/^\s+|\s+$//g; + @built_config{$option} = [split /\s*,\s*/, $vals]; + } + + # special case: triggers hash + my %triggers; + foreach (split ',', $config->{_}->{triggers}) { + my ($match, $response) = split /=>/; + # strip outer quotes + $match =~ s/^[^']*'|'[^']*$//g; + $response =~ s/^[^']*'|'[^']*$//g; + $triggers{$match} = $response; + } + + $built_config{uid} = getpwnam($built_config{user}) + or die "Cannot get uid of $built_config{user}: $!\n"; + $built_config{gid} = getgrnam($built_config{group}) + or die "Cannot get gid of $built_config{group}: $!\n"; + + + $built_config{triggers} = \%triggers; + + return %built_config; +} +1; diff --git a/idalius.pl b/idalius.pl index dbfb6d2..cc6b150 100755 --- a/idalius.pl +++ b/idalius.pl @@ -7,10 +7,10 @@ use POE; use POE::Kernel; use POE::Component::IRC; use POE::Component::IRC::Plugin::NickServID; -use sb_config; +use config_file; my $config_file = "bot.conf"; -my %config = sb_config::parse_config($config_file); +my %config = config_file::parse_config($config_file); my $current_nick = $config{nick}; @@ -188,7 +188,7 @@ sub irc_msg { } sub irc_disconnected { - %config = sb_config::parse_config($config_file); + %config = config_file::parse_config($config_file); $irc->yield(connect => { }); } diff --git a/sb_config.pm b/sb_config.pm deleted file mode 100644 index a6ac9cb..0000000 --- a/sb_config.pm +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env perl - -package sb_config; - -use strict; -use warnings; -use Config::Tiny; - -sub parse_config -{ - my @scalar_configs = ( - 'nick', - 'username', - 'ircname', - 'server', - 'port', - 'usessl', - 'password', - 'must_id', - 'quit_msg', - 'user', - 'group'); - my @list_configs = ( - 'channels', - 'ignore', - 'admins'); - my @optional_configs = ( - 'password'); - my $file = $_[0]; - my %built_config; - my $config = Config::Tiny->read($file); - - # FIXME catch undefined/missing config options - foreach my $option (@scalar_configs) { - my $value = $config->{_}->{$option}; - if (! defined $value && ! grep {$_ eq $option} @optional_configs) { - die "Option \"$option\" must be set in $file\n"; - } - $built_config{$option} = $config->{_}->{$option}; - } - - foreach my $option (@list_configs) { - my $vals = $config->{_}->{$option}; - $vals =~ s/^\s+|\s+$//g; - @built_config{$option} = [split /\s*,\s*/, $vals]; - } - - # special case: triggers hash - my %triggers; - foreach (split ',', $config->{_}->{triggers}) { - my ($match, $response) = split /=>/; - # strip outer quotes - $match =~ s/^[^']*'|'[^']*$//g; - $response =~ s/^[^']*'|'[^']*$//g; - $triggers{$match} = $response; - } - - $built_config{uid} = getpwnam($built_config{user}) - or die "Cannot get uid of $built_config{user}: $!\n"; - $built_config{gid} = getgrnam($built_config{group}) - or die "Cannot get gid of $built_config{group}: $!\n"; - - - $built_config{triggers} = \%triggers; - - return %built_config; -} -1; -- cgit v1.1