Пример #1
0
    def linkchanger(call):
        bot.answer_callback_query(call.id)
        course_to_change = call.data[5:]
        markup_yes_no = InlineKeyboardMarkup()
        markup_yes_no.row_width = 2
        markup_yes_no.add(InlineKeyboardButton("Add link", callback_data="addlink_"+course_to_change),
                          InlineKeyboardButton('Remove Link', callback_data="remlink_"+course_to_change))
        bot.send_message(call.message.chat.id, "please choose for "+course_to_change, reply_markup=markup_yes_no)

        @bot.callback_query_handler(func=lambda call: call.data.startswith("addlink_") or call.data.startswith("remlink_"))
        def tatticode(call):
            bot.answer_callback_query(call.id)
            course_name = call.data[8:]
            if call.data[0] == "a":
                msg = bot.send_message(call.message.chat.id, "please add a name for link in "+course_name)
                bot.register_next_step_handler(msg, get_name, course_name)
            elif call.data[0] == "r":
                print("remo")
                local_links = links[course_name]
                markup = InlineKeyboardMarkup()
                markup.row_width = len(local_links.keys())
                for text, url in local_links.items():
                    markup.add(InlineKeyboardButton(text, callback_data="linkrem_"+text))
                bot.send_message(call.message.chat.id, "please select a link to delete..", reply_markup=markup)

        def get_name(msg, course_name):
            li = msg.text
            bot.send_message(msg.chat.id, "this link will be added as " + li + " for "+course_name+" \nPlease send new link now....")
            bot.register_next_step_handler(msg, get_link, course_name, li)

        def get_link(msg, course_name, lin_nm):
            li = msg.text
            bot.send_message(msg.chat.id, "this will be added as new link " + lin_nm + " for "+course_name)
            links[course_name][lin_nm] = li
Пример #2
0
def callback_query(call):
    bot.answer_callback_query(call.id)
    bot.delete_message(call.message.chat.id, call.message.id)
    if is_reg(call.message):
        analytics_manager(call.data, users_dict[call.message.chat.id])
    else:
        bot.send_message(call.message.chat.id, "Please /start again")
Пример #3
0
def callback_query(call):
    bot.answer_callback_query(call.id)
    if is_reg(call.message):
        session = call.data[9:]
        get_marks(call.message, users_dict[call.message.chat.id], session)
    else:
        bot.send_message(call.message.chat.id, "Please /start again")
Пример #4
0
def callback_query(call):
    bot.answer_callback_query(call.id)
    if is_reg(call.message):
        bot.delete_message(call.message.chat.id, call.message.id)
        bot.send_message(call.message.chat.id, "Please click /hi again")
    else:
        bot.send_message(call.message.chat.id, "Please /start again")
Пример #5
0
def message_handler(message):
    if (is_reg(message)):
        front_page(users_dict[message.chat.id], message)
    else:
        bot.send_message(message.chat.id,
                         "ohhh! you are not logged in!",
                         reply_markup=gen_markup_login())
Пример #6
0
def handle(message, key):
    # if key == 'broadcast':
    #     bot.send_message(message.chat.id, " Please type your message.")
    #     bot.register_next_step_handler(message, get_msg)
    # if key == "change_classlinks":
    #     classlinks.set_classlinks(message)
    if key == "user_stats":
        bot.send_message(message.chat.id, "Number of reg. users : "+str(number_of_users()))
Пример #7
0
def classlinks_callback_handler(call):
    bot.answer_callback_query(call.id)
    if call.message.chat.id in users_dict:
        user = users_dict[call.message.chat.id]
        user.request_no = 0
        get_classlinks(call.message)
    else:
        bot.send_message(call.message.chat.id, "Please /start again")
Пример #8
0
def get_special(message, user):
    header_auth['Authorization'] = user.jwt_token
    header_auth['X-CSRFToken'] = user.cs_token
    special_li = requests.get(aviral_details_api, headers=header_auth).json()
    try:
        spe = special_li['program']
    except Exception as e:
        spe = "Please fix" + str(e) + " in code."
    bot.send_message(message.chat.id, spe)
