-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
46 lines (40 loc) · 1.48 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from pyrogram import Client, Message, Filters
import requests
import datetime
from data import get_cite, get_pdf, get_intext
time = datetime.datetime.now()
API_ID =
API_HASH = ""
BOT_TOKEN = ""
bot = Client("bot", API_ID, API_HASH, BOT_TOKEN)
@bot.on_message(Filters.command("start", prefixes=['/']))
async def create_user_profile(bot: bot, msg: Message):
chat_id = msg.chat.id
print(chat_id)
first_name = msg.chat.first_name
await bot.send_message(chat_id, "Send a DOI number or a DOI link for Harward style citation.")
@bot.on_message()
async def my_function(client, message):
chat_id = message.chat.id
msg = message["text"]
if "doi.org" in msg:
msg = msg.replace("https://doi.org/", "").replace("doi.org/", "")
try:
citation = await get_cite(msg)
if not citation:
text = "ERROR: DOI Not Found!"
print(text)
await bot.send_message(chat_id, text)
else:
pdf = await get_pdf(msg)
if not pdf:
pdf = "PDF not available!"
await bot.send_message(chat_id, pdf)
in_text = await get_intext(msg, citation)
await bot.send_message(chat_id, citation, disable_web_page_preview=True)
await bot.send_message(chat_id, in_text, disable_web_page_preview=True)
except Exception as e:
print(e)
text = "Citation not available. Make sure your link/code. is correct."
await bot.send_message(chat_id, text)
bot.run()