Explorar el Código

ircd/meetbot: Write elapsed time after topics.

parazyd hace 3 años
padre
commit
567dde40e0
Se han modificado 1 ficheros con 16 adiciones y 0 borrados
  1. 16 0
      bin/ircd/script/bots/meetbot/meetbot.py

+ 16 - 0
bin/ircd/script/bots/meetbot/meetbot.py

@@ -2,6 +2,7 @@
 import asyncio
 import asyncio
 import logging
 import logging
 import pickle
 import pickle
+from time import time
 
 
 from base58 import b58decode
 from base58 import b58decode
 from nacl.public import PrivateKey, Box
 from nacl.public import PrivateKey, Box
@@ -42,6 +43,8 @@ async def channel_listen(host, port, nick, chan):
         writer.write(msg.encode("utf-8"))
         writer.write(msg.encode("utf-8"))
         await writer.drain()
         await writer.drain()
 
 
+        elapsed=0
+
         logging.info("%s: Listening to channel", chan)
         logging.info("%s: Listening to channel", chan)
         while True:
         while True:
             msg = await reader.readline()
             msg = await reader.readline()
@@ -91,10 +94,16 @@ async def channel_listen(host, port, nick, chan):
                     CHANS[chan]["topics"] = topics
                     CHANS[chan]["topics"] = topics
                     writer.write(reply.encode("utf-8"))
                     writer.write(reply.encode("utf-8"))
                     await writer.drain()
                     await writer.drain()
+                    elapsed=time()
                     continue
                     continue
 
 
                 if msg_title == "!end":
                 if msg_title == "!end":
                     logging.info("%s: Got !end", chan)
                     logging.info("%s: Got !end", chan)
+                    reply = f"PRIVMSG {chan} :Elapsed time: {round((time() - elapsed)/60, 1)} min"
+                    elapsed=0
+                    logging.info("%s: Send: %s", chan, reply)
+                    writer.write((reply + "\r\n").encode("utf-8"))
+                    await writer.drain()
                     reply = f"PRIVMSG {chan} :Meeting ended"
                     reply = f"PRIVMSG {chan} :Meeting ended"
                     logging.info("%s: Send: %s", chan, reply)
                     logging.info("%s: Send: %s", chan, reply)
                     writer.write((reply + "\r\n").encode("utf-8"))
                     writer.write((reply + "\r\n").encode("utf-8"))
@@ -158,6 +167,13 @@ async def channel_listen(host, port, nick, chan):
                 if msg_title == "!next":
                 if msg_title == "!next":
                     logging.info("%s: Got !next", chan)
                     logging.info("%s: Got !next", chan)
                     topics = CHANS[chan]["topics"]
                     topics = CHANS[chan]["topics"]
+
+                    reply = f"PRIVMSG {chan} :Elapsed time: {round((time() - elapsed)/60, 1)} min"
+                    logging.info("%s: Send: %s", chan, reply)
+                    writer.write((reply + "\r\n").encode("utf-8"))
+                    await writer.drain()
+                    elapsed=time()
+
                     if len(topics) == 0:
                     if len(topics) == 0:
                         reply = f"PRIVMSG {chan} :No further topics"
                         reply = f"PRIVMSG {chan} :No further topics"
                     else:
                     else: