Try loading avatar from avatar.png, enhance message body triggers, block music.youtube.com
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/chen/trunk@29 32723744-9b23-0b4a-b1da-9b2e968f9461
This commit is contained in:
parent
2b5624a80e
commit
8932097e37
15
README
Normal file
15
README
Normal file
@ -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
|
19
README.org
19
README.org
@ -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
|
|
38
main.py
38
main.py
@ -32,7 +32,9 @@ block_list = (
|
|||||||
"www.youtube.com",
|
"www.youtube.com",
|
||||||
"youtube.com",
|
"youtube.com",
|
||||||
"m.youtube.com",
|
"m.youtube.com",
|
||||||
|
"music.youtube.com",
|
||||||
)
|
)
|
||||||
|
# FIXME: Gopher support when?
|
||||||
req_list = (
|
req_list = (
|
||||||
"http://",
|
"http://",
|
||||||
"https://",
|
"https://",
|
||||||
@ -56,7 +58,7 @@ class Lifo(list):
|
|||||||
if len(self) > self.size:
|
if len(self) > self.size:
|
||||||
self.pop()
|
self.pop()
|
||||||
|
|
||||||
|
# Cheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeen
|
||||||
class ChenBot(ClientXMPP):
|
class ChenBot(ClientXMPP):
|
||||||
messages = defaultdict(
|
messages = defaultdict(
|
||||||
lambda: {
|
lambda: {
|
||||||
@ -138,18 +140,12 @@ class ChenBot(ClientXMPP):
|
|||||||
message.send()
|
message.send()
|
||||||
|
|
||||||
async def parse_urls(self, msg, urls, sender, mtype):
|
async def parse_urls(self, msg, urls, sender, mtype):
|
||||||
if "nsfw" in msg["body"].lower():
|
body = msg["body"].lower()
|
||||||
return
|
if "nsfl" in body: return
|
||||||
if "#nospoil" in msg["body"].lower():
|
if "nsfw" in body: return
|
||||||
return
|
if "#nospoil" in body: return
|
||||||
if "discord.com" in msg["body"].lower():
|
if "!repo" in body:
|
||||||
msg.reply("Ew, discord! :<\n").send()
|
msg.reply("https://git.chaotic.ninja/usr/yakumo_izuru/chen\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()
|
|
||||||
for u in urls:
|
for u in urls:
|
||||||
if u in self.messages[sender]["links"]:
|
if u in self.messages[sender]["links"]:
|
||||||
continue
|
continue
|
||||||
@ -189,8 +185,22 @@ class ChenBot(ClientXMPP):
|
|||||||
...
|
...
|
||||||
|
|
||||||
async def update_info(self):
|
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 = 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["DESC"] = "Shikigami of the Shikigami of the Gap Youkai"
|
||||||
vcard["NICKNAME"] = "Chen"
|
vcard["NICKNAME"] = "Chen"
|
||||||
vcard["FN"] = "Chen"
|
vcard["FN"] = "Chen"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user