From 5168564002ed0b9adfebb7d480487a531d3d06d7 Mon Sep 17 00:00:00 2001 From: "koizumi.aoi" Date: Mon, 20 Feb 2023 01:11:10 +0000 Subject: [PATCH] feat: remove sed because I don't need it and the big thing: nick ain't hardcoded anymore, it's now configurable! git-svn-id: file:///srv/svn/repo/chen/trunk@17 32723744-9b23-0b4a-b1da-9b2e968f9461 --- config.ini.default | 3 ++- main.py | 47 +++++++++++----------------------------------- requirements.txt | 1 - 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/config.ini.default b/config.ini.default index baa8690..c8348a8 100644 --- a/config.ini.default +++ b/config.ini.default @@ -1,4 +1,5 @@ [chen] jid = chen@example.com password = b0TPA55W0rD -autojoin = room1@muc.example.com room2@muc.example.com room3@muc.example.com \ No newline at end of file +nick = Chen +autojoin = room1@muc.example.com room2@muc.example.com room3@muc.example.com diff --git a/main.py b/main.py index 3749f32..1fbb06f 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,6 @@ import os import mimetypes import asyncio from collections import defaultdict -from PythonSed import Sed from slixmpp import ClientXMPP from urllib.parse import urlparse, parse_qs, urlunparse from pantomime import normalize_mimetype @@ -29,7 +28,13 @@ headers = { "Cache-Control": "no-cache", } -block_list = ("localhost", "127.0.0.1", "0.0.0.0") +block_list = ( + "localhost", + "127.0.0.1", + "0.0.0.0", + "youtu.be", + "www.youtube.com", +) req_list = ("http://", "https://") html_files = ("text/html", "application/xhtml+xml") @@ -141,39 +146,10 @@ class ChenBot(ClientXMPP): uri = urlparse(u) await self.parse_uri(uri, sender, mtype) - def sed_command(self, msg, sender, mtype): - try: - text = msg["body"] - if not sed_cmd.match(text): - self.messages[sender]["messages"].add(text) - return - sed_args = sed_parse.split(text) - - if len(sed_args) < 4: - return - - sed = Sed() - sed.load_string(text) - - for message in self.messages[sender]["messages"]: - if sed_args[1] not in message: - continue - msg = io.StringIO(message) - res = "\n".join(sed.apply(msg, None)) - self.messages[sender]["messages"].add(res) - return self.send_message( - mto=sender, - mbody=res, - mtype=mtype, - ) - - except Exception: - return - - def __init__(self, jid, password, nick="Chen", autojoin=None): + def __init__(self, jid, password, nick, autojoin=None): ClientXMPP.__init__(self, jid, password) self.jid = jid - self.nick = nick + self.nick = nick or [] self.autojoin = autojoin or [] self.register_plugin("xep_0030") self.register_plugin("xep_0060") @@ -187,8 +163,6 @@ class ChenBot(ClientXMPP): self.add_event_handler("session_start", self.session_start) self.add_event_handler("message", self.message) self.add_event_handler("groupchat_message", self.muc_message) - # self.add_event_handler("vcard_avatar_update", self.debug_event) - # self.add_event_handler("stream_error", self.debug_event) self.add_event_handler("disconnected", lambda _: self.connect()) async def session_start(self, event): @@ -250,8 +224,9 @@ if __name__ == "__main__": config.read("config.ini") jid = config["chen"]["jid"] password = config["chen"]["password"] + nick = config["chen"]["nick"] autojoin = config["chen"]["autojoin"].split() - bot = ChenBot(jid, password, autojoin=autojoin) + bot = ChenBot(jid, password, nick, autojoin=autojoin) bot.connect() bot.process(forever=True) diff --git a/requirements.txt b/requirements.txt index a1a4d74..e4dd893 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ requests slixmpp beautifulsoup4 -git+https://github.com/GillesArcas/PythonSed#egg=PythonSed pantomime aiohttp