예제 #1
0
	def persist(self):
		ewutils.execute_sql_query("REPLACE INTO districts(id_server, {district}, {controlling_faction}, {capturing_faction}, {capture_points}, {slimes}, {time_unlock}, {cap_side}, {degradation}, {horde_cooldown}, {gaiaslime}) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)".format(
			district = ewcfg.col_district,
			controlling_faction = ewcfg.col_controlling_faction,
			capturing_faction = ewcfg.col_capturing_faction,
			capture_points = ewcfg.col_capture_points,
			slimes = ewcfg.col_district_slimes,
			time_unlock = ewcfg.col_time_unlock,
			cap_side = ewcfg.col_cap_side,
			degradation = ewcfg.col_degradation,
			horde_cooldown = ewcfg.col_horde_cooldown,
			gaiaslime = ewcfg.col_gaiaslime,
		), (
			self.id_server,
			self.name,
			self.controlling_faction,
			self.capturing_faction,
			self.capture_points,
			self.slimes,
			self.time_unlock,
			self.cap_side,
			self.degradation,
			self.horde_cooldown,
			self.gaiaslime
		))
예제 #2
0
def delete_world_event(id_event):
    try:
        ewutils.execute_sql_query(
            "DELETE FROM world_events WHERE {id_event} = %s".format(
                id_event=ewcfg.col_id_event, ), (id_event, ))
    except:
        ewutils.logMsg("Error while deleting world event {}".format(id_event))
예제 #3
0
    def __init__(self, id_server=None, name=None, id_role=None):
        if id_server is not None and name is not None:
            self.id_server = id_server
            self.name = name

            data = ewutils.execute_sql_query(
                "SELECT {id_role} FROM roles WHERE id_server = %s AND {name} = %s"
                .format(id_role=ewcfg.col_id_role,
                        name=ewcfg.col_role_name), (id_server, name))

            if len(data) > 0:  # if data is not empty, i.e. it found an entry
                # data is always a two-dimensional array and if we only fetch one row, we have to type data[0][x]
                self.id_role = data[0][0]
            else:  # create new entry
                ewutils.execute_sql_query(
                    "REPLACE INTO roles ({id_server}, {name}) VALUES (%s, %s)".
                    format(id_server=ewcfg.col_id_server,
                           name=ewcfg.col_role_name), (id_server, name))
        elif id_server is not None and id_role is not None:
            self.id_server = id_server
            self.id_role = id_role

            data = ewutils.execute_sql_query(
                "SELECT {name} FROM roles WHERE id_server = %s AND {id_role} = %s"
                .format(id_role=ewcfg.col_id_role,
                        name=ewcfg.col_role_name), (id_server, id_role))

            if len(data) > 0:  # if data is not empty, i.e. it found an entry
                # data is always a two-dimensional array and if we only fetch one row, we have to type data[0][x]
                self.name = data[0][0]
예제 #4
0
    def __init__(self, id_server=None, id_user=None, farm=None):
        if id_server is not None and id_user is not None and farm is not None:
            self.id_server = id_server
            self.id_user = id_user
            self.name = farm

            data = ewutils.execute_sql_query(
                "SELECT {time_lastsow}, {phase}, {time_lastphase}, {slimes_onreap}, {action_required}, {crop} FROM farms WHERE id_server = %s AND id_user = %s AND {col_farm} = %s"
                .format(
                    time_lastsow=ewcfg.col_time_lastsow,
                    col_farm=ewcfg.col_farm,
                    phase=ewcfg.col_phase,
                    time_lastphase=ewcfg.col_time_lastphase,
                    slimes_onreap=ewcfg.col_slimes_onreap,
                    action_required=ewcfg.col_action_required,
                    crop=ewcfg.col_crop,
                ), (id_server, id_user, farm))

            if len(data) > 0:  # if data is not empty, i.e. it found an entry
                # data is always a two-dimensional array and if we only fetch one row, we have to type data[0][x]
                self.time_lastsow = data[0][0]
                self.phase = data[0][1]
                self.time_lastphase = data[0][2]
                self.slimes_onreap = data[0][3]
                self.action_required = data[0][4]
                self.crop = data[0][5]
            else:  # create new entry
                ewutils.execute_sql_query(
                    "REPLACE INTO farms (id_server, id_user, {col_farm}) VALUES (%s, %s, %s)"
                    .format(col_farm=ewcfg.col_farm),
                    (id_server, id_user, farm))
