msparks / irssiscripts
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
irssiscripts / rtm.pl
| 54f77d3f » | msparks | 2009-01-22 | 1 | # rtm.pl - add new tasks to rememberthemilk.com | |
| 2 | # | ||||
| 3 | # Install: | ||||
| 4 | # 1) /script load rtm | ||||
| 5 | # 2) /set rtm_email <your remember the milk email address> | ||||
| 6 | # 3) /save | ||||
| 7 | # | ||||
| 8 | # Usage: | ||||
| 9 | # /rtm <task> <options> | ||||
| 10 | # | ||||
| 11 | # where: | ||||
| 12 | # <task> task name, e.g. "do laundry" | ||||
| 13 | # <options> a string formatted like: [D: tomorrow E: 3 hours] | ||||
| 14 | # | ||||
| 15 | # possible options (case insensitive): | ||||
| 16 | # D: due | ||||
| 17 | # E: time estimate | ||||
| 18 | # L: list | ||||
| 19 | # O: location | ||||
| 20 | # P: priority | ||||
| 21 | # R: repeat | ||||
| 22 | # S: tags (comma separated) | ||||
| 23 | # U: url | ||||
| 24 | # | ||||
| 25 | # Examples: | ||||
| 26 | # Do the dishes for an hour, priority 2. | ||||
| 27 | # /rtm do dishes [E: 1 hour P: 2] | ||||
| 28 | # | ||||
| 29 | # Do homework, due tomorrow. | ||||
| 30 | # /rtm homework [D: tomorrow] | ||||
| 31 | # | ||||
| 32 | # See also: | ||||
| 33 | # http://www.rememberthemilk.com/help/answers/sending/emailinbox.rtm | ||||
| 34 | use strict; | ||||
| 35 | use Irssi; | ||||
| 36 | |||||
| 37 | use vars qw($VERSION %IRSSI); | ||||
| 38 | |||||
| 39 | $VERSION = '1.0'; | ||||
| 40 | %IRSSI = ( | ||||
| 41 | authors => 'Matt "f0rked" Sparks', | ||||
| 42 | contact => 'ms+irssi@quadpoint.org', | ||||
| 43 | name => 'rtm', | ||||
| 44 | description => 'Add new tasks to rememberthemilk.com', | ||||
| 45 | license => 'BSD', | ||||
| 46 | url => 'http://quadpoint.org', | ||||
| 47 | changed => '2007-09-08', | ||||
| 48 | ); | ||||
| 49 | |||||
| 50 | |||||
| 51 | sub rtm_print | ||||
| 52 | { | ||||
| 53 | my($text) = @_; | ||||
| 54 | my $window = Irssi::active_win(); | ||||
| 55 | my $b = chr(2); | ||||
| 56 | $window->print("[${b}rtm${b}] $text", MSGLEVEL_CRAP); | ||||
| 57 | } | ||||
| 58 | |||||
| 59 | |||||
| 60 | sub add_task | ||||
| 61 | { | ||||
| 62 | my($email, $text, $options_str) = @_; | ||||
| 63 | my %opt_list = (priority => "p", | ||||
| 64 | due => "d", | ||||
| 65 | repeat => "r", | ||||
| 66 | estimate => "e", | ||||
| 67 | tags => "s", | ||||
| 68 | location => "o", | ||||
| 69 | url => "u", | ||||
| 70 | list => "l"); | ||||
| 71 | |||||
| 72 | # parse out options | ||||
| 73 | my %options; | ||||
| 74 | |||||
| 75 | my $key = ""; | ||||
| 76 | for my $word (split / /, $options_str) { | ||||
| 77 | if ($word =~ /:$/) { | ||||
| 78 | $word =~ s/:$//; | ||||
| 79 | if (grep /^\Q$word\E$/i, keys(%opt_list)) { | ||||
| 80 | $key = $opt_list{$word}; | ||||
| 81 | } elsif (grep /^\Q$word\E$/i, values(%opt_list)) { | ||||
| 82 | $key = $word; | ||||
| 83 | } | ||||
| 84 | next; | ||||
| 85 | } | ||||
| 86 | $options{$key} .= "$word " if $key ne ""; | ||||
| 87 | } | ||||
| 88 | |||||
| 89 | open SM, qq(| mail -s "$text" $email); | ||||
| 90 | for my $key (keys %options) { | ||||
| 91 | printf SM "%s: %s\n", $key, substr($options{$key}, 0, -1); | ||||
| 92 | } | ||||
| 3d7c1736 » | msparks | 2009-06-27 | 93 | print SM "\n\n"; | |
| 54f77d3f » | msparks | 2009-01-22 | 94 | close SM; | |
| 95 | } | ||||
| 96 | |||||
| 97 | |||||
| 98 | sub cmd_rtm | ||||
| 99 | { | ||||
| 100 | my($data, $server, $witem) = @_; | ||||
| 101 | my $email_addr = Irssi::settings_get_str("rtm_email"); | ||||
| 102 | if (!$email_addr) { | ||||
| 103 | rtm_print("your rememberthemilk.com email address is not set. ". | ||||
| 104 | "Use /set rtm_email <email address> to set it. Don't forget ". | ||||
| 105 | "to /save."); | ||||
| 106 | return; | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | # task options are specified in [ ] at the end of the data | ||||
| 110 | my($options) = $data =~ / \[\s*(.+?)\s*\]\s*$/; | ||||
| 111 | $data =~ s/ \[(.+?)\]\s*$//; | ||||
| 112 | $data =~ s/^\s*(.+?)\s*$/$1/; | ||||
| 113 | |||||
| 114 | add_task($email_addr, $data, $options); | ||||
| 115 | |||||
| 116 | if ($options) { | ||||
| 117 | rtm_print("$data [$options]"); | ||||
| 118 | } else { | ||||
| 119 | rtm_print($data); | ||||
| 120 | } | ||||
| 121 | } | ||||
| 122 | |||||
| 123 | |||||
| 124 | Irssi::command_bind("rtm", "cmd_rtm"); | ||||
| 125 | Irssi::settings_add_str("rtm", "rtm_email", ""); | ||||
