def check_group(message, callback=None): """ #TODO [UNUSED] Check whether the user are the admin of the group it needed for some command that can only be call by admin :param message: :param callback: :return: """ is_in_group = helper.conversationIsGroup(message) if not is_in_group: mac.send_message( "Hello, I can't do it from here, please do it from your group.", message.conversation) return def callback_check_group(isAdmin): if not callback: return callback(isAdmin) print(isAdmin) mac.get_group_info(message.conversation, message.who, callback=callback_check_group)
def check_stake(message): is_in_group = helper.conversationIsGroup(message) if not is_in_group: mac.send_message( "Hello, I can't set your from here, please do it from your group.", message.conversation) return group_id = message.conversation.split("@")[0] payload = {'wa_group_id': group_id} check_stakes_post = requests.post( "http://{}/api/whatsappbot/check_stakes".format(BASE_IP), data=payload) check_stakes_data = check_stakes_post.json() check_stakes_lists = check_stakes_data["list_game"] if len(check_stakes_lists) == 0: mac.send_message("There isn't any winner in this game", message.conversation) check_stakes_rows = [["phone_number", "stake", "value"]] for check_stake in check_stakes_lists: check_stakes_rows.append([ check_stake["phone_number"], check_stake["stake"], check_stake["value"] ]) table = texttable.Texttable() table.add_rows(check_stakes_rows) mac.send_message( u"📡 Wait, contacting the server guy to see current results", message.conversation) mac.send_message(table.draw(), message.conversation)
def check_stake(message): is_in_group = helper.conversationIsGroup(message) if not is_in_group: mac.send_message( "Hello, I can't set your from here, please do it from your group.", message.conversation) return mac.send_message( u"📡 Wait, contacting the server guy to see current results", message.conversation)
def set_group(message): params = message.predicate.split(" ") is_in_group = helper.conversationIsGroup(message) if not is_in_group: mac.send_message( "Hello, I can't set your from here, please do it from your group.", message.conversation) return if len(params) < 2: mac.send_message( "Please specify the default balance and the rtp ammount for your players", message.conversation) mac.send_message("You can ask for my #help if you are not sure", message.conversation) return if len(params) > 2: mac.send_message( "Please check your command again, it seems it contain too much arguments", message.conversation) mac.send_message( "You can ask for my #help if you are not sure how to setup", message.conversation) return for param in params: is_number_only = helper.isAllNumber(param) if not is_number_only: mac.send_message( "Hey, I can't really understand your command. Please only use number for balance and rtp", message.conversation) return mac.send_message("Setting the group..", message.conversation) group_id = message.conversation.split("@")[0] (balance, rtp) = params payload = {'wa_group_id': group_id, 'init_point': balance, 'rtp': rtp} set_group_post = requests.post( 'http://{}/trivia/api/whatsappbot/update_point'.format(BASE_IP), data=payload) set_group_data = set_group_post.json() if not set_group_data or not set_group_data['message']: mac.send_message("I Failed to setup the group, no message field", message.conversation) return if not helper.isResponseSuccess(set_group_post.status_code): mac.send_message( 'I failed to setup the group, here is the message \n {}'.format( set_group_data['message']), message.conversation) return mac.send_message(GROUP_FINISH_SETTING, message.conversation)