예제 #5
0
async def shakeoff(cmd):
    user_data = EwUser(member=cmd.message.author)

    if cmd.mentions_count == 0:
        response = "God knows there are like a million third eyes floating around. You'll have to specify whose you're looking for."

    elif cmd.mentions_count > 1:
        response = "You're not that good at finding private eyes. Look for one at a time."

    else:
        target_data = EwUser(member=cmd.mentions[0])
        try:
            ewutils.execute_sql_query(
                "UPDATE mutations SET {data} = %s WHERE {id_server} = %s AND {mutation} = %s and {id_user} = %s;"
                .format(
                    data=ewcfg.col_mutation_data,
                    id_server=ewcfg.col_id_server,
                    id_user=ewcfg.col_id_user,
                    mutation=ewcfg.col_id_mutation,
                ), ("", user_data.id_server, ewcfg.mutation_id_oneeyeopen,
                    target_data.id_user))
            response = "You search high and low for {}'s third eye, shouting a bit to give it a good scare. If it was stalking you it certainly isn't now.".format(
                cmd.mentions[0].display_name)
        except:
            ewutils.logMsg("Failed to undo tracking for {}.".format(
                user_data.id_user))
            response = ""
    return await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
예제 #6
0
    def __init__(self, id_server=None, district=None):
        if id_server is not None and district is not None:
            self.id_server = id_server
            self.name = district

            # find the district's property class
            for poi in ewcfg.poi_list:
                if poi.id_poi == self.name:
                    self.property_class = poi.property_class.lower()

            self.max_capture_points = ewcfg.max_capture_points[
                self.property_class]

            data = ewutils.execute_sql_query(
                "SELECT {controlling_faction}, {capturing_faction}, {capture_points} FROM districts WHERE id_server = %s AND {district} = %s"
                .format(
                    controlling_faction=ewcfg.col_controlling_faction,
                    capturing_faction=ewcfg.col_capturing_faction,
                    capture_points=ewcfg.col_capture_points,
                    district=ewcfg.col_district,
                ), (id_server, district))

            if len(data) > 0:  # if data is not empty, i.e. it found an entry
                # data is always a two-dimensional array and if we only fetch one row, we have to type data[0][x]
                self.controlling_faction = data[0][0]
                self.capturing_faction = data[0][1]
                self.capture_points = data[0][2]
                # ewutils.logMsg("EwDistrict object '" + self.name + "' created.  Controlling faction: " + self.controlling_faction + "; Capture progress: %d" % self.capture_points)
            else:  # create new entry
                ewutils.execute_sql_query(
                    "REPLACE INTO districts ({id_server}, {district}) VALUES (%s, %s)"
                    .format(id_server=ewcfg.col_id_server,
                            district=ewcfg.col_district),
                    (id_server, district))
예제 #7
0
 def persist(self):
     ewutils.execute_sql_query(
         "REPLACE INTO districts(id_server, {district}, {controlling_faction}, {capturing_faction}, {capture_points}) VALUES(%s, %s, %s, %s, %s)"
         .format(district=ewcfg.col_district,
                 controlling_faction=ewcfg.col_controlling_faction,
                 capturing_faction=ewcfg.col_capturing_faction,
                 capture_points=ewcfg.col_capture_points),
         (self.id_server, self.name, self.controlling_faction,
          self.capturing_faction, self.capture_points))
