3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-24 11:42:35 +01:00

Plugins/Plang: rename channel to namespace

This commit is contained in:
Pragmatic Software 2020-07-12 22:09:59 -07:00
parent 457ee84556
commit bc432fa8fe

View File

@ -32,15 +32,15 @@ sub initialize {
# register some built-in functions # register some built-in functions
$self->{plang}->{interpreter}->add_function_builtin('factset', $self->{plang}->{interpreter}->add_function_builtin('factset',
# parameters are [['param1 name', default arg], ['param2 name', default arg], ...] # parameters are [['param1 name', default arg], ['param2 name', default arg], ...]
[['channel', undef], ['keyword', undef], ['text', undef]], [['namespace', undef], ['keyword', undef], ['text', undef]],
sub { $self->set_factoid(@_) }); sub { $self->set_factoid(@_) });
$self->{plang}->{interpreter}->add_function_builtin('factget', $self->{plang}->{interpreter}->add_function_builtin('factget',
[['channel', undef], ['keyword', undef], ['meta', ['STRING', 'action']]], [['namespace', undef], ['keyword', undef], ['meta', ['STRING', 'action']]],
sub { $self->get_factoid(@_) }); sub { $self->get_factoid(@_) });
$self->{plang}->{interpreter}->add_function_builtin('factappend', $self->{plang}->{interpreter}->add_function_builtin('factappend',
[['channel', undef], ['keyword', undef], ['text', undef]], [['namespace', undef], ['keyword', undef], ['text', undef]],
sub { $self->append_factoid(@_) }); sub { $self->append_factoid(@_) });
# register the `plang` command # register the `plang` command
@ -132,27 +132,27 @@ sub is_locked {
sub get_factoid { sub get_factoid {
my ($self, $plang, $name, $arguments) = @_; my ($self, $plang, $name, $arguments) = @_;
my ($channel, $keyword, $meta) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]); my ($namespace, $keyword, $meta) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]);
my $result = $self->{pbot}->{factoids}->get_meta($channel, $keyword, $meta); my $result = $self->{pbot}->{factoids}->get_meta($namespace, $keyword, $meta);
return ['STRING', $result]; return ['STRING', $result];
} }
sub set_factoid { sub set_factoid {
my ($self, $plang, $name, $arguments) = @_; my ($self, $plang, $name, $arguments) = @_;
my ($channel, $keyword, $text) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]); my ($namespace, $keyword, $text) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]);
return ['ERROR', "Factoid $channel.$keyword is locked. Cannot set."] if $self->is_locked($channel, $keyword); return ['ERROR', "Factoid $namespace.$keyword is locked. Cannot set."] if $self->is_locked($namespace, $keyword);
$self->{pbot}->{factoids}->add_factoid('text', $channel, 'Plang', $keyword, $text); $self->{pbot}->{factoids}->add_factoid('text', $namespace, 'Plang', $keyword, $text);
return ['STRING', $text]; return ['STRING', $text];
} }
sub append_factoid { sub append_factoid {
my ($self, $plang, $name, $arguments) = @_; my ($self, $plang, $name, $arguments) = @_;
my ($channel, $keyword, $text) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]); my ($namespace, $keyword, $text) = ($arguments->[0]->[1], $arguments->[1]->[1], $arguments->[2]->[1]);
return ['ERROR', "Factoid $channel.$keyword is locked. Cannot append."] if $self->is_locked($channel, $keyword); return ['ERROR', "Factoid $namespace.$keyword is locked. Cannot append."] if $self->is_locked($namespace, $keyword);
my $action = $self->{pbot}->{factoids}->get_meta($channel, $keyword, 'action'); my $action = $self->{pbot}->{factoids}->get_meta($namespace, $keyword, 'action');
$action = "" if not defined $action; $action = "" if not defined $action;
$action .= $text; $action .= $text;
$self->{pbot}->{factoids}->add_factoid('text', $channel, 'Plang', $keyword, $action); $self->{pbot}->{factoids}->add_factoid('text', $namespace, 'Plang', $keyword, $action);
return ['STRING', $action]; return ['STRING', $action];
} }