mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-02 07:24:09 +01:00
Add factoid effective-level metadata and ability to kick from such factoids
Factoids can now have an effective-level metadata field. When set, certain functionality requiring an effective-level will be enabled. For now, that is currently only the /kick command, which has an effective-level of 10. Factoids with an effective-level set will also have the locked metadata attribute set as well to prevent people from changing the factoid. The locked and/or effective-level attributes will be removable only by admins whose level is equal to or greater than the effective-level.
This commit is contained in:
parent
39399e78ae
commit
f3b3e90cdc
@ -43,6 +43,7 @@ my %factoid_metadata_levels = (
|
||||
locked => 10,
|
||||
add_nick => 10,
|
||||
nooverride => 10,
|
||||
effective_level => 20,
|
||||
# all others are allowed to be factset by anybody/default to level 0
|
||||
);
|
||||
|
||||
@ -159,6 +160,22 @@ sub factset {
|
||||
return "You must be at least level $meta_level to set '$key'";
|
||||
}
|
||||
}
|
||||
|
||||
if (lc $key eq 'effective-level' and defined $value and $level > 0) {
|
||||
if ($value > $level) {
|
||||
return "You cannot set `effective-level` greater than your level, which is $level.";
|
||||
} elsif ($value < 0) {
|
||||
return "You cannot set a negative effective-level.";
|
||||
}
|
||||
|
||||
$self->{pbot}->{factoids}->{factoids}->set($channel, $trigger, 'locked', '1');
|
||||
}
|
||||
|
||||
if (lc $key eq 'locked' and exists $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{'effective-level'}) {
|
||||
if ($level < $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{'effective-level'}) {
|
||||
return "You cannot unlock this factoid because its effective-level is greater than your level.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $oldvalue;
|
||||
@ -228,6 +245,20 @@ sub factunset {
|
||||
}
|
||||
}
|
||||
|
||||
if (exists $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{'effective-level'}) {
|
||||
if (lc $key eq 'locked') {
|
||||
if ($level >= $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{'effective-level'}) {
|
||||
$self->{pbot}->{factoids}->{factoids}->unset($channel, $trigger, 'effective-level');
|
||||
} else {
|
||||
return "You cannot unlock this factoid because its effective-level is higher than your level.";
|
||||
}
|
||||
} elsif (lc $key eq 'effective-level') {
|
||||
if ($level < $self->{pbot}->{factoids}->{factoids}->hash->{$channel}->{$trigger}->{'effective-level'}) {
|
||||
return "You cannot unset the effective-level because it is higher than your level.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $oldvalue;
|
||||
|
||||
if(defined $owner_channel) {
|
||||
@ -1109,8 +1140,14 @@ sub factchange {
|
||||
return "$keyword not found in channel $chan.";
|
||||
}
|
||||
|
||||
if(not $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host") and $factoids->{$channel}->{$trigger}->{'locked'}) {
|
||||
return "$trigger is locked and cannot be changed.";
|
||||
my $admininfo = $self->{pbot}->{admins}->loggedin($channel, "$nick!$user\@$host");
|
||||
if ($factoids->{$channel}->{$trigger}->{'locked'}) {
|
||||
return "$trigger is locked and cannot be changed." if not defined $admininfo;
|
||||
|
||||
if (exists $factoids->{$channel}->{$trigger}->{'effective-level'}
|
||||
and $admininfo->{level} < $factoids->{$channel}->{$trigger}->{'effective-level'}) {
|
||||
return "$trigger is locked with an effective-level higher than your level and cannot be changed.";
|
||||
}
|
||||
}
|
||||
|
||||
my $ret = eval {
|
||||
|
@ -670,9 +670,10 @@ sub interpreter {
|
||||
$action =~ s/^\/([^ ]+) \Q$nick\E:\s+/\/$1 /;
|
||||
$action =~ s/^\Q$nick\E:\s+//;
|
||||
|
||||
if($action =~ s/^\/say\s+//i || $action =~ s/^\/me\s+/* $botnick /i
|
||||
if ($action =~ s/^\/say\s+//i || $action =~ s/^\/me\s+/* $botnick /i
|
||||
|| $action =~ /^\/msg\s+/i) {
|
||||
$action = "/say $tonick: $action";
|
||||
} elsif ($action =~ m/^\/kick\s+/i) {
|
||||
} else {
|
||||
$action = "/say $tonick: $keyword is $action";
|
||||
}
|
||||
@ -716,8 +717,18 @@ sub interpreter {
|
||||
return $ref_from . "$keyword is $action";
|
||||
}
|
||||
} else {
|
||||
if($action =~ m/^\/say/i || $action =~ m/^\/me/i || $action =~ m/^\/msg/i) {
|
||||
if ($action =~ m/^\/(?:say|me|msg)/i) {
|
||||
return $action;
|
||||
} elsif ($action =~ s/^\/kick\s+//) {
|
||||
if (not exists $self->{factoids}->hash->{$channel}->{$keyword}->{'effective-level'}) {
|
||||
return "/say $nick: I don't have the effective-level to do that.";
|
||||
}
|
||||
my $level = 10;
|
||||
if ($level >= $self->{factoids}->hash->{$channel}->{$keyword}->{'effective-level'}) {
|
||||
return "/$self->{pbot}->{secretstuff}kick " . $action;
|
||||
} else {
|
||||
return "/say $nick: My effective-level isn't high enough to do that.";
|
||||
}
|
||||
} else {
|
||||
return "$keyword is $action";
|
||||
}
|
||||
|
@ -114,8 +114,7 @@ sub process_line {
|
||||
$nick_override = $1;
|
||||
$has_code = $2 if length $2 and $nick_override !~ /^(?:enum|struct|union)$/;
|
||||
$preserve_whitespace = 1;
|
||||
my $similar = $self->{pbot}->{nicklist}->is_present_similar($from, $nick_override);
|
||||
$nick_override = $similar if $similar;
|
||||
my $nick_override = $self->{pbot}->{nicklist}->is_present($from, $nick_override);
|
||||
$processed += 100;
|
||||
} elsif($cmd_text =~ s/^\s*([^,:\(\)\+\*\/ ]+)[,:]?\s+$bot_trigger(.*)$//) {
|
||||
$nick_override = $1;
|
||||
@ -373,6 +372,27 @@ sub output_result {
|
||||
$pbot->{conn}->privmsg($to, $line) if $to !~ /\Q$botnick\E/i;
|
||||
$pbot->{antiflood}->check_flood($to, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $checkflood;
|
||||
}
|
||||
} elsif($line =~ s/^\/$self->{pbot}->{secretstuff}kick\s+//) {
|
||||
$pbot->{antiflood}->check_flood($from, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/kick ' . $line, 0, 0, 0) if $checkflood;
|
||||
my ($victim, $reason) = split / /, $line, 2;
|
||||
|
||||
if (not defined $reason) {
|
||||
if (open my $fh, '<', $self->{pbot}->{registry}->get_value('general', 'module_dir') . '/insults.txt') {
|
||||
my @insults = <$fh>;
|
||||
close $fh;
|
||||
$reason = $insults[rand @insults];
|
||||
chomp $reason;
|
||||
} else {
|
||||
$reason = 'Bye!';
|
||||
}
|
||||
}
|
||||
|
||||
if ($self->{pbot}->{chanops}->can_gain_ops($from)) {
|
||||
$self->{pbot}->{chanops}->add_op_command($from, "kick $from $victim $reason");
|
||||
$self->{pbot}->{chanops}->gain_ops($from);
|
||||
} else {
|
||||
$pbot->{conn}->privmsg($from, "$victim: $reason") if defined $from && $from !~ /\Q$botnick\E/i;
|
||||
}
|
||||
} else {
|
||||
$pbot->{conn}->privmsg($from, $line) if defined $from && $from !~ /\Q$botnick\E/i;
|
||||
$pbot->{antiflood}->check_flood($from, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $checkflood;
|
||||
|
@ -137,6 +137,9 @@ sub initialize {
|
||||
# load registry entries from file to overwrite defaults
|
||||
$self->{registry}->load;
|
||||
|
||||
my @chars = ("A".."Z", "a".."z", "0".."9");
|
||||
$self->{secretstuff} = $chars[rand @chars] for 1..32;
|
||||
|
||||
# create implicit bot-admin account for bot
|
||||
my $botnick = $self->{registry}->get_value('irc', 'botnick');
|
||||
$self->{admins}->add_admin($botnick, '.*', "$botnick!stdin\@localhost", 90, 'admin', 1);
|
||||
|
Loading…
Reference in New Issue
Block a user