Commits

Shinya Okano committed ca2ddc5

botのハンドラからskypeオブジェクトにアクセスできるようにした

  • Participants
  • Parent commits c5351e7

Comments (0)

Files changed (2)

File skypehub/handlers.py

 from skypehub.models import Message
 
-def message_logging_receiver(message, status):
+def message_logging_receiver(handler, message, status):
     Message.objects.create(
         body=message.Body,
         sender=message.Sender.Handle,
     default_statuses = ('RECEIVED',)
     default_receivers = ()
 
-    def __init__(self):
+    def __init__(self, skype=None):
         self.receivers = list(self.default_receivers)
+        self.skype = skype
 
     def connect(self, receiver, statuses=None):
         if statuses is None:
     def dispatch(self, message, status):
         for statuses, receiver in self.receivers:
             if status in statuses:
-                receiver(message, status)
+                receiver(self, message, status)
 
 on_message = OnMessageHandler()
 on_message.connect(message_logging_receiver)

File skypehub/management/commands/runskypebot.py

             import_module("%s.skypebot" % app)
 
         # attach skype
+        on_message.skype = skype
         skype.OnMessageStatus = on_message.dispatch
 
         skype.Attach()