diff options
| author | Teddy Wing | 2016-09-17 04:59:15 -0400 |
|---|---|---|
| committer | Teddy Wing | 2016-09-17 04:59:15 -0400 |
| commit | 28e3fda0889d3e77efa3522422324bf7bc0dd548 (patch) | |
| tree | 689f491391bd847a154424c358935c4fe3cff6fc | |
| parent | fec6b41579b88a8d2f23bab236d3c1e2e2d60e19 (diff) | |
| download | irssi-slack-profile-28e3fda0889d3e77efa3522422324bf7bc0dd548.tar.bz2 | |
Add `/slack_profile_set` command
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.
| -rw-r--r-- | slack_profile.pl | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/slack_profile.pl b/slack_profile.pl index 0163cce..9a37429 100644 --- a/slack_profile.pl +++ b/slack_profile.pl @@ -197,6 +197,13 @@ sub update_user_profile { }); } +sub cmd_set { + my ($data, $server, $window_item) = @_; + my ($key, $value) = split /\s+/, $data, 2; + + update_user_profile($key, $value); +} + sub find_user { my ($username) = @_; @@ -280,8 +287,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'); |
