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
This commit is contained in:
parent
f0fd093d7c
commit
5168564002
@ -1,4 +1,5 @@
|
|||||||
[chen]
|
[chen]
|
||||||
jid = chen@example.com
|
jid = chen@example.com
|
||||||
password = b0TPA55W0rD
|
password = b0TPA55W0rD
|
||||||
autojoin = room1@muc.example.com room2@muc.example.com room3@muc.example.com
|
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 mimetypes
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from PythonSed import Sed
|
|
||||||
from slixmpp import ClientXMPP
|
from slixmpp import ClientXMPP
|
||||||
from urllib.parse import urlparse, parse_qs, urlunparse
|
from urllib.parse import urlparse, parse_qs, urlunparse
|
||||||
from pantomime import normalize_mimetype
|
from pantomime import normalize_mimetype
|
||||||
@ -29,7 +28,13 @@ headers = {
|
|||||||
"Cache-Control": "no-cache",
|
"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://")
|
req_list = ("http://", "https://")
|
||||||
html_files = ("text/html", "application/xhtml+xml")
|
html_files = ("text/html", "application/xhtml+xml")
|
||||||
|
|
||||||
@ -141,39 +146,10 @@ class ChenBot(ClientXMPP):
|
|||||||
uri = urlparse(u)
|
uri = urlparse(u)
|
||||||
await self.parse_uri(uri, sender, mtype)
|
await self.parse_uri(uri, sender, mtype)
|
||||||
|
|
||||||
def sed_command(self, msg, sender, mtype):
|
def __init__(self, jid, password, nick, autojoin=None):
|
||||||
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):
|
|
||||||
ClientXMPP.__init__(self, jid, password)
|
ClientXMPP.__init__(self, jid, password)
|
||||||
self.jid = jid
|
self.jid = jid
|
||||||
self.nick = nick
|
self.nick = nick or []
|
||||||
self.autojoin = autojoin or []
|
self.autojoin = autojoin or []
|
||||||
self.register_plugin("xep_0030")
|
self.register_plugin("xep_0030")
|
||||||
self.register_plugin("xep_0060")
|
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("session_start", self.session_start)
|
||||||
self.add_event_handler("message", self.message)
|
self.add_event_handler("message", self.message)
|
||||||
self.add_event_handler("groupchat_message", self.muc_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())
|
self.add_event_handler("disconnected", lambda _: self.connect())
|
||||||
|
|
||||||
async def session_start(self, event):
|
async def session_start(self, event):
|
||||||
@ -250,8 +224,9 @@ if __name__ == "__main__":
|
|||||||
config.read("config.ini")
|
config.read("config.ini")
|
||||||
jid = config["chen"]["jid"]
|
jid = config["chen"]["jid"]
|
||||||
password = config["chen"]["password"]
|
password = config["chen"]["password"]
|
||||||
|
nick = config["chen"]["nick"]
|
||||||
autojoin = config["chen"]["autojoin"].split()
|
autojoin = config["chen"]["autojoin"].split()
|
||||||
bot = ChenBot(jid, password, autojoin=autojoin)
|
bot = ChenBot(jid, password, nick, autojoin=autojoin)
|
||||||
|
|
||||||
bot.connect()
|
bot.connect()
|
||||||
bot.process(forever=True)
|
bot.process(forever=True)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
requests
|
requests
|
||||||
slixmpp
|
slixmpp
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
git+https://github.com/GillesArcas/PythonSed#egg=PythonSed
|
|
||||||
pantomime
|
pantomime
|
||||||
aiohttp
|
aiohttp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user