Python telegram.ext.ConversationHandler.END Examples

The following are 24 code examples of telegram.ext.ConversationHandler.END(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module telegram.ext.ConversationHandler , or try the search function .
Example #1
Source File: ranklist.py    From superCodingBot with MIT License 9 votes vote down vote up
def polo(self, bot, update, user_data):
        msg = update.message.text.upper()
        conn = sqlite3.connect(self.mount_point + 'coders1.db')
        c = conn.cursor()
        c.execute("SELECT name FROM handles WHERE name=(?)", (msg,))
        if c.fetchone():
            keyboard = [[InlineKeyboardButton("Hackerearth", callback_data='HElist8'),
                         InlineKeyboardButton("Hackerrank", callback_data='HRlist8')],
                        [InlineKeyboardButton("Codechef", callback_data='CClist8'),
                         InlineKeyboardButton("Spoj", callback_data='SPlist8')],
                        [InlineKeyboardButton("Codeforces", callback_data='CFlist8'),
                         InlineKeyboardButton("ALL", callback_data='ALLlist8')]]
            reply_markup = InlineKeyboardMarkup(keyboard)
            update.message.reply_text('please select the judge or select all for showing all',
                                      reply_markup=reply_markup)
            user_data['name1'] = msg
            conn.close()
            return XOLO
        else:
            conn.close()
            update.message.reply_text("Sorry this name is not registered with me.")
            return ConversationHandler.END

    # FUNCTION TO SHOW THE KIND OF RANKLIST USER WANTS 
Example #2
Source File: commands.py    From CryptoKitties with MIT License 6 votes vote down vote up
def attribute_list(self,bot,update):
		try:
			with closing(self.conn.cursor()) as cur:
				uid = update.message.from_user.id
				if str.lower(update.message.text) == "end":
					message = "Thanks for registering =)\n"
					message = "If you want to toggle 10 minute scans, please do a /alert"
					update.message.reply_text(message,parse_mode='HTML')
					return ConversationHandler.END
				else:
					cur.execute("""INSERT INTO Attribute VALUES(%s,%s)""",(uid,update.message.text,))
					message= update.message.text
					message += " has been added as an attribute. Please enter the next attribute \n"
					message += "If you're done with adding your cattributes, please reply with end"
					update.message.reply_text(message,parse_mode='HTML')
					return ATTLIST

		except Exception as e:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=Tokens().error_channel(),text=catcherror,parse_mode='HTML') 
Example #3
Source File: commands.py    From CryptoKitties with MIT License 6 votes vote down vote up
def register(self, bot,update):
		try:
			with closing(self.conn.cursor()) as cur:
				uid = update.message.from_user.id
				cur.execute("""SELECT telegram_id FROM User WHERE telegram_id = %s""",(uid,))
				if cur.rowcount == 0:
					message = "Registering you in my database! \n"
					message += "Can I please have the generation index?\n"
					message += "This bot will search for the generation index less than or equals to the number you input\n"
					message += "If you feel threatened at any point of time, do a /cancel to abort this conversation."
					cur.execute("""INSERT INTO User VALUES(%s,NULL,NULL,NULL,NULL,'No')""",(uid,))
					update.message.reply_text(message,parse_mode='HTML')
					return GENERATION
				else:
					message = "You are already registered in my database. To remove your details, do a /forget"
					update.message.reply_text(message,parse_mode='HTML')
					return ConversationHandler.END


		except Exception as e:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=Tokens().error_channel(),text=catcherror,parse_mode='HTML') 
Example #4
Source File: admin.py    From superCodingBot with MIT License 6 votes vote down vote up
def broadcast_message(self, bot, update):
        message = update.message.text
        conn = sqlite3.connect(self.mount_point + 'coders1.db')
        c = conn.cursor()
        c.execute('select id from handles union select id from subscribers')
        for row in c.fetchall():
            try:
                bot.send_message(text=message, chat_id=row[0])
            except:
                pass
            time.sleep(1)
        c.close()
        conn.close()
        return ConversationHandler.END

    # END OF ADMIN CONVERSATION HANDLER TO BROADCAST MESSAGE

    # START OF ADMIN CONVERSATION HANDLER TO REPLACE THE DATABASE 
