aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-09-12 17:34:07 -0400
committerTeddy Wing2016-09-12 17:34:07 -0400
commitef0ac1da4b67c679ddf431bf25bf32b2305fd2a1 (patch)
tree1baba2f5dfd45390e1b5c7af2b23f4b530d5b66d
parentdcd362a651f6adfef8ddf38cb1c35bdb9923eca2 (diff)
downloadirssi-slack-profile-ef0ac1da4b67c679ddf431bf25bf32b2305fd2a1.tar.bz2
swhois: Use a more declarative style when no arguments are given
Make the code more DRY by setting `$username` to the current nick if it isn't passed to the command. This way we don't have to run `print_whois` twice.
-rw-r--r--slack_profile.pl32
1 files changed, 15 insertions, 17 deletions
diff --git a/slack_profile.pl b/slack_profile.pl
index e15ac2a..43a3e24 100644
--- a/slack_profile.pl
+++ b/slack_profile.pl
@@ -191,28 +191,26 @@ sub print_whois {
sub swhois {
my ($username, $server, $window_item) = @_;
- if ($username) {
- # If $username starts with @, strip it
- $username =~ s/^@//;
-
- if (my $user = find_user($username)) {
- my $profile = fetch_user_profile($user);
- foreach my $key (keys %{$profile->{'fields'}}) {
- my $label = $profile->{'fields'}->{$key}->{'label'};
- my $value = $profile->{'fields'}->{$key}->{'value'};
- $user->{$label} = $value;
- }
-
- print_whois($user);
- }
- }
- else {
+ if (!$username) {
if (!$server || !$server->{connected}) {
Irssi::print("Not connected to server");
return;
}
- my $user = find_user($server->{'nick'});
+ $username = $server->{'nick'};
+ }
+
+ # If $username starts with @, strip it
+ $username =~ s/^@//;
+
+ if (my $user = find_user($username)) {
+ my $profile = fetch_user_profile($user);
+ foreach my $key (keys %{$profile->{'fields'}}) {
+ my $label = $profile->{'fields'}->{$key}->{'label'};
+ my $value = $profile->{'fields'}->{$key}->{'value'};
+ $user->{$label} = $value;
+ }
+
print_whois($user);
}
}