mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 05:49:27 +01:00
Add built-in users
command
This commit is contained in:
parent
55d7561479
commit
0848c5752f
37
PBot/PBot.pm
37
PBot/PBot.pm
@ -328,7 +328,7 @@ sub listcmd {
|
|||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
my $text;
|
my $text;
|
||||||
|
|
||||||
my $usage = "Usage: list <modules|commands|users>";
|
my $usage = "Usage: list <modules|commands>";
|
||||||
|
|
||||||
if (not defined $arguments) {
|
if (not defined $arguments) {
|
||||||
return $usage;
|
return $usage;
|
||||||
@ -358,37 +358,6 @@ sub listcmd {
|
|||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($arguments =~ /^users$/i) {
|
|
||||||
$text = "Users: ";
|
|
||||||
my $last_channel = "";
|
|
||||||
my $sep = "";
|
|
||||||
foreach my $channel (sort keys %{ $self->{users}->{users}->{hash} }) {
|
|
||||||
next if $from =~ m/^#/ and $channel ne $from and $channel ne '.*';
|
|
||||||
if ($last_channel ne $channel) {
|
|
||||||
$text .= $sep . ($channel eq ".*" ? "global" : $channel) . ": ";
|
|
||||||
$last_channel = $channel;
|
|
||||||
$sep = "";
|
|
||||||
}
|
|
||||||
foreach my $hostmask (sort { return 0 if $a eq '_name' or $b eq '_name'; $self->{users}->{users}->{hash}->{$channel}->{$a}->{name} cmp $self->{users}->{users}->{hash}->{$channel}->{$b}->{name} } keys %{ $self->{users}->{users}->{hash}->{$channel} }) {
|
|
||||||
next if $hostmask eq '_name';
|
|
||||||
$text .= $sep;
|
|
||||||
my $has_cap = 0;
|
|
||||||
foreach my $key (keys %{$self->{users}->{users}->{hash}->{$channel}->{$hostmask}}) {
|
|
||||||
next if $key eq '_name';
|
|
||||||
if ($self->{capabilities}->exists($key)) {
|
|
||||||
$has_cap = 1;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$text .= '+' if $has_cap;
|
|
||||||
$text .= $self->{users}->{users}->{hash}->{$channel}->{$hostmask}->{name};
|
|
||||||
$sep = " ";
|
|
||||||
}
|
|
||||||
$sep = "; ";
|
|
||||||
}
|
|
||||||
return $text;
|
|
||||||
}
|
|
||||||
return $usage;
|
return $usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,7 +395,7 @@ sub evalcmd {
|
|||||||
|
|
||||||
$self->{logger}->log("[$from] $nick!$user\@$host Evaluating [$arguments]\n");
|
$self->{logger}->log("[$from] $nick!$user\@$host Evaluating [$arguments]\n");
|
||||||
|
|
||||||
my $ret;
|
my $ret = '';
|
||||||
my $result = eval $arguments;
|
my $result = eval $arguments;
|
||||||
if ($@) {
|
if ($@) {
|
||||||
if (length $result) {
|
if (length $result) {
|
||||||
@ -436,6 +405,8 @@ sub evalcmd {
|
|||||||
}
|
}
|
||||||
$ret =~ s/ at \(eval \d+\) line 1.//;
|
$ret =~ s/ at \(eval \d+\) line 1.//;
|
||||||
}
|
}
|
||||||
|
$result = 'Undefined.' if not defined $result;
|
||||||
|
$result = 'No output.' if not length $result;
|
||||||
return "/say $ret $result";
|
return "/say $ret $result";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ sub initialize {
|
|||||||
$self->{pbot}->{commands}->register(sub { $self->userdel(@_) }, "userdel", 1);
|
$self->{pbot}->{commands}->register(sub { $self->userdel(@_) }, "userdel", 1);
|
||||||
$self->{pbot}->{commands}->register(sub { $self->userset(@_) }, "userset", 1);
|
$self->{pbot}->{commands}->register(sub { $self->userset(@_) }, "userset", 1);
|
||||||
$self->{pbot}->{commands}->register(sub { $self->userunset(@_) }, "userunset", 1);
|
$self->{pbot}->{commands}->register(sub { $self->userunset(@_) }, "userunset", 1);
|
||||||
|
$self->{pbot}->{commands}->register(sub { $self->users(@_) }, "users", 0);
|
||||||
$self->{pbot}->{commands}->register(sub { $self->mycmd(@_) }, "my", 0);
|
$self->{pbot}->{commands}->register(sub { $self->mycmd(@_) }, "my", 0);
|
||||||
|
|
||||||
$self->{pbot}->{capabilities}->add('admin', 'can-useradd', 1);
|
$self->{pbot}->{capabilities}->add('admin', 'can-useradd', 1);
|
||||||
@ -266,16 +267,13 @@ sub logout {
|
|||||||
sub get_loggedin_user_metadata {
|
sub get_loggedin_user_metadata {
|
||||||
my ($self, $channel, $hostmask, $key) = @_;
|
my ($self, $channel, $hostmask, $key) = @_;
|
||||||
my $user = $self->loggedin($channel, $hostmask);
|
my $user = $self->loggedin($channel, $hostmask);
|
||||||
if ($user) {
|
return $user->{lc $key} if $user;
|
||||||
return $user->{lc $key};
|
|
||||||
}
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub logincmd {
|
sub logincmd {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
||||||
my $channel = $from;
|
my $channel = $from;
|
||||||
|
|
||||||
return "Usage: login [channel] password" if not $arguments;
|
return "Usage: login [channel] password" if not $arguments;
|
||||||
|
|
||||||
if ($arguments =~ m/^([^ ]+)\s+(.+)/) {
|
if ($arguments =~ m/^([^ ]+)\s+(.+)/) {
|
||||||
@ -299,28 +297,58 @@ sub logincmd {
|
|||||||
|
|
||||||
sub logoutcmd {
|
sub logoutcmd {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
||||||
|
|
||||||
$from = $arguments if length $arguments;
|
$from = $arguments if length $arguments;
|
||||||
my ($user_channel, $user_hostmask) = $self->find_user_account($from, "$nick!$user\@$host");
|
my ($user_channel, $user_hostmask) = $self->find_user_account($from, "$nick!$user\@$host");
|
||||||
|
return "/msg $nick You do not have a user account." if not defined $user_channel;
|
||||||
if (not defined $user_channel) {
|
|
||||||
return "/msg $nick You do not have a user account.";
|
|
||||||
}
|
|
||||||
|
|
||||||
my $u = $self->{users}->{hash}->{$user_channel}->{$user_hostmask};
|
my $u = $self->{users}->{hash}->{$user_channel}->{$user_hostmask};
|
||||||
my $channel_text = $user_channel eq '.*' ? '' : " for $user_channel";
|
my $channel_text = $user_channel eq '.*' ? '' : " for $user_channel";
|
||||||
|
return "/msg $nick You are not logged into $u->{name} ($user_hostmask)$channel_text." if not $u->{loggedin};
|
||||||
if (not $u->{loggedin}) {
|
|
||||||
return "/msg $nick You are not logged into $u->{name} ($user_hostmask)$channel_text.";
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->logout($user_channel, $user_hostmask);
|
$self->logout($user_channel, $user_hostmask);
|
||||||
return "/msg $nick Logged out of $u->{name} ($user_hostmask)$channel_text.";
|
return "/msg $nick Logged out of $u->{name} ($user_hostmask)$channel_text.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub users {
|
||||||
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
my $channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
|
||||||
|
$channel = $from if not defined $channel;
|
||||||
|
|
||||||
|
my $text = "Users: ";
|
||||||
|
my $last_channel = "";
|
||||||
|
my $sep = "";
|
||||||
|
foreach my $chan (sort keys %{ $self->{users}->{hash} }) {
|
||||||
|
next if $from =~ m/^#/ and $chan ne $channel and $chan ne '.*';
|
||||||
|
next if $from !~ m/^#/ and $channel =~ m/^#/ and $chan ne $channel;
|
||||||
|
|
||||||
|
if ($last_channel ne $chan) {
|
||||||
|
$text .= $sep . ($chan eq ".*" ? "global" : $chan) . ": ";
|
||||||
|
$last_channel = $chan;
|
||||||
|
$sep = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach my $hostmask (sort { return 0 if $a eq '_name' or $b eq '_name'; $self->{users}->{hash}->{$chan}->{$a}->{name} cmp $self->{users}->{hash}->{$chan}->{$b}->{name} } keys %{ $self->{users}->{hash}->{$chan} }) {
|
||||||
|
next if $hostmask eq '_name';
|
||||||
|
$text .= $sep;
|
||||||
|
my $has_cap = 0;
|
||||||
|
foreach my $key (keys %{$self->{users}->{hash}->{$chan}->{$hostmask}}) {
|
||||||
|
next if $key eq '_name';
|
||||||
|
if ($self->{pbot}->{capabilities}->exists($key)) {
|
||||||
|
$has_cap = 1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$text .= '+' if $has_cap;
|
||||||
|
$text .= $self->{users}->{hash}->{$chan}->{$hostmask}->{name};
|
||||||
|
$sep = " ";
|
||||||
|
}
|
||||||
|
$sep = "; ";
|
||||||
|
}
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
sub useradd {
|
sub useradd {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
my ($name, $channel, $hostmask, $capabilities, $password) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 5);
|
my ($name, $channel, $hostmask, $capabilities, $password) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 5);
|
||||||
$capabilities //= 'none';
|
$capabilities //= 'none';
|
||||||
|
|
||||||
@ -357,7 +385,6 @@ sub useradd {
|
|||||||
|
|
||||||
sub userdel {
|
sub userdel {
|
||||||
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
|
||||||
|
|
||||||
my ($channel, $hostmask) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
my ($channel, $hostmask) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
|
||||||
|
|
||||||
if (not defined $channel or not defined $hostmask) {
|
if (not defined $channel or not defined $hostmask) {
|
||||||
|
Loading…
Reference in New Issue
Block a user