Example #5
Source File: compiler.py    From superCodingBot with MIT License 6 votes vote down vote up
def code(bot, update, user_data):
        query = update.callback_query
        val = query.data
        val = str(val).replace("so1", "")
        if val == "code":
            bot.edit_message_text(
                text="selected",
                chat_id=query.message.chat_id, message_id=query.message.message_id)
            bot.send_message(chat_id=query.message.chat_id, text="please enter your code\n"
                                                                  "Please make sure that "
                                                                  "the first line is not a comment line",
                             reply_markup=ForceReply(True))
            return DECODE
        elif val == "file":
            bot.edit_message_text(text="please send your .txt file\nMaximum size 2mb", chat_id=query.message.chat_id,
                                  message_id=query.message.message_id)
            return FILE
        else:
            return ConversationHandler.END

    # FUNCTION TO GET TESTCASE FILE 
Example #6
Source File: compiler.py    From superCodingBot with MIT License 6 votes vote down vote up
def filetest(self, bot, update, user_data):
        file_id = update.message.document.file_id
        if ComHandler.check_file_size(update):
            return ConversationHandler.END
        newFile = bot.get_file(file_id)
        newFile.download('test.txt')
        with open('test.txt', 'rt') as f:
            source = f.read()
        s1 = (str(user_data['code'])).replace("«", "<<").replace("»", ">>")
        result = self.compiler.run({'source': s1,
                               'lang': user_data['lang'],
                               'testcases': [source]
                               })
        Utility.paginate(bot, update, result)
        user_data.clear()
        os.remove('test.txt')
        return ConversationHandler.END 
Example #7
Source File: compiler.py    From superCodingBot with MIT License 6 votes vote down vote up
def filer(bot, update, user_data):
        file_id = update.message.document.file_id
        if ComHandler.check_file_size(update):
            return ConversationHandler.END
        newFile = bot.get_file(file_id)
        newFile.download('abcd.txt')
        with open('abcd.txt', 'r') as f:
            source = f.read()
        user_data['code'] = source
        custom_keyboard = [['#no test case', '#send a .txt file']]
        reply_markup = ReplyKeyboardMarkup(custom_keyboard, one_time_keyboard=True, resize_keybord=True)
        update.message.reply_text(
            'Please send test cases together as you would do in online ide\nIf you dont want to provide test cases select #no test case\n I you want to send test cases as .txt file select #send a .txt file',
            reply_markup=reply_markup)
        # REMOVING THE FILE AFTER PROCESS IS COMPLETE
        os.remove('abcd.txt')
        return TESTCASES

    # FUNCTION TO GET THE SOURCE CODE SENT BY USER 
Example #8
Source File: codeforces.py    From superCodingBot with MIT License 6 votes vote down vote up
def qselcf(self, bot, update):
        query = update.callback_query
        val = query.data
        if val == 'Acf1':
            strn = self.get_random_ques('A')
        elif val == 'Bcf1':
            strn = self.get_random_ques('B')
        elif val == 'Ccf1':
            strn = self.get_random_ques('C')
        elif val == 'Dcf1':
            strn = self.get_random_ques('D')
        elif val == 'Ecf1':
            strn = self.get_random_ques('E')
        elif val == 'Fcf1':
            strn = self.get_random_ques('F')
        elif val == 'OTHERScf1':
            strn = self.get_random_ques('OTHERS')
        val = str(val).replace("cf1", "")
        bot.edit_message_text(
            text="Random " + val + " question from codeforces\n\n" + strn,
            chat_id=query.message.chat_id,
            message_id=query.message.message_id)
        return ConversationHandler.END
        # END OF CONVERSATION HANDLER FOR GETTING RANDOM QUESTION FROM CODEFORCES 