Пример #9
0
def get_announcement(message, user):
    anc = user.get_announcement()
    output_string = "Announcement No: "+str(user.request_no) + '\n'
    output_string += "\n Date:-" + str(anc['date'])
    output_string += "\n Title:-" + str(anc['title'])
    markup = InlineKeyboardMarkup()
    markup.row_width = 2
    markup.add(InlineKeyboardButton(text="Notification Link", url=str(anc['link'])),
               InlineKeyboardButton(text="Next ->", callback_data="announcement"))
    bot.send_message(message.chat.id, output_string, reply_markup=markup)
Пример #10
0
def get_msg(message):
    global broadcast_msg
    broadcast_msg = message.text
    bot.reply_to(message, "Preview of message:")
    bot.send_message(message.chat.id, broadcast_msg)
    markup = InlineKeyboardMarkup()
    markup.row_width = 2
    markup.add(InlineKeyboardButton("sure", callback_data="broadcast_yes"),
               InlineKeyboardButton("Cancel", callback_data="no_a"))
    bot.send_message(message.chat.id, "Please select", reply_markup=markup)
Пример #11
0
def get_password(message, username):
    password = message.text
    print("Login to aviral called")
    user = avi.login(username, password, message.chat.id)
    if user is None:
        bot.send_message(message.chat.id,
                         "Can't login to aviral. please /start again")
    else:
        users_dict[message.chat.id] = user
        front_page(user, message)
Пример #12
0
def login_callback(call):
    if not is_reg(call.message):
        bot.answer_callback_query(call.id)
        bot.send_message(call.message.chat.id,
                         "Please enter you Roll number like mitXXXXXXXXX")
        bot.register_next_step_handler(call.message, get_username)
    else:
        bot.answer_callback_query(call.id)
        bot.send_message(call.message.chat.id,
                         "You are already logged in just click /start")
Пример #13
0
def get_marks(message, user, session):
    bot.delete_message(message.chat.id, message.id)
    wait_msg_cont = "Getting marks for " + session + " Session...." + "\n\n" 
    wait_msg = bot.send_message(message.chat.id, wait_msg_cont, parse_mode="MarkDown")
    header_auth['session'] = session
    header_auth['Authorization'] = user.jwt_token
    header_auth['X-CSRFToken'] = user.cs_token
    god_draft = None
    try:
        user_marks = requests.get(aviral_marks_api, headers=header_auth)
        user_data = requests.get(aviral_details_api, headers=header_auth)
        user_sem_data = requests.get(aviral_semester_result_api, headers=header_auth)
        god_draft = json.loads(user_marks.text)
        marks = "\nNo Results for this session.."
        try:
            sgpi = Parser.sgpi_parser(user_sem_data.json(), session, analytics=user.flags['analytics_enabled'])
            marks = Parser.marks_parser(god_draft, user.username, session, analytics=user.flags['analytics_enabled'])
            cgpi = Parser.cgpi_parser(user_data.json(), session, analytics=user.flags['analytics_enabled'])

        except:
            sgpi = "error parsing sgpi"
            print("issue in getting sgpi api")
        bot.send_message(message.chat.id, marks,  parse_mode="MarkDown")
        if marks != "\nNo Results for this session..":
            bot.send_message(message.chat.id, sgpi,  parse_mode="MarkDown")
            bot.send_message(message.chat.id, cgpi,  parse_mode="MarkDown")
            if user.flags['analytics_enabled']:
                save_marks(user, session, god_draft)
    except Exception as e:
        print(str(e))
        bot.send_message(message.chat.id, "something went wrong!!! please /start again")
        del users_dict[message.chat.id]
        user.del_user_db()
    bot.delete_message(wait_msg.chat.id, wait_msg.id)
    return god_draft
