};
#
+# This is a list of default values for the remote API. These
+# are used if the values are not registered by the library user.
+#
+my $remote_api = {
+ io => sub { print @_, "\n" },
+ config_init => \&_builtin_config_init,
+ config_get => \&_builtin_config_get,
+ config_set => \&_builtin_config_set,
+ config_has => \&_builtin_config_has,
+ config_save => \&_builtin_config_save,
+ config_del => \&_builtin_config_del,
+ color => sub { return '' },
+ module_path => sub { return dirname(realpath($0)) },
+ quote => sub { return $_ },
+ reload => sub {},
+};
+
+#
# List of known commands and handlers
#
my $videosite_commands = {
},
'reload' => sub {
- init();
+ $remote_api->{reload}->();
},
'mode' => sub {
};
#
-# This is a list of default values for the remote API. These
-# are used if the values are not registered by the library user.
-#
-my $remote_api = {
- io => sub { print @_, "\n" },
- config_init => \&_builtin_config_init,
- config_get => \&_builtin_config_get,
- config_set => \&_builtin_config_set,
- config_has => \&_builtin_config_has,
- config_save => \&_builtin_config_save,
- config_del => \&_builtin_config_del,
- color => sub { return '' },
- module_path => sub { return dirname(realpath($0)) },
- quote => sub { return $_ },
-};
-
-#
# Output a string on the client.
# Works like (s)printf in that it takes a format string and a list of
# values to be replaced. Undefined values will be printed as '(undef)'
return $b;
}
+sub _config_del {
+ my $path = shift;
+
+ _debug("config: removing %s", join('.', @{$path}));
+ $remote_api->{config_del}->($path);
+}
+
#
# The _config_list_* are helper functions taking a path to a comma separated
# string. The string is interpreted as a list and the action performed
}
_debug("Removing %s from list %s", $item, join('.', @{$path}));
- @c = map { $item ne $_ } split(/\s*,\s*/, _config_get($path));
+ @c = grep { $item ne $_ } split(/\s*,\s*/, _config_get($path));
- _config_set($path, join('.', @c));
+ _config_set($path, join(',', @c));
}
#
# Save the config to durable storage
#
sub _cmd_save {
- $remote_api->{config_save}->();
+ if ($remote_api->{config_save}->()) {
+ _io("Config saved");
+ } else {
+ _io(sprintf("%sConfig save failed%s", _colorpair("*red"), _colorpair()));
+ }
}
#
$name = lc($name);
+ unless($name =~ m|^[a-z]+$|) {
+ _io("%s is not a valid connector name (only letters are allowed)", $name);
+ return;
+ }
+
if (_config_list_has(['defined-connectors'], $name)) {
_io("Connector already exists");
return;
my $g;
my $m;
my $p;
+ my $skip;
+ my $mode = _config_get(['mode']);
- # Look if we should ignore this line
+ #
+ # If /nosave is present in the message switch to display mode, regardless
+ # of config setting
+ #
if ($message =~ m,(?:\s|^)/nosave(?:\s|$),) {
- return;
+ $mode = 'display';
}
_push_output($event->{ewpf});
($m, $p) = $g->get($message);
while (defined($m)) {
_debug('Metadata: %s', Dumper($m));
+ $skip = 0;
if (exists($remote_api->{link_callback})) {
- $remote_api->{link_callback}->($m);
+ $skip = $remote_api->{link_callback}->($m);
}
- if ('download' eq _config_get(['mode'])) {
- _io(
- sprintf('%s>>> %sSaving %s%%s%s %s%%s',
- _colorpair('*red'),
- _colorpair(),
- _colorpair('*yellow'),
- _colorpair(),
- _colorpair('*green'),
- ),
- $m->{'SOURCE'},
- $m->{'TITLE'}
- );
- unless($getter->get($m)) {
- _io(sprintf('%s>>> FAILED', _colorpair('*red')));
+ unless($skip) {
+ if ('download' eq $mode) {
+ _io(
+ sprintf('%s>>> %sSaving %s%%s%s %s%%s',
+ _colorpair('*red'),
+ _colorpair(),
+ _colorpair('*yellow'),
+ _colorpair(),
+ _colorpair('*green'),
+ ),
+ $m->{'SOURCE'},
+ $m->{'TITLE'}
+ );
+ unless($getter->get($m)) {
+ _io(sprintf('%s>>> FAILED', _colorpair('*red')));
+ }
+ } elsif ('display' eq $mode) {
+ _io(
+ sprintf('%s>>> %sSaw %s%%s%s %s%%s',
+ _colorpair('*magenta'),
+ _colorpair(),
+ _colorpair('*yellow'),
+ _colorpair(),
+ _colorpair('*green')
+ ),
+ $m->{'SOURCE'},
+ $m->{'TITLE'}
+ );
+ } else {
+ _io(sprintf('%s>>> Invalid operation mode', _colorpair('*red')));
}
- } elsif ('display' eq _config_get(['mode'])) {
- _io(
- sprintf('%s>>> %sSaw %s%%s%s %s%%s',
- _colorpair('*magenta'),
- _colorpair(),
- _colorpair('*yellow'),
- _colorpair(),
- _colorpair('*green')
- ),
- $m->{'SOURCE'},
- $m->{'TITLE'}
- );
- } else {
- _io(sprintf('%s>>> Invalid operation mode', _colorpair('*red')));
}
# Remove the matched part from the message and try again (there may be