def __resetPayments(group_id, bot): import Keyboards import Statements results = executeQuery( "SELECT * FROM PAYMENTS WHERE GROUP_ID=? AND EXPIRATION=?", [group_id, getExpiration(group_id)]) n_p = countNetflixers(group_id) status = [] for i in range(0, n_p): status.append(0) if results: executeQuery( "UPDATE PAYMENTS SET STATUS=0 WHERE GROUP_ID=? AND EXPIRATION=?", [group_id, getExpiration(group_id)]) bot.send_message( group_id, Statements.IT.TimeToPay.replace('$$', moneyEach(group_id)), reply_markup=Keyboards.buildKeyboardForPayment(group_id, status), parse_mode='markdown') else: expiration = getExpiration(group_id) for user in getAllUsers(group_id): try: executeQuery("INSERT INTO PAYMENTS VALUES(?,?,?,?,?)", [expiration, group_id, user[0], user[2], 0]) except sqlite3.IntegrityError: pass bot.send_message(group_id, Statements.IT.TimeToPay.replace( '$$', moneyEach(group_id)), reply_markup=Keyboards.buildKeyboardForPayment( group_id, [0, 0, 0, 0]), parse_mode='markdown')
def lang_command(m): bot.send_message( m.chat.id, Const.choose_language, reply_markup=Keyboards.lang_inline_keyboard(), parse_mode="HTML", )
def no(call): # If user is not admin if call.from_user.id != Utils.getAdminID(call.message.chat.id): bot.answer_callback_query(call.id, Statements.IT.NotAdmin, show_alert=True, cache_time=10) else: # If callback is coming from list's confirmation message if call.message.text[:34] == Statements.IT.ConfirmList: bot.edit_message_text(Statements.IT.Start.replace( '$$', call.from_user.first_name), call.message.chat.id, call.message.message_id, reply_markup=Keyboards.buildKeyboardForUser( call.message.chat.id), parse_mode='markdown') # If callback is coming from expiration's confirmation message elif call.message.text[:-4] == Statements.IT.ConfirmSchedule[:-6]: bot.edit_message_text(Statements.IT.Schedule, call.message.chat.id, call.message.message_id, reply_markup=Keyboards.DateKeyboard, parse_mode='markdown') # If callback is coming from reset's confirmation message elif call.message.text == Statements.IT.ConfirmReset.replace( '*', '', 2): bot.edit_message_text(Statements.IT.AlreadyConfigured, call.message.chat.id, call.message.message_id, reply_markup=Keyboards.Reset, parse_mode='markdown')
def addMember(call): # Max reached if Utils.countNetflixers(call.message.chat.id) == 4: bot.answer_callback_query(call.id, Statements.IT.MaxReached, show_alert=True) # Duplicated user elif call.from_user.first_name in Utils.listNetflixers( call.message.chat.id): bot.answer_callback_query(call.id, Statements.IT.AlreadySigned, show_alert=True) else: # Add user in USERS table Utils.executeQuery( "INSERT INTO USERS(GROUP_ID,CHAT_ID,USERNAME,FIRST_NAME) VALUES (?,?,?,?)", [ call.message.chat.id, call.from_user.id, call.from_user.username, call.from_user.first_name ]) # Update record in GROUPS table, increment number of user joined Utils.executeQuery( "UPDATE GROUPS SET NETFLIXERS=NETFLIXERS+1 WHERE GROUP_ID=?", [call.message.chat.id]) # Create an updated keyboard with new member updatedKeyboard = Keyboards.buildKeyboardForUser(call.message.chat.id) #updatedKeyboard = Keyboards.buildKeyboardForUser(Utils.listNetflixers(call.message.chat.id)) # Edit the keyboard markup of the same message bot.edit_message_reply_markup(chat_id=call.message.chat.id, message_id=call.message.message_id, reply_markup=updatedKeyboard) # Answer to the callback bot.answer_callback_query(call.id, Statements.IT.Added)
async def process_start_command(message: types.Message): await message.answer( "Please, select language 🇬🇧\n" "Пожалуйста, выбери язык 🇷🇺\n", reply_markup=keyboard.languages()) if not database.user_exists(message.from_user.id): database.add_user(message.from_user.id) await msg.delete_message(bot, message)
def paymentNotify(group_id): if Settings.DEBUG: return Utils.__resetPayments(group_id, bot) expiration = Utils.getExpiration(group_id) for user in Utils.getAllUsers(group_id): Utils.newPayment(expiration, group_id, user) bot.send_message( group_id, Statements.IT.TimeToPay.replace("$$", Utils.moneyEach(group_id)), reply_markup=Keyboards.buildKeyboardForPayment(group_id, [0, 0, 0, 0]), parse_mode='markdown')
def goods(message): m = message.chat.id bot.send_message(m, Dictionary.SELECT_BAG, reply_markup=Keyboards.back_btn()) # for i in Goods.select(): # bot.send_photo(m,i.bag_name, reply_markup=Keyboards.back_btn()) # bot.send_message(m,reply_markup=Keyboards.price_of_bag()) pass
def removeUser(call): # If id of the user is different from id the user in button if int(call.from_user.id) != int(call.data[7:]): bot.answer_callback_query(call.id,Statements.IT.NotPermitted,show_alert=True,cache_time=10) else: # Delete user from db Utils.executeQuery("DELETE FROM USERS WHERE CHAT_ID=? AND GROUP_ID=?",[call.from_user.id,call.message.chat.id]) # Decrement counter in GROUPS table Utils.executeQuery("UPDATE GROUPS SET NETFLIXERS=NETFLIXERS - 1 WHERE GROUP_ID=?",[call.message.chat.id]) # Create an updated keyboard updatedKeyboard = Keyboards.buildKeyboardForUser(call.message.chat.id) #updatedKeyboard = Keyboards.buildKeyboardForUser(Utils.listNetflixers(call.message.chat.id)) # Edit keyboard markup in the same message bot.edit_message_reply_markup(chat_id=call.message.chat.id,message_id=call.message.message_id,reply_markup=updatedKeyboard) # Answer to the callback bot.answer_callback_query(call.id,Statements.IT.Removed)
def payed(call): # Get current status of the user from db stato = Utils.getStatus(call.message.chat.id,Utils.getExpiration(call.message.chat.id),call.data[6:]) # If the user has already payed if stato == 1: bot.answer_callback_query(call.id,Statements.IT.AlreadyPayed.replace('$$',Utils.getUser(call.message.chat.id,call.data[6:])[2]),show_alert=True) else: # If name is different and is not admin if int(call.from_user.id) != int(call.data[6:]) and call.from_user.id != Utils.getAdminID(call.message.chat.id): bot.answer_callback_query(call.id,Statements.IT.NotPermitted,show_alert=True,cache_time=10) return # If the user is not the admin, the payment's status is set to -1, mean 'waiting for admin confirm' elif int(call.from_user.id) == int(call.data[6:]) and int(call.from_user.id) != Utils.getAdminID(call.message.chat.id): # If user is waiting for confirmation if Utils.getStatus(call.message.chat.id,Utils.getExpiration(call.message.chat.id),call.from_user.id) == -1: bot.answer_callback_query(call.id,Statements.IT.IsWaiting,show_alert=True,cache_time=10) return else: # Otherwise set user's status to -1, wait for confirmation Utils.executeQuery("UPDATE PAYMENTS SET STATUS=-1 WHERE GROUP_ID=? AND CHAT_ID=? AND EXPIRATION=?",[call.message.chat.id,call.data[6:],Utils.getExpiration(call.message.chat.id)]) bot.answer_callback_query(call.id,Statements.IT.WaitingFor,show_alert=True,cache_time=10) # If is admin elif int(call.from_user.id) == Utils.getAdminID(call.message.chat.id): # Update payment status into db to payed Utils.executeQuery("UPDATE PAYMENTS SET STATUS=1 WHERE GROUP_ID=? AND CHAT_ID=? AND EXPIRATION=?",[call.message.chat.id,call.data[6:],Utils.getExpiration(call.message.chat.id)]) if int(call.from_user.id) != int(call.data[6:]): username = "******".format(str(Utils.getUser(call.message.chat.id,call.data[6:])[1])) if not username: username = Utils.getUser(call.message.chat.id,call.data[6:])[2] bot.send_message(call.message.chat.id,Statements.IT.PaymentAccepted.replace('$$',username),parse_mode='markdown') # Get current status of all users results = Utils.getAllStatus(call.message.chat.id,Utils.getExpiration(call.message.chat.id)) everyonePayed = True for status in results: if status != 1: everyonePayed = False # If everyone has already payed if everyonePayed: bot.edit_message_text(Statements.IT.EveryonePaid.replace('$$',Utils.newExpiration(Utils.getExpiration(call.message.chat.id))),call.message.chat.id,call.message.message_id,reply_markup={},parse_mode='markdown') return # Get current status of all users status = Utils.getAllStatus(call.message.chat.id,Utils.getExpiration(call.message.chat.id)) # Create an update keyboard with new status kb = Keyboards.buildKeyboardForPayment(call.message.chat.id,status) # Edit message markup with updated keyboard bot.edit_message_reply_markup(chat_id=call.message.chat.id,message_id=call.message.message_id,reply_markup=kb)
def back_btn(m): bot.send_message(m.chat.id, text=Dictionary.BACK, reply_markup=Keyboards.main_menu())
def lang(call): Keyboards.lang(call, bot) bot.send_message(call.message.chat.id, Dictionary.WELCOME)
def start_menu(m): message = m.chat.id bot.send_message(message, Const.enter_message, reply_markup=Keyboards.lang_inline_keyboard())
def home_btn(m): bot.send_message(m.chat.id, text=Dictionary.HOME, reply_markup=Keyboards.main_menu())