From 18fea2501c8d28c2a8318fcff8540f52e29155e0 Mon Sep 17 00:00:00 2001 From: Ville Ranki Date: Sat, 28 Mar 2020 22:04:15 +0200 Subject: [PATCH] Allow setting message type in \!url --- README.md | 7 ++++++- modules/url.py | 27 +++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 988c189..0c0f972 100644 --- a/README.md +++ b/README.md @@ -171,10 +171,13 @@ See: https://github.com/taspinar/twitterscraper/tree/master/twitterscraper #### Url Watches all messages in a room and if a url is found tries to fetch it and -spit out the title if found. +spit out the title if found. Defaults to off and needs to be activated on every room you want this. +You can choose to send titles as notices (as in Matrix spec) or normal +messages (IRC users might prefer this). This is a global setting currently. + Commands: * !url status - show current status @@ -182,6 +185,8 @@ Commands: * !url description - spam descriptions * !url both - spam both title and description * !url off - stop spamming +* !url text - send titles as normal text (must be owner) +* !url notice - sends titles as notices (must be owner) Example: diff --git a/modules/url.py b/modules/url.py index 4e4238e..f094a04 100644 --- a/modules/url.py +++ b/modules/url.py @@ -21,6 +21,7 @@ class MatrixModule(BotModule): self.bot = None self.status = dict() # room_id -> what to do with urls + self.type = "m.notice" # notice or text self.STATUSES = { "OFF": "Not spamming this channel", @@ -87,7 +88,7 @@ class MatrixModule(BotModule): msg = f"Description: {description}" if msg is not None: - await self.bot.send_text(room, msg) + await self.bot.send_text(room, msg, self.type) @lru_cache(maxsize=128) def get_content_from_url(self, url): @@ -150,10 +151,30 @@ class MatrixModule(BotModule): ) return + # set type to notice + elif len(args) == 1 and args[0] == "notice": + bot.must_be_owner(event) + self.type = "m.notice" + bot.save_settings() + await bot.send_text( + room, "Sending titles as notices from now on." + ) + return + + # show status + elif len(args) == 1 and args[0] == "text": + bot.must_be_owner(event) + self.type = "m.text" + bot.save_settings() + await bot.send_text( + room, "Sending titles as text from now on." + ) + return + # invalid command await bot.send_text( room, - "Sorry, I did not understand. I only understand 'title', 'description', 'both' and 'status' commands", + "Sorry, I did not understand. See README for command list.", ) return @@ -167,6 +188,8 @@ class MatrixModule(BotModule): super().set_settings(data) if data.get("status"): self.status = data["status"] + if data.get("type"): + self.type = data["type"] def help(self): return "If I see a url in a message I will try to get the title from the page and spit it out"