Explorar o código

darkirc/meetbot: Implement topic deletion

parazyd %!s(int64=3) %!d(string=hai) anos
pai
achega
ba40de60b2
Modificáronse 1 ficheiros con 27 adicións e 0 borrados
  1. 27 0
      bin/darkirc/script/bots/meetbot/meetbot.py

+ 27 - 0
bin/darkirc/script/bots/meetbot/meetbot.py

@@ -144,6 +144,33 @@ async def channel_listen(host, port, nick, chan):
                     await writer.drain()
                     continue
 
+                if msg_title == "!deltopic":
+                    logging.info("%s: Got !deltopic", chan)
+                    topics = CHANS[chan]["topics"]
+                    if len(topics) == 0:
+                        reply = f"PRIVMSG {chan} :No topics"
+                        logging.info("%s: Send: %s", chan reply)
+                        writer.write((reply + "\r\n").encode("utf-8"))
+                        await writer.drain()
+                        continue
+
+                    try:
+                        topic = msg.split(" ", 4)
+                        topic = int(topic[4].rstrip())
+                        del topics[topic-1]
+                        CHANS[chan]["topics"] = topics
+                        reply = f"PRIVMSG {chan} :Removed topic {topic}"
+                        logging.info("%s: Send: %s", chan reply)
+                        writer.write((reply + "\r\n").encode("utf-8"))
+                        await writer.drain()
+                    except:
+                        reply = f"PRIVMSG {chan} :Topic not found"
+                        logging.info("%s: Send: %s", chan reply)
+                        writer.write((reply + "\r\n").encode("utf-8"))
+                        await writer.drain()
+
+                    continue
+
                 if msg_title == "!list":
                     logging.info("%s: Got !list", chan)
                     topics = CHANS[chan]["topics"]