def lvl(user, display_name, channel, message=None): if not message: tags = db(opt.TAGS).find_one_by_id(user) if tags and tags.get('bot') == 1: util.send_message(messages.user_bot_message(display_name), channel) else: user = db(opt.USERS).find_one_by_id(user) if user and user.get('user_level'): util.send_message( messages.user_level( display_name, str(user['user_level']), str(user['current_experience']), str((((user['user_level']) + 1)**2) * 10)), channel) else: util.send_message(messages.not_registered(display_name), channel) else: target = db(opt.USERS).find_one({ 'username': re.compile('^' + re.escape(message) + '$', re.IGNORECASE) }) if target and target.get('user_level'): tags = db(opt.TAGS).find_one_by_id(target['_id']) if tags and tags.get('bot') == 1: util.send_message( messages.user_bot_message(target['username']), channel) else: util.send_message( messages.user_level( target['username'], str(target['user_level']), str(target['current_experience']), str((((target['user_level']) + 1)**2) * 10)), channel) else: util.send_message(messages.user_not_registered(display_name), channel)
if params[0] == 'join': tags = db(opt.TAGS).find_one_by_id(user) if tags and tags.get('bot') == 1: continue else: dungeon = db(opt.GENERAL).find_one_by_id(0) channel_raids = db(opt.CHANNELS).find_one({'name': channel}) if dungeon['raid_start'] == 1 and channel_raids['raid_events'] == 1: if not [usr for usr in raid_users if user in usr]: raid_user = db(opt.USERS).find_one_by_id(user) if raid_user and raid_user.get('user_level'): raid_users.append((channel, raid_user['_id'])) else: if time.time() > user_cmd_use_time + global_cooldown: register_thread = threading.Thread(target = util.queue_message_to_one, args=(messages.not_registered(display_name), channel)) register_thread.start() db(opt.USERS).update_one(user, { '$set': { 'cmd_use_time': time.time() } }, upsert=True) if params[0] == 'suggest': cmd.suggest(display_name, channel, message[len(params[0])+2:]) ### Admin Commands ### tags = db(opt.TAGS).find_one_by_id(user) if tags: if params[0] == 'text': if tags.get('admin') == 1: modes = ['vgr', 'vbr', 'gr', 'br', 'fail'] try: if params[1] in modes:
def enterdungeon(user_id, display_name, channel): user = db(opt.USERS).find_one_by_id(user_id) if user and user.get('user_level'): enter_time = time.time() if int(user['next_entry'] - enter_time) <= 0: dungeon = db(opt.GENERAL).find_one_by_id(0) dungeon_level = dungeon['dungeon_level'] user_level = user['user_level'] if user_level > dungeon_level: level_run = dungeon_level success_rate = 65 + ((user_level - dungeon_level) * 7) success_rate = success_rate if success_rate <= 100 else 100 experience_gain = int(60 * dungeon_level) * (1 - ( (user_level - dungeon_level)) * 0.2) experience_gain = experience_gain if experience_gain >= 0 else 0 dungeon_timeout = 3600 else: level_run = user_level success_rate = 65 experience_gain = int(60 * user_level) dungeon_timeout = 3600 if experience_gain == 0: util.send_message( messages.dungeon_too_low_level(display_name, str(dungeon_level)), channel) return dungeon_success = random.randint(1, 101) db(opt.USERS).update_one( user['_id'], { '$set': { 'last_entry': enter_time, 'next_entry': enter_time + dungeon_timeout } }) if dungeon_success <= success_rate: run_quality = random.randint(1, 101) if run_quality <= 10: experience_gain = int(experience_gain * 0.5) try: message = emoji.emojize( list( db(opt.TEXT).get_random_documents_by_match( {'mode': 'vbr'}, 1))[0]['text']) except: message = 'Very Bad Run' util.send_message( messages.dungeon_very_bad_run(display_name, message, str(experience_gain)), channel) elif run_quality >= 90: experience_gain = int(experience_gain * 1.5) try: message = emoji.emojize( list( db(opt.TEXT).get_random_documents_by_match( {'mode': 'vgr'}, 1))[0]['text']) except: message = 'Very Good Run' util.send_message( messages.dungeon_very_good_run(display_name, message, str(experience_gain)), channel) else: run_quality = random.randint(75, 126) experience_gain = int(experience_gain * run_quality * 0.01) if run_quality < 100: try: message = emoji.emojize( list( db(opt.TEXT).get_random_documents_by_match( {'mode': 'br'}, 1))[0]['text']) except: message = 'Bad Run' util.send_message( messages.dungeon_bad_run(display_name, message, str(experience_gain)), channel) else: try: message = emoji.emojize( list( db(opt.TEXT).get_random_documents_by_match( {'mode': 'gr'}, 1))[0]['text']) except: message = 'Good Run' util.send_message( messages.dungeon_good_run(display_name, message, str(experience_gain)), channel) db(opt.USERS).update_one( user['_id'], { '$inc': { 'total_experience': experience_gain, 'current_experience': experience_gain, 'dungeon_wins': 1 } }) db(opt.GENERAL).update_one(0, { '$inc': { 'total_experience': experience_gain, 'total_wins': 1 } }) user_experience = user['current_experience'] + experience_gain if (((user_level + 1)**2) * 10) - user_experience <= 0: db(opt.USERS).update_one( user['_id'], { '$inc': { 'user_level': 1, 'current_experience': -(((user['user_level'] + 1)**2) * 10) } }) level_up_thread = threading.Thread( target=util.queue_message_to_one, args=(messages.user_level_up( display_name, str(user['user_level'] + 1)), channel)) level_up_thread.start() else: db(opt.USERS).update_one(user['_id'], {'$inc': { 'dungeon_losses': 1 }}) db(opt.GENERAL).update_one(0, {'$inc': {'total_losses': 1}}) try: message = emoji.emojize( list( db(opt.TEXT).get_random_documents_by_match( {'mode': 'fail'}, 1))[0]['text']) except: message = 'Failed Run' util.send_message( messages.dungeon_failed(display_name, message), channel) db(opt.USERS).update_one(user['_id'], {'$inc': {'dungeons': 1}}) db(opt.GENERAL).update_one(0, {'$inc': {'total_dungeons': 1}}) else: util.send_message( messages.dungeon_already_entered( display_name, str( datetime.timedelta( seconds=(int(user['next_entry']) - enter_time))).split('.')[0]), channel) else: util.send_message(messages.not_registered(display_name), channel)
def winrate(user, display_name, channel, message=None): if not message: tags = db(opt.TAGS).find_one_by_id(user) if tags and tags.get('bot') == 1: util.send_message(messages.user_bot_message(display_name), channel) else: user = db(opt.USERS).find_one_by_id(user) if user and user.get('user_level'): if user['dungeons'] == 0: util.send_message( messages.no_entered_dungeons(display_name), channel) else: dungeons = user['dungeons'] wins = user['dungeon_wins'] losses = user['dungeon_losses'] if wins == 1: win_word = ' Win' else: win_word = ' Wins' if losses == 1: lose_word = ' Loss' else: lose_word = ' Losses' util.send_message( messages.user_stats( display_name, str(wins), win_word, str(losses), lose_word, str(round((((wins) / (dungeons)) * 100), 3))), channel) else: util.send_message(messages.not_registered(display_name), channel) else: target = db(opt.USERS).find_one({ 'username': re.compile('^' + re.escape(message) + '$', re.IGNORECASE) }) if target and target.get('user_level'): tags = db(opt.TAGS).find_one_by_id(target) if tags and tags.get('bot') == 1: util.send_message( messages.user_bot_message(target['username']), channel) else: same_user = None if user == target['_id']: same_user = True if target['dungeons'] == 0: if same_user: util.send_message( messages.no_entered_dungeons(display_name), channel) else: util.send_message( messages.user_no_entered_dungeons(display_name), channel) else: dungeons = target['dungeons'] wins = target['dungeon_wins'] losses = target['dungeon_losses'] if wins == 1: win_word = ' Win' else: win_word = ' Wins' if losses == 1: lose_word = ' Loss' else: lose_word = ' Losses' util.send_message( messages.user_stats( target['username'], str(wins), win_word, str(losses), lose_word, str(round((((wins) / (dungeons)) * 100), 3))), channel) else: util.send_message(messages.user_not_registered(display_name), channel)