Add support of Tomuss
This commit is contained in:
parent
4cc233fcd2
commit
4587df372a
3 changed files with 50 additions and 3 deletions
11
EDTuser.py
11
EDTuser.py
|
@ -1,6 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
import requests
|
import requests
|
||||||
from EDTcalendar import Calendar
|
from EDTcalendar import Calendar
|
||||||
|
from feedparser import parse
|
||||||
|
|
||||||
KFET_URL = "http://kfet.bdeinfo.org/orders"
|
KFET_URL = "http://kfet.bdeinfo.org/orders"
|
||||||
|
|
||||||
|
@ -20,6 +21,8 @@ class User:
|
||||||
self.nt_last = get_now()
|
self.nt_last = get_now()
|
||||||
self.kfet = None
|
self.kfet = None
|
||||||
self.await_cmd = str()
|
self.await_cmd = str()
|
||||||
|
self.tomuss_rss = str()
|
||||||
|
self.tomuss_last = str()
|
||||||
|
|
||||||
def calendar(self, time: str = "", pass_week: bool = False):
|
def calendar(self, time: str = "", pass_week: bool = False):
|
||||||
return Calendar(time, self.resources, pass_week=pass_week)
|
return Calendar(time, self.resources, pass_week=pass_week)
|
||||||
|
@ -45,3 +48,11 @@ class User:
|
||||||
res = 3
|
res = 3
|
||||||
self.kfet = None if res else self.kfet
|
self.kfet = None if res else self.kfet
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def get_tomuss(self):
|
||||||
|
entry = list()
|
||||||
|
if self.tomuss_rss:
|
||||||
|
entry = [e for e in parse(self.tomuss_rss).entries]
|
||||||
|
if not self.tomuss_last:
|
||||||
|
return entry
|
||||||
|
return entry[self.tomuss_last:]
|
||||||
|
|
|
@ -19,5 +19,8 @@
|
||||||
"err_num": "Invalid number ! \u274C",
|
"err_num": "Invalid number ! \u274C",
|
||||||
"notif_time_cooldown": "Notification `{}` set to `{}` ! \u2705",
|
"notif_time_cooldown": "Notification `{}` set to `{}` ! \u2705",
|
||||||
"notif_info": "_Notification_\n*State:* {}\n*Time:* {}\n*Cooldown:* {}",
|
"notif_info": "_Notification_\n*State:* {}\n*Time:* {}\n*Cooldown:* {}",
|
||||||
"notif_await": "Please send the new value !"
|
"notif_await": "Please send the new value !",
|
||||||
|
"settomuss": "Tomuss set \u2705",
|
||||||
|
"settomuss_error": "Invalid RSS feed ! \u274C",
|
||||||
|
"settomuss_wait": "Send the RSS feed link of your Tomuss !"
|
||||||
}
|
}
|
37
bot.py
37
bot.py
|
@ -22,6 +22,7 @@ from ics.parse import ParseError
|
||||||
from requests.exceptions import ConnectionError, InvalidSchema, MissingSchema
|
from requests.exceptions import ConnectionError, InvalidSchema, MissingSchema
|
||||||
from pyzbar.pyzbar import decode
|
from pyzbar.pyzbar import decode
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from feedparser import parse
|
||||||
|
|
||||||
|
|
||||||
if not isdir("logs"):
|
if not isdir("logs"):
|
||||||
|
@ -82,16 +83,18 @@ async def notif():
|
||||||
with shelve.open("edt", writeback=True) as db:
|
with shelve.open("edt", writeback=True) as db:
|
||||||
for u in db:
|
for u in db:
|
||||||
nt = None
|
nt = None
|
||||||
kg = None
|
kf = None
|
||||||
|
tm = None
|
||||||
try:
|
try:
|
||||||
nt = db[u].get_notif()
|
nt = db[u].get_notif()
|
||||||
kf = db[u].get_kfet()
|
kf = db[u].get_kfet()
|
||||||
|
tm = db[u].get_tomuss()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if nt:
|
if nt:
|
||||||
await bot.send_message(int(u), lang(db[u], "notif_event")+str(nt), parse_mode=ParseMode.MARKDOWN)
|
await bot.send_message(int(u), lang(db[u], "notif_event")+str(nt), parse_mode=ParseMode.MARKDOWN)
|
||||||
if kf is not None:
|
if kf:
|
||||||
if kf == 1:
|
if kf == 1:
|
||||||
kf = lang(db[u], "kfet")
|
kf = lang(db[u], "kfet")
|
||||||
elif kf == 2:
|
elif kf == 2:
|
||||||
|
@ -99,6 +102,17 @@ async def notif():
|
||||||
else:
|
else:
|
||||||
kf = lang(db[u], "kfet_err")
|
kf = lang(db[u], "kfet_err")
|
||||||
await bot.send_message(int(u), kf, parse_mode=ParseMode.MARKDOWN)
|
await bot.send_message(int(u), kf, parse_mode=ParseMode.MARKDOWN)
|
||||||
|
if tm:
|
||||||
|
for i in tm:
|
||||||
|
msg = markdown.text(
|
||||||
|
markdown.bold(i.title),
|
||||||
|
markdown.code(i.summary.replace("<br>", "\n").replace("<b>", "").replace("</b>", "")),
|
||||||
|
sep="\n"
|
||||||
|
)
|
||||||
|
await bot.send_message(int(u), msg, parse_mode=ParseMode.MARKDOWN)
|
||||||
|
db[u].tomuss_last = i
|
||||||
|
|
||||||
|
|
||||||
await sleep(60)
|
await sleep(60)
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,6 +151,7 @@ async def start(message: types.Message):
|
||||||
key.add(reply_keyboard.KeyboardButton("Setkfet"))
|
key.add(reply_keyboard.KeyboardButton("Setkfet"))
|
||||||
key.add(reply_keyboard.KeyboardButton("Setedt"))
|
key.add(reply_keyboard.KeyboardButton("Setedt"))
|
||||||
key.add(reply_keyboard.KeyboardButton("Notif"))
|
key.add(reply_keyboard.KeyboardButton("Notif"))
|
||||||
|
key.add(reply_keyboard.KeyboardButton("Settomuss"))
|
||||||
await message.reply(lang(user, "welcome"), parse_mode=ParseMode.MARKDOWN, reply_markup=key)
|
await message.reply(lang(user, "welcome"), parse_mode=ParseMode.MARKDOWN, reply_markup=key)
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,6 +224,17 @@ async def edt_await(message: types.Message):
|
||||||
await message.reply(lang(db[user_id], "setedt_wait"), parse_mode=ParseMode.MARKDOWN)
|
await message.reply(lang(db[user_id], "setedt_wait"), parse_mode=ParseMode.MARKDOWN)
|
||||||
|
|
||||||
|
|
||||||
|
@dp.message_handler(lambda msg: msg.text.lower() == "settomuss")
|
||||||
|
async def edt_await(message: types.Message):
|
||||||
|
user_id = str(message.from_user.id)
|
||||||
|
await message.chat.do(types.ChatActions.TYPING)
|
||||||
|
logger.info(f"{message.from_user.username} do settomuss")
|
||||||
|
with dbL:
|
||||||
|
with shelve.open("edt", writeback=True) as db:
|
||||||
|
db[user_id].await_cmd = "settomuss"
|
||||||
|
await message.reply(lang(db[user_id], "settomuss_wait"), parse_mode=ParseMode.MARKDOWN)
|
||||||
|
|
||||||
|
|
||||||
@dp.message_handler(commands="getedt")
|
@dp.message_handler(commands="getedt")
|
||||||
async def edt_geturl(message: types.Message):
|
async def edt_geturl(message: types.Message):
|
||||||
user_id = str(message.from_user.id)
|
user_id = str(message.from_user.id)
|
||||||
|
@ -303,6 +329,13 @@ async def await_cmd(message: types.message):
|
||||||
db[user_id].kfet = int(message.text)
|
db[user_id].kfet = int(message.text)
|
||||||
msg = lang(db[user_id], "kfet_set")
|
msg = lang(db[user_id], "kfet_set")
|
||||||
|
|
||||||
|
elif db[user_id].await_cmd == "settomuss":
|
||||||
|
if not len(parse(message.text).entries):
|
||||||
|
msg = lang(db[user_id], "settomuss_error")
|
||||||
|
else:
|
||||||
|
db[user_id].tomuss_rss = message.text
|
||||||
|
msg = lang(db[user_id], "settomuss")
|
||||||
|
|
||||||
elif db[user_id].await_cmd in ["time", "cooldown"]:
|
elif db[user_id].await_cmd in ["time", "cooldown"]:
|
||||||
try:
|
try:
|
||||||
value = int(message.text)
|
value = int(message.text)
|
||||||
|
|
Reference in a new issue