mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-23 04:19:27 +01:00
Spinach now detects when players leave the channel
This commit is contained in:
parent
5caf0648d0
commit
4b9a249014
@ -31,6 +31,10 @@ sub initialize {
|
||||
|
||||
$self->{pbot}->{timer}->register(sub { $self->spinach_timer }, 1, 'spinach timer');
|
||||
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.part', sub { $self->on_departure(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.quit', sub { $self->on_departure(@_) });
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.kick', sub { $self->on_kick(@_) });
|
||||
|
||||
$self->{leaderboard_filename} = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/spinachlb.sqlite3';
|
||||
$self->{questions_filename} = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/spinachq.json';
|
||||
|
||||
@ -47,6 +51,24 @@ sub unload {
|
||||
$self->{pbot}->{timer}->unregister('spinach timer');
|
||||
}
|
||||
|
||||
sub on_kick {
|
||||
my ($self, $event_type, $event) = @_;
|
||||
my ($nick, $user, $host) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host);
|
||||
my ($victim, $reason) = ($event->{event}->to, $event->{event}->{args}[1]);
|
||||
my $channel = $event->{event}->{args}[0];
|
||||
return 0 if lc $channel ne $self->{channel};
|
||||
$self->player_left($nick, $user, $host);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub on_departure {
|
||||
my ($self, $event_type, $event) = @_;
|
||||
my ($nick, $user, $host, $channel, $args) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to, $event->{event}->args);
|
||||
return 0 if lc $channel ne $self->{channel};
|
||||
$self->player_left($nick, $user, $host);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub load_questions {
|
||||
my $self = shift;
|
||||
|
||||
@ -474,6 +496,19 @@ my %color = (
|
||||
reset => "\x0F",
|
||||
);
|
||||
|
||||
sub player_left {
|
||||
my ($self, $nick, $user, $host) = @_;
|
||||
|
||||
my $id = $self->{pbot}->{messagehistory}->{database}->get_message_account($nick, $user, $host);
|
||||
|
||||
for (my $i = 0; $i < @{$self->{state_data}->{players}}; $i++) {
|
||||
if ($self->{state_data}->{players}->[$i]->{id} == $id) {
|
||||
splice @{$self->{state_data}->{players}}, $i--, 1;
|
||||
$self->{pbot}->{conn}->privmsg($self->{channel}, "$color{bold}$nick has left the game!$color{reset}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub run_one_state {
|
||||
my $self = shift;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user