Example #9
Source File: ranklist.py    From superCodingBot with MIT License 5 votes vote down vote up
def solo(self, bot, update):
        query = update.callback_query
        val = query.data
        choices = ['HElist7', 'HRlist7', 'CClist7', 'SPlist7', 'CFlist7', 'ALLlist7']
        if val not in choices:
            return ConversationHandler.END
        val = str(val).replace("list7", "")
        conn = sqlite3.connect(self.mount_point + 'coders1.db')
        c = conn.cursor()
        if val == "ALL":
            a = str(query.from_user.id)
            bot.edit_message_text(text='Sending please wait',
                                  chat_id=query.message.chat_id,
                                  message_id=query.message.message_id)
            mysel = c.execute("SELECT name, HE, HR, SP, CC, CF FROM datas WHERE id=" + a)
            self.utility.xlsx_creator(mysel, 'me.xlsx')
            bot.send_document(chat_id=query.message.chat_id, document=open('me.xlsx', 'rb'))
            os.remove('me.xlsx')
        else:
            a = str(query.from_user.id)
            c.execute("SELECT " + val + " FROM datas WHERE id=" + a)
            for i in c.fetchall():
                if i[0] is None or i[0] == "":
                    bot.edit_message_text(text="NOT REGISTERED",
                                          chat_id=query.message.chat_id,
                                          message_id=query.message.message_id)
                else:
                    bot.edit_message_text(text="" + i[0],
                                          chat_id=query.message.chat_id,
                                          message_id=query.message.message_id)
        conn.commit()
        conn.close()
        return ConversationHandler.END

    # FUNCTION TO GET THE RANKLIST MENU OF THE USER BY SEARCHING HIS NAME 
Example #10
Source File: commands.py    From CryptoKitties with MIT License 5 votes vote down vote up
def cancel(self,bot,update):
		try:
			with closing(self.conn.cursor()) as cur:
				uid = update.message.from_user.id
				message = "And here I was, thinking we could be friends :("
				update.message.reply_text(message,parse_mode='HTML')
				cur.execute("""DELETE FROM User WHERE telegram_id = %s""",(uid,))
				cur.execute("""DELETE FROM Attribute WHERE telegram_id = %s""",(uid,))
				return ConversationHandler.END


		except Exception as e:
			catcherror = traceback.format_exc()
			bot.sendMessage(chat_id=Tokens().error_channel(),text=catcherror,parse_mode='HTML') 
Example #11
Source File: admin.py    From superCodingBot with MIT License 5 votes vote down vote up
def getDb(self, bot, update):
        if self.not_admin(update):
            return ConversationHandler.END
        update.message.reply_text("send your sqlite database")
        return DB 
Example #12
Source File: admin.py    From superCodingBot with MIT License 5 votes vote down vote up
def broadcast(self, bot, update):
        if self.not_admin(update):
            return ConversationHandler.END
        update.message.reply_text("Send your message")
        return BDC 
Example #13
Source File: register.py    From superCodingBot with MIT License 5 votes vote down vote up
def judge(bot, update, user_data):
        query = update.callback_query
        choices = ['HEreg1', 'HRreg1', 'CFreg1', 'CCreg1', 'SPreg1']
        if query.data not in choices:
            return ConversationHandler.END
        user_data['code'] = str(query.data).replace("reg1", "")
        bot.edit_message_text(text='selected',
                              chat_id=query.message.chat_id,
                              message_id=query.message.message_id)
        bot.send_message(chat_id=query.message.chat_id, text="please enter your handle",reply_markup=ForceReply(True))
        return HANDLE 
Example #14
Source File: ranklist.py    From superCodingBot with MIT License 5 votes vote down vote up
def holo(self, bot, update):
        query = update.callback_query
        val = query.data
        choices = ['HElist6', 'HRlist6', 'CClist6', 'SPlist6', 'CFlist6', 'ALLlist6']
        if val not in choices:
            return ConversationHandler.END
        val = str(val).replace("list6", "")
        if val == "ALL":
            try:
                bot.edit_message_text(text='I am sending you the details',
                                      chat_id=query.message.chat_id,
                                      message_id=query.message.message_id)
                bot.send_document(chat_id=query.message.chat_id, document=open(self.mount_point + 'all.xlsx', 'rb'))
            except FileNotFoundError:
                bot.edit_message_text(text='Sorry no entry found',
                                      chat_id=query.message.chat_id,
                                      message_id=query.message.message_id)
                return ConversationHandler.END
        else:
            try:
                bot.edit_message_text(text='I am sending you the details',
                                      chat_id=query.message.chat_id,
                                      message_id=query.message.message_id)
                bot.send_document(chat_id=query.message.chat_id, document=open(self.mount_point + val + ".xlsx", 'rb'))
            except FileNotFoundError:
                bot.edit_message_text(text='Sorry no entry found',
                                      chat_id=query.message.chat_id,
                                      message_id=query.message.message_id)
                return ConversationHandler.END
        return ConversationHandler.END 
