From 8932097e37020128662a0d11dbde5e64a5387889 Mon Sep 17 00:00:00 2001 From: "yakumo.izuru" Date: Wed, 21 Feb 2024 20:30:32 +0000 Subject: [PATCH] Try loading avatar from avatar.png, enhance message body triggers, block music.youtube.com Signed-off-by: Izuru Yakumo git-svn-id: file:///srv/svn/repo/chen/trunk@29 32723744-9b23-0b4a-b1da-9b2e968f9461 --- README | 15 +++++++++++++++ README.org | 19 ------------------- main.py | 38 ++++++++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 README delete mode 100644 README.org diff --git a/README b/README new file mode 100644 index 0000000..d2c76e0 --- /dev/null +++ b/README @@ -0,0 +1,15 @@ +chen +==== + +XMPP bot to preview links and file contents. Shikigami of the Shikigami of the Gap Youkai +Based on Angel[1], without the sed(1) and YT redirect features. + +Run +--- + +* pip3 install --user -r requirements.txt +* $EDITOR config.ini.default (save as config.ini) +* python3 main.py + + +[1]: https://wiki.kalli.st/Angel diff --git a/README.org b/README.org deleted file mode 100644 index d3a6ef2..0000000 --- a/README.org +++ /dev/null @@ -1,19 +0,0 @@ -#+TITLE: Chen XMPP bot -#+AUTHOR: Izuru Yakumo - -XMPP bot to preview links and file contents. Shikigami of the Shikigami of the Gap Youkai - -* Configuration - copy the =config.ini.default= to =.config.ini= and set your variables accordly - -* Running - install the dependencies from =requirements.txt= - #+BEGIN_QUOTE - $ pip install -r requirements.txt - #+END_QUOTE - and run it with =python3.8+= - #+BEGIN_QUOTE - $ python main.py - or - $ dtach -n /tmp/chen.sock python3 main.py - #+END_QUOTE diff --git a/main.py b/main.py index c730536..8617ae2 100644 --- a/main.py +++ b/main.py @@ -32,7 +32,9 @@ block_list = ( "www.youtube.com", "youtube.com", "m.youtube.com", + "music.youtube.com", ) +# FIXME: Gopher support when? req_list = ( "http://", "https://", @@ -56,7 +58,7 @@ class Lifo(list): if len(self) > self.size: self.pop() - +# Cheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeen class ChenBot(ClientXMPP): messages = defaultdict( lambda: { @@ -138,18 +140,12 @@ class ChenBot(ClientXMPP): message.send() async def parse_urls(self, msg, urls, sender, mtype): - if "nsfw" in msg["body"].lower(): - return - if "#nospoil" in msg["body"].lower(): - return - if "discord.com" in msg["body"].lower(): - msg.reply("Ew, discord! :<\n").send() - if "discord.gg" in msg["body"].lower(): - msg.reply("Do you really want to invite someone to Hell? [meow in disarray]\n").send() - if "cdn.discordapp.com" in msg["body"].lower(): - msg.reply("Use a proper media host nya\n").send() - if "!repo" in msg["body"].lower(): - msg.reply("https://git.chaotic.ninja/yakumo.izuru/chen\n").send() + body = msg["body"].lower() + if "nsfl" in body: return + if "nsfw" in body: return + if "#nospoil" in body: return + if "!repo" in body: + msg.reply("https://git.chaotic.ninja/usr/yakumo_izuru/chen\n").send() for u in urls: if u in self.messages[sender]["links"]: continue @@ -189,8 +185,22 @@ class ChenBot(ClientXMPP): ... async def update_info(self): + with open("avatar.png", "rb") as avatar_file: + avatar = avatar_file.read() + + avatar_type = "image/png" + avatar_id = self.plugin["xep_0084"].generate_id(avatar) + avatar_bytes = len(avatar) + + asyncio.gather(self.plugin["xep_0084"].publish_avatar(avatar)) + asyncio.gather(self.plugin["xep_0153"].set_avatar(avatar=avatar, mtype=avatar_type)) + info = { + "id": avatar_id, + "type": avatar_type, + "bytes": avatar_bytes, + } vcard = self.plugin["xep_0054"].make_vcard() - vcard["URL"] = "https://git.chaotic.ninja/yakumo.izuru/chen" + vcard["URL"] = "git://git.chaotic.ninja/yakumo_izuru/chen" vcard["DESC"] = "Shikigami of the Shikigami of the Gap Youkai" vcard["NICKNAME"] = "Chen" vcard["FN"] = "Chen"