Bot::BasicBot::Pluggable::Module::Vars - change internal module variables


Bot-BasicBot-Pluggable documentation Contained in the Bot-BasicBot-Pluggable distribution.

Index


Code Index:

NAME

Top

Bot::BasicBot::Pluggable::Module::Vars - change internal module variables

VERSION

Top

version 0.93

SYNOPSIS

Top

Bot modules have variables that they can use to change their behaviour. This module, when loaded, gives people who are logged in and autneticated the ability to change these variables from the IRC interface. The variables that are set are in the object store, and begin "user_", so:

  !set Module foo bar

will set the store key 'user_foo' to 'bar' in the 'Module' module.

IRC USAGE

Top

!set <module> <variable> <value>

Sets the variable to value in a given module. Module must be loaded.

!unset <module> <variable>

Unsets a variable (deletes it entirely) for the current load of the module.

!vars <module>

Lists the variables and their current values in a module.

AUTHOR

Top

Mario Domgoergen <mdom@cpan.org>

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Bot-BasicBot-Pluggable documentation Contained in the Bot-BasicBot-Pluggable distribution.

package Bot::BasicBot::Pluggable::Module::Vars;
BEGIN {
  $Bot::BasicBot::Pluggable::Module::Vars::VERSION = '0.93';
}
use base qw(Bot::BasicBot::Pluggable::Module);
use warnings;
use strict;

sub help {
    return
"Change internal module variables. Usage: !set <module> <variable> <value>, !unset <module> <variable>, !vars <module>.";
}

sub told {
    my ( $self, $mess ) = @_;
    my $body = $mess->{body};
    return 0 unless defined $body;
    my ( $command, $mod, $var, $value ) = split( /\s+/, $body, 4 );
    $command = lc($command);

    return if !$self->authed( $mess->{who} );

    if ( $command eq "!set" ) {
        my $module = $self->{Bot}->module($mod);
        return "No such module '$module'." unless $module;
        $value = defined($value) ? $value : '';    # wipe if no value.
        $module->set( "user_$var", $value );
        return "Set.";

    }
    elsif ( $command eq "!unset" ) {
        return "Usage: !unset <module> <variable>." unless $var;
        my $module = $self->{Bot}->module($mod);
        return "No such module '$module'." unless $module;
        $module->unset("user_$var");
        return "Unset.";

    }
    elsif ( $command eq "!vars" ) {
        return "You must pass a module" unless defined $mod;
        my $module = $self->bot->module($mod);
        return "No such module '$mod'." unless $module;
        my @vars =
          map { my $mod = $_; $mod =~ s/^user_// ? $mod : () }
          $module->store_keys( res => ["^user"] );
        return "$mod has no variables." unless @vars;
        return "Variables for $mod: "
          . (
            join ", ", map { "'$_' => '" . $module->get("user_$_") . "'" } @vars
          ) . ".";
    }
}

1;

__END__