Example #15
Source File: ranklist.py    From superCodingBot with MIT License 5 votes vote down vote up
def xolo(self, bot, update, user_data):
        query = update.callback_query
        val = query.data
        choices = ['HElist8', 'HRlist8', 'CClist8', 'SPlist8', 'CFlist8', 'ALLlist8']
        if val not in choices:
            return ConversationHandler.END
        val = str(val).replace("list8", "")
        name1 = user_data['name1']
        conn = sqlite3.connect(self.mount_point + 'coders1.db')
        c = conn.cursor()
        if val == "ALL":
            bot.edit_message_text(text='Sending please wait',
                                  chat_id=query.message.chat_id,
                                  message_id=query.message.message_id)
            mysel = c.execute("SELECT name, HE, HR, SP, CC, CF FROM datas WHERE name=(?)", (name1,))
            self.utility.xlsx_creator(mysel, 'det.xlsx')
            bot.send_document(chat_id=query.message.chat_id, document=open('det.xlsx', 'rb'))
            os.remove('det.xlsx')
        else:
            c.execute("SELECT " + val + " FROM datas WHERE name=(?)", (name1,))
            for i in c.fetchall():
                if i[0] is None or i[0] == "":
                    bot.edit_message_text(text="Not Registered",
                                          chat_id=query.message.chat_id,
                                          message_id=query.message.message_id)
                else:
                    bot.edit_message_text(text="" + i[0],
                                          chat_id=query.message.chat_id,
                                          message_id=query.message.message_id)
        user_data.clear()
        conn.close()
        return ConversationHandler.END

    # FUNCTION TO SHOW THE RANKLIST OF ALL THE PEOPLE 
Example #16
Source File: broadcasts.py    From BotListBot with MIT License 5 votes vote down vote up
def send_broadcast(bot, update, user_data):
    uid = update.effective_user.id

    try:
        bc = user_data['broadcast']
        text = bc['text']
        recipient = bc['target_chat_id']
        mode = bc.get('mode', 'just_send')
    except AttributeError:
        bot.formatter.send_failure(uid, "Missing attributes for broadcast. Aborting...")
        return ConversationHandler.END

    mid = bc.get('reply_to_message_id')

    if mode == 'replying':
        msg = util.send_md_message(bot, recipient, text, reply_to_message_id=mid)
    elif mode == 'editing':
        msg = bot.formatter.send_or_edit(recipient, text, to_edit=mid)
    else:
        msg = util.send_md_message(bot, recipient, text)

    # Post actions
    buttons = [
        InlineKeyboardButton(captions.PIN,
                             callback_data=util.callback_for_action('pin_message', {'mid': msg.message_id})),
        InlineKeyboardButton('Add "Thank You" counter',
                             callback_data=util.callback_for_action('add_thank_you',
                                                                    {'cid': recipient, 'mid': msg.message_id})),
    ]
    reply_markup = InlineKeyboardMarkup(util.build_menu(buttons, 1))
    mid = util.mid_from_update(update)
    action_taken = "edited" if mode == 'editing' else "broadcasted"
    bot.formatter.send_or_edit(uid, mdformat.success("Message {}.".format(action_taken)), mid, reply_markup=reply_markup) 
Example #17
Source File: compiler.py    From superCodingBot with MIT License 5 votes vote down vote up
def testcases(self, bot, update, user_data):
        markup = ReplyKeyboardRemove()
        s = update.message.text
        if s == "#send a .txt file":
            update.message.reply_text("Please send your testcases as a .txt file\nMaximum size 2mb",
                                      reply_markup=markup)
            return FILETEST
            # CONVERTING UNICODE CHARACTER TO DOUBLE GREATER THAN OR LESS THAN
            # WEIRD
        s1 = (str(user_data['code'])).replace("«", "<<").replace("»", ">>")
        if s == "#no test case":
            # USING COMPILER FUNCTION FROM helper.py script
            result = self.compiler.run({'source': s1,
                                   'lang': user_data['lang']
                                   })
            # GETTING OUTPUT FROM result CLASS in helper.py script
            Utility.paginate(bot, update, result)
        else:
            # AGAIN THE SAME DRILL
            result = self.compiler.run({'source': s1,
                                   'lang': user_data['lang'],
                                   'testcases': [s]
                                   })
            Utility.paginate(bot, update, result)
        user_data.clear()
        return ConversationHandler.END

    # FUNCTION FOR THE CASE WHERE USER HAD SELECTED OTHER 
