diff options
| author | Teddy Wing | 2016-09-17 05:15:39 -0400 |
|---|---|---|
| committer | Teddy Wing | 2016-09-17 05:15:39 -0400 |
| commit | e566b8e43841e998ef49780c44a88146937f8534 (patch) | |
| tree | 8f1e1633f22af88d7bd8ea14d082a3e29de37cea | |
| parent | b2adb8415387659671290a7bbe4be6bad10cbf7e (diff) | |
| parent | c680a0ed48c550cb4e7de9898b85cc9ec7f4b114 (diff) | |
| download | irssi-slack-profile-e566b8e43841e998ef49780c44a88146937f8534.tar.bz2 | |
Merge branch 'set-profile-fields'
| -rw-r--r-- | TODO | 4 | ||||
| -rw-r--r-- | slack_profile.pl | 48 |
2 files changed, 49 insertions, 3 deletions
@@ -15,4 +15,6 @@ v Get presence information on the requested user v Get the requested user's GitHub URL and Gigster Karma fields (needs users.profile API) v3: -- Add a command to set/change the current user's profile fields +v Add a command to set/change the current user's profile fields +- Profile field completion (see https://github.com/irssi/scripts.irssi.org/blob/22060fc4669627a9859c92efa2d6651e3673d494/scripts/go.pl) +- Pad colons diff --git a/slack_profile.pl b/slack_profile.pl index 706da77..15ce828 100644 --- a/slack_profile.pl +++ b/slack_profile.pl @@ -156,6 +156,50 @@ sub fetch_user_presence { return $resp->{'presence'}; } +sub underscorize { + my ($string) = @_; + + my $result = lc $string; + $result =~ s/ /_/g; + $result =~ s/[^a-z_]//g; + + return $result; +} + +sub update_user_profile { + my ($key, $value) = @_; + + my $user = find_user($server->{'nick'}); + + my @profile_fields = qw(first_name last_name email phone skype title); + + # If $key is a custom field, find the custom field's id and use + # that as the key instead. + unless ($key ~~ @profile_fields) { + # Find key in custom field labels + for my $custom_field (keys %{$user->{'fields'}}) { + if (underscorize($user->{'fields'}->{$custom_field}->{'label'}) + eq $key) { + $key = $custom_field; + last; + } + } + } + + my $resp = slack_api('users.profile.set', { + user => $user->{'id'}, + name => $key, + value => $value, + }); +} + +sub cmd_set { + my ($data) = @_; + my ($key, $value) = split /\s+/, $data, 2; + + update_user_profile($key, $value); +} + sub find_user { my ($username) = @_; @@ -239,8 +283,8 @@ sub swhois { Irssi::command_bind('swhois', 'swhois'); -Irssi::command_bind('slack_profile', 'sync'); -Irssi::command_bind('slack_profile sync', 'sync'); +Irssi::command_bind('slack_profile_sync', 'sync'); +Irssi::command_bind('slack_profile_set', 'cmd_set'); Irssi::command_bind('help', 'help'); |