Пример #14
0
def poll_callback_handler(call):
    bot.answer_callback_query(call.id)
    bot.send_message(call.message.chat.id, "Remember few points")
    bot.send_message(call.message.chat.id,
                     "1. User can create only one poll at a time")
    bot.send_message(call.message.chat.id,
                     "2. For any poll only first reponse will be recorded")
    bot.send_message(call.message.chat.id,
                     "3. Poll cannot have multiple responses ")
    bot.send_message(call.message.chat.id,
                     "Enter briefy what the poll is about")
    bot.register_next_step_handler(call.message, create_poll)
Пример #15
0
def logout(user):
    try:
        user.del_user_db()
        bot.send_message(
            user.chat_id,
            "Ohhhh okay then byeee....\n\nNote: After logout all your data will be deleted from our DB and cache.\n Send /hi or /start again to start"
        )
        del users_dict[user.chat_id]
    except:
        print("Issue deleting user!!")
        bot.send_message(user.chat_id,
                         "Error while logging out. Send /hi or /start again.")
Пример #16
0
def login_callback(call):
    bot.answer_callback_query(call.id)
    if not is_reg(call.message):
        bot.answer_callback_query(call.id)
        bot.send_message(
            call.message.chat.id,
            "you are not even logged in dada.\n Please click /start")
    else:
        bot.answer_callback_query(call.id)
        if call.message.chat.id in users_dict:
            logout(users_dict[call.message.chat.id])
        else:
            bot.send_message(call.message.chat.id,
                             "Sorry!! we messed up .. :(\n just click /start")
Пример #17
0
 def tatticode(call):
     bot.answer_callback_query(call.id)
     course_name = call.data[8:]
     if call.data[0] == "a":
         msg = bot.send_message(call.message.chat.id, "please add a name for link in "+course_name)
         bot.register_next_step_handler(msg, get_name, course_name)
     elif call.data[0] == "r":
         print("remo")
         local_links = links[course_name]
         markup = InlineKeyboardMarkup()
         markup.row_width = len(local_links.keys())
         for text, url in local_links.items():
             markup.add(InlineKeyboardButton(text, callback_data="linkrem_"+text))
         bot.send_message(call.message.chat.id, "please select a link to delete..", reply_markup=markup)
Пример #18
0
def analytics_manager(data, user):
    if data == "enable_analytics_no":
        user.flags['analytics_enabled'] = False
        set_flag(user.username, "analytics_enabled", False)
        msg = bot.send_message(user.chat_id, "okay, Your new marks will not be used for analytics from now.")
        time.sleep(5)
        bot.delete_message(user.chat_id, msg.id)
    if data == "enable_analytics_yes":
        user.flags['analytics_enabled'] = True
        set_flag(user.username, "analytics_enabled", True)
        msg = bot.send_message(user.chat_id,
                               "okay, but opting in and out multiple time will block the feature for you.")
        time.sleep(5)
        bot.delete_message(user.chat_id, msg.id)
Пример #19
0
def get_poll_result(message):
    user = users_dict[message.chat.id]
    current_poll = user.current_poll
    options = current_poll.options
    response = current_poll.response
    total_response = current_poll.total_response
    bot.send_message(message.chat.id,
                     "Total " + str(total_response) + " response")
    for index, resp_count in current_poll.response.items():
        bot.send_message(
            message.chat.id,
            str(options[index]) + " - " + str(
                (response[index] / total_response) * 100) + "%")
    user.current_poll = None
Пример #20
0
def announce_callback_handler(call):
    if call.data == "announcement":
        bot.answer_callback_query(call.id)
        if call.message.chat.id in users_dict:
            get_announcement(call.message, users_dict[call.message.chat.id])
        else:
            bot.send_message(call.message.chat.id, "Please /start again")
    elif call.data == "refresh_anc":
        bot.answer_callback_query(call.id)
        user = users_dict[call.message.chat.id]
        user.request_no = 0
        if call.message.chat.id in users_dict:
            get_announcement(call.message, users_dict[call.message.chat.id])
        else:
            bot.send_message(call.message.chat.id, "Please /start again")
Пример #21
0
def get_classlinks(message):
    if message.chat.id not in users_dict:
        bot.send_message(message.chat.id, "Please click /start again....")
    else:
        user = users_dict[message.chat.id]
        for course in user.enrolled_courses:
            markup = InlineKeyboardMarkup()
            if course in links.keys():
                local_links = links[course]
                markup.row_width = len(local_links.keys())
                for text, url in local_links.items():
                    markup.add(InlineKeyboardButton(text, url=url))
            else:
                markup.add(InlineKeyboardButton("No links found"))
            bot.send_message(message.chat.id, course, reply_markup=markup)
Пример #22
0
def display_poll(message):
    user = users_dict[message.chat.id]
    current_poll = user.current_poll
    answered_poll = user.answered_poll
    if bool(answered_poll) and current_poll in answered_poll:
        bot.send_message(message.chat.id,
                         "You have already answered to this poll")
        get_poll_result(message)
    else:
        #bot.send_message(message.chat.id, str(current_poll.question))
        markup = InlineKeyboardMarkup()
        markup.row_width = 1
        for index, option in current_poll.options.items():
            markup.add(InlineKeyboardButton(text=option, callback_data=index))
        bot.send_message(message.chat.id,
                         str(current_poll.question),
                         reply_markup=markup)
Пример #23
0
def get_options(message):
    current_option = message.text
    poll = poll_dict[message.chat.id]
    options = poll.options
    if not options:
        poll.options = {
            "Option " + str(poll.current_option_no): current_option
        }
    else:
        options["Option " + str(poll.current_option_no)] = current_option
        poll.options = options
    poll.current_option_no += 1
    if poll.current_option_no <= poll.no_of_options:
        bot.reply_to(message, "Give option " + str(poll.current_option_no))
        bot.register_next_step_handler(message, get_options)
    else:
        bot.send_message(message.chat.id, "Poll has been created")
Пример #24
0
def get_session(message, user):
    msg = bot.send_message(user.chat_id, "Getting session details.....")
    header_auth['Authorization'] = user.jwt_token
    header_auth['X-CSRFToken'] = user.cs_token
    header_auth['session'] = user.session
    try:
        sessions = requests.get(url=aviral_sessions_api, headers=header_auth).json()
        markup = InlineKeyboardMarkup()
        markup.row_width = 2
        for i in sessions:
            if i["current"]:
                markup.add(InlineKeyboardButton(i['name'], callback_data="getmarks_" + i['session_id']))
        bot.send_message(user.chat_id, "Which Session??", reply_markup=markup)
    except Exception as e:
        print("error getting session")
        print(str(e))
        bot.send_message(user.chat_id, "error getting session details. /start again")
    bot.delete_message(msg.chat.id, msg.id)
Пример #25
0
def get_active_poll(message):
    user = users_dict[message.chat.id]
    active_poll = {}
    counter = 1
    if bool(poll_dict):
        for message_id, poll in poll_dict.items():
            active_poll["Active Poll " + str(counter)] = poll
            counter += 1
        user.active_poll = active_poll
        markup = InlineKeyboardMarkup()
        markup.row_width = 1
        for index, poll in active_poll.items():
            markup.add(
                InlineKeyboardButton(text=poll.about_poll,
                                     callback_data=index))
        bot.send_message(message.chat.id,
                         "Choose a poll to answer",
                         reply_markup=markup)
    else:
        bot.send_message(message.chat.id, "There is no active poll")
Пример #26
0
def front_page(user, message):
    bot.send_message(message.chat.id, "Hiii " + user.name + " ... ")
    markup = InlineKeyboardMarkup()
    markup.row_width = 1
    #
    markup.add(
        InlineKeyboardButton("Aviral marks " + emojis.get_emoji("bar_chart"),
                             callback_data="aviral")
    )  # InlineKeyboardButton("New announcements", callback_data="announcement")
    markup.add(
        InlineKeyboardButton("OPT IN/OUT for Marks Analytics",
                             callback_data="enable_analytics"))
    markup.add(
        InlineKeyboardButton("Online Class links", callback_data="classlinks"))
    markup.add(
        InlineKeyboardButton("Logout", callback_data="logout")
    )  # InlineKeyboardButton("Create Poll", callback_data="create_poll"),
    markup.row_width = 2
    markup.add(InlineKeyboardButton("About", callback_data="about"),
               InlineKeyboardButton("FAQ", callback_data="faq"))
    if user.is_admin:
        bot.send_message(message.chat.id, "Awesome you are an admin!!!")
        markup.add(
            InlineKeyboardButton("Admin Panel", callback_data="admin_panel"))
    bot.send_message(message.chat.id,
                     "Here are some things you can do",
                     reply_markup=markup)
Пример #27
0
def enable_analytics(message, user):
    if user.flags['analytics_enabled']:
        yes_msg = "You have analytics enabled.\n\n Analytics do not share anything and does not even have any open api " \
                  "to access any records, as aviral dont provide any analytics so we have" \
                  + "to maintain our own little DB to give you analytics. It is not shared and all the code is hosted " \
                    "on " \
                    "github so you can ensure that there is no API support for any privacy" \
                  + " invading calls."
        msg = bot.send_message(message.chat.id, yes_msg)
        # time.sleep(10)
        # bot.delete_message(message.chat.id, msg.id)
        yes_msg = "But still if you dont want to contribute to rank analytics then it okay too. You can opt out from " \
                  "here. You can still use ZeNo as before but without analytics. \n\n"
        yes_msg += "Here are some things to keep in mind when opting out.\n" \
                   + "1. You wont be able to see your ranks also.\n" \
                   + "2. Your old data will take time to flush out from system but your new marks will not be stored " \
                     "from immediate effect.\n" \
                   + "3. As of now you can't opt in one you opt out.\n\n\n\n Please wait......"
        msg1 = bot.send_message(message.chat.id, yes_msg)
        time.sleep(10)
        bot.delete_message(message.chat.id, msg.id)
        bot.delete_message(message.chat.id, msg1.id)
        markup = InlineKeyboardMarkup()
        markup.row_width = 2
        markup.add(InlineKeyboardButton("Disable Analytics for me", callback_data="enable_analytics_no"),
                   InlineKeyboardButton("Cancel", callback_data="cancel"))
        bot.send_message(message.chat.id, "Do you want to opt out?", reply_markup=markup)
    else:
        markup = InlineKeyboardMarkup()
        markup.row_width = 2
        markup.add(InlineKeyboardButton("Enable Analytics for me", callback_data="enable_analytics_yes"),
                   InlineKeyboardButton("Cancel", callback_data="cancel"))
        bot.send_message(message.chat.id, "Do you want to opt in?", reply_markup=markup)
Пример #28
0
def message_handler(message):
    hello_msg = (
        "Hey, I am ZeNo. I was created to save your time so you can do your assignments with one hand!\n"
        "Please wait while i check your status.....")
    bot.send_message(message.chat.id, hello_msg)
    if (is_reg(message)):
        bot.send_message(message.chat.id, "you are registered with us!")
        front_page(users_dict[message.chat.id], message)
    else:
        bot.send_message(message.chat.id,
                         "ohhh! you are not logged in!",
                         reply_markup=gen_markup_login())
Пример #29
0
def admin_panel(message):
    bot.send_message(message.chat.id, "Admins have superpowers!!! Use it wisely.")
    markup = InlineKeyboardMarkup()
    for i, j in get_modules().items():
        markup.add(InlineKeyboardButton(j, callback_data=i))
    bot.send_message(message.chat.id, "Here are some things only admin can do", reply_markup=markup)
Пример #30
0
def classlinks_callback_handler(call):
    bot.answer_callback_query(call.id)
    res = helper.Pages.get_note(call.data)
    bot.send_message(call.message.chat.id, res)