Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

restructure skype start and comment oddities

  • Loading branch information...
commit bc3f2cb0c82839822598d6fa4f016598ff7eab35 1 parent a91b5a7
pat brisbin authored
Showing with 30 additions and 17 deletions.
  1. +30 −17 lib/basil/skype.rb
47 lib/basil/skype.rb
View
@@ -3,22 +3,40 @@
module Basil
class Skype < Server
def start
- # for some reason, using the nested block approach seems to make
- # things quicker and more consistent
+ # Note: there are a number of oddities in how the dbus connection
+ # behaves. Also, if you break this code by violating the below,
+ # you won't get an exception, basil just stops listening.
+ #
+ # Therefore, if you touch this method, keep in mind the following:
+ #
+ # 1. You must use nested blocks when you need to access multiple
+ # parts of a skype object.
+ #
+ # 2. The order of your nesting seems to matter. Though I've yet to
+ # determine how or why.
+ #
+ # 3. Sometimes, it's required you use the block argument
+ # immediately.
+ #
+ # 4. Sometimes, it's required you don't pass the block argument to
+ # any external methods.
+ #
Rype.on(:chatmessage_received) do |chatmessage|
- chatmessage.chat do |chat|
- chat.members do |members|
- is_private = members.length == 2
-
- chatmessage.from do |from|
- chatmessage.from_name do |from_name|
- chatmessage.body do |body|
- to, text = parse_body(body)
+ chatmessage.from do |from|
+ chatmessage.from_name do |from_name|
+ chatmessage.body do |body|
+ chatmessage.chat do |chat|
+ chat.members do |members|
+ is_private = members.length == 2
+ to, text = parse_body(body)
to = Config.me if !to && is_private
msg = Message.new(to, from, from_name, text, chat.chatname)
- send_message(chat, reply) if reply = dispatch_message(msg)
+ if reply = dispatch_message(msg)
+ prefix = reply.to ? "#{reply.to.split(' ').first}, " : ''
+ chat.send_message(prefix + reply.text)
+ end
end
end
end
@@ -34,7 +52,7 @@ def broadcast_message(msg)
chats.each do |chat|
chat.topic do |topic|
if [topic, chat.chatname].include?(msg.chat)
- send_message(chat, msg)
+ chat.send_message(msg.text)
end
end
end
@@ -43,11 +61,6 @@ def broadcast_message(msg)
private
- def send_message(chat, msg)
- prefix = msg.to ? "#{msg.to.split(' ').first}, " : ''
- chat.send_message(prefix + msg.text)
- end
-
def parse_body(body)
case body
when /^! *(.*)/ ; [Config.me, $1]
Please sign in to comment.
Something went wrong with that request. Please try again.