Пример #1
0
def register(bot, update, args):
	""" Responsible for registering a new user.
	    Test cases handled : 1. Check whether correct number of credentials are entered.
				 2. Check whether this chat id is already registered.
				 3. Check whether the credentials are correct by logging in the college website.
	    Adds the data to database. Note password has to go through enc() which handles encrpytion.
	    Replies either with error_messages or success_message based on outcome. """ 

	chat_id = update.message.chat_id
	try:
		reg_num, pwd = args
	except ValueError:
		logger.info("Incorrect number of credentials by %s",chat_id)
		error_message = "Hmmm.. Is the format correct? It should be in the form : Try again typing\n */register RegisterNo Password*"
		reply(bot,update,error_message)
		return
	reg_status = db.is_registered(chat_id)
	if (reg_status):
		error_message = "Already registered with registration number : {}!\n Use */unregister* to unregister".format(reg_status)
		reply(bot,update,error_message)
		return
	try:
		name = scraper.scrape(reg_num,pwd,'check_registration')
	except:
		error_message = "Are you sure you entered the correct registration/password?"
		reply(bot,update,error_message)
		return
	db.register(chat_id,reg_num,enc(pwd))
	logger.info("Registered %s (%s)",name,reg_num)
	success_message = "Registered *" + name + "*!"
	success_message += "\n\n Delete the message you sent for registering to ensure no one else reads it"
	reply(bot,update,success_message)
	return
Пример #2
0
def marks(bot, update, args):
	chat_id = update.message.chat_id
	reg_status = db.is_registered(chat_id)
	if (not reg_status):
		error_message ="Are you registered?"
		reply(bot,update,error_message)
		return
	registration_number,password = db.get_credentials(chat_id)
	marks_message = scraper.scrape(registration_number,dec(str(password)),'marks',args)
	reply(bot,update,marks_message)
	return
Пример #3
0
def attendance(bot, update, args):
	chat_id = update.message.chat_id
	reg_status = db.is_registered(chat_id)
	if (not reg_status):
		error_message = "Are you registered?"
		logger.info("%s tried to fetch attendance without registering",chat_id)
		reply(bot,update,error_message)
		return
	registration_number,password = db.get_credentials(chat_id)
	attendance_message = scraper.scrape(registration_number,dec(str(password)),'attendance',args)
	logger.info("%s was sent attendance",registration_number)
	reply(bot,update,attendance_message);
	return
Пример #4
0
def unregister(bot, update):
	chat_id = update.message.chat_id
	reg_status = db.is_registered(chat_id)
	if (not reg_status):
		error_message = "There is nothing to unregister! Use `/register` to register"
		reply(bot,update,error_message)
		return
	if (not db.unregister(chat_id)):
		error_message = "Something wrong happened while unregistering. It has been notified to my master"
		logger.error("Unexpected error in unregistering : Chat id : %s",chat_id)
		reply(bot,update,error_message)
		return
	logger.info("Registered %s",reg_status)
	success_message = "Successfully unregistered *" + reg_status +"*.\n\n Send feedback using /feedback and your feedback. Thank you"
	reply(bot,update,success_message)
	return
Пример #5
0
def timetable(bot, update, args):
	chat_id = update.message.chat_id
	reg_status = db.is_registered(chat_id)
	if (not reg_status):
		error_message = "Are you registered?"
		reply(bot,update,error_message)
		return
	timetable_message = db.get_timetable(chat_id)
	if (timetable_message):
		reply(bot,update,timetable_message)
		return
	registration_number,password = db.get_credentials(chat_id)
	timetable_message = scraper.scrape(registration_number,dec(str(password)),'timetable',args)
	db.set_timetable(chat_id,timetable_message,hashlib.sha1(timetable_message).hexdigest())
	reply(bot,update,timetable_message)
	return
Пример #6
0
 def filter(self, message):
     return is_registered(message.from_user.id, message.chat_id)