def create_token(user_id): while True: value = random.randint(0,99999) token = encode(user_id * 10000000 + value) if token_status(token) == -1: return token
def get_rewards(token): validity = box.token_status(token) if validity != 0: return jsonify(option1={"code": -1, "description": "NOT FOUND", "name": "NOT FOUND"}, option2={"code": -1, "description": "NOT FOUND", "name": "NOT FOUND"}, option3={"code": -1, "description": "NOT FOUND", "name": "NOT FOUND"},) given_options = items.get_rewards() box.add_source1(token,request.environ.get('HTTP_X_REAL_IP', request.remote_addr)) box.add_options(token,given_options[0]["code"],given_options[1]["code"],given_options[2]["code"]) # Make an announcement if any legendaries found legendary_amount = 0 for option in given_options: if option["code"] > 4000000-1: legendary_amount += 1 if legendary_amount > 3: print("Invalid amount of legendaries found.") if legendary_amount == 3: webhook.send_public_message("**NO WAY!** <@{}> just found ***THREE LEGENDARIES*** in a lootbox!\nThat's a chance of 1 in 1 MILLION!".format(box.get_token_data(token)[1])) if legendary_amount == 2: webhook.send_public_message("<@{}> just opened a lootbox with two legendaries! Wow!".format(box.get_token_data(token)[1])) if legendary_amount == 1: webhook.send_public_message("<@{}> just found a legendary item in a lootbox!".format(box.get_token_data(token)[1])) return jsonify(option1=given_options[0],option2=given_options[1],option3=given_options[2])
def open_lootbox(token): #validity = token validity = box.token_status(token) if validity == -1: # Invalid token return render_template( 'notoken.html', reason="You have filled in a non-existent token!") if validity == 2: # Token already used return render_template( 'notoken.html', reason="This lootbox has already been redeemed!") if validity == 0: # The user is prepared to open the lootbox. return render_template('open.html', token=token) if validity == 1: # The user can make a choice. data = box.get_token_data(token) choices = [int(data[3]), int(data[4]), int(data[5])] choices = [items.import_reward(option) for option in choices] return render_template('choice.html', choices=choices, token=token) return 'This is strange! How did you get here?\nPlease report this to the Game Masters!'
def choose_reward(token,choice): validity = box.token_status(token) if validity != 1: return redirect(url_for('open_lootbox', token=token)) data = box.get_token_data(token) given_options = [int(data[3]),int(data[4]),int(data[5])] if choice not in given_options: return render_template('notoken.html', reason='ERROR: {} is not a valid option.'.format(choice)) box.add_source2(token,request.environ.get('HTTP_X_REAL_IP', request.remote_addr)) webhook.send_private_message(config.universal_prefix + "SUCCESS {} {}".format(token,choice)) return render_template('finish.html')
def choose_reward(token, choice): validity = box.token_status(token) if validity != 1: return redirect(url_for('open_lootbox', token=token)) data = box.get_token_data(token) given_options = [int(data[3]), int(data[4]), int(data[5])] if choice not in given_options: return render_template( 'notoken.html', reason='ERROR: {} is not a valid option.'.format(choice)) headers_list = request.headers.getlist("X-Forwarded-For") user_source = headers_list[0] if headers_list else request.remote_addr box.add_source2(token, user_source) print(user_source) webhook.send_private_message( config.universal_prefix + "SUCCESS {} {} <@{}>".format(token, choice, box.get_token_data(token)[1])) return render_template('finish.html')
def process(message, isGameMaster=False, isAdmin=False, isPeasant=False): user_id = message.author.id message_channel = message.channel.id help_msg = "**List of commands:**\n" args = message.content.split(' ') # ============================================================= # # BOT COMMANDS # # ============================================================= if isPeasant == True: if check.is_command(message, ['success'], False, unip): token = args[1] choice = args[2] if box.token_status(token) != 1: return [Mailbox().respond("Wrong status, buddy.")] data = box.get_token_data(token) given_options = [int(data[3]), int(data[4]), int(data[5])] if int(choice) not in given_options: return [ Mailbox().respond("Invalid choice!", True).spam( "A webhook has given an invalid bug. This means one of the following two things;\n1. There's bug;\n2. Someone's trying to hack the bots through a webhook.\n\nBoth are not good." ) ] box.add_choice(token, choice) invt.take_item(int(box.get_token_data(token)[1]), int(choice[1:4]), int(choice[4:7])) return [ Mailbox().respond("Got it! *(I hope.)* Thanks.", True).thank(box.get_token_data(token)[11]) ] # ============================================================= # # ADMINISTRATOR # # ============================================================= if isAdmin == True: help_msg += "\n __Admin commands:__\n" if is_command(message, ['gift']): target = check.users(message) if not target: return [ Mailbox().respond( "No target provided! Please provide a target.", True) ] answer = Mailbox() for user_id in target: answer.gift(user_id) return [answer] if is_command(message, ['botanswer']): return [ Mailbox().respond( "Sounds pretty cool! How about you did something about it? *cough cough*" ) ] elif is_command(message, ['delete_category', 'start']): return [ Mailbox().respond(PERMISSION_MSG.format("Administrator"), True) ] # ============================================================= # # GAME MASTERS # # ============================================================= if isGameMaster == True: help_msg += "\n__Game Master commands:__\n" elif is_command(message, []): return [Mailbox().respond(PERMISSION_MSG.format("Game Master"), True)] # ============================================================= # # PARTICIPANTS # # ============================================================= if isParticipant(user_id): help_msg += "\n__Participant commands:__\n" user_undead = int(db_get(user_id, 'undead')) elif is_command(message, []): return [Mailbox().respond(PERMISSION_MSG.format("Participant"), True)] # ============================================================= # # EVERYONE # # ============================================================= help_msg += '\n\n' if is_command(message, ['lead']): number = check.numbers(message) if not number: return [Mailbox().respond(gen.gain_leaderboard(user_id), True)] return [ Mailbox().respond(gen.gain_leaderboard(user_id, max(number)), True) ] if is_command(message, ['lead'], True): msg = "**Usage:** Gain a list of the most active users on the server.\n\n`" + prefix + "leaderboard <number>`\n\n" msg += "**Example:** `" + prefix + "lead 10`.\nThe number is optional, and doesn't have to be given." help_msg += "`" + prefix + "leaderboard` - See an activity leaderboard.\n" if is_command(message, ['refer']): target = check.users(message, 1) if target[0] == user_id: return [ Mailbox().respond("Sorry, bud! You cannot refer yourself.") ] if not target: return [ Mailbox().respond( "No target provided! Please provide us with a target!") ] if gen.update_refer(user_id, target[0]) == True: return [ Mailbox().respond( "Alright! Expect you and <@{}> to have some extra luck getting a lootbox soon... ;)" .format(target[0])).gift(user_id).gift(target[0]) ] return [ Mailbox().respond("**ERROR:** You have already referred someone!") ] if is_command(message, ['rr', 'roulette', 'suicide']): return [roulette.surrender(True), roulette.take_shot(message)] if is_command(message, ['rr', 'roulette', 'suicide'], True): msg = "**Usage:** Play a game of Russian roulette!\n\n`" + prefix + "rr`\n\nTry it out! It's fun." return [Mailbox().respond(msg, True)] help_msg += "`" + prefix + "rr` - Play some Russian roulette!\n" if is_command(message, ['rs', 'roulscore', 'rscore']): target = check.users(message, 1) if not target: return [roulette.profile(message.author.id)] return [roulette.profile(target[0])] if is_command(message, ['rs', 'roulscore', 'rscore'], True): msg = "**Usage:** Check your current game progress.\n\n`" + prefix + "rs <user>`\n\n" msg += "**Example:** `" + prefix + "rs @Randium#6521`\nMentioning a user is optional." return [Mailbox().respond(msg, True)] help_msg += "`" + prefix + "rs` - See Russian Roulette score.\n" if roulette.is_playing(message.author): if is_command(message, ['surrender']): return [roulette.surrender(False, message.author)] if is_command(message, ['surrender'], True): msg = "**Usage:** Leave the game if you think you're gonna die.\n\n`" + prefix + "surrender`\n\nLeaving the game counts as a loss, but not as a death." help_msg += "`" + prefix + "surrender` - Leave the Russian roulette game.\n" # Profile commands profile_commands = process_profile(message=message, is_game_master=isGameMaster, is_admin=isAdmin, is_peasant=isPeasant) if profile_commands: return profile_commands help_msg += "\n`" + prefix + "age` - Set your age\n" help_msg += "`" + prefix + "bio` - Set your bio\n" help_msg += "`" + prefix + "gender` - Set your gender\n" help_msg += "`" + prefix + "profile` - View a player's profile\n" # -------------------------------------------------------------- # HELP # -------------------------------------------------------------- help_msg += "\n\n*If you have any more questions, feel free to ask any of the Game Masters!*" '''help''' if is_command(message, ['help']) and is_command(message, ['help'], True) == False: return [Mailbox().respond(help_msg, True)] if is_command(message, ['help'], True): answer = Mailbox().respond( "Hey there! `" + prefix + "help` will give you a list of commands that you can use.") answer.respond_add( "\nIf you have any questions, feel free to ask any of the Game Masters!" ) return [answer] if message.content.startswith(prefix): return [ roulette.surrender(True), Mailbox().respond( "Sorry bud, couldn't find what you were looking for.", True) ] return [roulette.surrender(True)]
def process(message, isGameMaster=False, isAdmin=False, isPeasant=False): user_id = message.author.id message_channel = message.channel.id help_msg = "**List of commands:**\n" args = message.content.split(' ') # ============================================================= # # BOT COMMANDS # # ============================================================= if isPeasant == True: if is_command(message, ['success']): token = args[1] choice = args[2] if box.token_status(token) != 2: return [] data = box.get_token_data(token) given_options = [int(data[3]), int(data[4]), int(data[5])] if choice not in given_options: return [ Mailbox().respond("Invalid choice!", True).spam( "A webhook has given an invalid bug. This means one of the following two things;\n1. There's bug;\n2. Someone's trying to hack the bots through a webhook.\n\nBoth are not good." ) ] box.add_choice(token, choice) return [ Mailbox().respond( "Got it! Thanks.\n*(Well, not really, this still needs to be done, but...)*" ) ] # ============================================================= # # ADMINISTRATOR # # ============================================================= if isAdmin == True: help_msg += "\n __Admin commands:__\n" elif is_command(message, ['delete_category', 'start']): return [ Mailbox().respond(PERMISSION_MSG.format("Administrator"), True) ] # ============================================================= # # GAME MASTERS # # ============================================================= if isGameMaster == True: help_msg += "\n__Game Master commands:__\n" elif is_command(message, []): return [Mailbox().respond(PERMISSION_MSG.format("Game Master"), True)] # ============================================================= # # PARTICIPANTS # # ============================================================= if isParticipant(user_id): help_msg += "\n__Participant commands:__\n" user_undead = int(db_get(user_id, 'undead')) elif is_command(message, []): return [Mailbox().respond(PERMISSION_MSG.format("Participant"), True)] # ============================================================= # # EVERYONE # # ============================================================= help_msg += '\n\n' if is_command(message, ['lead']): number = check.numbers(message) if not number: return [Mailbox().respond(gen.gain_leaderboard(user_id))] return [ Mailbox().respond(gen.gain_leaderboard(user_id, max(number)), True) ] if is_command(message, ['lead'], True): msg = "**Usage:** Gain a list of the most active users on the server.\n\n`" + prefix + "leaderboard <number>`\n\n" msg += "**Example:** `" + prefix + "lead 10`.\nThe number is optional, and doesn't have to be given." help_msg += "`" + prefix + "lead` - See an activity leaderboard.\n" # Profile commands profile_commands = process_profile(message=message, is_game_master=isGameMaster, is_admin=isAdmin, is_peasant=isPeasant) if profile_commands: return profile_commands help_msg += "`" + prefix + "age` - Set your age\n" help_msg += "`" + prefix + "bio` - Set your bio\n" help_msg += "`" + prefix + "gender` - Set your gender\n" help_msg += "`" + prefix + "profile` - View a player's profile\n" # -------------------------------------------------------------- # HELP # -------------------------------------------------------------- help_msg += "\n\n*If you have any more questions, feel free to ask any of the Game Masters!*" '''help''' if is_command(message, ['help']) and is_command(message, ['help'], True) == False: return [Mailbox().respond(help_msg, True)] if is_command(message, ['help'], True): answer = Mailbox().respond( "Hey there! `" + prefix + "help` will give you a list of commands that you can use.") answer.respond_add( "\nIf you have any questions, feel free to ask any of the Game Masters!" ) return [answer] if message.content.startswith(prefix): return [ Mailbox().respond( "Sorry bud, couldn't find what you were looking for.", True) ] return []