def buttonPressedOwner(update, context): query = update.callback_query chat_id = query.message.chat.id callbackdata = query.data user = Role.Verify(chat_id=chat_id) #if user unregchat if re.match(r"unregchat(.*)", callbackdata): userchat_id = re.findall(r"unregchat(.*)", callbackdata)[0] msg = open_message("owner","unregchat") user.unregChat(userchat_id) update.callback_query.edit_message_reply_markup(reply_markup=None) #update.callback_query.message.reply_text(text=f"Done, those chat/group were deleted") update.callback_query.message.reply_text(text=msg) #if owner klik approve button elif re.match(r"insert.*", callbackdata): #extract callbackdata from format "insertUserchat_id,chat_name,owner_id" datachat = re.findall(r"insert(.*)", callbackdata) #convert it to list of string hasildatachat = datachat[0].split(',') userchat_id = hasildatachat[0] userchat_name = hasildatachat[1] owner_id = hasildatachat[2] msgowner = open_message("owner","approvedchat") msgrequestor = open_message("user","requestornotify") #insert to db user = Role.Verify(userchat_id) user.registerChat(userchat_id, userchat_name, owner_id) query.edit_message_reply_markup(reply_markup=None) #query.message.reply_text(text=f'Done, those chat has been registered to your token.\nYou can unregister by /unregchat', parse_mode=ParseMode.HTML) query.message.reply_text(text=msgowner, parse_mode=ParseMode.HTML) #send notif to requestor context.bot.send_message(chat_id=userchat_id, text=msgrequestor, parse_mode=ParseMode.HTML)
def reqtoken_handler(update, context): chat_id = update.effective_chat.id user = Role.Verify(chat_id) hasilpasscode = user.reqPasscode(chat_id, nexttoken=None) if hasilpasscode: passcode = hasilpasscode[0] username = hasilpasscode[1] button = [] msg = open_message("user","reqtoken") #create dict for button buttondict = {'next60': 'next 60s', 'next3600': 'next 1h', 'next7200': 'next 2h', 'next14400': 'next 4h'} #build button for next token from buttondict for callbackdata, teks in buttondict.items(): button.append(InlineKeyboardButton( text=teks, callback_data=callbackdata ) ) buttonmarkup = InlineKeyboardMarkup(messageformat.buildButton(button, 2)) #update.message.reply_text(text=f"<code>username: {username}</code>\nHere is the passcode <code>{passcode}</code>", parse_mode=ParseMode.HTML, reply_markup=buttonmarkup) update.message.reply_text(text=msg.format(username, passcode), parse_mode=ParseMode.HTML, reply_markup=buttonmarkup) else: msg = open_message("user","reqtokennotreg") #update.message.reply_text(text=f"Sorry, this chat/group does not belong to any token.\n please register by clicking this /registerchat", parse_mode=ParseMode.HTML) update.message.reply_text(text=msg, parse_mode=ParseMode.HTML)
def unregtoken_handler(update, context): chat_id = update.effective_chat.id user = Role.Verify(chat_id=chat_id) user.unregToken(chat_id=chat_id) msg = open_message("owner","unregtoken") #update.message.reply_text(text=f"Done, your token has been unregistered.\nYou could always import it again using /registertoken") update.message.reply_text(text=msg)
def listtoken_handler(update, context): chat_id = update.effective_chat.id role = Role.Verify(chat_id) #clear groupdict and button messageformat.groupdict = {} messageformat.markupdept = {} keyboard, teks = role.listToken() msg = open_message("alluser","listtoken") #update.message.reply_text(text=f"Token registered to this bot.\n<code>{teks}</code>", parse_mode=ParseMode.HTML) update.message.reply_text(text=msg.format(teks), parse_mode=ParseMode.HTML)
def registerchat_handler(update, context): chat_id = update.effective_chat.id role = Role.Verify(chat_id) #clear groupdict and button messageformat.groupdict = {} messageformat.markupdept = {} hasil = role.listToken() keyboardmarkup = hasil[0] teks = hasil[1] msg = open_message("alluser", "registerchat") update.message.reply_text(text=msg.format(teks), reply_markup=keyboardmarkup,parse_mode=ParseMode.HTML)
def buttonPressedNext(update, context): query = update.callback_query chat_id = query.message.chat.id message_id = query.message.message_id callbackdata = query.data from_userfirstname = query.from_user.first_name nexttoken = int(re.findall(r"next(.*)", callbackdata)[0]) msg = open_message("user","reqtokennext") user = Role.Verify(chat_id) passcode, waktu, username = user.reqPasscode(chat_id, nexttoken) query.edit_message_reply_markup(reply_markup=None) #query.message.reply_text(text=f"<code>username: {username}</code>\n{from_userfirstname} here is your passcode:\n\n<code>{passcode}active until {waktu}</code>", parse_mode=ParseMode.HTML) query.message.reply_text(text=msg.format(username, from_userfirstname, passcode, waktu), parse_mode=ParseMode.HTML)
def listchat_handler(update, context, unreg=False): chat_id = update.effective_chat.id user = Role.Verify(chat_id=chat_id) listchat, markupchat = user.listChat(chat_id=chat_id) print(listchat) if unreg: #update.message.reply_text(text=f"Ini list chat yang udah approved \n{listchat}\n <b>Klik button di bawah buat unreg chat yang lu approve boss.</b>", reply_markup=markupchat,parse_mode=ParseMode.HTML) msg = open_message("owner","listchatunreg") update.message.reply_text(text=msg.format(listchat), reply_markup=markupchat,parse_mode=ParseMode.HTML) else: #update.message.reply_text(text=f"Ini list chat yang udah approved \n{listchat}\n Kalo mau unreg chatnya, klik /unregchat", parse_mode=ParseMode.HTML) msg = open_message("owner","listchat") update.message.reply_text(text=msg.format(listchat), parse_mode=ParseMode.HTML) return
def unregchat_handler(update,context): chat_id = update.effective_chat.id user = Role.Verify(chat_id=chat_id).currentRole print("ini tipe instance user >> {}".format(type(user))) if isinstance(user, Role.Owner): listchat_handler(update=update, context=context, unreg=True) elif isinstance(user, Role.User): print("masu isinstance user role") if user.unregChat(chat_id=chat_id): msg = open_message("user","unregchat") #update.message.reply_text(text="Done, this chat has been unregistered from token.\n You will no longer receive bot update") update.message.reply_text(text=msg) else: msg = open_message("user","unregtokennotreg") #update.message.reply_text(text="This chat isn't registered to any token yet") update.message.reply_text(text=msg) return
def importToken(update, context): chat_id = update.effective_message.chat_id if update.effective_chat.last_name: chat_name = re.findall(r"^\S*..", update.effective_chat.first_name + " " + update.effective_chat.last_name)[0] else: chat_name = re.findall(r"^\S*..", update.effective_chat.first_name)[0] url = context.user_data.get('url') sdtid = context.user_data.get('file') username = context.user_data.get('username') setpin = context.user_data.get('setpin') grup = context.user_data.get('grup') #create instance user = Role.Verify(chat_id) #download if sdtid if sdtid: sdtid.download(f'sdtid/{username}.sdtid') print(type(grup)) user.registerToken(chat_id=chat_id, chat_name=chat_name, username=username, setpin=setpin, team_name=grup, token=url, sdtid=sdtid) msg = open_message("user","importtoken") #update.message.reply_text(text=f'done, {username} to {grup} imported.\n\n Now you can register your this chat or group chat to your corresponding token.\n') update.message.reply_text(text=msg.format(username, grup)) return ConversationHandler.END
def start_handler(update, context): chat_id = update.message.chat.id user = Role.Verify(chat_id) menu = user.menu() update.message.reply_text(text=f"{menu}\n\nYou can read the tutorial here /about", parse_mode=ParseMode.HTML)