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: https://svn.yakumo.dev/yakumo.izuru/chen/trunk@17 32723744-9b23-0b4a-b1da-9b2e968f9461
This commit is contained in:
parent
5ade971f0a
commit
eb48f13017
@ -1,4 +1,5 @@
|
||||
[chen]
|
||||
jid = chen@example.com
|
||||
password = b0TPA55W0rD
|
||||
nick = Chen
|
||||
autojoin = room1@muc.example.com room2@muc.example.com room3@muc.example.com
|
47
main.py
47
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)
|
||||
|
@ -1,6 +1,5 @@
|
||||
requests
|
||||
slixmpp
|
||||
beautifulsoup4
|
||||
git+https://github.com/GillesArcas/PythonSed#egg=PythonSed
|
||||
pantomime
|
||||
aiohttp
|
||||
|
Loading…
x
Reference in New Issue
Block a user