예제 #8
0
async def possess_weapon(cmd):
	user_data = EwUser(member = cmd.message.author)
	response = ""
	if user_data.life_state != ewcfg.life_state_corpse:
		response = "You have no idea what you're doing."
	elif not user_data.get_inhabitee():
		response = "You're not **{}**ing anyone right now.".format(ewcfg.cmd_inhabit)
	elif user_data.slimes >= ewcfg.slimes_to_possess_weapon:
		response = "You'll have to become stronger before you can perform occult arts of this level."
	else:
		server = cmd.guild
		inhabitee_id = user_data.get_inhabitee()
		inhabitee_data = EwUser(id_user = inhabitee_id, id_server = user_data.id_server)
		inhabitee_member = server.get_member(inhabitee_id)
		inhabitee_name = inhabitee_member.display_name
		if inhabitee_data.weapon < 0:
			response = "{} is not wielding a weapon right now.".format(inhabitee_name)
		elif inhabitee_data.get_possession():
			response = "{} is already being possessed.".format(inhabitee_name)
		else:
			proposal_response = "You propose a trade to {}.\n" \
				"You will possess their weapon to empower it, and in return they'll sacrifice a fifth of their slime to your name upon their next kill.\n" \
				"Will they **{}** this exchange, or **{}** it?".format(inhabitee_name, ewcfg.cmd_accept, ewcfg.cmd_refuse)
			await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, proposal_response))
    
			accepted = False
			try:
				msg = await cmd.client.wait_for('message', timeout = 30, check=lambda message: message.author == inhabitee_member and 
														message.content.lower() in [ewcfg.cmd_accept, ewcfg.cmd_refuse])
				if msg != None:
					if msg.content.lower() == ewcfg.cmd_accept:
						accepted = True
					elif msg.content.lower() == ewcfg.cmd_refuse:
						accepted = False
			except:
				accepted = False

			if accepted:
				ewutils.execute_sql_query(
				"UPDATE inhabitations SET {empowered} = %s WHERE {id_fleshling} = %s AND {id_ghost} = %s".format(
					empowered = ewcfg.col_empowered,
					id_fleshling = ewcfg.col_id_fleshling,
					id_ghost = ewcfg.col_id_ghost,
				), (
					'weapon',
					inhabitee_id,
					user_data.id_user,
				))
				user_data.change_slimes(n = -ewcfg.slimes_to_possess_weapon, source = ewcfg.source_ghost_contract)
				user_data.persist()
				accepted_response = "You feel a metallic taste in your mouth as you sign {}'s spectral contract. You see them bind themselves to your weapon, which now bears their mark. It feels cold to the touch.".format(cmd.message.author.display_name)
				await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(inhabitee_member, accepted_response))
			else:
				response = "You should've known better, why would anyone ever trust you?"
	
	if response:
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
예제 #9
0
 def unvouch(self, faction=None):
     if faction is None:
         return
     ewutils.execute_sql_query(
         "DELETE FROM vouchers WHERE {id_user} = %s AND {id_server} = %s AND {faction} = %s"
         .format(id_user=ewcfg.col_id_user,
                 id_server=ewcfg.col_id_server,
                 faction=ewcfg.col_faction),
         (self.id_user, self.id_server, faction))
예제 #10
0
 def vouch(self, faction=None):
     if faction is None:
         return
     ewutils.execute_sql_query(
         "REPLACE INTO vouchers ({id_user}, {id_server}, {faction}) VALUES (%s,%s,%s)"
         .format(id_user=ewcfg.col_id_user,
                 id_server=ewcfg.col_id_server,
                 faction=ewcfg.col_faction),
         (self.id_user, self.id_server, faction))
예제 #11
0
def kill_dead_offers(id_server):
	time_now = int(time.time() / 60)
	ewutils.execute_sql_query("DELETE FROM offers WHERE {id_server} = %s AND {time_sinceoffer} < %s".format(
		id_server = ewcfg.col_id_server,
		time_sinceoffer = ewcfg.col_time_sinceoffer,
	),(
		id_server,
		time_now - ewcfg.fish_offer_timeout,
	))
