Просмотр исходного кода

bin/ircd/script: send cap command from meeting bot on starting

ghassmo 4 лет назад
Родитель
Сommit
47ee7d7e5b
1 измененных файлов с 20 добавлено и 6 удалено
  1. 20 6
      bin/ircd/script/meeting_bot.py

+ 20 - 6
bin/ircd/script/meeting_bot.py

@@ -5,25 +5,36 @@ async def start():
     host = "127.0.0.1"
     port = 11066
     channel = "#dev"
-    nickname = "meeting"
+    nickname = "meeting_bot"
 
     print(f"Start a connection {host}:{port}")
     reader, writer = await asyncio.open_connection(host, port)
 
+    print("Send CAP msg")
+    cap_msg = f"CAP REQ : no-history \r\n"
+    writer.write(cap_msg.encode('utf8'))
+
     print("Send NICK msg")
     nick_msg = f"NICK {nickname} \r\n"
     writer.write(nick_msg.encode('utf8'))
 
+    print("Send CAP END msg")
+    cap_end_msg = f"CAP END \r\n"
+    writer.write(cap_end_msg.encode('utf8'))
+
     print(f"Send JOIN msg: {channel}")
     join_msg = f"JOIN {channel} \r\n"
     writer.write(join_msg.encode('utf8'))
 
     topics = []
 
+    print("Start...")
     while True:
-        msg = await reader.read(350)
+        msg = await reader.read(1024)
         msg = msg.decode('utf8').strip()
 
+        print(msg)
+
         if not msg:
             print("Error: Receive empty msg")
             break
@@ -56,16 +67,19 @@ async def start():
                 reply = f"PRIVMSG {channel} :add topic: {topic} \r\n"
 
             if msg_title == "#m_list":
-                tp = " ".join(
-                    [f"{i}-{topic}" for i, topic in enumerate(topics, 1)])
+                rep = f"PRIVMSG {channel} :topics: \r\n"
+                writer.write(rep.encode('utf8'))
 
-                reply = f"PRIVMSG {channel} :topics: {tp} \r\n"
+                for i, topic in enumerate(topics, 1):
+                    rep = f"PRIVMSG {channel} :{i}-{topic} \r\n"
+                    writer.write(rep.encode('utf8'))
+                await writer.drain()
 
             if msg_title == "#m_next":
                 if len(topics) == 0:
                     reply = f"PRIVMSG {channel} :no topics \r\n"
                 else:
-                    tp = topics.pop(0) 
+                    tp = topics.pop(0)
                     reply = f"PRIVMSG {channel} :current topic: {tp} \r\n"
 
             if reply != None: