| Age | Commit message (Collapse) | Author |
|
Prefix the filename with the name of our script for better uniqueness
and a clearer connection to this script.
|
|
|
|
We only need the `$server` object if we're doing a WHOIS for the current
nick. That's because if there's no server, there's no current nick.
Otherwise, as long as the Slack API token is configured, a server isn't
needed and shouldn't necessarily be required in order to request the
information.
|
|
Removes a level of indentation and looks cleaner.
|
|
Include a help document that can be accessed from inside Irssi showing a
description of the `swhois` command and some examples.
Leaned how to do this and format the output from:
- https://github.com/irssi/scripts.irssi.org/blob/master/scripts/trackbar.pl
- https://github.com/irssi/scripts.irssi.org/blob/22060fc4669627a9859c92efa2d6651e3673d494/scripts/spotify.pl
- https://github.com/irssi/irssi/blob/b1ffd5f6472584aa3966746da9728c5afefcc4ce/docs/help/in/rehash.in
- https://github.com/irssi/scripts.irssi.org/blob/22060fc4669627a9859c92efa2d6651e3673d494/scripts/clearable.pl
|
|
Include a short description, Slack API key configuration settings, usage
information, sample output, and license information.
|
|
|
|
No longer needed. Was using this for debugging purposes.
|
|
Include a short description, a note about needing a Slack API key, and
usage information.
|
|
Since we can't do anything in the script if the user hasn't configured
their Slack API token, die if it isn't set. Display a message to users
telling them to set their API token along with the URL where they can
obtain one.
Also don't print the "Fetching users list..." message until we check for
the Slack token because if we die then that message makes no sense.
|
|
Let users know that we're requesting the users list from Slack and that
it could take a while to get.
|
|
Underscores seem to be the convention in filenames so why not follow
that.
|
|
Use the current nick from `$server->{nick}` as the default argument to
`/swhois`.
Extracted the whois printing functionality to its own subroutine so that
it can be more easily executed whether or not an argument is passed to
the command.
|
|
This is to allow us to run `/swhois` without an argument to get
information about our current nick.
|
|
Since I couldn't install LWP on my Raspberry Pi, I'm switching to
HTTP::Tiny, which did install successfully.
|
|
Add a space before the colons so that it lines up with the colons of the
other fields.
|
|
In `find_user`, we check whether the Storable file is there (and
non-zero). If it isn't, we fetch the users list from the Slack API.
Renamed the subroutine containing the HTTP code to `fetch_users_list`
from `users_list` to better convey the fact that it has to reach out to
the web in order to get it.
Store the Storable object in the Irssi scripts directory (instead of our
local development directory as it was previously).
Use the correct Slack API URL in our HTTP request, and also include our
Slack API token from the Irssi settings.
Add better error handling and messaging when the API request fails for
whatever reason. Die on error so we don't end up executing the
`retrieve` line (otherwise this line will cause an error complaining
that the `users.list.plstore` file doesn't exist if it hasn't yet been
created).
If the API call succeeds and Slack gives us an 'ok' response, then
`store` the JSON-decoded users list array in our serialized cache file
and assign it to the `@users_list` global variable so we additionally
have it in memory..
|
|
Users can set this with `/set slack_profile_token`. It's required in
order to query the Slack API.
|
|
This break statement doesn't even get executed any more because we're
returning the user right above it.
|
|
|
|
Because this name is so much clearer. I had used data because that's
what's used in the Irssi command example.
|
|
Certain fields that we weren't checking against could be empty (title
and email). If that's the case, I don't think we should be printing a
line with a field label and empty value.
Add a new subroutine that prints the field if it's not blank. This
eliminates all the repetitive `if` statements.
|
|
|
|
Include full name, title, email, phone number, and skype name.
|
|
Wasn't sure whether I could make assignments in an if condition in Perl
so I had this line originally, but when I tried the other syntax it
worked, so I'm getting rid of this one.
|
|
This way we can actively store the users list in memory instead of
always unpickling it from Storage and the filesystem.
We'll need to work out exactly where this file should be stored, too.
Ideally that would be configurable.
|
|
Create a command that will retrieve 'whois' information about a given
user. This command takes a username argument and searches our users.list
database for a match. It then prints out a field from the user hash.
We'll want to print out more information in a more structured display,
but this is just for testing within Irssi.
The server conditional check is commented out so I can test this without
connecting to a server.
Running `/swhois` without an argument should print whois information for
the current user/nick. Will have to look up how to get that information.
|
|
Put this in a subroutine called `find_user` that takes a username as
input. This username will be searched for in the list and the
corresponding user hash will be returned if found.
|
|
|
|
In my very unscientific performance "benchmarks", there appeared to be
no significant difference between binary search and linear search. In
light of that, I've decided to go with linear search instead to reduce
complexity in the code and also account for the fact that Slack makes
the claim that the `users.list` is returned "in no particular order"
(https://api.slack.com/methods/users.list).
My "benchmarks", run on a late 2012 Core i5 MacBook Air:
Binary Search (JSON decode):
$ time perl slack-profile.pl
real 0m2.039s
user 0m2.019s
sys 0m0.017s
$ time perl slack-profile.pl
real 0m1.981s
user 0m1.961s
sys 0m0.017s
$ time perl slack-profile.pl
real 0m2.065s
user 0m2.045s
sys 0m0.016s
$ time perl slack-profile.pl
real 0m2.039s
user 0m2.017s
sys 0m0.018s
$ time perl slack-profile.pl
real 0m1.997s
user 0m1.978s
sys 0m0.017s
Binary Search (Storable):
$ time perl slack-profile.pl
real 0m0.118s
user 0m0.102s
sys 0m0.013s
$ time perl slack-profile.pl
real 0m0.117s
user 0m0.100s
sys 0m0.014s
$ time perl slack-profile.pl
real 0m0.123s
user 0m0.105s
sys 0m0.016s
$ time perl slack-profile.pl
real 0m0.123s
user 0m0.107s
sys 0m0.014s
$ time perl slack-profile.pl
real 0m0.127s
user 0m0.109s
sys 0m0.016s
$ time perl slack-profile.pl
real 0m0.125s
user 0m0.108s
sys 0m0.015s
Linear Search (JSON decode):
$ time perl slack-profile.pl
real 0m2.017s
user 0m1.998s
sys 0m0.015s
$ time perl slack-profile.pl
real 0m2.025s
user 0m2.005s
sys 0m0.016s
$ time perl slack-profile.pl
real 0m2.011s
user 0m1.992s
sys 0m0.016s
$ time perl slack-profile.pl
real 0m2.064s
user 0m2.044s
sys 0m0.017s
$ time perl slack-profile.pl
real 0m2.166s
user 0m2.147s
sys 0m0.016s
Linear Search (Storable):
$ time perl slack-profile.pl
real 0m0.120s
user 0m0.103s
sys 0m0.014s
$ time perl slack-profile.pl
real 0m0.125s
user 0m0.107s
sys 0m0.015s
$ time perl slack-profile.pl
real 0m0.129s
user 0m0.110s
sys 0m0.016s
$ time perl slack-profile.pl
real 0m0.121s
user 0m0.106s
sys 0m0.013s
$ time perl slack-profile.pl
real 0m0.118s
user 0m0.101s
sys 0m0.014s
|
|
This is _much_ faster than decoding the JSON string. The difference is
between ~2 seconds and ~0.120 milliseconds.
Also messed around with rough testing the performance of binary search
vs. linear search again.
|
|
Create a `binary_search` subroutine that will allow us to search through
an array.
Used Wikipedia and Rosetta Code as a reference:
- https://en.wikipedia.org/wiki/Binary_search_algorithm#Algorithm
- http://rosettacode.org/wiki/Binary_search#Perl
In order to test matches, `binary_search` expects an anonymous function
that will return 0, 1, or -1 depending on the result of the comparison.
The anonymous function we use compares usernames alphabetically to the
one we want to find.
Finally, we have a section commented out that performs a linear search
for a user in the members array. We will time this and the binary search
version to see how they compare. Slack attests that the `users.list` API
method provides users "in no particular order"
(https://api.slack.com/methods/users.list), however most users appear to
be ordered by username. The one exception appears to be 'slackbot', who
appears at the end of the list.
|
|
We have the output from the Slack API's `users.list` method stored in a
file. Read that file and decode the JSON into Perl scalars so that we
can filter the list for a specific user.
|
|
File this code away into its own container so we can work on some JSON
decoding.
|
|
Figured out how to make an HTTPS request in Perl. We'll need this
structure in order to interact with the Slack Web API.
|