Created
October 5, 2011 20:29
-
-
Save tal/1265605 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Skype | |
| extend self | |
| GROUPS = { | |
| :city => '#bennygilt/$f5558ce446c1793f', | |
| :city_announcements => '#swimming_bird/$877f4e5a36f23a8d' | |
| } | |
| def invoke cmd, name | |
| oas = ['osascript'] | |
| oas << %q{-e 'tell application "Skype"'} | |
| oas << %Q{-e 'send command "#{cmd}" script name "#{name}"'} | |
| oas << %q{-e 'end tell'} | |
| `#{oas.join(' ')}` | |
| end | |
| def running? | |
| `ps aux | grep 'Skype.app'`.chomp.split("\n").size > 2 | |
| end | |
| def missed_chats | |
| chats = invoke "SEARCH MISSEDCHATS", 'missed chats' | |
| chats.sub(/^CHATS\s+/,'').split(' ').collect {|id| Chat.new(id)} | |
| end | |
| def message_city msg | |
| Chat.city.send_message msg | |
| end | |
| def message_city_annoucements msg | |
| Chat.city_announcements.send_message msg | |
| end | |
| class Chat | |
| def initialize(id) | |
| @id = id | |
| end | |
| def hash | |
| @id.split(';')[1] | |
| end | |
| def from | |
| m = @id.match(/\#(.+?)\//) | |
| m[1] if m | |
| end | |
| def to | |
| m = @id.match(/\#(.+?)\/\$(.+?);/) | |
| m[2] if m | |
| end | |
| def send_message msg | |
| Skype.invoke %Q{CHATMESSAGE #{@id} #{msg}}, 'send chat' | |
| end | |
| def inspect | |
| %Q{#<#{self.class} id=#{@id.inspect}>} | |
| end | |
| class << self | |
| GROUPS.each do |name,id| | |
| define_method name do | |
| new(id) | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment