async def update_slimernalia_kingpin(client, server): return # Depose current slimernalia kingpin kingpin_state = EwGamestate(id_server=server.id, id_state='slimernaliakingpin') old_kingpin_id = int(kingpin_state.value) if old_kingpin_id != None and old_kingpin_id > 0: kingpin_state.value = '-1' try: old_kingpin_member = server.get_member(old_kingpin_id) await ewrolemgr.updateRoles(client=client, member=old_kingpin_member) except: ewutils.logMsg( "Error removing kingpin of slimernalia role from {} in server {}." .format(old_kingpin_id, server.id)) # Update the new kingpin of slimernalia new_kingpin_id = ewutils.get_most_festive(server) kingpin_state.value = str(new_kingpin_id) # Reset the new kingpin's festivity upon getting the award old_festivity = ewstats.get_stat(id_server=server.id, id_user=new_kingpin_id, metric=ewcfg.stat_festivity) ewstats.set_stat(id_server=server.id, id_user=new_kingpin_id, metric=ewcfg.stat_festivity, value=0) #new_kingpin.festivity = 0 #new_kingpin.persist() try: new_kingpin_member = server.get_member(new_kingpin_id) await ewrolemgr.updateRoles(client=client, member=new_kingpin_member) except: ewutils.logMsg( "Error adding kingpin of slimernalia role to user {} in server {}." .format(new_kingpin_id, server.id)) if new_kingpin_member: # Format and release a message from Phoebus about how who just won and how much slime they got announce_content = ewcfg.slimernalia_kingpin_announcement.format( player=("@" + str(new_kingpin_member.id)), festivity=old_festivity) announce = discord.Embed() announce.set_thumbnail(url="https://i.imgur.com/aVfaB9I.png") announce.description = "**Phoebus**{}".format(ewcfg.emote_verified) announce.color = discord.Color.green() announce.add_field(name='\u200b', value=announce_content) channel = get_channel(server=server, channel_name="auditorium") await send_message(client, channel, embed=announce)
def inaccessible(user_data=None, poi=None): if poi == None or user_data == None: return True if user_data.life_state == ewcfg.life_state_observer: return False if user_data.life_state == ewcfg.life_state_shambler and poi.id_poi in [ ewcfg.poi_id_rowdyroughhouse, ewcfg.poi_id_copkilltown, ewcfg.poi_id_juviesrow ]: return True source_poi = poi_static.id_to_poi.get(user_data.poi) # locks that inhibit a POI for lock in ewcfg.region_lock_states: if poi.id_poi == lock: for state in ewcfg.region_lock_states.get(lock): gamestate = EwGamestate(id_server=user_data.id_server, id_state=state) if gamestate.bit == 0: return True shipstate = EwGamestate(id_server=user_data.id_server, id_state='shipstate') if ((shipstate.bit == 0) and (user_data.poi == 'ufoufo' or poi.id_poi == 'ufoufo')) or ( poi.id_poi == 'ufoufo' and user_data.life_state == ewcfg.life_state_corpse): return True bans = user_data.get_bans() vouchers = user_data.get_vouchers() locked_districts_list = poi_utils.retrieve_locked_districts( user_data.id_server) if (len(poi.factions) > 0 and (set(vouchers).isdisjoint(set(poi.factions)) or user_data.faction != "") and user_data.faction not in poi.factions) or ( len(poi.life_states) > 0 and user_data.life_state not in poi.life_states): return True elif (len(poi.factions) > 0 and len(bans) > 0 and set(poi.factions).issubset(set(bans))): return True elif poi.id_poi in locked_districts_list and user_data.life_state not in [ ewcfg.life_state_executive, ewcfg.life_state_lucky ]: return True else: return False
async def launch(cmd): user_data = EwUser(member=cmd.message.author) protected = False cosmetics = bknd_item.inventory(id_user=user_data.id_user, id_server=cmd.guild.id, item_type_filter=ewcfg.it_cosmetic) for cosmetic in cosmetics: cosmetic_data = EwItem(id_item=cosmetic.get('id_item')) if cosmetic_data.item_props.get('id_cosmetic') == 'skinsuit': if cosmetic_data.item_props.get('adorned') == 'true': protected = True if user_data.poi != 'ufoufo': response = "Launch what, dumbass? My patience?" elif not protected: response = "The aliens aren't gonna let you start the ship. You're basically their captive now." elif not ewcfg.dh_active or ewcfg.dh_stage != 3: response = "Wait, your alien espionage is waaaay out of season." else: launchstate = EwGamestate(id_state='shipstate', id_server=cmd.guild.id) if launchstate.bit == 1: response = "PCHOOOOOOOOOO! Weird bleeps and bloops begin to increase in frequency as the ship rises back into the air!" launchstate.bit = 0 launchstate.persist() else: response = "WHOOOOOOOO -CRASH! Your poor piloting crashes the ship back down. Your fellow alien crew seems excited, like you just chugged a whole bottle of their galactic lager or something. Good thing the hull is so shock resistant or you wouldn't be able to joyride again." launchstate.bit = 1 launchstate.persist() return await fe_utils.send_message(cmd.client, cmd.message.channel,fe_utils.formatMessage(cmd.message.author, response))
async def hailcab(cmd): user_data = EwUser(member = cmd.message.author) blockstate = EwGamestate(id_server=cmd.guild.id, id_state='blockparty') poi = ''.join([i for i in blockstate.value if not i.isdigit()]) if poi == 'outsidethe': poi = ewcfg.poi_id_711 if poi != user_data.poi: response = "You can't hail a cab right now. All the cabbies are hiding for cover thanks to all the violence. Good job on that, by the way." else: if user_data.life_state in [ewcfg.life_state_enlisted, ewcfg.life_state_juvenile]: if user_data.faction == ewcfg.faction_rowdys and user_data.life_state == ewcfg.life_state_enlisted: dest = ewcfg.poi_id_rowdyroughhouse elif user_data.faction == ewcfg.faction_killers and user_data.life_state == ewcfg.life_state_enlisted: dest = ewcfg.poi_id_copkilltown else: dest = ewcfg.poi_id_juviesrow await asyncio.sleep(5) response = "**TAXI!** You shout into the crowd for a ride home. The drivers don't notice you're a miscreant, and pick you up without a second thought. They got nervous when you asked to return to your gang base, and forgot to ask for any fare. Nice!" await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) ewutils.moves_active[cmd.message.author.id] = 0 user_data.poi = dest user_data.persist() await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author) return await user_data.move_inhabitants(id_poi=dest, visitor=user_data.id_user) elif user_data.life_state == ewcfg.life_state_corpse: response = "You're already dead. The cabbies unfortunately tend to avoid black people, so you should probably just float back to the sewers." else: response = "The cabbie looks confused. Why would a person like you need a cab?" return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
def make_relics_found_board(id_server, title): existing_relics = len(static_relic.relic_list) relic_count_state = EwGamestate(id_server=id_server, id_state='donated_relics') relic_count_donated = int(relic_count_state.value) allrelics = ['TOTAL', existing_relics - 1] donatedrelics = ['DONATED', relic_count_donated] return format_board(entries=[donatedrelics, allrelics], title=title, entry_type=ewcfg.entry_type_relics)
async def ufo_observe(cmd): user_data = EwUser(member = cmd.message.author) cosmetics = bknd_item.inventory(id_user=user_data.id_user, id_server=cmd.guild.id, item_type_filter=ewcfg.it_cosmetic) protected = False for cosmetic in cosmetics: cosmetic_data = EwItem(id_item=cosmetic.get('id_item')) if cosmetic_data.item_props.get('id_cosmetic') == 'skinsuit': if cosmetic_data.item_props.get('adorned') == 'true': protected = True shipstate = EwGamestate(id_state='shipstate', id_server=cmd.guild.id) if user_data.poi != 'ufoufo': return await ewdebug.scrutinize(cmd=cmd) elif not protected: response = "Those aliens would probably ass-probe the f**k out of you if you messed with their equipment. Better not." elif shipstate.bit == 1: response = "The ship is grounded. Can't see much from here." elif cmd.tokens_count <= 1: response = "Observe what?" elif not ewcfg.dh_active or ewcfg.dh_stage != 3: response = "Wait, your alien espionage is waaaay out of season." else: poi_seek = ewutils.flattenTokenListToString(cmd.tokens[1:]) poi_sought = poi_static.id_to_poi.get(poi_seek) if poi_sought is None: response = "The aliens know all the district names. You don't have to make up weird shit." elif poi_sought.id_poi == 'ufoufo': return await ewdebug.scrutinize(cmd=cmd) elif poi_sought.is_street: response = "You try to zoom in on a specific street, but you're a little too high up to get that level of detail." elif poi_sought.id_poi == 'blackpond' or (not poi_sought.is_district and not poi_sought.is_outskirts and not poi_sought.is_pier and poi_sought.id_poi not in [ewcfg.poi_id_slimesendcliffs, ewcfg.poi_id_ferry, ewcfg.poi_id_sodafountain, ewcfg.poi_id_stockexchange, ewcfg.poi_id_ab_farms, ewcfg.poi_id_og_farms, ewcfg.poi_id_jr_farms]): response = "The X-ray vision on this viewport sucks. You can't really see indoors." elif poi_sought.id_poi in [ewcfg.poi_id_rowdyroughhouse, ewcfg.poi_id_copkilltown]: response = "Do you want to blow your cover, dumbass? Stop acting like a gangster. The gang bases are mostly indoors anyway." else: new_permissions = {"ufo-ufo": ["read", "send", "connect"]} new_permissions[poi_sought.channel] = ["read"] current_poi = poi_static.id_to_poi.get('ufoufo') response = "" if current_poi is not None: response = 'You point the observation reticle over at {}.'.format(poi_sought.str_name) district_data = EwDistrict(id_server=cmd.guild.id, district='ufoufo') poi_static.id_to_poi['ufoufo'].permissions = new_permissions players_in_district = district_data.get_players_in_district(min_slimes=0, life_states=[ewcfg.life_state_enlisted, ewcfg.life_state_corpse, ewcfg.life_state_juvenile, ewcfg.life_state_shambler], ignore_offline=True) server = ewcfg.server_list[cmd.guild.id] for playerid in players_in_district: member_object = server.get_member(playerid) await ewrolemgr.updateRoles(client=cmd.client, member=member_object) return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
async def beam_me_up(cmd): user_data = EwUser(member=cmd.message.author) protected = False cosmetics = bknd_item.inventory(id_user=user_data.id_user, id_server=cmd.guild.id, item_type_filter=ewcfg.it_cosmetic) for cosmetic in cosmetics: cosmetic_data = EwItem(id_item=cosmetic.get('id_item')) print(cosmetic_data.item_props) if cosmetic_data.item_props.get('id_cosmetic') == 'skinsuit': if cosmetic_data.item_props.get('adorned') == 'true': protected = True poi_sought = poi_static.id_to_poi.get(user_data.poi) shipstate = EwGamestate(id_server=user_data.id_server, id_state='shipstate') if not protected: response = "Why would aliens abduct you? What makes you so special?" elif poi_sought.id_poi == 'ufoufo': response = 'You\'re already in here.' elif poi_sought.id_poi != ewcfg.poi_id_west_outskirts: response = "Hey, get a bit closer. The ship's in the West Outskirts. Beam up power doesn't grow on trees, you know." elif shipstate.bit == 1: response = 'The ship\'s on the ground right now, it can\'t beam shit.' else: await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage( cmd.message.author, "You are being abducted by aliens. The ship is 20 seconds away." )) ewutils.active_restrictions[user_data.id_user] = 2 await asyncio.sleep(20) ewutils.active_restrictions[user_data.id_user] = 0 ewutils.moves_active[cmd.message.author.id] = 0 user_data.poi = 'ufoufo' user_data.persist() await ewrolemgr.updateRoles(client=ewutils.get_client(), member=cmd.message.author) await user_data.move_inhabitants(id_poi='ufoufo') return await fe_utils.send_message( cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
def canCreateRelic(item, id_server, createstate=0): state = EwGamestate(id_server=id_server, id_state=item) if state.bit is not None: return None else: state.bit = 0 state.value = "" if createstate == 1: state.persist() return 1
async def blockparty(cmd): if not cmd.message.author.guild_permissions.administrator: return else: blockstate = EwGamestate(id_server=cmd.guild.id, id_state='blockparty') if cmd.tokens_count > 1: if cmd.tokens[1] == 'slimegen': blockstate.bit = 1 blockstate.persist() response = "Slimegen turned on." elif cmd.tokens[1] == 'close': blockstate.bit = 0 blockstate.value = '' blockstate.persist() response = "OK, closing up." else: poi_sought = ewutils.flattenTokenListToString(cmd.tokens[1:]) poi = poi_static.id_to_poi.get(poi_sought) if poi is not None: time_end = int(time()) + (60 * 60 * 6) # 6 hours blockstate.value = "{}{}".format(poi.id_poi, time_end) blockstate.persist() response = "Block party in {}! Everybody in!".format(poi.str_name) else: response = "Never heard of it." else: response = "I see you haven't gotten any smarter. Try !blockparty <setting>. Settings include 'close', 'slimegen', and any POI." return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
async def abduct(cmd): user_data = EwUser(member=cmd.message.author) item_sought = bknd_item.find_item(item_search='batterypack', id_user=cmd.message.author.id, id_server=cmd.guild.id) protected = False cosmetics = bknd_item.inventory(id_user=user_data.id_user, id_server=cmd.guild.id, item_type_filter=ewcfg.it_cosmetic) for cosmetic in cosmetics: cosmetic_data = EwItem(id_item=cosmetic.get('id_item')) if cosmetic_data.item_props.get('id_cosmetic') == 'skinsuit': if cosmetic_data.item_props.get('adorned') == 'true': protected = True shipstate = EwGamestate(id_server=user_data.id_server, id_state='shipstate') if user_data.poi != 'ufoufo': response = "Abduct what, dumbass? My patience?" elif not protected: response = "The aliens aren't gonna let you start the ship. You're basically their captive now." elif not ewcfg.dh_active or ewcfg.dh_stage != 3: response = "Wait, your alien espionage is waaaay out of season." elif cmd.mentions_count == 0: response = "Abduct who?" elif cmd.mentions_count > 1: response = "One victim at a time, please." elif shipstate.bit == 1: response = 'The ship\'s on the ground right now, it can\'t reach you.' else: if item_sought: target_data = EwUser(member = cmd.mentions[0]) target_poi = poi_static.id_to_poi.get(target_data.poi) target_channel = fe_utils.get_channel(cmd.message.guild, target_poi.channel) if target_poi.id_poi == 'blackpond' or ( not target_poi.is_district and not target_poi.is_outskirts and not target_poi.is_pier and target_poi.id_poi not in [ ewcfg.poi_id_slimesendcliffs, ewcfg.poi_id_ferry, ewcfg.poi_id_sodafountain, ewcfg.poi_id_stockexchange, ewcfg.poi_id_ab_farms, ewcfg.poi_id_og_farms, ewcfg.poi_id_jr_farms]): response = "The tractor beam on this ship sucks. You can't really see indoors." return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) elif target_poi.id_poi in [ewcfg.poi_id_rowdyroughhouse, ewcfg.poi_id_copkilltown]: response = "Don't do that." return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) bknd_item.item_delete(id_item=item_sought.get('id_item')) ewutils.moves_active[target_data.id_user] = 0 response = 'You plug in your battery pack and begin to abduct {} They\'re 20 seconds away.'.format(cmd.mentions[0].display_name) await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response)) await fe_utils.send_message(cmd.client, target_channel, fe_utils.formatMessage(cmd.mentions[0], "You are being abducted by aliens. The ship is 20 seconds away.")) ewutils.active_restrictions[target_data.id_user] = 2 await asyncio.sleep(20) ewutils.active_restrictions[target_data.id_user] = 0 ewutils.moves_active[cmd.message.author.id] = 0 target_data.poi = 'ufoufo' user_data.persist() target_data.persist() await ewrolemgr.updateRoles(client=ewutils.get_client(), member=cmd.mentions[0]) await target_data.move_inhabitants(id_poi='ufoufo') else: response = "The going energy cost for abduction is pretty expensive these days. You better have a battery pack before you do something like that." return await fe_utils.send_message(cmd.client, cmd.message.channel, fe_utils.formatMessage(cmd.message.author, response))
async def stock_market_tick(stock_data, id_server): market_data = EwMarket(id_server=id_server) company_data = EwCompany(id_server=id_server, stock=stock_data.id_stock) crashstate = EwGamestate(id_server=id_server, id_state='stockcrashdive').bit # Nudge the value back to stability. market_rate = stock_data.market_rate if market_rate >= 1030: market_rate -= 10 elif market_rate <= 970: market_rate += 10 # Invest/Withdraw effects coin_rate = 0 #stock_at_last_tick = EwStock(id_server=id_server, stock=stock_data.id_stock, timestamp=market_data.time_lasttick) #latest_stock = EwStock(id_server=id_server, stock=stock_data.id_stock) if stock_data.previous_entry != 0: total_shares = [stock_data.total_shares, stock_data.previous_entry[4]] else: total_shares = [ stock_data.total_shares, EwStock(id_server=id_server, stock=stock_data.id_stock, timestamp=market_data.time_lasttick).total_shares ] # Add profit bonus. profits = company_data.recent_profits profit_bonus = profits / 100 # - 1 * ((latest_stock.exchange_rate / ewcfg.default_stock_exchange_rate) ** 0.2) profit_bonus = min(50, max(profit_bonus, -50)) market_rate += (profit_bonus / 2) if total_shares[0] != total_shares[1]: # Positive if net investment, negative if net withdrawal. coin_change = (total_shares[0] - total_shares[1]) coin_rate = ((coin_change * 1.0) / total_shares[1] if total_shares[1] != 0 else 1) if coin_rate > 1.0: coin_rate = 1.0 elif coin_rate < -0.5: coin_rate = -0.5 coin_rate = round((coin_rate * ewcfg.max_iw_swing) if coin_rate > 0 else ( coin_rate * 2 * ewcfg.max_iw_swing)) market_rate += coin_rate # Tick down the boombust cooldown. if stock_data.boombust < 0: stock_data.boombust += 1 elif stock_data.boombust > 0: stock_data.boombust -= 1 # Adjust the market rate. fluctuation = 0 # (random.randrange(5) - 2) * 100 noise = (random.randrange(19) - 9) * 2 subnoise = (random.randrange(13) - 6) # Some extra excitement! if noise == 0 and subnoise == 0: boombust = (random.randrange(3) - 1) * 200 if crashstate == 1 and boombust > 0: boombust = -boombust # If a boombust occurs shortly after a previous boombust, make sure it's the opposite effect. (Boom follows bust, bust follows boom.) if (stock_data.boombust > 0 and boombust > 0) or (stock_data.boombust < 0 and boombust < 0): boombust *= -1 if boombust != 0: stock_data.boombust = ewcfg.cd_boombust if boombust < 0: stock_data.boombust *= -1 else: boombust = 0 market_rate += fluctuation + noise + subnoise + boombust if market_rate > 500 and crashstate == 1: market_rate = round(market_rate / 1.25) if market_rate < 300: market_rate = (300 + noise + subnoise) # percentage = ((market_rate / 10) - 100) # percentage_abs = percentage * -1 exchange_rate_increase = round( (market_rate - ewcfg.default_stock_market_rate) * min(stock_data.exchange_rate, ewcfg.default_stock_exchange_rate) / ewcfg.default_stock_market_rate) percentage = exchange_rate_increase / stock_data.exchange_rate percentage_abs = percentage * -1 # negative exchange rate causes problems, duh # exchange_rate_increase = max(exchange_rate_increase, -stock_data.exchange_rate + 1000) points = abs(exchange_rate_increase / 1000.0) stock_data.exchange_rate += exchange_rate_increase stock_data.market_rate = market_rate # Give some indication of how the market is doing to the users. response = ewcfg.stock_emotes.get( stock_data.id_stock) + ' ' + ewcfg.stock_names.get( stock_data.id_stock) + ' ' if stock_data.exchange_rate < 1000: response += 'has gone bankrupt!' if stock_data.total_shares > 0: majority_shareholder = get_majority_shareholder( stock=stock_data.id_stock, id_server=id_server) player_data = EwPlayer(id_user=majority_shareholder) shares = getUserTotalShares(stock=stock_data.id_stock, id_user=majority_shareholder, id_server=stock_data.id_server) shares_lost = round(shares * 0.9) stock_data.total_shares -= shares_lost updateUserTotalShares(stock=stock_data.id_stock, id_user=majority_shareholder, id_server=stock_data.id_server, shares=shares - shares_lost) response += ' The majority shareholder {} is held responsible. SlimeCorp seizes 90% of their shares in the company to pay for the damages.'.format( player_data.display_name) stock_data.exchange_rate = 10000 else: response += ' SlimeCorp pumps several billion slimecoin into bailing the company out and a new image campaign.' stock_data.exchange_rate = ewcfg.default_stock_exchange_rate stock_data.market_rate = ewcfg.default_stock_market_rate else: # Market is up ... if market_rate > 1200: response += 'is skyrocketing!!! Slime stock is up {p:.3g} points!!!'.format( p=points) elif market_rate > 1100: response += 'is booming! Slime stock is up {p:.3g} points!'.format( p=points) elif market_rate > 1000: response += 'is doing well. Slime stock is up {p:.3g} points.'.format( p=points) # Market is down ... elif market_rate < 800: response += 'is plummeting!!! Slime stock is down {p:.3g} points!!!'.format( p=points) elif market_rate < 900: response += 'is stagnating! Slime stock is down {p:.3g} points!'.format( p=points) elif market_rate < 1000: response += 'is a bit sluggish. Slime stock is down {p:.3g} points.'.format( p=points) # Perfectly balanced else: response += 'is holding steady. No change in slime stock value.' response += ' ' + ewcfg.stock_emotes.get(stock_data.id_stock) stock_data.persist() company_data.total_profits += company_data.recent_profits company_data.recent_profits = 0 company_data.persist() # Send the announcement. return response
async def updateRoles( client = None, member = None, server_default = None, refresh_perms = True, remove_or_apply_flag = None, new_poi = None ): time_now = int(time.time()) if server_default != None: user_data = EwUser(id_user=member.id, id_server=server_default) else: user_data = EwUser(member=member) id_server = user_data.id_server if member == None: return ewutils.logMsg("error: member was not supplied for updateRoles") # roles_map = ewutils.getRoleMap(member.guild.roles) roles_map_user = ewutils.getRoleIdMap(member.roles) user_poi = poi_static.id_to_poi.get(user_data.poi) if new_poi is not None: user_poi = poi_static.id_to_poi.get(new_poi) if user_data.life_state != ewcfg.life_state_kingpin and ewcfg.role_kingpin in roles_map_user: # Fix the life_state of kingpins, if somehow it wasn't set. user_data.life_state = ewcfg.life_state_kingpin user_data.persist() elif user_data.life_state != ewcfg.life_state_grandfoe and ewcfg.role_grandfoe in roles_map_user: # Fix the life_state of a grand foe. user_data.life_state = ewcfg.life_state_grandfoe user_data.persist() faction_roles_remove = [ ewcfg.role_juvenile, ewcfg.role_juvenile_active, ewcfg.role_juvenile_pvp, ewcfg.role_rowdyfuckers, ewcfg.role_rowdyfuckers_pvp, ewcfg.role_rowdyfuckers_active, ewcfg.role_slimecorp, ewcfg.role_slimecorp_pvp, ewcfg.role_slimecorp_active, ewcfg.role_copkillers, ewcfg.role_copkillers_pvp, ewcfg.role_copkillers_active, ewcfg.role_corpse, ewcfg.role_corpse_pvp, ewcfg.role_corpse_active, ewcfg.role_kingpin, ewcfg.role_grandfoe, ewcfg.role_executive, ewcfg.role_tutorial, ] # Manage faction roles. faction_role = ewutils.get_faction(user_data=user_data) if ewcfg.dh_stage == 4 and ewcfg.dh_active: faction_role = ewcfg.role_juvenile faction_roles_remove.remove(faction_role) non_wanted_pois = [ ewcfg.poi_id_copkilltown, ewcfg.poi_id_rowdyroughhouse, ewcfg.poi_id_juviesrow, ewcfg.poi_id_thebreakroom, ewcfg.poi_id_mine, ewcfg.poi_id_mine_bubble, ewcfg.poi_id_mine_sweeper, ewcfg.poi_id_juviesrow_pier, ewcfg.poi_id_jr_farms ] pvp_role = None active_role = None lastwarp = ewutils.last_warps.get(user_data.id_user) lastwarp = 0 if lastwarp is None else lastwarp + 19 #add 19 secs to the last time someone started a teleport to check pvp flagging # If faction has an associated PVP role if faction_role in ewcfg.role_to_pvp_role: if (not user_poi.is_apartment and \ user_poi.id_poi not in non_wanted_pois) or lastwarp > time_now: # and \ # (user_data.life_state != ewcfg.life_state_juvenile or user_data.slimelevel > ewcfg.max_safe_level): pvp_role = ewcfg.role_to_pvp_role.get(faction_role) faction_roles_remove.remove(pvp_role) # if ewutils.is_otp(user_data): # active_role = ewcfg.role_to_active_role.get(faction_role) # faction_roles_remove.remove(active_role) tutorial_role = None if user_poi.id_poi in poi_static.tutorial_pois: tutorial_role = ewcfg.role_tutorial faction_roles_remove.remove(tutorial_role) # Manage location roles. if user_poi != None: # poi_role = user_poi.role poi_major_role = user_poi.major_role poi_minor_role = user_poi.minor_role poi_permissions = user_poi.permissions else: # poi_role = None poi_major_role = None poi_minor_role = None poi_permissions = None poi_permissions_remove = [] for poi in poi_static.poi_list: if poi.permissions != None and poi.permissions != poi_permissions: poi_permissions_remove.append(poi.id_poi) poi_roles_remove = [] for poi in poi_static.poi_list: #if poi.major_role != None and poi.major_role != poi_major_role: poi_roles_remove.append(poi.major_role) # if poi.minor_role != None and poi.minor_role != poi_minor_role: poi_roles_remove.append(poi.minor_role) misc_roles_remove = [ ewcfg.role_gellphone, ewcfg.role_slimernalia ] # Remove user's gellphone role if they don't have a phone role_gellphone = None if user_data.has_gellphone(): role_gellphone = ewcfg.role_gellphone misc_roles_remove.remove(ewcfg.role_gellphone) role_slimernalia = None currentkingpin = EwGamestate(id_server=id_server, id_state='slimernaliakingpin').value if currentkingpin == str(user_data.id_user): role_slimernalia = ewcfg.role_slimernalia misc_roles_remove.remove(ewcfg.role_slimernalia) role_ids = [] for role_id in roles_map_user: try: role_data = EwRole(id_server=id_server, id_role=role_id) roleName = role_data.name if roleName != None and roleName not in faction_roles_remove and roleName not in misc_roles_remove and roleName not in poi_roles_remove and role_data.id_role != '': role_ids.append(int(role_data.id_role)) except: ewutils.logMsg('error: couldn\'t find role with id {}'.format(role_id)) try: role_data = EwRole(id_server=id_server, name=faction_role) if not role_data.id_role in role_ids and role_data.id_role != '': role_ids.append(int(role_data.id_role)) # ewutils.logMsg('found role {} with id {}'.format(role_data.name, role_data.id_role)) except: ewutils.logMsg('error: couldn\'t find faction role {}'.format(faction_role)) try: role_data = EwRole(id_server=id_server, name=pvp_role) if not role_data.id_role in role_ids and role_data.id_role != '': role_ids.append(int(role_data.id_role)) # ewutils.logMsg('found role {} with id {}'.format(role_data.name, role_data.id_role)) except: ewutils.logMsg('error: couldn\'t find pvp role {}'.format(pvp_role)) try: role_data = EwRole(id_server=id_server, name=active_role) if not role_data.id_role in role_ids and role_data.id_role != '': role_ids.append(int(role_data.id_role)) # ewutils.logMsg('found role {} with id {}'.format(role_data.name, role_data.id_role)) except: ewutils.logMsg('error: couldn\'t find active role {}'.format(active_role)) try: role_data = EwRole(id_server=id_server, name=tutorial_role) if not role_data.id_role in role_ids and role_data.id_role != '': role_ids.append(int(role_data.id_role)) # ewutils.logMsg('found role {} with id {}'.format(role_data.name, role_data.id_role)) except: ewutils.logMsg('error: couldn\'t find tutorial role {}'.format(tutorial_role)) # poi roles are disabled # try: # major_role_data = EwRole(id_server = id_server, name = poi_major_role) # if not major_role_data.id_role in role_ids and major_role_data.id_role != '': # role_ids.append(int(major_role_data.id_role)) # ewutils.logMsg('found role {} with id {}'.format(role_data.name, role_data.id_role)) # except: # ewutils.logMsg('error: couldn\'t find major role {}'.format(poi_major_role)) # try: # minor_role_data = EwRole(id_server = id_server, name = poi_minor_role) # if not minor_role_data.id_role in role_ids and minor_role_data.id_role != '': # role_ids.append(int(minor_role_data.id_role)) # ewutils.logMsg('found role {} with id {}'.format(role_data.name, role_data.id_role)) # except: # ewutils.logMsg('error: couldn\'t find minor role {}'.format(poi_minor_role)) try: role_data = EwRole(id_server=id_server, name=role_gellphone) if not role_data.id_role in role_ids and role_data.id_role != '': role_ids.append(int(role_data.id_role)) # ewutils.logMsg('found role {} with id {}'.format(role_data.name, role_data.id_role)) except: ewutils.logMsg('error: couldn\'t find gellphone role {}'.format(role_gellphone)) try: role_data = EwRole(id_server=id_server, name=role_slimernalia) if not role_data.id_role in role_ids and role_data.id_role != '': role_ids.append(int(role_data.id_role)) # ewutils.logMsg('found role {} with id {}'.format(role_data.name, role_data.id_role)) except: ewutils.logMsg('error: couldn\'t find slimernalia role {}'.format(role_slimernalia)) # if faction_role not in role_names: # role_names.append(faction_role) # if poi_role != None and poi_role not in role_names: # role_names.append(poi_role) # replacement_roles = [] # for name in role_names: # role = roles_map.get(name) # if role != None: # replacement_roles.append(role) # else: # ewutils.logMsg("error: role missing \"{}\"".format(name)) # ewutils.logMsg('looking for {} roles to replace'.format(len(role_ids))) replacement_roles = [] for role in member.guild.roles: if role.id in role_ids: # ewutils.logMsg('found role {} with id {}'.format(role.name, role.id)) replacement_roles.append(role) # ewutils.logMsg('found {} roles to replace'.format(len(replacement_roles))) try: await member.edit(roles=replacement_roles) except Exception as e: ewutils.logMsg('error: failed to replace roles for {}:{}'.format(member.display_name, str(e))) if refresh_perms: await refresh_user_perms(client=client, id_server=id_server, used_member=member, new_poi = new_poi)
async def kick(id_server): # Gets data for all living players from the database all_living_players = bknd_core.execute_sql_query( "SELECT {poi}, {id_user} FROM users WHERE id_server = %s AND {life_state} > 0 AND {time_last_action} < %s" .format(poi=ewcfg.col_poi, id_user=ewcfg.col_id_user, time_last_action=ewcfg.col_time_last_action, life_state=ewcfg.col_life_state), (id_server, (int(time.time()) - ewcfg.time_kickout))) client = ewutils.get_client() blockparty = EwGamestate(id_server=id_server, id_state='blockparty') party_poi = ''.join([i for i in blockparty.value if not i.isdigit()]) if party_poi == 'outsidethe': party_poi = ewcfg.poi_id_711 for player in all_living_players: try: poi = poi_static.id_to_poi[player[0]] id_user = player[1] # checks if the player should be kicked from the subzone and kicks them if they should. if poi.is_subzone and poi.id_poi not in [ ewcfg.poi_id_thesphere, ewcfg.poi_id_thebreakroom ]: # Don't load the user until we know that we need to user_data = EwUser(id_user=id_user, id_server=id_server) # Some subzones could potentially have multiple mother districts. # Make sure to get one that's accessible before attempting a proper kickout. mother_district_chosen = random.choice(poi.mother_districts) if inaccessible( user_data=user_data, poi=poi_static.id_to_poi.get(mother_district_chosen)): # If the randomly chosen mother district is inaccessible, make one more attempt. mother_district_chosen = random.choice( poi.mother_districts) else: pass if not inaccessible( user_data=user_data, poi=poi_static.id_to_poi.get(mother_district_chosen)): if user_data.poi != party_poi and user_data.life_state not in [ ewcfg.life_state_kingpin, ewcfg.life_state_lucky, ewcfg.life_state_executive ]: server = ewcfg.server_list[id_server] member_object = server.get_member(id_user) user_data.poi = mother_district_chosen user_data.time_lastenter = int(time.time()) user_data.change_crime( n=50) # loitering:punishable by death user_data.persist() await ewrolemgr.updateRoles(client=client, member=member_object) await user_data.move_inhabitants( id_poi=mother_district_chosen) mother_district_channel = fe_utils.get_channel( server, poi_static. id_to_poi[mother_district_chosen].channel) response = "You have been kicked out for loitering! You can only stay in a sub-zone and twiddle your thumbs for 1 hour at a time." await fe_utils.send_message( client, mother_district_channel, fe_utils.formatMessage(member_object, response)) except: ewutils.logMsg( 'failed to move inactive player out of subzone with poi {}: {}' .format(player[0], player[1]))