Example #18
Source File: app.py    From superCodingBot with MIT License 5 votes vote down vote up
def receive_cf(self, bot, update):
        file_id = update.message.document.file_id
        newFile = bot.get_file(file_id)
        newFile.download(self.mount_point + 'codeforces.json')
        update.message.reply_text("saved")
        with open(self.mount_point + 'codeforces.json', 'r') as code_json:
            self.cf.change_cf(json.load(code_json))
        return ConversationHandler.END

    # END OF ADMIN CONVERSATION HANDLER TO REPLACE THE CODEFORCES JSON 
Example #19
Source File: app.py    From superCodingBot with MIT License 5 votes vote down vote up
def getCf(self, bot, update):
        if not str(update.message.chat_id) in self.admin_list:
            update.message.reply_text("sorry you are not an admin")
            return ConversationHandler.END
        update.message.reply_text("send your json file")
        return self.CF 
Example #20
Source File: app.py    From superCodingBot with MIT License 5 votes vote down vote up
def cancel(bot, update, user_data):
        update.message.reply_text('Cancelled')
        user_data.clear()
        return ConversationHandler.END

    # FUNCTION FOR LOGGING ALL KINDS OF ERRORS 
Example #21
Source File: ranklist.py    From superCodingBot with MIT License 4 votes vote down vote up
def selection(self, bot, update):
        query = update.callback_query
        val = query.data
        val = str(val).replace("sel1", "")
        if val == "all":
            keyboard = [[InlineKeyboardButton("Hackerearth", callback_data='HElist6'),
                         InlineKeyboardButton("Hackerrank", callback_data='HRlist6')],
                        [InlineKeyboardButton("Codechef", callback_data='CClist6'),
                         InlineKeyboardButton("Spoj", callback_data='SPlist6')],
                        [InlineKeyboardButton("Codeforces", callback_data='CFlist6'),
                         InlineKeyboardButton("ALL", callback_data='ALLlist6')]]
            reply_markup = InlineKeyboardMarkup(keyboard)
            bot.edit_message_text(text='please select the judge or select all for showing all',
                                  reply_markup=reply_markup,
                                  chat_id=query.message.chat_id,
                                  message_id=query.message.message_id)
            return HOLO
        elif val == "mine":
            conn = sqlite3.connect(self.mount_point + 'coders1.db')
            c = conn.cursor()
            print(str(query.from_user.id))
            c.execute("SELECT id FROM datas WHERE id=" + str(query.from_user.id))
            if c.fetchone():
                keyboard = [[InlineKeyboardButton("Hackerearth", callback_data='HElist7'),
                             InlineKeyboardButton("Hackerrank", callback_data='HRlist7')],
                            [InlineKeyboardButton("Codechef", callback_data='CClist7'),
                             InlineKeyboardButton("Spoj", callback_data='SPlist7')],
                            [InlineKeyboardButton("Codeforces", callback_data='CFlist7'),
                             InlineKeyboardButton("ALL", callback_data='ALLlist7')]]
                reply_markup = InlineKeyboardMarkup(keyboard)
                bot.edit_message_text(text='please select the judge or select all for showing all',
                                      reply_markup=reply_markup,
                                      chat_id=query.message.chat_id,
                                      message_id=query.message.message_id)
                c.close()
                return SOLO
            else:
                conn.close()
                bot.edit_message_text(
                    text='You are not registered to the bot. please register to it using /register command',
                    chat_id=query.message.chat_id,
                    message_id=query.message.message_id)
                return ConversationHandler.END

        elif val == "getName":
            bot.edit_message_text(text='selected',
                                  chat_id=query.message.chat_id,
                                  message_id=query.message.message_id)
            bot.send_message(text="please enter the name", chat_id=query.message.chat_id, reply_markup=ForceReply(True))
            return POLO
        else:
            return ConversationHandler.END

    # FUNCTION TO GET THE USERS RANKLIST 
Example #22
Source File: register.py    From superCodingBot with MIT License 4 votes vote down vote up
def handle(self, bot, update, user_data):
        user = str(update.message.from_user.id)
        handle1 = update.message.text
        name1 = user_data['name']
        code1 = user_data['code']
        rating_obj = ratings.Rating()
        all_data = rating_obj.getAllData(code1, handle1)
        if all_data is None:
            update.message.reply_text('wrong id')
            user_data.clear()
            return ConversationHandler.END
        conn = sqlite3.connect(self.mount_point + 'coders1.db')
        c = conn.cursor()
        c.execute("INSERT OR IGNORE INTO datas (id, name, " + code1 + ") VALUES (?, ?, ?)", (user, name1, all_data))
        c.execute("INSERT OR IGNORE INTO handles (id, name, " + code1 + ") VALUES (?, ?, ?)", (user, name1, handle1))
        if c.rowcount == 0:
            c.execute("UPDATE datas SET " + code1 + " = (?) , name= (?) WHERE id = (?) ", (all_data, name1, user))
            c.execute("UPDATE handles SET " + code1 + " = (?) , name= (?) WHERE id = (?) ", (handle1, name1, user))
        if code1 == 'SP':
            c.execute("INSERT OR IGNORE INTO priority (id) VALUES(?)", (user,))
        else:
            rating = rating_obj.parse_rating(code1, all_data)
            c.execute("INSERT OR IGNORE INTO priority (id," + code1 + ") VALUES(?, ?)", (user, rating))
            if c.rowcount == 0:
                c.execute("UPDATE  priority SET " + code1 + " = (?) WHERE id = (?) ", (rating, user))
        conn.commit()
        # BELOW LINES ARE USED TO CREATE XLSX FILES OF ALL SORTS OF RANKLIST
        # SO WHEN USER ASKS FOR RANKLIST THERE IS NO DELAY
        mysel = c.execute(
            "SELECT datas.name, datas.HE, datas.HR, datas.SP, datas.CF, datas.CC FROM datas INNER JOIN priority ON datas.id=priority.id ORDER BY CAST(priority.CF AS FLOAT) DESC, CAST(priority.CC AS FLOAT) DESC, CAST(priority.HR AS FLOAT) DESC, CAST(priority.HE AS FLOAT) DESC")
        Utility.xlsx_creator(mysel, self.mount_point + 'all.xlsx')
        if code1 == 'SP':
            mysel = c.execute("SELECT name, " + code1 + " FROM datas")
            Utility.xlsx_creator(mysel, self.mount_point + code1 + ".xlsx")
        else:
            mysel = c.execute(
                "SELECT datas.name, datas." + code1 + " FROM datas INNER JOIN priority ON datas.id=priority.id ORDER BY CAST(priority." + code1 + " AS FLOAT) DESC")
            Utility.xlsx_creator(mysel, self.mount_point + code1 + ".xlsx")
        conn.close()
        update.message.reply_text("Succesfully Registered")
        update.message.reply_text(name1 + "    \n" + all_data)
        user_data.clear()
        return ConversationHandler.END 
Example #23
Source File: geeks_for_geeks.py    From superCodingBot with MIT License 4 votes vote down vote up
def gfg2(bot, update, user_data):
        query = update.callback_query
        val = query.data
        val = str(val).replace("gfg2", "")
        if val == "Advanced Data Structures":
            keyboard = [[InlineKeyboardButton("Advanced Lists", callback_data='Advanced Listsgfg3'),
                         InlineKeyboardButton("Trie", callback_data='Triegfg3')],
                        [InlineKeyboardButton("Suffix Array and Suffix Tree",
                                              callback_data='Suffix Array and Suffix Treegfg3'),
                         InlineKeyboardButton("AVL Tree", callback_data='AVL Treegfg3')],
                        [InlineKeyboardButton("Splay Tree",
                                              callback_data='Splay Treegfg3'),
                         InlineKeyboardButton("B Tree", callback_data='B Treegfg3')],
                        [InlineKeyboardButton("Segment Tree", callback_data='Segment Treegfg3'),
                         InlineKeyboardButton("Red Black Tree", callback_data='Red Black Treegfg3')],
                        [InlineKeyboardButton("K Dimensional Tree", callback_data='K Dimensional Treegfg3'),
                         InlineKeyboardButton("Others", callback_data='Othersgfg3')]]
            reply_markup = InlineKeyboardMarkup(keyboard)
            bot.edit_message_text(text="Please select", reply_markup=reply_markup, chat_id=query.message.chat_id,
                                  message_id=query.message.message_id)
            return GFG3
        else:
            try:
                with open("geeks_for_geeks/"+user_data['gfg'], encoding='utf-8') as data_file:
                    data = json.load(data_file)
                se = data[val]
                s = ""
                s1 = ""
                a = 0
                for i in se:
                    a = a + 1
                    if a <= 50:
                        s = s + '<a href="' + se[i] + '">' + i + '</a>\n\n'
                    else:
                        s1 = s1 + '<a href="' + se[i] + '">' + i + '</a>\n\n'
                bot.edit_message_text(text=val + "\n\n" + s, chat_id=query.message.chat_id,
                                      message_id=query.message.message_id, parse_mode=ParseMode.HTML)
                if len(s1) != 0:
                    bot.send_message(text=val + "\n\n" + s1, chat_id=query.message.chat_id, parse_mode=ParseMode.HTML)
            except:
                return ConversationHandler.END
            user_data.clear()
            return ConversationHandler.END

    # FUNCTION TO SHOW SUBMENU 3 
Example #24
Source File: update_rank_list.py    From superCodingBot with MIT License 4 votes vote down vote up
def updasel(self, bot, update):
        query = update.callback_query
        val = query.data
        val = str(val).replace("upd5", "")
        a = str(query.from_user.id)
        conn = sqlite3.connect(self.mount_point + 'coders1.db')
        c = conn.cursor()
        c.execute("SELECT id FROM handles WHERE id=(?)", (a,))
        if not not_registered.NotRegistered.fetchone(c, query, bot):
            conn.close()
            return ConversationHandler.END
        if val == "ALL":
            # IF USER SELECTED ALL UPDATING ALL HIS VALUES
            c.execute('SELECT id, HE, HR, CC, SP, CF FROM handles WHERE id=(?)', (a,))
            self.utility.update_function(c)
            bot.delete_message(chat_id=query.message.chat_id, message_id=query.message.message_id)
        else:
            # ELSE ONLY UPDATING THE PARTICULAR ENTRY
            c.execute("SELECT " + val + " FROM handles WHERE id=(?)", (a,))
            for row in c.fetchall():
                if row[0] == "" or row[0] is None:
                    bot.edit_message_text(text='You are not registered to the bot with' + val,
                                          chat_id=query.message.chat_id,
                                          message_id=query.message.message_id)
                    conn.close()
                    return ConversationHandler.END
                else:
                    print(row[0])
                    i = 0
                    while i < 5:
                        ans = self.rating_obj.getAllData(val, str(row[0]))
                        if ans is not None:
                            break
                        i = i + 1
                    c.execute("UPDATE datas SET " + val + " = (?)  WHERE id = (?) ", (ans, a))
                    if not val == 'SP':
                        rating = self.rating_obj.parse_rating(val, ans)
                        c.execute("UPDATE priority SET " + val + " = (?) WHERE id = (?) ", (rating, a))
                bot.edit_message_text(text="" + ans, chat_id=query.message.chat_id, message_id=query.message.message_id)
            # RECREATING ALL THE XLMX FILES
            if val == 'SP':
                mysel = c.execute("SELECT name, " + val + " FROM datas")
                self.utility.xlsx_creator(mysel, self.mount_point + val + ".xlsx")
            else:
                mysel = c.execute(
                    "SELECT datas.name, datas." + val + " FROM datas INNER JOIN priority ON datas.id=priority.id ORDER BY CAST(priority." + val + " AS FLOAT) DESC")
                self.utility.xlsx_creator(mysel, self.mount_point + val + ".xlsx")
            mysel = c.execute(
                "SELECT datas.name, datas.HE, datas.HR, datas.SP, datas.CF, datas.CC FROM datas INNER JOIN priority ON datas.id=priority.id ORDER BY CAST(priority.CF AS FLOAT) DESC, CAST(priority.CC AS FLOAT) DESC, CAST(priority.HR AS FLOAT) DESC, CAST(priority.HE AS FLOAT) DESC")
            self.utility.xlsx_creator(mysel, self.mount_point + 'all.xlsx')
        bot.send_message(text='Successfully updated',
                         chat_id=query.message.chat_id)
        conn.commit()
        conn.close()
        return ConversationHandler.END