Commit 439d511

mo <mo.khan@gmail.com>
2018-05-19 17:20:40
add methods to change status.
1 parent 2a03aaa
Changed files (2)
lib/del/robot.rb
@@ -37,6 +37,17 @@ module Del
       end
     end
 
+    {
+      away!: :away,
+      do_not_disturb!: :dnd,
+      offline!: :xa,
+      online!: :chat
+    }.each do |name, value|
+      define_method name do
+        xmpp_connection.update_status(value)
+      end
+    end
+
     private
 
     attr_reader :configuration
lib/del/xmpp_connection.rb
@@ -15,7 +15,7 @@ module Del
       connect_to_xmpp_server
       roster = discover_users
       listen_for_direct_messages(robot)
-      update_status
+      update_status(:chat)
       discover_rooms(robot, roster)
     end
 
@@ -36,6 +36,11 @@ module Del
       Del.logger.error(error)
     end
 
+    # :chat, :away, :dnd, :xa
+    def update_status(show = :chat, message: nil)
+      client.send(Jabber::Presence.new(show, message))
+    end
+
     private
 
     def client
@@ -91,10 +96,6 @@ module Del
       end
     end
 
-    def update_status(status = :chat)
-      client.send(Jabber::Presence.new(status))
-    end
-
     def discover_rooms(robot, roster)
       configuration.default_rooms.each do |room|
         room_jid = jid_for(room, configuration.muc_domain.dup, robot.name)