aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)Author
2016-09-18Increase version v1.00 -> v1.01HEADv1.01masterTeddy Wing
2016-09-18Merge branch 'swhois--trim-surrounding-spaces-from-argument'Teddy Wing
2016-09-18swhois: Trim leading & trailing whitespace from nick argumentTeddy Wing
When the nick is tab completed, it will get a space appended to it which is included in the `$username` argument passed to our command. That caused `find_user` to fail because it does an exact string equal match on the username. Ensure surrounding spaces are trimmed so that the comparison can be executed correctly.
2016-09-18Merge branch 'remove-smartmatch'Teddy Wing
2016-09-18Replace smartmatch operatorTeddy Wing
Change the smartmatch operator to `grep` instead because after Perl 5.18 it causes this warning: Smartmatch is experimental at slack_profile.pl line 306. Using advice from: http://www.perlmonks.org/?node_id=1067462
2016-09-17Merge branch 'update-readme-with-documentation-of-new-commands'v1.00Teddy Wing
2016-09-17README: Update usage section to include info on new commandsTeddy Wing
Document the `/slack_profile_set` and `/slack_profile_sync` commands.
2016-09-17Merge branch 'add-help-for-new-commands'Teddy Wing
2016-09-17Update TODOTeddy Wing
2016-09-17Add comment header documentation to all subroutinesTeddy Wing
Provide descriptions of what all subroutines do along with examples in some cases.
2016-09-17Document `slack_profile_sync` & `slack_profile_set` in script headerTeddy Wing
Add brief information about these two commands to the script's comment header as an additional documentation resource. This also builds on the brief documentation of the `/swhois` command here.
2016-09-17Update TODOTeddy Wing
2016-09-17help: Add built-in help for `slack_profile_sync` & `slack_profile_set`Teddy Wing
2016-09-17Merge branch 'pad-colons'Teddy Wing
2016-09-17Update TODOTeddy Wing
2016-09-17print_whois: Pad labels to vertically align colonsTeddy Wing
Previously, if field labels were longer than five charaters, they wouldn't be aligned with the colons `:` of the other fields in WHOIS output. The lack of alignment didn't look good. This change pads the field labels with spaces on their right side to make the colons line up visually and vertically. We also make a more fundamental change to how the subroutine works. Instead of trying to print fields immediately using `maybe_print_field`, they are instead added to an array of hashes. When we want to print fields, we loop over this array and only print those fields that contain non-blank values.
2016-09-17Merge branch 'profile-field-completion'Teddy Wing
2016-09-17Update TODOTeddy Wing
2016-09-17complete_profile_field: Correctly get current nickTeddy Wing
Previously we tried getting the current nick as `$server->{'nick'}`. This was, however, just a placeholder. Sure, it's how we got the current nick in an `Irssi::command_bind`, but we don't have a `$server` argument passed to us in the `complete word` signal. Instead, we get the current server from the active window passed to the signal, and from that server then obtain the current nick. This allows us to add custom field labels to the completion list. We also wrap all of this in an `if` statement that checks whether there is an active server on the window object. If not, then we don't add custom fields to the completion list. Without this condition, trying to use `$window->{'active_server'}` would prevent _all_ completions from working. Instead, we still want default Slack profile fields to continue working because they don't depend on an API call. We just want to disable completions for custom fields because they depend on a request to the user profile API endpoint.
2016-09-17find_user: Only request custom fields & presence if not already thereTeddy Wing
Previously we would make API requests for user profile information and presence information every time we invoked `find_user($nick)`. Since we store all users in memory in `@users_list`, once that data is requested the first time, it's saved for future use. If the data is already there locally in memory, there's no point in wasting time and network to request the data again. So only make the API requests if we don't already have the data.
2016-09-17update_user_profile: Use correct nickTeddy Wing
Previously the subroutine tried to use a nonexistent `$server` variable to get the current user's nick. To fix that, we get the server nick in `cmd_set` where we have access to it and then pass the nick to `update_user_profile`.
2016-09-17complete_profile_field: Add custom fields to completion listTeddy Wing
In addition to the Slack defaults, add custom fields as completions to give users an easy way to modify those as well. We move the requests for the custom fields (profile endpoint) and presence information into `find_user` instead of `swhois` because otherwise the custom fields aren't available to `complete_profile_field` or `update_user_profile` unless an `/swhois` has previously been run for the current nick. That was a bug.
2016-09-17cmd_set: Only call `update_user_profile` if `$key` is setTeddy Wing
If the `/slack_profile_set` command is called with no arguments (in this case, no key), then don't call this subroutine because it requests the Slack API. We should only make remote requests when we have enough information.
2016-09-17complete_profile_field: Fill in rest of field nameTeddy Wing
Previously we would replace the argument with the completion regardless of what the user typed. With this change, if they started to type one of the available fields (e.g. `/slack_profile_set ph<TAB>`), then the argument will complete with the rest of the field name.
2016-09-17complete_profile_field: Simplify complist dataTeddy Wing
Just set the array of default profile fields as the complist directly instead of doing the loop/push rigmarole.
2016-09-17Add completion of default Slack profile fieldsTeddy Wing
When using the `/slack_profile_set` command, complete the key names of default Slack profile fields. This obviates the need for users to remember and type the full key name. Based on: https://github.com/irssi/scripts.irssi.org/blob/22060fc4669627a9859c92efa2d6651e3673d494/scripts/go.pl Doesn't work for Slack custom profile fields yet. Also should probably consolidate repeated `@profile_fields` array.
2016-09-17Merge branch 'fix-in-memory-cache-after-running-sync-command'Teddy Wing
2016-09-17Fix users list bug after running 'sync' commandTeddy Wing
After running the `/slack_profile_sync` command, you would get an error trying to get the data from `@users_list` in the loop in `find_user`. This had to do with retrieving the data from the serialised `Storable` cache file. I'm not sure why there's a difference between the `retrieve`d cache version and the version downloaded and JSON decoded directly from the API, but that discrepancy caused the error. Now only refresh the `@users_list` with the `Storable` data if we haven't already fetched. Otherwise doing this is redundant because `fetch_users_list` sets `@users_list`. When we do `retrieve`, do the array trick, because that's the only time when we need to reach inside an outer array. In the loop, just want to use the plain `@users_list` so that we can have a consistent interface for both the API-fetched and cache-fetched versions.
2016-09-17Update TODOTeddy Wing
2016-09-17Merge branch 'set-profile-fields'Teddy Wing
2016-09-17Update TODOTeddy Wing
2016-09-17update_user_profile: Remove unnecessary commentTeddy Wing
Now that that functionality is implemented, this comment serves no purpose.
2016-09-17cmd_set: Get rid of unused variablesTeddy Wing
2016-09-17Add `/slack_profile_set` commandTeddy Wing
A new command that leverages `update_user_profile` to change a given profile field. Should this command delegate directly to `update_user_profile` (now that I think about it) instead of using an intermediary subroutine? I'm not sure. Also note that we removed the `/slack_profile` command and changed `/slack_profile sync` to `/slack_profile_sync`. I had trouble getting the subcommand setup to work. When I tried adding a `/slack_profile set` command, the `/slack_profile` command would be run when I tried to invoke it. I tried `\&cmd_set` syntax, `sub { cmd_set(); }` syntax, etc. for all the commands but it kept doing the same thing. Tried looking at some other scripts to see how they do it, but couldn't really figure it out except for 'trackbar' which uses a single subroutine for all it's subcommands which I didn't want to do. That's when I realised that subcommands kind of suck. I mean, you have to tab complete twice in order to invoke the command. Wouldn't it be so much nicer if you only had to tab complete the first command? So I changed the spaces to underscores which I think is better.
2016-09-17update_user_profile: Allow updating of custom fieldsTeddy Wing
Slack provides a set of default fields on a profile (relevant ones for editing are added to `@profile_fields`). Additionally, teams can add custom profile fields. These use unique ids that must be pulled from a profile object. This change maps an underscorized field name with a custom field id so that the id can be passed in the API call to change the field's value. The `@profile_fields` array is for now just to remind me what fields are available to change by default on profile. In the future, this will be used for key name completion.
2016-09-17Update TODOTeddy Wing
2016-09-12Add `underscorize` subroutineTeddy Wing
Takes a string and returns a lowercased underscored representation of it with non-alphabetic characters removed. Examples: GitHub string's Karma This is a test BOOYA KACHA Test @%^Test Becomes: github_strings karma this_is_a_test booya_kacha test_test
2016-09-12Start of a subroutine to update profile fieldsTeddy Wing
This doesn't work, but includes some rough code to allow updating of profile fields. A key and value are passed to the sub. These will be sent to the API as the field to update. We get the user by querying with the current nick (we'll have to get the `$server` from somewhere). Then a sample API call using `slack_api`. Also include some ideas on how we can update custom fields more easily because their non-human-readable ids must be used as a key in order to update them.
2016-09-12Merge branch 'sync-command'Teddy Wing
2016-09-12Add command to refresh users listTeddy Wing
New command `/slack_profile sync` (and `/slack_profile` for now) re-fetches the users list from the Slack API. This gives users a way to update their cache manually in case they find that the information is out of date.
2016-09-12Merge branch 'fetch-profile-fields'Teddy Wing
2016-09-12Update TODOTeddy Wing
2016-09-12Add user presence to WHOIS outputTeddy Wing
Display whether the requested user is online or away.
2016-09-12Update TODOTeddy Wing
2016-09-12slack_api: Move `die`s outside the subroutineTeddy Wing
Don't cause the command to break WHOIS output. Previously when we were only using it to call the 'users.list' Slack API method it was fine because the WHOIS output didn't directly depend on fetching the entire users list (since we have a cache). Now that we query the Slack API on each `/swhois` (the 'users.profile.get' method), we don't want to break profile output that can easily come from our cached data by dying. There's still value in displaying profile information without custom fields. We remove the `die` calls from `slack_api` and change them to a single `die` in the `fetch_users_list` method, since if this fails we really do want to stop script execution. In that case, if we don't get the users list back from the API, we can't set it to our in-memory cache nor store it to our cache file.
2016-09-12print_whois: Make field printing more genericTeddy Wing
Don't rely on specific custom fields. Instead, just attach all of them to the `$user` object that gets passed to `print_whois` and print the lot in a generic way.
2016-09-12swhois: Use a more declarative style when no arguments are givenTeddy Wing
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.
2016-09-12Get & print user profile information from SlackTeddy Wing
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.
2016-09-12slack_api: Allow API arguments to be passed to the subTeddy Wing
When calling the `slack_api` subroutine, an optional `$args` parameter can be passed which is a hash of Slack API arguments. The token gets added to this hash and the whole thing is set to the API URL query string.
2016-09-12Make the HTTP request subroutine more genericTeddy Wing
Allow any Slack API method to be requested instead of just the `users.list` method. This will enable us to use other Slack API methods leveraging the same HTTP code. The `fetch_users_list` subroutine now calls out to `slack_api` in order to retrieve its data.