예제 #12
0
async def inhabit(cmd):
	user_data = EwUser(member = cmd.message.author)
	response = ""
		
	if user_data.life_state != ewcfg.life_state_corpse:
		# Only ghosts can inhabit other players
		response = "You have no idea what you're doing."
	else:
		if cmd.mentions_count > 1:
			response = "Are you trying to split yourself in half? You can only inhabit one body at a time."
		elif cmd.mentions_count == 1:
			member = cmd.mentions[0]
			target_data = EwUser(member = member)

			if ewutils.channel_name_is_poi(cmd.message.channel.name) == False:
				# Has to be done in a gameplay channel
				response = "You can't disturb the living from here."
			elif cmd.message.channel.name == ewcfg.channel_sewers:
				# Can't be done from the sewers
				response = "Try doing that in the overworld, it's difficult from down here."
			elif target_data.life_state == ewcfg.life_state_kingpin:
				# Can't target generals
				response = "He is far too strong for you to inhabit his body."
			elif user_data.poi != target_data.poi:
				# Player must be on the same location as their target
				response = "You'll have to find them first."
			elif target_data.life_state == ewcfg.life_state_corpse:
				# Can't target ghosts
				response = "You can't do that to your fellow ghost."
			elif ewmap.poi_is_pvp(target_data.poi) == False:
				response = "{} is not mired in the ENDLESS WAR right now.".format(member.display_name)
			elif user_data.id_killer == target_data.id_user:
				# Can't target the player's killer
				response = "You wouldn't want a repeat of last time, better find someone else."
			else:
				# cancel the ghost's movement
				ewutils.moves_active[cmd.message.author.id] = 0
				# drop any previous inhabitation by the ghost
				user_data.remove_inhabitation()
				# add the new inhabitation
				ewutils.execute_sql_query(
					"REPLACE INTO inhabitations({id_ghost}, {id_fleshling}, {id_server}) VALUES (%s, %s, %s)".format(
						id_ghost = ewcfg.col_id_ghost,
						id_fleshling = ewcfg.col_id_fleshling,
						id_server = ewcfg.col_id_server,
					),(
						user_data.id_user,
						target_data.id_user,
						user_data.id_server,
					)
				)

				response = "{}\'s body is inhabitted by the ghost of {}!".format(member.display_name, cmd.message.author.display_name)
		else:
			response = "Your spookiness is appreciated, but ENDLESS WAR didn\'t understand that name."

	return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
예제 #13
0
 def clear(self):
     try:
         ewutils.execute_sql_query(
             "DELETE FROM mutations WHERE {mutation_counter} = %s".format(
                 mutation_counter=ewcfg.col_mutation_counter),
             (self.mutation_counter))
     except:
         ewutils.logMsg("Failed to clear mutation {} for user {}.".format(
             self.id_mutation, self.id_user))
예제 #14
0
 def persist(self):
     ewutils.execute_sql_query(
         "REPLACE INTO quadrants ({col_id_server}, {col_id_user}, {col_quadrant}, {col_target}, {col_target2}) VALUES (%s, %s, %s, %s, %s)"
         .format(col_id_server=ewcfg.col_id_server,
                 col_id_user=ewcfg.col_id_user,
                 col_quadrant=ewcfg.col_quadrant,
                 col_target=ewcfg.col_quadrants_target,
                 col_target2=ewcfg.col_quadrants_target2),
         (self.id_server, self.id_user, self.quadrant, self.id_target,
          self.id_target2))
예제 #15
0
 def clear_mutations(self):
     try:
         ewutils.execute_sql_query(
             "DELETE FROM mutations WHERE {id_server} = %s AND {id_user} = %s"
             .format(id_server=ewcfg.col_id_server,
                     id_user=ewcfg.col_id_user),
             (self.id_server, self.id_user))
     except:
         ewutils.logMsg("Failed to clear mutations for user {}.".format(
             self.id_user))
예제 #16
0
	def deal(self):
		ewutils.execute_sql_query("DELETE FROM offers WHERE {id_user} = %s AND {id_server} = %s AND {col_offer_give} = %s".format(
			id_user = ewcfg.col_id_user,
			id_server = ewcfg.col_id_server,
			col_offer_give = ewcfg.col_offer_give,
		),(
			self.id_user,
			self.id_server,
			self.offer_give
		))
