Bachir Soussi Chiadmi 7 years ago
parent
commit
7d1dbf7424
1 changed files with 30 additions and 27 deletions
  1. 30 27
      cedbot_muc.py

+ 30 - 27
cedbot_muc.py

@@ -84,6 +84,25 @@ class MUCBot(sleekxmpp.ClientXMPP):
                                         # password=the_room_password,
                                         wait=True)
 
+
+
+    def send_msg(self, msg, body):
+        self.send_message(mto=msg['from'].bare,
+                          mbody=body,
+                          mtype='groupchat')
+
+    # def beep(hz):
+    #     # TODO: make convesdis beeping
+    #
+    # def speak():
+    #     # TODO: make convesdis speaking
+    #
+    def learn(question, user):
+        # TODO: record unanswerable questions with user from and ask me
+        print('unanswered question "%s" by %s' % (question, user))
+
+
+
     def muc_message(self, msg):
         """
         Process incoming message stanzas from any chat room. Be aware
@@ -108,21 +127,21 @@ class MUCBot(sleekxmpp.ClientXMPP):
         """
         if msg['mucnick'] != self.nick:
             if self.nick in msg['body']:
-                send_msg(msg=":), %s." % msg['mucnick'])
+                send_msg(self, msg, ":), %s." % msg['mucnick'])
 
                 if '?' in msg['body']:
                     if 'who are you' in msg['body']:
-                        send_msg(msg="I am the chatbot from De La Convivialité des Espaces Discrets")
-                        send_msg(msg="check this http://convivialite-espaces-discrets.net ;)")
+                        send_msg(self, msg, "I am the chatbot from De La Convivialité des Espaces Discrets")
+                        send_msg(self, msg, "check this http://convivialite-espaces-discrets.net ;)")
                     else:
-                        send_msg(msg="humm ...")
-                        send_msg(msg="it seems that you asked me a question")
-                        send_msg(msg="but i'm not able to understand it ... yet :/")
-                        send_msg(msg="I'm just a bot after all")
-                        send_msg(msg="but I'll try to learn how to answer you")
-                        send_msg(msg="please come back later")
-                        send_msg(msg="i'll tell you when i'm ready :)")
-                        learn(question=msg['body'], user=msg['mucnick'])
+                        send_msg(self, msg, "humm ...")
+                        send_msg(self, msg, "it seems that you asked me a question")
+                        send_msg(self, msg, "but i'm not able to understand it ... yet :/")
+                        send_msg(self, msg, "I'm just a bot after all")
+                        send_msg(self, msg, "but I'll try to learn how to answer you")
+                        send_msg(self, msg, "please come back later")
+                        send_msg(self, msg, "i'll tell you when i'm ready :)")
+                        learn(msg['body'], msg['mucnick'])
 
     def muc_online(self, presence):
         """
@@ -140,22 +159,6 @@ class MUCBot(sleekxmpp.ClientXMPP):
             send_msg(msg="Hello, %s %s" % (presence['muc']['role'],presence['muc']['nick']))
 
 
-    def send_msg(msg):
-        self.send_message(mto=msg['from'].bare,
-                          mbody=msg,
-                          mtype='groupchat')
-
-    # def beep(hz):
-    #     # TODO: make convesdis beeping
-    #
-    # def speak():
-    #     # TODO: make convesdis speaking
-    #
-    def learn(question, user):
-        # TODO: record unanswerable questions with user from and ask me
-        print('unanswered question "%s" by %s' % (question, user)) 
-
-
 if __name__ == '__main__':
     # Setup the command line arguments.
     optp = OptionParser()