def persist(self): try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Save the object. cursor.execute( "REPLACE INTO markets({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" .format(ewcfg.col_id_server, ewcfg.col_slimes_casino, ewcfg.col_rate_market, ewcfg.col_rate_exchange, ewcfg.col_boombust, ewcfg.col_time_lasttick, ewcfg.col_slimes_revivefee, ewcfg.col_negaslime, ewcfg.col_clock, ewcfg.col_weather, ewcfg.col_day, ewcfg.col_decayed_slimes), (self.id_server, self.slimes_casino, self.rate_market, self.rate_exchange, self.boombust, self.time_lasttick, self.slimes_revivefee, self.negaslime, self.clock, self.weather, self.day, self.decayed_slimes)) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def persist(self, conn=None, cursor=None): our_cursor = False our_conn = False try: # Get database handles if they weren't passed. if (cursor == None): if (conn == None): conn = ewutils.databaseConnect() our_conn = True cursor = conn.cursor() our_cursor = True # Save the object. cursor.execute( "REPLACE INTO users({}, {}, {}, {}, {}, {}, {}, {}, {}) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)" .format(col_id_user, col_id_server, col_slimes, col_time_lastkill, col_time_lastrevive, col_id_killer, col_time_lastspar, col_time_expirpvp, col_time_lasthaunt), (self.id_user, self.id_server, self.slimes, self.time_lastkill, self.time_lastrevive, self.id_killer, self.time_lastspar, self.time_expirpvp, self.time_lasthaunt)) if our_cursor: conn.commit() finally: # Clean up the database handles. if (our_cursor): cursor.close() if (our_conn): conn.close()
def player_update(member=None, server=None): id_server_old = "" try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Get existing player info (or create a record if it's a new player) player = EwPlayer(id_user=member.id, id_server=server.id) # Update values with Member data. id_server_old = player.id_server player.id_server = server.id player.avatar = member.avatar_url player.display_name = member.display_name # Save the updated data. player.persist() conn.commit() finally: cursor.close() ewutils.databaseClose(conn_info) # Log server changes if (server.id != id_server_old): ewutils.logMsg('active server for {} changed from "{}" to "{}"'.format( member.display_name, id_server_old, server.id))
def persist(self): try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Save the object. cursor.execute( "REPLACE INTO swilldermuk_prank_index({}, {}, {}, {}) VALUES(%s, %s, %s, %s)" .format( col_id_server, col_id_user_pranker, col_id_user_pranked, col_prank_count, ), ( self.id_server, self.id_user_pranker, self.id_user_pranked, self.prank_count, )) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def persist(self): try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Save the object. cursor.execute( "REPLACE INTO markets ({id_server}, {time_lasttick}, {slimes_revivefee}, {negaslime}, {clock}, {weather}, {day}, {decayed_slimes}, {donated_slimes}, {donated_poudrins}, {caught_fish}, {splattered_slimes}) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" .format( id_server=ewcfg.col_id_server, time_lasttick=ewcfg.col_time_lasttick, slimes_revivefee=ewcfg.col_slimes_revivefee, negaslime=ewcfg.col_negaslime, clock=ewcfg.col_clock, weather=ewcfg.col_weather, day=ewcfg.col_day, decayed_slimes=ewcfg.col_decayed_slimes, donated_slimes=ewcfg.col_donated_slimes, donated_poudrins=ewcfg.col_donated_poudrins, caught_fish=ewcfg.col_caught_fish, splattered_slimes=ewcfg.col_splattered_slimes, ), ( self.id_server, self.time_lasttick, self.slimes_revivefee, self.negaslime, self.clock, self.weather, self.day, self.decayed_slimes, self.donated_slimes, self.donated_poudrins, self.caught_fish, self.splattered_slimes, )) cursor.execute( "DELETE FROM bazaar_wares WHERE {} = %s".format( ewcfg.col_id_server, ), (self.id_server, )) # Write out all current item rows. for name in self.bazaar_wares: cursor.execute( "INSERT INTO bazaar_wares({}, {}, {}) VALUES(%s, %s, %s)". format( ewcfg.col_id_server, ewcfg.col_name, ewcfg.col_value, ), ( self.id_server, name, self.bazaar_wares[name], )) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
async def slimecoin(cmd): resp = await ewcmd.start(cmd=cmd) response = "" try: conn = ewutils.databaseConnect() cursor = conn.cursor() market_data = EwMarket(id_server=cmd.message.server.id, conn=conn, cursor=cursor) user_slimecredit = EwUser(member=cmd.message.author, conn=conn, cursor=cursor).slimecredit finally: cursor.close() conn.close() net_worth = int(user_slimecredit * (market_data.rate_exchange / 1000000.0)) response = "You have {:,} SlimeCoin, currently valued at {:,} slime.".format( user_slimecredit, net_worth) # Send the response to the player. await cmd.client.edit_message( resp, ewutils.formatMessage(cmd.message.author, response))
def item_destroyall(id_server=None, id_user=None, member=None): if member != None: id_server = member.server.id id_user = member.id if id_server != None and id_user != None: try: # Get database handles if they weren't passed. conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() cursor.execute( "DELETE FROM items WHERE {id_server} = %s AND {id_user} = %s AND {soulbound} = 0" .format( id_user=ewcfg.col_id_user, id_server=ewcfg.col_id_server, soulbound=ewcfg.col_soulbound, ), (id_server, id_user)) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def persist(self): try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Save the object. cursor.execute( "REPLACE INTO items({}, {}, {}, {}, {}, {}, {}, {}) VALUES(%s, %s, %s, %s, %s, %s, %s, %s)" .format(ewcfg.col_id_item, ewcfg.col_id_server, ewcfg.col_id_user, ewcfg.col_item_type, ewcfg.col_time_expir, ewcfg.col_stack_max, ewcfg.col_stack_size, ewcfg.col_soulbound), (self.id_item, self.id_server, self.id_user, self.item_type, self.time_expir if self.time_expir is not None else self.item_props['time_expir'], self.stack_max, self.stack_size, (1 if self.soulbound else 0))) # Remove all existing property rows. cursor.execute( "DELETE FROM items_prop WHERE {} = %s".format( ewcfg.col_id_item), (self.id_item, )) # Write out all current property rows. for name in self.item_props: cursor.execute( "INSERT INTO items_prop({}, {}, {}) VALUES(%s, %s, %s)". format(ewcfg.col_id_item, ewcfg.col_name, ewcfg.col_value), (self.id_item, name, self.item_props[name])) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def int_is_zine(id_book = None, id_server = None, negative = False): direction = '>' if negative: direction = '<' book_list = [] try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() cursor.execute(( "SELECT b.id_book " + "FROM books AS b " + "WHERE b.id_server = %s AND b.book_state {} 0 ".format(direction) + "ORDER BY b.id_book" ), ( id_server, )) data = cursor.fetchall() if data != None: for row in data: book_list.append(row[0]) finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info) if id_book in book_list: return True else: return False
def persist(self, conn=None, cursor=None): our_cursor = False our_conn = False try: # Get database handles if they weren't passed. if (cursor == None): if (conn == None): conn = ewutils.databaseConnect() our_conn = True cursor = conn.cursor() our_cursor = True # Save the object. cursor.execute( "REPLACE INTO servers({}, {}, {}) VALUES(%s, %s, %s)".format( ewcfg.col_id_server, ewcfg.col_name, ewcfg.col_icon), (self.id_server, self.name, self.icon)) if our_cursor: conn.commit() finally: # Clean up the database handles. if (our_cursor): cursor.close() if (our_conn): conn.close()
async def negaslime(cmd): negaslime = 0 try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Count all negative slime currently possessed by dead players. cursor.execute("SELECT sum({}) FROM users WHERE id_server = %s AND {} < 0".format( ewcfg.col_slimes, ewcfg.col_slimes ), (cmd.message.server.id, )) result = cursor.fetchone(); if result != None: negaslime = result[0] if negaslime == None: negaslime = 0 finally: cursor.close() ewutils.databaseClose(conn_info) # Add persisted negative slime. market_data = EwMarket(id_server = cmd.message.server.id) negaslime += market_data.negaslime await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, "The dead have amassed {:,} negative slime.".format(negaslime)))
def persist(self): if self.icon == None: self.icon = "" try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Save the object. cursor.execute("REPLACE INTO servers({}, {}, {}) VALUES(%s, %s, %s)".format( ewcfg.col_id_server, ewcfg.col_name, ewcfg.col_icon ), ( self.id_server, self.name, self.icon )) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def track_maximum(id_server=None, id_user=None, user=None, metric=None, value=0): if (id_user == None) and (id_server == None): if (user != None): id_server = user.id_server id_user = user.id_user try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() old_value = get_stat(id_server=id_server, id_user=id_user, metric=metric) if old_value < value: set_stat(id_server=id_server, id_user=id_user, metric=metric, value=value) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def item_create(item_type=None, id_user=None, id_server=None, item_props=None, conn=None, cursor=None): our_cursor = False our_conn = False item_def = ewcfg.item_def_map.get(item_type) if item_def == None: ewutils.logMsg( 'Tried to create invalid item_type: {}'.format(item_type)) return try: # Get database handles if they weren't passed. if (cursor == None): if (conn == None): conn = ewutils.databaseConnect() our_conn = True cursor = conn.cursor() our_cursor = True # Create the item in the database. cursor.execute( "INSERT INTO items({}, {}, {}, {}, {}, {}) VALUES(%s, %s, %s, %s, %s, %s)" .format(ewcfg.col_item_type, ewcfg.col_id_user, ewcfg.col_id_server, ewcfg.col_soulbound, ewcfg.col_stack_max, ewcfg.col_stack_size), (item_type, id_user, id_server, (1 if item_def.soulbound else 0), item_def.stack_max, item_def.stack_size)) item_id = cursor.lastrowid conn.commit() if item_id > 0: # If additional properties are specified in the item definition or in this create call, create and persist them. if item_props != None or item_def.item_props != None: item_inst = EwItem(id_item=item_id) if item_def.item_props != None: item_inst.item_props.update(item_def.item_props) if item_props != None: item_inst.item_props.update(item_props) item_inst.persist(conn=conn, cursor=cursor) conn.commit() finally: # Clean up the database handles. if (our_cursor): cursor.close() if (our_conn): conn.close() return item_id
def make_kingpin_board(server=None, title=""): entries = [] try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() cursor.execute( "SELECT {name}, {state}, {faction}, {category} FROM users, players WHERE users.id_server = %s AND {state} = %s AND users.{id_user} = players.{id_user} ORDER BY {category} DESC" .format(name=ewcfg.col_display_name, state=ewcfg.col_life_state, faction=ewcfg.col_faction, category=ewcfg.col_slimes, id_user=ewcfg.col_id_user), (server.id, ewcfg.life_state_kingpin)) rows = cursor.fetchall() for row in rows: entries.append(row) finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info) return format_board(entries=entries, title=title)
def persist(self, conn=None, cursor=None): our_cursor = False our_conn = False try: # Get database handles if they weren't passed. if (cursor == None): if (conn == None): conn = ewutils.databaseConnect() our_conn = True cursor = conn.cursor() our_cursor = True # Save the object. cursor.execute( "REPLACE INTO markets({}, {}, {}, {}, {}, {}, {}, {}, {}, {}) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" .format(ewcfg.col_id_server, ewcfg.col_slimes_casino, ewcfg.col_rate_market, ewcfg.col_rate_exchange, ewcfg.col_boombust, ewcfg.col_time_lasttick, ewcfg.col_slimes_revivefee, ewcfg.col_negaslime, ewcfg.col_clock, ewcfg.col_weather), (self.id_server, self.slimes_casino, self.rate_market, self.rate_exchange, self.boombust, self.time_lasttick, self.slimes_revivefee, self.negaslime, self.clock, self.weather)) if our_cursor: conn.commit() finally: # Clean up the database handles. if (our_cursor): cursor.close() if (our_conn): conn.close()
def item_delete(id_item=None, conn=None, cursor=None): our_cursor = False our_conn = False try: # Get database handles if they weren't passed. if (cursor == None): if (conn == None): conn = ewutils.databaseConnect() our_conn = True cursor = conn.cursor() our_cursor = True # Create the item in the database. cursor.execute( "DELETE FROM items WHERE {} = %s".format(ewcfg.col_id_item), (id_item, )) conn.commit() finally: # Clean up the database handles. if (our_cursor): cursor.close() if (our_conn): conn.close()
def __init__(self, id_user = None, id_server = None, id_mutation = None): # Retrieve the object from the database if the user is provided. if(id_user != None) and (id_server != None) and (id_mutation != None): self.id_server = id_server self.id_user = id_user self.id_mutation = id_mutation try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor(); # Retrieve object cursor.execute("SELECT {data}, {mutation_counter} FROM mutations WHERE id_user = %s AND id_server = %s AND {id_mutation} = %s".format( data = ewcfg.col_mutation_data, mutation_counter = ewcfg.col_mutation_counter, id_mutation = ewcfg.col_id_mutation ), ( id_user, id_server, id_mutation )) result = cursor.fetchone(); if result != None: # Record found: apply the data to this object. self.data = result[0] self.mutation_counter = result[1] finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def persist(self): try: # Get database handles if they weren't passed. conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor(); # Save the object. cursor.execute("REPLACE INTO mutations(id_user, id_server, {id_mutation}, {data}, {mutation_counter}) VALUES(%s, %s, %s, %s, %s)".format( id_mutation = ewcfg.col_id_mutation, data = ewcfg.col_mutation_data, mutation_counter = ewcfg.col_mutation_counter ), ( self.id_user, self.id_server, self.id_mutation, self.data, self.mutation_counter )) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def make_zines_top_board(server=None): board = "{zine} ▓▓▓▓▓ BESTSELLING ZINES ▓▓▓▓▓ {zine}\n".format( zine="<:zine:655854388761460748>") try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() cursor.execute( ("SELECT b.title, b.author, b.sales " + "FROM books as b " + "WHERE b.id_server = %s AND b.book_state = 1 " + "ORDER BY b.sales DESC LIMIT 5"), (server.id, )) data = cursor.fetchall() if data != None: for row in data: board += "{} `{:_>3} | {} by {}`\n".format( ewcfg.emote_blank, row[2], row[0].replace("`", ""), row[1].replace("`", "")) finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info) return board
def __init__( self, id_server = None ): if(id_server != None): self.id_server = id_server try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Retrieve object cursor.execute("SELECT {}, {} FROM servers WHERE id_server = %s".format( ewcfg.col_name, ewcfg.col_icon ), (self.id_server, )) result = cursor.fetchone(); if result != None: # Record found: apply the data to this object. self.name = result[0] else: # Create a new database entry if the object is missing. cursor.execute("REPLACE INTO servers({}) VALUES(%s)".format( ewcfg.col_id_server ), ( self.id_server, )) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def make_slimeoids_top_board(server=None): board = "{mega} ▓▓▓▓▓ TOP SLIMEOIDS (CLOUT) ▓▓▓▓▓ {mega}\n".format( mega="<:megaslime:436877747240042508>") try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() cursor.execute( ("SELECT pl.display_name, sl.name, sl.clout " + "FROM slimeoids AS sl " + "INNER JOIN players AS pl ON sl.id_user = pl.id_user " + "WHERE sl.id_server = %s AND sl.life_state = 2 " + "ORDER BY sl.clout DESC LIMIT 3"), (server.id, )) data = cursor.fetchall() if data != None: for row in data: board += "{} `{:_>3} | {}'s {}`\n".format( ewcfg.emote_blank, row[2], row[0].replace("`", ""), row[1].replace("`", "")) finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info) return board
def persist(self): try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Save the object. cursor.execute( "REPLACE INTO book_sales({}, {}, {}, {}, {}) VALUES(%s, %s, %s, %s, %s)".format( ewcfg.col_id_book, ewcfg.col_id_server, ewcfg.col_id_user, ewcfg.col_bought, ewcfg.col_rating, ), ( self.id_book, self.id_server, self.id_user, self.bought, self.rating, )) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def make_userdata_board(server = None, category = "", title = "", lowscores = False, rows = 5, divide_by = 1): entries = [] try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() cursor.execute("SELECT {name}, {state}, {faction}, {category} FROM users, players WHERE users.id_server = %s AND users.{id_user} = players.{id_user} ORDER BY {category} {order} LIMIT {limit}".format( name = ewcfg.col_display_name, state = ewcfg.col_life_state, faction = ewcfg.col_faction, category = category, id_user = ewcfg.col_id_user, order = ('DESC' if lowscores == False else 'ASC'), limit = rows ), ( server.id, )) i = 0 row = cursor.fetchone() while (row != None) and (i < rows): if row[1] == ewcfg.life_state_kingpin or row[1] == ewcfg.life_state_grandfoe or row[1] == ewcfg.life_state_lucky: row = cursor.fetchone() else: entries.append(row) row = cursor.fetchone() i += 1 finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info) return format_board(entries = entries, title = title, divide_by = divide_by)
def set_stat(id_server=None, id_user=None, user=None, metric=None, value=0): if (id_user == None) and (id_server == None): if (user != None): id_server = user.id_server id_user = user.id_user try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() cursor.execute( "REPLACE INTO stats({id_server}, {id_user}, {metric}, {value}) VALUES(%s, %s, %s, %s)" .format(id_server=ewcfg.col_id_server, id_user=ewcfg.col_id_user, metric=ewcfg.col_stat_metric, value=ewcfg.col_stat_value), (id_server, id_user, metric, value)) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info) ewevent.process_stat_change(id_server=id_server, id_user=id_user, metric=metric, value=value)
def persist(self): try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Save the object. cursor.execute("REPLACE INTO enemy_status_effects({}, {}, {}, {}, {}, {}, {}) VALUES(%s, %s, %s, %s, %s, %s, %s)".format( ewcfg.col_id_server, ewcfg.col_id_enemy, ewcfg.col_id_status, ewcfg.col_time_expir, ewcfg.col_value, ewcfg.col_source, ewcfg.col_status_target, ), ( self.id_server, self.id_enemy, self.id_status, self.time_expire, self.value, self.source, self.id_target, )) conn.commit() finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
def __init__(self, id_server=None, conn=None, cursor=None): if (id_server != None): self.id_server = id_server our_cursor = False our_conn = False try: # Get database handles if they weren't passed. if (cursor == None): if (conn == None): conn = ewutils.databaseConnect() our_conn = True cursor = conn.cursor() our_cursor = True # Retrieve object cursor.execute( "SELECT {}, {}, {}, {}, {}, {}, {}, {}, {} FROM markets WHERE id_server = %s" .format( ewcfg.col_slimes_casino, ewcfg.col_rate_market, ewcfg.col_rate_exchange, ewcfg.col_boombust, ewcfg.col_time_lasttick, ewcfg.col_slimes_revivefee, ewcfg.col_negaslime, ewcfg.col_clock, ewcfg.col_weather, ), (self.id_server, )) result = cursor.fetchone() if result != None: # Record found: apply the data to this object. self.slimes_casino = result[0] self.rate_market = result[1] self.rate_exchange = result[2] self.boombust = result[3] self.time_lasttick = result[4] self.slimes_revivefee = result[5] self.negaslime = result[6] self.clock = result[7] self.weather = result[8] else: # Create a new database entry if the object is missing. cursor.execute( "REPLACE INTO markets(id_server) VALUES(%s)", (id_server, )) conn.commit() finally: # Clean up the database handles. if (our_cursor): cursor.close() if (our_conn): conn.close()
def __init__(self, id_item=None, conn=None, cursor=None): if (id_item != None): self.id_item = id_item our_cursor = False our_conn = False try: # Get database handles if they weren't passed. if (cursor == None): if (conn == None): conn = ewutils.databaseConnect() our_conn = True cursor = conn.cursor() our_cursor = True # Retrieve object cursor.execute( "SELECT {}, {}, {}, {}, {}, {}, {} FROM items WHERE id_item = %s" .format(ewcfg.col_id_server, ewcfg.col_id_user, ewcfg.col_item_type, ewcfg.col_time_expir, ewcfg.col_stack_max, ewcfg.col_stack_size, ewcfg.col_soulbound), (self.id_item, )) result = cursor.fetchone() if result != None: # Record found: apply the data to this object. self.id_server = result[0] self.id_user = result[1] self.item_type = result[2] self.time_expir = result[3] self.stack_max = result[4] self.stack_size = result[5] self.soulbound = (result[6] != 0) # Retrieve additional properties cursor.execute( "SELECT {}, {} FROM items_prop WHERE id_item = %s". format(ewcfg.col_name, ewcfg.col_value), (self.id_item, )) for row in cursor: self.item_props[row[0]] = row[1] else: # Item not found. self.id_item = -1 finally: # Clean up the database handles. if (our_cursor): cursor.close() if (our_conn): conn.close()
def __init__(self, id_item=None): if (id_item != None): self.id_item = id_item # the item props don't reset themselves automatically which is why the items_prop table had tons of extraneous rows (like food items having medal_names) self.item_props.clear() try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() # Retrieve object cursor.execute( "SELECT {}, {}, {}, {}, {}, {}, {} FROM items WHERE id_item = %s" .format(ewcfg.col_id_server, ewcfg.col_id_user, ewcfg.col_item_type, ewcfg.col_time_expir, ewcfg.col_stack_max, ewcfg.col_stack_size, ewcfg.col_soulbound), (self.id_item, )) result = cursor.fetchone() if result != None: # Record found: apply the data to this object. self.id_server = result[0] self.id_user = result[1] self.item_type = result[2] self.time_expir = result[3] self.stack_max = result[4] self.stack_size = result[5] self.soulbound = (result[6] != 0) # Retrieve additional properties cursor.execute( "SELECT {}, {} FROM items_prop WHERE id_item = %s". format(ewcfg.col_name, ewcfg.col_value), (self.id_item, )) for row in cursor: # this try catch is only necessary as long as extraneous props exist in the table try: self.item_props[row[0]] = row[1] except: ewutils.logMsg( "extraneous item_prop row detected.") else: # Item not found. self.id_item = -1 finally: # Clean up the database handles. cursor.close() ewutils.databaseClose(conn_info)
async def equip(cmd): response = "" user_data = EwUser(member=cmd.message.author) if cmd.message.channel.name != ewcfg.channel_dojo: response = "You must go to the #{} to change your equipment.".format( ewcfg.channel_dojo) elif user_data.life_state == ewcfg.life_state_corpse: response = "Ghosts can't equip weapons." elif user_data.life_state == ewcfg.life_state_juvenile: response = "Juvies can't equip weapons." else: value = None if cmd.tokens_count > 1: value = cmd.tokens[1] value = value.lower() weapon = ewcfg.weapon_map.get(value) if weapon != None: response = weapon.str_equip try: conn_info = ewutils.databaseConnect() conn = conn_info.get('conn') cursor = conn.cursor() user_skills = ewutils.weaponskills_get( member=cmd.message.author) user_data.weapon = weapon.id_weapon weaponskillinfo = user_skills.get(weapon.id_weapon) if weaponskillinfo == None: user_data.weaponskill = 0 user_data.weaponname = "" else: user_data.weaponskill = weaponskillinfo.get('skill') user_data.weaponname = weaponskillinfo.get('name') user_data.persist() conn.commit() finally: cursor.close() ewutils.databaseClose(conn_info) else: response = "Choose your weapon: {}".format( ewutils.formatNiceList(names=ewcfg.weapon_names, conjunction="or")) # Send the response to the player. await cmd.client.send_message( cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))