-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (61 loc) · 2.54 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from datetime import datetime
from telegram.ext import (
Application,
CommandHandler,
)
import logging
# from tele.pattern_matching import Pattern_Matching
import canvas_handler
from telegram import ForceReply, Update
from tele.constants import(
CANVAS_URL,
CANVAS_TOKEN,
API_KEY
)
from tele.subscribe_manager import SubscribeManager
canvas_client = canvas_handler.CanvasTele(CANVAS_URL, CANVAS_TOKEN)
sub = SubscribeManager(CANVAS_URL, CANVAS_TOKEN)
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO,
filename='TeleBot.log',
filemode='a')
logger = logging.getLogger(__name__)
logging.getLogger().addHandler(logging.StreamHandler())
async def start(update, context) -> None:
"""Send a message when the command /start is issued."""
user = update.effective_user
await update.message.reply_html(
rf"Hi {user.mention_html()}!",
reply_markup=ForceReply(selective=True),
)
async def help(update, context) -> None:
text_to_send = """
List of commands available:\t
⇝ /courses - To get the list of courses use command
⇝ /due - To get list of assignments for all subjects.
⇝ /sub - To subscribe to a particular course announcements.
⇝ /unsub - To unsubscribe to a particular course announcements.
"""
await update.message.reply_text(text_to_send)
def error(update, error):
"""Log Errors caused by Updates."""
logger.warning('Update {} caused error {}'.format(update, error))
def main():
application = Application.builder().token(API_KEY).build()
job_queue = application.job_queue
job_queue.run_repeating(callback=canvas_client.get_annoucements,
interval=300)
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("help", help))
application.add_handler(CommandHandler("courses", canvas_client.get_courses_list))
application.add_handler(CommandHandler("due", canvas_client.get_assingment))
# application.add_handler(CommandHandler("ask", Pattern_Matching.matching))
application.add_handler(CommandHandler("sub", sub.subscribe_announcement))
application.add_handler(CommandHandler("unsub", sub.unsubscribe))
# log all errors
application.add_error_handler(error)
application.run_polling()
logger.info('Bot started.')
if __name__ == "__main__":
main()