aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2016-09-12 16:47:00 -0400
committerTeddy Wing2016-09-12 16:47:00 -0400
commitdcd362a651f6adfef8ddf38cb1c35bdb9923eca2 (patch)
tree48e6f2c25562570d8d6adfef9348961010346177
parent68c7884bd109076b1a7c67bedcf91e36ec50ea6c (diff)
downloadirssi-slack-profile-dcd362a651f6adfef8ddf38cb1c35bdb9923eca2.tar.bz2
Get & print user profile information from Slack
Fetch profile information from the Slack API's `users.profile.get` method. Grab the custom fields from the response and print these as part of the SWHOIS output. Note that this currently only works when a nick argument is passed to the command. This is just an initial version. It should be cleaned up such that getting the custom fields is probably in its own subroutine, and more importantly that fetching the profile fields from the API doesn't stop WHOIS output if the API call fails. After all, most WHOIS information can be gathered from the local cache.
-rw-r--r--slack_profile.pl20
1 files changed, 20 insertions, 0 deletions
diff --git a/slack_profile.pl b/slack_profile.pl
index f7b1c1d..e15ac2a 100644
--- a/slack_profile.pl
+++ b/slack_profile.pl
@@ -129,6 +129,17 @@ sub fetch_users_list {
store \@users_list, users_list_cache;
}
+sub fetch_user_profile {
+ my ($user) = @_;
+
+ my $resp = slack_api('users.profile.get', {
+ user => $user->{'id'},
+ include_labels => 1
+ });
+
+ return $resp->{'profile'};
+}
+
sub find_user {
my ($username) = @_;
@@ -171,6 +182,8 @@ sub print_whois {
maybe_print_field('phone', $user->{'profile'}->{'phone'});
maybe_print_field('skype', $user->{'profile'}->{'skype'});
maybe_print_field('tz ', $user->{'tz_label'});
+ maybe_print_field('gh ', $user->{'GitHub'});
+ maybe_print_field('karma', $user->{'Karma'});
Irssi::print('End of SWHOIS');
}
@@ -183,6 +196,13 @@ sub swhois {
$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);
}
}