예제 #17
0
async def possess_fishing_rod(cmd):
	user_data = EwUser(member = cmd.message.author)
	response = ""
	if user_data.life_state != ewcfg.life_state_corpse:
		response = "You have no idea what you're doing."
	elif not user_data.get_inhabitee():
		response = "You're not **{}**ing anyone right now.".format(ewcfg.cmd_inhabit)
	elif user_data.slimes >= ewcfg.slimes_to_possess_fishing_rod:
		response = "You'll have to become stronger before you can perform occult arts of this level."
	else:
		server = cmd.guild
		inhabitee_id = user_data.get_inhabitee()
		inhabitee_data = EwUser(id_user = inhabitee_id, id_server = user_data.id_server)
		inhabitee_member = server.get_member(inhabitee_id)
		inhabitee_name = inhabitee_member.display_name
		if inhabitee_data.get_possession():
			response = "{} is already being possessed.".format(inhabitee_name)
		else:
			proposal_response = "You propose a trade to {}.\n" \
				"You will possess their fishing rod to enhance it, making it more attractive to fish. In exchange, you will corrupt away all of the fish's slime, and absorb it as antislime.\n" \
				"Both of you will need to reel the fish in together, and failing to do so will nullify this contract.\nWill they **{}** this exchange, or **{}** it?".format(inhabitee_name, ewcfg.cmd_accept, ewcfg.cmd_refuse)
			await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, proposal_response))
    
			accepted = False
			try:
				msg = await cmd.client.wait_for('message', timeout = 30, check=lambda message: message.author == inhabitee_member and 
														message.content.lower() in [ewcfg.cmd_accept, ewcfg.cmd_refuse])
				if msg != None:
					if msg.content.lower() == ewcfg.cmd_accept:
						accepted = True
					elif msg.content.lower() == ewcfg.cmd_refuse:
						accepted = False
			except:
				accepted = False

			if accepted:
				ewutils.execute_sql_query(
				"UPDATE inhabitations SET {empowered} = %s WHERE {id_fleshling} = %s AND {id_ghost} = %s".format(
					empowered = ewcfg.col_empowered,
					id_fleshling = ewcfg.col_id_fleshling,
					id_ghost = ewcfg.col_id_ghost,
				), (
					'rod',
					inhabitee_id,
					user_data.id_user,
				))
				user_data.change_slimes(n = -ewcfg.slimes_to_possess_fishing_rod, source = ewcfg.source_ghost_contract)
				user_data.persist()
				accepted_response = "You feel a metallic taste in your mouth as you sign {}'s spectral contract. Their ghastly arms superpose yours, enhancing your grip and causing shadowy tendrils to appear near your rod's hook.".format(cmd.message.author.display_name)
				await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(inhabitee_member, accepted_response))
			else:
				response = "You should've known better, why would anyone ever trust you?"
	
	if response:
		return await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
예제 #18
0
 def persist(self):
     ewutils.execute_sql_query(
         "REPLACE INTO ads ({}, {}, {}, {}, {}) VALUES (%s, %s, %s, %s, %s)"
         .format(
             ewcfg.col_id_ad,
             ewcfg.col_id_server,
             ewcfg.col_id_sponsor,
             ewcfg.col_ad_content,
             ewcfg.col_time_expir,
         ), (self.id_ad, self.id_server, self.id_sponsor, self.content,
             self.time_expir))
예제 #19
0
파일: ew.py 프로젝트: seaniman/endless-war
	def clear_allstatuses(self):
		try:
			ewutils.execute_sql_query("DELETE FROM status_effects WHERE {id_server} = %s AND {id_user} = %s".format(
					id_server = ewcfg.col_id_server,
					id_user = ewcfg.col_id_user
				),(
					self.id_server,
					self.id_user
				))
		except:
			ewutils.logMsg("Failed to clear status effects for user {}.".format(self.id_user))
예제 #20
0
파일: ew.py 프로젝트: seaniman/endless-war
	def remove_inhabitation(self):
		user_is_alive = self.life_state != ewcfg.life_state_corpse
		ewutils.execute_sql_query("DELETE FROM inhabitations WHERE {id_target} = %s AND {id_server} = %s".format(
			# remove ghosts inhabiting player if user is a fleshling,
			# or remove fleshling inhabited by player if user is a ghost
			id_target = ewcfg.col_id_fleshling if user_is_alive else ewcfg.col_id_ghost,
			id_server = ewcfg.col_id_server,
		),(
			self.id_user,
			self.id_server
		))
예제 #21
0
	def __init__(self, id_server = None, district = None):
		if id_server is not None and district is not None:
			self.id_server = id_server
			self.name = district

			# find the district's property class
			for poi in ewcfg.poi_list:
				if poi.id_poi == self.name:
					self.property_class = poi.property_class.lower()

			if len(self.property_class) > 0:
				self.max_capture_points = ewcfg.limit_influence[self.property_class]
			else:
				self.max_capture_points = 0


			data = ewutils.execute_sql_query("SELECT {controlling_faction}, {capturing_faction}, {capture_points},{slimes}, {time_unlock}, {cap_side}, {degradation}, {horde_cooldown}, {gaiaslime} FROM districts WHERE id_server = %s AND {district} = %s".format(

				controlling_faction = ewcfg.col_controlling_faction,
				capturing_faction = ewcfg.col_capturing_faction,
				capture_points = ewcfg.col_capture_points,
				district = ewcfg.col_district,
				slimes = ewcfg.col_district_slimes,
				time_unlock = ewcfg.col_time_unlock,
				cap_side = ewcfg.col_cap_side,
				degradation = ewcfg.col_degradation,
				horde_cooldown = ewcfg.col_horde_cooldown,
				gaiaslime = ewcfg.col_gaiaslime,
			), (
				id_server,
				district
			))

			if len(data) > 0:  # if data is not empty, i.e. it found an entry
				# data is always a two-dimensional array and if we only fetch one row, we have to type data[0][x]
				self.controlling_faction = data[0][0]
				self.capturing_faction = data[0][1]
				self.capture_points = data[0][2]
				self.slimes = data[0][3]
				self.time_unlock = data[0][4]
				self.cap_side = data[0][5]
				self.degradation = data[0][6]
				self.horde_cooldown = data[0][7]
				self.gaiaslime = data[0][8]

				# ewutils.logMsg("EwDistrict object '" + self.name + "' created.  Controlling faction: " + self.controlling_faction + "; Capture progress: %d" % self.capture_points)
			else:  # create new entry
				ewutils.execute_sql_query("REPLACE INTO districts ({id_server}, {district}) VALUES (%s, %s)".format(
					id_server = ewcfg.col_id_server,
					district = ewcfg.col_district
				), (
					id_server,
					district
				))
예제 #22
0
	def cancel_possession(self):
		user_is_alive = self.life_state != ewcfg.life_state_corpse
		ewutils.execute_sql_query(
			"UPDATE inhabitations SET {empowered} = '' WHERE {id_target} = %s AND {id_server} = %s".format(
				empowered = ewcfg.col_empowered,
				id_target = ewcfg.col_id_fleshling if user_is_alive else ewcfg.col_id_ghost,
				id_server = ewcfg.col_id_server,
			),(
				self.id_user,
				self.id_server,
			)
		)
예제 #23
0
def create_ad(id_server, id_sponsor, content, time_expir):
	ewutils.execute_sql_query("INSERT INTO ads ({}, {}, {}, {}) VALUES (%s, %s, %s, %s)".format(
		ewcfg.col_id_server,
		ewcfg.col_id_sponsor,
		ewcfg.col_ad_content,
		ewcfg.col_time_expir,
	),(
		id_server,
		id_sponsor,
		content,
		time_expir,
	))
예제 #24
0
	def __init__(
		self,
		id_server = None,
		id_user = None,
		offer_give = None,

	):
		if id_server is not None and id_user is not None and offer_give is not None:
			self.id_server = id_server
			self.id_user = id_user
			self.offer_give = offer_give

			data = ewutils.execute_sql_query(
				"SELECT {time_sinceoffer} FROM offers WHERE id_server = %s AND id_user = %s AND {col_offer_give} = %s".format(
					time_sinceoffer = ewcfg.col_time_sinceoffer,
					col_offer_give = ewcfg.col_offer_give,
				), (
					id_server,
					id_user,
					offer_give,
				)
			)

			if len(data) > 0:  # if data is not empty, i.e. it found an entry
				# data is always a two-dimensional array and if we only fetch one row, we have to type data[0][x]
				self.time_sinceoffer = data[0][0]

			data = ewutils.execute_sql_query(
				"SELECT {col_offer_receive} FROM offers WHERE id_server = %s AND id_user = %s AND {col_offer_give} = %s".format(
					col_offer_receive = ewcfg.col_offer_receive,
					col_offer_give = ewcfg.col_offer_give,
				), (
					id_server,
					id_user,
					offer_give,
				)
			)

			if len(data) > 0:  # if data is not empty, i.e. it found an entry
				# data is always a two-dimensional array and if we only fetch one row, we have to type data[0][x]
				self.offer_receive = data[0][0]

			else:  # create new entry
				ewutils.execute_sql_query(
					"REPLACE INTO offers(id_server, id_user, {col_offer_give}) VALUES (%s, %s, %s)".format(
						col_offer_give = ewcfg.col_offer_give,
					), (
						id_server,
						id_user,
						offer_give,
					)
				)
예제 #25
0
 def persist(self):
     ewutils.execute_sql_query(
         "INSERT INTO stocks ({id_server}, {stock}, {market_rate}, {exchange_rate}, {boombust}, {total_shares}, {timestamp}) VALUES(%s, %s, %s, %s, %s, %s, %s)"
         .format(id_server=ewcfg.col_id_server,
                 stock=ewcfg.col_stock,
                 market_rate=ewcfg.col_market_rate,
                 exchange_rate=ewcfg.col_exchange_rate,
                 boombust=ewcfg.col_boombust,
                 total_shares=ewcfg.col_total_shares,
                 timestamp=ewcfg.col_timestamp),
         (self.id_server, self.id_stock, self.market_rate,
          self.exchange_rate, self.boombust, self.total_shares,
          self.timestamp))
예제 #26
0
	def persist(self):
		ewutils.execute_sql_query(
			"REPLACE INTO gamestates ({id_server}, {id_state},  {col_bit}, {col_value}) VALUES (%s, %s, %s, %s)".format(
				id_server=ewcfg.col_id_server,
				id_state = ewcfg.col_id_state,
				col_bit=ewcfg.col_bit,
				col_value=ewcfg.col_value
			), (
				self.id_server,
				self.id_state,
				self.bit,
				self.value
			))
예제 #27
0
 def persist(self):
     try:
         ewutils.execute_sql_query(
             "REPLACE INTO companies({recent_profits}, {total_profits}, {id_server}, {stock}) VALUES(%s,%s,%s,%s)"
             .format(recent_profits=ewcfg.col_recent_profits,
                     total_profits=ewcfg.col_total_profits,
                     id_server=ewcfg.col_id_server,
                     stock=ewcfg.col_stock),
             (self.recent_profits, self.total_profits, self.id_server,
              self.id_stock))
     except:
         ewutils.logMsg("Failed to save company {} to the database.".format(
             self.id_stock))
예제 #28
0
def give_item(member=None, id_item=None, id_user=None, id_server=None):

    if id_user is None and id_server is None and member is not None:
        id_server = member.server.id
        id_user = member.id

    if id_server is not None and id_user is not None and id_item is not None:
        ewutils.execute_sql_query(
            "UPDATE items SET id_user = %s WHERE id_server = %s AND {id_item} = %s"
            .format(id_item=ewcfg.col_id_item), (id_user, id_server, id_item))

    return

    return True
예제 #29
0
	def persist(self):
		ewutils.execute_sql_query(
			"REPLACE INTO offers(id_server, id_user, {col_offer_give}, {col_offer_receive}, {col_time_sinceoffer}) VALUES (%s, %s, %s, %s, %s)".format(
				col_offer_give = ewcfg.col_offer_give,
				col_offer_receive = ewcfg.col_offer_receive,
				col_time_sinceoffer = ewcfg.col_time_sinceoffer
			), (
				self.id_server,
				self.id_user,
				self.offer_give,
				self.offer_receive,
				self.time_sinceoffer
			)
		)
예제 #30
0
    def persist(self):

        try:
            ewutils.execute_sql_query(
                "REPLACE INTO transports ({id_server}, {poi}, {transport_type}, {current_line}, {current_stop}) VALUES (%s, %s, %s, %s, %s)"
                .format(id_server=ewcfg.col_id_server,
                        poi=ewcfg.col_poi,
                        transport_type=ewcfg.col_transport_type,
                        current_line=ewcfg.col_current_line,
                        current_stop=ewcfg.col_current_stop),
                (self.id_server, self.poi, self.transport_type,
                 self.current_line, self.current_stop))
        except:
            ewutils.logMsg("Failed to write transport {} to database.".format(
                self.poi))