IGNOU Telegram Bot v1.0
This commit is contained in:
commit
3c12b45d62
18 changed files with 1240 additions and 0 deletions
0
bot/plugins/__init__.py
Normal file
0
bot/plugins/__init__.py
Normal file
33
bot/plugins/book.py
Normal file
33
bot/plugins/book.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from pyrogram import Client
|
||||
from pyrogram import filters
|
||||
|
||||
from bot.helper.ignoubooks import IgnouBooks
|
||||
from bot.config import Config
|
||||
|
||||
# Completed Add DB Support
|
||||
@Client.on_message(filters.command(['book']) & filters.chat(Config.SUDO_CHAT))
|
||||
def books(client: Client, message):
|
||||
text = message.text
|
||||
try:
|
||||
course_code = text.split(" ")[1].upper()
|
||||
subject_code = text.split(" ")[2].upper()
|
||||
except IndexError:
|
||||
message.reply_text('Wrong Course Name or Subject Code 😐')
|
||||
return
|
||||
|
||||
if books.find_one(subject_code):
|
||||
# add code for database books for sending from cache
|
||||
pass
|
||||
|
||||
if subject_code.upper() == 'LIST':
|
||||
message.reply_text(IgnouBooks(course=course_code).get_courseSubjectlist())
|
||||
else:
|
||||
message.reply_text("please wait.. sending books")
|
||||
files = IgnouBooks(course=course_code, subject=subject_code).getDownload()
|
||||
for file in files:
|
||||
client.send_document(
|
||||
message.
|
||||
chat,
|
||||
id,
|
||||
file,
|
||||
caption=f'Downloaded using {Config.USERNAME}')
|
272
bot/plugins/result.py
Normal file
272
bot/plugins/result.py
Normal file
|
@ -0,0 +1,272 @@
|
|||
from pyrogram import Client
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import (
|
||||
InlineKeyboardMarkup,
|
||||
InlineKeyboardButton,
|
||||
CallbackQuery,
|
||||
Message
|
||||
)
|
||||
|
||||
import datetime
|
||||
|
||||
from bot.database import Database
|
||||
from bot.config import Config
|
||||
from bot.helper.ignouresult import IgnouResult
|
||||
|
||||
from bot.helper.extractor import User
|
||||
|
||||
db = Database()
|
||||
|
||||
|
||||
# Completed
|
||||
@Client.on_message(filters.regex('^(m|M)y'))
|
||||
@Client.on_message(filters.command(['my']))
|
||||
async def my(_, message):
|
||||
user: User = User(await db.get_user(message.from_user.id))
|
||||
|
||||
if 'my' == message.text.lower():
|
||||
if user.myenrollment:
|
||||
await result_card(_, message)
|
||||
else:
|
||||
await message.reply_text("Set Your Enrollment using \n my 197xx00xx22")
|
||||
return
|
||||
else:
|
||||
student = message.text.split()
|
||||
try:
|
||||
await db.update(
|
||||
db.user,
|
||||
message.from_user.id,
|
||||
{"$set": {"myenrollment": student[1] + student[2]}})
|
||||
|
||||
await message.reply_text("Data Saved Successfully ")
|
||||
except IndexError:
|
||||
await message.reply_text("First Set your Enrollment using \n my course_code enrollment")
|
||||
|
||||
|
||||
# Completed
|
||||
@Client.on_message(filters.regex("^\D+\d{8,10}") | filters.regex("^\d{8,10}"))
|
||||
async def result_card(_, message: Message):
|
||||
get_course = False
|
||||
user: User = User(await db.get_user(message.from_user.id))
|
||||
|
||||
if message.text.isnumeric():
|
||||
if not user.course:
|
||||
await message.reply("You must check once result with Course code \n example : bca 197xx00xx22")
|
||||
return
|
||||
else:
|
||||
get_course = user.course
|
||||
# elif 'my' in message.text.lower() or 'last' in message.text.lower():
|
||||
# user: User = await db.get_user(message.from_user.id)
|
||||
|
||||
result_query = ''
|
||||
if get_course:
|
||||
result_query = get_course + message.text
|
||||
elif 'my' in message.text.lower():
|
||||
result_query = user.myenrollment
|
||||
elif "last" in message.text.lower():
|
||||
result_query = user.course + user.enrollment
|
||||
else:
|
||||
result_query = message.text
|
||||
|
||||
student: IgnouResult = IgnouResult(result_query)
|
||||
result = student.gradeResultString()
|
||||
|
||||
if not result:
|
||||
await message.reply_text('Enrollment no is not correct or \nGrade Card Site is Down 🤕')
|
||||
return
|
||||
|
||||
if not user.following.get(student.enrollmentNo):
|
||||
inline_keyboard = InlineKeyboardMarkup(
|
||||
[
|
||||
[ # First row
|
||||
InlineKeyboardButton( # Generates a callback query when pressed
|
||||
"Add to Watch List 👀",
|
||||
callback_data=f"add_{student.courseId}_{student.enrollmentNo}"
|
||||
),
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
"Share this 🤖",
|
||||
switch_inline_query=f"\nTry this Easy IGNOU Bot\n 👉🏻 {Config.USERNAME} \n\n Created by @r0sh7n"
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
else:
|
||||
inline_keyboard = InlineKeyboardMarkup(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
"Share this 🤖",
|
||||
switch_inline_query=f"\nTry this Easy IGNOU Bot\n 👉🏻 {Config.USERNAME} \n Created by @r0sh7n"
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
|
||||
await message.reply_text(
|
||||
result.get("result", '') + Config.FOOTER_CREDIT,
|
||||
parse_mode='html',
|
||||
reply_markup=inline_keyboard)
|
||||
|
||||
await db.update_last_action(
|
||||
message.from_user.id,
|
||||
{"course": student.courseId, "enrollment": student.enrollmentNo})
|
||||
|
||||
# Tee Result Card
|
||||
result: IgnouResult = IgnouResult(result_query).teeResultString()
|
||||
if result:
|
||||
await message.reply_text(
|
||||
result.get("result", '') + Config.FOOTER_CREDIT,
|
||||
parse_mode='html')
|
||||
|
||||
|
||||
@Client.on_callback_query(filters.regex("^add") | filters.regex("^remove"))
|
||||
async def watch_list(_, callback_query: CallbackQuery):
|
||||
"""
|
||||
callback_query example:
|
||||
add_bca_192112313
|
||||
remove_bca_1092313
|
||||
"""
|
||||
_, course, enrollment = callback_query.data.split("_")
|
||||
|
||||
today_date = datetime.datetime.today().strftime('%B %d, %Y')
|
||||
|
||||
# info about follower who is following enrollment
|
||||
user_dict = {
|
||||
"username": callback_query.from_user.username,
|
||||
"name": callback_query.from_user.first_name,
|
||||
"_id": callback_query.from_user.id,
|
||||
"added_on": datetime.date.today().isoformat()
|
||||
}
|
||||
|
||||
# add enrollment in following list
|
||||
if 'add' in callback_query.data:
|
||||
|
||||
# Grade Card
|
||||
student = IgnouResult(course + enrollment)
|
||||
result = student.gradeResultJson()
|
||||
|
||||
# if unable to fetch result from ignou site
|
||||
if result.get("status") != "ok":
|
||||
await callback_query.answer("Unable to fetch details\nTry after sometime ", show_alert=True)
|
||||
return
|
||||
|
||||
# student data
|
||||
student_info = result.get("student", {})
|
||||
|
||||
# result pass fail in dict(passed,failed)
|
||||
count = result.get("count", {})
|
||||
|
||||
# student info in user following section
|
||||
await db.update(
|
||||
db.user,
|
||||
callback_query.from_user.id,
|
||||
{
|
||||
"$set": {
|
||||
f"following.{enrollment}": {
|
||||
"name": student_info.get("name"),
|
||||
"course": student_info.get("course")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
# this dict gonna update in crawler db
|
||||
info_dict = {
|
||||
"_id": enrollment
|
||||
}
|
||||
|
||||
# check if student is already in crawler db
|
||||
if not await db.find(
|
||||
db.crawler,
|
||||
enrollment
|
||||
):
|
||||
# collection info then update in info_dict : Dict variable
|
||||
student_db = {
|
||||
"name": student_info.get("name", ""),
|
||||
"course": course,
|
||||
"grade": {
|
||||
"count": {
|
||||
"passed": count.get("passed", 0),
|
||||
"failed": count.get("failed", 0)
|
||||
},
|
||||
"checked": today_date
|
||||
},
|
||||
}
|
||||
|
||||
# updating info_dict : Dict with student_db
|
||||
info_dict.update(student_db)
|
||||
|
||||
# Tee Card Json
|
||||
result = student.teeResultJson()
|
||||
|
||||
# list of out result in tee
|
||||
count = result.get("count", 0)
|
||||
|
||||
# this for tee section in crawler
|
||||
student_db = {
|
||||
"tee": {
|
||||
"count": count or 0,
|
||||
"checked": today_date
|
||||
},
|
||||
}
|
||||
|
||||
# updating again info_dict with new tee student_db
|
||||
info_dict.update(student_db)
|
||||
|
||||
# adding follower info in info_dict
|
||||
info_dict.update(
|
||||
{
|
||||
"followers": {
|
||||
str(callback_query.from_user.id): user_dict
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
# inserting first time student in crawlre db
|
||||
await db.insert(
|
||||
db.crawler,
|
||||
info_dict
|
||||
)
|
||||
|
||||
# if student is already in crawler db then
|
||||
# just update following and followers secion
|
||||
# in user db in crawler db
|
||||
else:
|
||||
await db.update(
|
||||
db.crawler,
|
||||
enrollment,
|
||||
{
|
||||
"$set": {
|
||||
f"followers.{callback_query.from_user.id}": user_dict}
|
||||
})
|
||||
|
||||
# remove inline_button from result
|
||||
await callback_query.edit_message_reply_markup()
|
||||
# push notification to user
|
||||
await callback_query.answer(
|
||||
f"{student_info.get('name')} Added in Watch List 🙃\n😇You will automatically receive result once it published in IGNOU 🌐",
|
||||
show_alert=True)
|
||||
|
||||
# this conditon for remove followed user
|
||||
# from crawler followers section and in user following section
|
||||
elif "remove" in callback_query.data:
|
||||
|
||||
await db.update(
|
||||
db.user,
|
||||
callback_query.from_user.id,
|
||||
{
|
||||
"$unset": {
|
||||
f"following.{enrollment}": ""
|
||||
}
|
||||
})
|
||||
await db.update(
|
||||
db.crawler,
|
||||
enrollment,
|
||||
{
|
||||
"$unset": {
|
||||
f"followers.{callback_query.from_user.id}": ""
|
||||
}
|
||||
}
|
||||
)
|
||||
await callback_query.answer("User Removed from Watchlist 👀")
|
141
bot/plugins/user.py
Normal file
141
bot/plugins/user.py
Normal file
|
@ -0,0 +1,141 @@
|
|||
import re
|
||||
|
||||
from pyrogram import Client
|
||||
from pyrogram import filters
|
||||
|
||||
from pyrogram.types import (
|
||||
InlineKeyboardButton,
|
||||
InlineKeyboardMarkup,
|
||||
CallbackQuery,
|
||||
Message
|
||||
)
|
||||
|
||||
from bot.database import Database
|
||||
from bot.helper.extractor import User, Student
|
||||
from bot.config import Config
|
||||
from bot.plugins.result import result_card
|
||||
|
||||
db = Database()
|
||||
|
||||
|
||||
@Client.on_message(filters.command(['start', 'help']))
|
||||
async def start(_, message):
|
||||
if 'start' in message.text.lower():
|
||||
|
||||
if not await db.is_user_exist(message.from_user.id):
|
||||
await db.add_user(message.from_user.id, message.from_user.first_name)
|
||||
|
||||
await message.reply_text(f"Welcome , {message.from_user.first_name} 🥳 \n \
|
||||
[Click here for more details 🔍]({Config.HELP_URL})", disable_web_page_preview=True)
|
||||
|
||||
elif 'help' in message.text.lower():
|
||||
|
||||
await message.reply_text(f"{Config.HELP_URL}")
|
||||
|
||||
await db.update_last_used_on(message.from_user.id)
|
||||
|
||||
@Client.on_message(filters.command(["stats"]))
|
||||
async def stats(client: Client,message : Message):
|
||||
|
||||
user: User = User(await db.get_user(message.from_user.id))
|
||||
total_user = await db.total_users_count()
|
||||
total_crawler = await db.total_crawlers_count()
|
||||
total_following = len(user.following)
|
||||
|
||||
msg = f"""
|
||||
Hi, {message.from_user.first_name}
|
||||
|
||||
Your Stat 🙃
|
||||
TG 🆔 : {message.from_user.id}
|
||||
Following 🕵️ : {total_following}
|
||||
"""
|
||||
if user.is_admin or message.from_user.id in Config.SUDO_ADMIN:
|
||||
try:
|
||||
user_enrollment_not = re.findall("\d+",user.myenrollment)[0]
|
||||
user_crawler_info: Student = Student(await db.get_student(user_enrollment_not))
|
||||
msg += f" Followers 👼 : {len(user_crawler_info.followers)}\n"
|
||||
except (IndexError, AttributeError, TypeError):
|
||||
pass
|
||||
|
||||
site_info = await db.get_site_update("ignou")
|
||||
grade_checked = site_info.get("grade_checked","error in monitoring")
|
||||
tee_checked = site_info.get("tee_checked","error in monitoring ")
|
||||
|
||||
msg += f"""
|
||||
{Config.USERNAME} Stat 🤖
|
||||
Total User 🙆: {total_user}
|
||||
Result Monitoring 😎: {total_crawler}
|
||||
|
||||
👀 Last Grade Card Checked
|
||||
🕗 -> {grade_checked}
|
||||
|
||||
Last Tee Result Check
|
||||
🕗 -> {tee_checked}
|
||||
"""
|
||||
await message.reply_text(msg)
|
||||
|
||||
|
||||
@Client.on_callback_query(filters.regex("^user"))
|
||||
async def user_info(_, callback_query: CallbackQuery):
|
||||
_, enrollment = callback_query.data.split("_")
|
||||
|
||||
user: User = User(await db.get_user(callback_query.from_user.id))
|
||||
|
||||
student: Student = Student(await db.find(
|
||||
db.crawler,
|
||||
enrollment,
|
||||
{"_id" : 0}
|
||||
))
|
||||
|
||||
followed_by = len(student.followers)
|
||||
|
||||
msg_string = f"""👩🏻🎓 {student.name}
|
||||
🆔 {enrollment} ({student.course})
|
||||
Grade Card : ✝️ {student.grade.passed+student.grade.failed} ✅ {student.grade.passed} ❎ {student.grade.failed}
|
||||
Grade Card Updated on {student.grade.checked}
|
||||
"""
|
||||
if user.is_admin or callback_query.from_user.id in Config.SUDO_ADMIN:
|
||||
msg_string += f"Followed by {followed_by} 👀"
|
||||
|
||||
await callback_query.answer(msg_string, show_alert=True)
|
||||
|
||||
|
||||
@Client.on_message(filters.command(['watchlist']))
|
||||
async def followed_list(_, message: Message):
|
||||
user: User = User(await db.get_user(message.from_user.id))
|
||||
|
||||
if len(user.following) == 0:
|
||||
await message.reply_text("Not followed anyone")
|
||||
return
|
||||
|
||||
buttons = []
|
||||
for enrollment, usr in user.following.items():
|
||||
row = [
|
||||
InlineKeyboardButton(
|
||||
usr.get("name").split()[0],
|
||||
callback_data=f"user_{enrollment}"
|
||||
),
|
||||
InlineKeyboardButton(
|
||||
"🗑",
|
||||
callback_data=f"remove_{usr.get('course')}_{enrollment}"
|
||||
),
|
||||
]
|
||||
|
||||
buttons.append(
|
||||
row
|
||||
)
|
||||
await message.reply_text(
|
||||
"<b>👩🏻🎓 Users in 👀 Watchlist</b>",
|
||||
reply_markup=InlineKeyboardMarkup(buttons),
|
||||
parse_mode="html")
|
||||
|
||||
|
||||
@Client.on_message(filters.command(['last']))
|
||||
async def last_result_check(_, message):
|
||||
user: User = User(await db.get_user(message.from_user.id))
|
||||
|
||||
if user.enrollment:
|
||||
await result_card(_, message)
|
||||
else:
|
||||
await message.reply_text("No recent result checked")
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue