예제 #1
0
파일: bot.py 프로젝트: manikanand06/tota-py
def term_selector(bot, update):
    query = update.callback_query
    chat_id = query.message.chat_id
    regNumber = database(chat_id, 'regNumber')
    umsPass = database(chat_id, 'umsPass')
    time_stamp = time()
    sess_start = database(chat_id, 'sess_start')
    if time_stamp - float(sess_start) <= 180:
        pickled_sess = db.hget(chat_id, 'sess_obj')
        sess = pickle.loads(pickled_sess)
    else:
        home_page = homeData(bot, update, regNumber, umsPass, chat_id, query)
        if home_page:
            sess = db.hget(chat_id, 'sess_obj')
            sess = pickle.loads(sess)
        else:
            return
    mte = Midterm(sess)
    mte.token_creator(mte.base_page)
    term_list = mte.term_list
    keyboared = []
    for index, item in enumerate(term_list):
        if item != None:
            keyboared.append(
                [ikb(item, callback_data='term_{}_{}'.format(item, index))])
    reply_keyboared_term = ikm(keyboared)
    bot.send_message(text="Choose Term -",
                     chat_id=chat_id,
                     reply_markup=reply_keyboared_term)
예제 #2
0
def received_information(bot, update, user_data):
    p = StrictRedis()
    text = update.message.text
    reg_pattern = re.compile(r"^[0-9]*$")
    category = user_data['choice']
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    if (category == 'Reg. Number'):
        if (re.match(reg_pattern, text) and len(text) <= 8):
            user_data[category] = text
            lock = threading.Lock()
            with lock:
                p.hset(update.message.chat_id, 'umsReg', text)
                del user_data['choice']
                update.message.reply_text("Now click on Password",
                                          reply_markup=markup_setup)
                return CHOOSING
        else:
            update.message.reply_text("Please enter a valid %s!" %
                                      user_data['choice'])
        return CHOOSING
    else:
        user_data[category] = text
        lock1 = threading.Lock()
        with lock1:
            p.hset(update.message.chat_id, 'umsPass', text)
            del user_data['choice']
            update.message.reply_text(
                "Thanks for entering Password!",
                reply_markup=ikm([[ikb('Load Data', callback_data='load')]]))
            return LOAD
예제 #3
0
파일: bot.py 프로젝트: manikanand06/tota-py
def received_information(bot, update, user_data):
    chat_id = update.message.chat_id
    text = update.message.text
    reg_pattern = re.compile(r"^[0-9]*$")
    category = user_data['choice']
    regNumber = None
    umsPass = None
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING,
                         timeout=3)
    if (category == 'Reg. Number'):
        if (re.match(reg_pattern, text) and len(text) <= 8):
            user_data[category] = text
            db.hset(chat_id, 'regNumber', text)
            del user_data['choice']
            update.message.reply_text("Now click on Password",
                                      reply_markup=markup_reg)
            return CHOOSING
        else:
            update.message.reply_text("Please enter a valid %s!" %
                                      user_data['choice'])
        return TYPING_REPLY
    else:
        user_data[category] = text
        umsPass = text
        db.hset(chat_id, 'umsPass', umsPass)
        del user_data['choice']
        update.message.reply_text(
            "Thanks for entering Password!",
            reply_markup=ikm([[ikb('Load Data', callback_data='load')]]))
        return LOAD
예제 #4
0
파일: bot.py 프로젝트: manikanand06/tota-py
def delme(bot, update):
    chat_id = update.message.chat_id
    db.delete(chat_id, '{}-msg'.format(chat_id),
              '{}-courselist'.format(chat_id), '{}-mte'.format(chat_id))
    update.message.reply_text(
        'Your data is erased.\nPlease press "Setup" to register.',
        reply_markup=ikm([[ikb('Setup', callback_data='Setup')]]))
    return -1
예제 #5
0
def options(bot, update):
    query = update.callback_query
    chat_id = query.message.chat_id
    d = StrictRedis()
    l = sorted(d.hkeys(chat_id))
    choice = query.data
    if choice == "Messages":
        counter = int(d.hget(chat_id, '#msg'))
        for i in range(0, counter):
            k = d.hget(chat_id, 'msg' + str(i))
            annc_sub, annc_by, annc_body = k.split('|')
            if i == counter - 1:
                bot.send_message(text=annc_sub + '\n\n' + annc_by + '\n\n' +
                                 annc_body,
                                 chat_id=chat_id,
                                 reply_markup=markup_options)
            else:
                bot.send_message(text=annc_sub + '\n\n' + annc_by + '\n\n' +
                                 annc_body,
                                 chat_id=chat_id)

        return
    elif choice == "Resources":
        num_courses = int(d.hget(chat_id, '#course'))
        course_markup = []
        temp = []
        t = []
        for i in range(0, num_courses, 2):
            if i + 1 < num_courses:
                course_markup.append([
                    ikb('{}'.format(d.hget(chat_id, 'c{}'.format(i))),
                        callback_data='{}'.format(
                            d.hget(chat_id, 'c{}'.format(i)))),
                    ikb('{}'.format(d.hget(chat_id, 'c{}'.format(i + 1))),
                        callback_data='{}'.format(
                            d.hget(chat_id, 'c{}'.format(i + 1))))
                ])
            else:
                course_markup.append([
                    ikb('{}'.format(d.hget(chat_id, 'c{}'.format(i))),
                        callback_data='{}'.format(
                            d.hget(chat_id, 'c{}'.format(i))))
                ])
        bot.send_message(text="Choose Subject --",
                         chat_id=chat_id,
                         reply_markup=ikm(course_markup))

    else:
        update.message.reply_text("Sorry Wrong Input!")
        return
예제 #6
0
 def msgDispatcher():
     lock = threading.Lock()
     with lock:
         chat_id = str(update.message.chat_id)
         if (chat_id in l) and (r.hget(chat_id, 'umsReg')) and (r.hget(
                 chat_id, 'umsPass')):
             update.message.reply_text('Welcome Back!',
                                       reply_markup=markup_options)
             return
         else:
             r.hmset(chat_id, data)
             update.message.reply_text(
                 "Hi Dear\n\n"
                 "I hope you are fine. My name is ToTa. "
                 "I am your personal bot to handle your daily tedious tasks of UMS. "
                 "\n\nI am created by Shekh Ataul.\nA.K.A -- DEVIL!"
                 "\n\nTo Get Started Press: Setup",
                 reply_markup=ikm([[ikb('Setup', callback_data='setup')]]))
             return
예제 #7
0
파일: bot.py 프로젝트: manikanand06/tota-py
def start(bot, update):
    chat_id = update.message.chat_id
    if (db.hexists(chat_id,
                   'regNumber')) and (db.hexists(chat_id, 'umsPass') and
                                      (db.exists('{}-msg'.format(chat_id)))):
        user = update.message.from_user
        user_full_name = '{} {}'.format(user.first_name, user.last_name)
        update.message.reply_text('Welcome back {}'.format(user_full_name),
                                  reply_markup=markup_options)
        return
    else:
        update.message.reply_text(
            "Hi Dear\n\n"
            "I hope you are fine. My name is *ToTa*  "
            "I am your personal bot to handle your daily tedious tasks of UMS "
            "\n\nI am created by *Shekh Ataul*\nA.K.A -- *DEVIL!*"
            "\n\nTo Get Started Press: *Setup*",
            reply_markup=ikm([[ikb('Setup', callback_data='Setup')]]),
            parse_mode=ParseMode.MARKDOWN)
예제 #8
0
def res(bot, update):
    c = StrictRedis()
    query = update.callback_query
    chat_id = query.message.chat_id
    course = query.data
    regNumber = c.hget(chat_id, 'umsReg')
    umsPass = c.hget(chat_id, 'umsPass')
    try:
        homeUms = Verto(regNumber, umsPass)
        homeData = homeUms.initiater()
        if homeData != 'Incorrect Credentials':
            pass
        else:
            bot.edit_message_text(text='Incorrect Credentials',
                                  chat_id=chat_id,
                                  message_id=query.message.message_id)
            raise ValueError("Something Went Wrong")
    except ValueError as error:
        return
    else:
        courseIns = Resources(homeUms.session, course)
        resList = courseIns.reslist()
        for i, item in enumerate(resList):
            txt = item[-1]
            start = txt.find('$lblFileUplaodByTeacher')
            txt = txt[start - 5:start]
            if item[2] == u'\xa0':
                item[2] = ''
            res_num_markup = ikm([[
                ikb('Download',
                    callback_data='hot{}YinZ{}'.format(course, txt))
            ]])
            text_data = 'Course - {}\n{} \n\n {}\n\n {}'.format(
                course, item[0], item[1].strip(), item[2].strip())
            bot.send_message(text=text_data,
                             chat_id=chat_id,
                             reply_markup=res_num_markup)
            x = '|'.join(item)
            c.hset(chat_id, '{}_{}'.format(course, item[-1]), x)
예제 #9
0
파일: bot.py 프로젝트: manikanand06/tota-py
def course_selected_data(bot, update):
    print('Course selected data Started')
    query = update.callback_query
    chat_id = query.message.chat_id
    course_selected = query.data
    regNumber = database(chat_id, 'regNumber')
    umsPass = database(chat_id, 'umsPass')
    time_stamp = time()
    sess_start = database(chat_id, 'sess_start')
    if time_stamp - float(sess_start) <= 180:
        pickled_sess = db.hget(chat_id, 'sess_obj')
        sess = pickle.loads(pickled_sess)
    else:
        home_page = homeData(bot, update, regNumber, umsPass, chat_id, query)
        if home_page:
            sess = db.hget(chat_id, 'sess_obj')
            sess = pickle.loads(sess)
        else:
            return
    course_data = Resources(sess, course_selected)
    course_data_list = course_data.course_content_list()
    for i, item in enumerate(course_data_list):
        txt = item[-1]
        start = txt.find('$lblFileUplaodByTeacher')
        txt = txt[start - 5:start]
        if item[2] == u'\xa0':
            item[2] = ''
        res_num_markup = ikm([[
            ikb('Download',
                callback_data='hot{}YinZ{}'.format(course_selected, txt))
        ]])
        text_data = 'Course - {}\n{} \n\n {}\n\n {}'.format(
            course_selected, item[0], item[1].strip(), item[2].strip())
        bot.send_message(text=text_data,
                         chat_id=chat_id,
                         reply_markup=res_num_markup)
        x = '|'.join(item)
        db.hset(chat_id, '{}_{}'.format(course_selected, item[-1]), x)
예제 #10
0
파일: bot.py 프로젝트: manikanand06/tota-py
def options(bot, update):
    print("Optins function starting......")
    query = update.callback_query
    chat_id = query.message.chat_id
    choice = query.data
    if choice == "Messages":
        msg_reader(bot, update, chat_id)

    elif choice == "Resources":
        regNumber = database(chat_id, 'regNumber')
        umsPass = database(chat_id, 'umsPass')
        course_db(bot, update, regNumber, umsPass, chat_id, query)
        course_markup = []
        temp = []
        t = []
        course_key = '{}-courselist'.format(chat_id)
        p = db.hkeys(course_key)
        num_courses = len(p)
        for i, item in enumerate(p):
            p[i] = item.decode('UTF-8')
        for i in range(0, num_courses, 2):
            key = '{}'.format(p[i])
            if i + 1 < num_courses:
                key1 = '{}'.format(p[i + 1])
                course_markup.append([
                    ikb(key, callback_data=key),
                    ikb(key1, callback_data=key1)
                ])
            else:
                course_markup.append([ikb(key, callback_data=key)])
        bot.send_message(text="Choose Subject --",
                         chat_id=chat_id,
                         reply_markup=ikm(course_markup))
    else:
        update.message.reply_text("Sorry Wrong Input!")
        return
예제 #11
0
import telegram
from user import Verto
from message import Message
from assingment import Resources
from multiprocessing import Pool

CHOOSING, TYPING_REPLY, TYPING_CHOICE, LOAD = range(4)
reply_keyboared_setup = [[
    ikb('Reg. Number', callback_data='Reg. Number'),
    ikb('Password', callback_data='Password')
]]
reply_keyboared_options = [[
    ikb('Messages', callback_data='Messages'),
    ikb('Resources', callback_data='Resources')
]]
markup_setup = ikm(reply_keyboared_setup)
markup_options = ikm(reply_keyboared_options)

logging.basicConfig(
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')


@run_async
def start(bot, update):
    r = StrictRedis()

    data = {
        'umsReg': '',
        'umsPass': '',
        'msg0': '',
예제 #12
0
파일: bot.py 프로젝트: manikanand06/tota-py
    level=logging.DEBUG,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

CHOOSING, TYPING_REPLY, TYPING_CHOICE, LOAD = range(4)

reply_keyboared_reg = [[
    ikb('Reg. Number', callback_data='Reg. Number'),
    ikb('Password', callback_data='Password')
]]
reply_keyboared_options = [[
    ikb('Messages', callback_data='Messages'),
    ikb('Resources', callback_data='Resources'),
    ikb('MTE Marks', callback_data='marks')
]]

markup_reg = ikm(reply_keyboared_reg)
markup_options = ikm(reply_keyboared_options)


##Database Methods
def delme(bot, update):
    chat_id = update.message.chat_id
    db.delete(chat_id, '{}-msg'.format(chat_id),
              '{}-courselist'.format(chat_id), '{}-mte'.format(chat_id))
    update.message.reply_text(
        'Your data is erased.\nPlease press "Setup" to register.',
        reply_markup=ikm([[ikb('Setup', callback_data='Setup')]]))
    return -1


def database(name, key):