Skip to content

Commit

Permalink
Add /away command #360
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Henning Thorsen committed Sep 25, 2021
1 parent 23a4065 commit 95f87fa
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Revision history for perl distribution Convos
- Fix trying to connect if wanted_state is "connected"
- Fix "Facts" bot action to only reply if the fact ends with "?"
- Add AWAY message to WHOIS response #360
- Add /away command #360
- Add more connection states: connecting and disconnecting
- Add server messages when connections state changes
- Add "Retry" button to loading screen
Expand Down
1 change: 1 addition & 0 deletions assets/js/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add('/shrug', '/shrug <msg>', 'Add a shrug to end of message. Message is optiona
add('/join', '/join <#channel>', 'Join channel and open up a chat window.');
add('/close', '/close [nick|#channel]', 'Close conversation.');
add('/nick', '/nick <nick>', 'Change your wanted nick.');
add('/away', '/away <message>', 'Add or remove an away message');
add('/kick', '/kick <nick>', 'Kick a user from the current channel.');
add('/mode', '/mode [+|-][b|o|v] <user>', 'Change mode of yourself or a user');
add('/topic', '/topic or /topic <new topic>', 'Show current topic, or set a new one.');
Expand Down
5 changes: 5 additions & 0 deletions assets/store/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export default class Connection extends Conversation {
return super.update(params);
}

wsEventSentAway(params) {
const conversation = this.findConversation(params) || this;
conversation.addMessages({message: params.reason, sent: params, type: 'notice'});
}

wsEventConnection(params) {
this.update({state: params.state});
}
Expand Down
20 changes: 20 additions & 0 deletions lib/Convos/Core/Connection/Irc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ sub send_p {
return $self->_send_list_p($message) if $cmd eq 'LIST';
return $self->_send_nick_p($message) if $cmd eq 'NICK';
return $self->_send_whois_p($message) if $cmd eq 'WHOIS';
return $self->_send_away_p($message) if $cmd eq 'AWAY';

return $self->_send_names_p($target) if $cmd eq 'NAMES';

Expand Down Expand Up @@ -504,6 +505,12 @@ sub _irc_event_rpl_topicwhotime { }

sub _is_current_nick { lc $_[0]->nick eq lc $_[1] }

sub _make_away_response {
my ($self, $msg, $res, $p) = @_;
$p->resolve(
{away => $msg->{command} eq 'rpl_unaway' ? false : true, reason => $msg->{params}[1] // ''});
}

sub _make_ctcp_string {
my $self = shift;
local $_ = join ' ', @_;
Expand Down Expand Up @@ -752,6 +759,19 @@ sub _sasl_mechanism {
return $mech =~ m!^(EXTERNAL|PLAIN)$! ? $mech : '';
}

sub _send_away_p {
my ($self, $away_message) = @_;
$away_message = trim $away_message // '';
$away_message = ":$away_message" if length $away_message;

return $self->_write_and_wait_p(
"AWAY $away_message", {away => false},
rpl_nowaway => {},
rpl_unaway => {},
'_make_away_response',
);
}

sub _send_clear_p {
my ($self, $what, $target) = @_;

Expand Down
18 changes: 18 additions & 0 deletions t/irc-commands.t
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,20 @@ $server->subtest(
}
);

$server->subtest(
'away' => sub {
$server->server_event_ok('_irc_event_away')->server_write_ok(['away.irc']);
$res = $connection->send_p('', '/away foo')->$wait_success;
$server->processed_ok;
is_deeply($res, {away => true, reason => 'You have been marked as being away'}, 'away');

$server->server_event_ok('_irc_event_away')->server_write_ok(['unaway.irc']);
$res = $connection->send_p('', '/away ')->$wait_success;
$server->processed_ok;
is_deeply($res, {away => false, reason => 'You are no longer marked as being away'}, 'unaway');
}
);

$server->subtest(
'close and part' => sub {
$res = $connection->send_p('#convos', '/close superwoman')->$wait_success;
Expand Down Expand Up @@ -459,6 +473,10 @@ $server->subtest(
done_testing;

__DATA__
@@ away.irc
:localhost 306 testman :You have been marked as being away
@@ unaway.irc
:localhost 305 testman :You are no longer marked as being away
@@ join-invite-only.irc
:localhost 473 superman #invite_only :Cannot join channel (+i)
@@ join-protected.irc
Expand Down

0 comments on commit 95f87fa

Please sign in to comment.