Exemplo n.º 1
0
async def craps(cmd):
	time_now = int(time.time())

	global last_crapsed_times
	last_used = last_crapsed_times.get(cmd.message.author.id)

	if last_used == None:
		last_used = 0

	if last_used + 2 > time_now:
		response = "**ENOUGH**"
	elif cmd.message.channel.name != ewcfg.channel_casino:
		# Only allowed in the slime casino.
		response = "You must go to the Casino to gamble your SlimeCoin."
	else:
		last_crapsed_times[cmd.message.author.id] = time_now
		value = None
		winnings = 0

		if cmd.tokens_count > 1:
			value = ewutils.getIntToken(tokens = cmd.tokens, allow_all = True)

		if value != None:
			user_data = EwUser(member = cmd.message.author)

			if value == -1:
				value = user_data.slimecredit

			elif value > user_data.slimecredit:
				response = "You don't have that much SlimeCoin to bet with."
			else:

				roll1 = random.randint(1,6)
				roll2 = random.randint(1,6)

				emotes_dice = [
					ewcfg.emote_dice1,
					ewcfg.emote_dice2,
					ewcfg.emote_dice3,
					ewcfg.emote_dice4,
					ewcfg.emote_dice5,
					ewcfg.emote_dice6
				]

				response = " {} {}".format(emotes_dice[roll1 - 1], emotes_dice[roll2 - 1])

				if (roll1 + roll2) == 7:
					winnings = 5 * value
					response += "\n\n**You rolled a 7! It's your lucky day. You won {:,} SlimeCoin.**".format(winnings)
				else:
					response += "\n\nYou didn't roll 7. You lost your SlimeCoins."

				# add winnings/subtract losses
				user_data.change_slimecredit(n = winnings - value, coinsource = ewcfg.coinsource_casino)
				user_data.persist()
		else:
			response = "Specify how much SlimeCoin you will wager."

	# Send the response to the player.
	await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 2
0
async def donate(cmd):
	time_now = int(time.time())

	if cmd.message.channel.name != ewcfg.channel_slimecorphq:
		# Only allowed in SlimeCorp HQ.
		response = "You must go to SlimeCorp HQ to donate slime."
		await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
		return

	user_data = EwUser(member = cmd.message.author)

	value = None
	if cmd.tokens_count > 1:
		value = ewutils.getIntToken(tokens = cmd.tokens, allow_all = True)

	if value != None:
		if value < 0:
			value = user_data.slimes
		if value <= 0:
			value = None

	if value != None and value < ewcfg.slimecoin_exchangerate:
		response = "You must volunteer to donate at least %d slime to receive compensation." % ewcfg.slimecoin_exchangerate

	elif value != None:
		# Amount of slime invested.
		cost_total = int(value)
		coin_total = int(value / ewcfg.slimecoin_exchangerate)

		if user_data.slimes < cost_total:
			response = "Acid-green flashes of light and bloodcurdling screams emanate from small window of SlimeCorp HQ. Unfortunately, you did not survive the procedure. Your body is dumped down a disposal chute to the sewers."
			user_data.die(cause = ewcfg.cause_donation)
			user_data.persist()
			# Assign the corpse role to the player. He dead.
			await ewrolemgr.updateRoles(client = cmd.client, member = cmd.message.author)
			sewerchannel = ewutils.get_channel(cmd.message.server, ewcfg.channel_sewers)
			await cmd.client.send_message(sewerchannel, "{} ".format(ewcfg.emote_slimeskull) + ewutils.formatMessage(cmd.message.author, "You have died in a medical mishap. {}".format(ewcfg.emote_slimeskull)))
		else:
			# Do the transfer if the player can afford it.
			user_data.change_slimes(n = -cost_total, source = ewcfg.source_spending)
			user_data.change_slimecredit(n = coin_total, coinsource = ewcfg.coinsource_donation)
			user_data.time_lastinvest = time_now

			# Persist changes
			user_data.persist()

			response = "You stumble out of a Slimecorp HQ vault room in a stupor. You don't remember what happened in there, but your body hurts and you've got {slimecoin:,} shiny new SlimeCoin in your pocket.".format(slimecoin = coin_total)

	else:
		response = ewcfg.str_exchange_specify.format(currency = "slime", action = "donate")

	# Send the response to the player.
	await cmd.client.send_message(cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 3
0
async def haunt(cmd):
	time_now = int(time.time())
	response = ""
	resp_cont = ewutils.EwResponseContainer(id_server = cmd.guild.id)

	if cmd.mentions_count > 1:
		response = "You can only spook one person at a time. Who do you think you are, the Lord of Ghosts?"
	else: 
		haunted_data = None
		member = None
		if cmd.mentions_count == 0 and cmd.tokens_count > 1:
			server = cmd.guild
			member = server.get_member(ewutils.getIntToken(cmd.tokens))
			haunted_data = EwUser(member = member)
		elif cmd.mentions_count == 1:
			member = cmd.mentions[0]
			haunted_data = EwUser(member = member)
		
		if member:
			# Get the user and target data from the database.
			user_data = EwUser(member = cmd.message.author)
			market_data = EwMarket(id_server = cmd.guild.id)
			target_mutations = haunted_data.get_mutations()
			target_poi = ewcfg.id_to_poi.get(haunted_data.poi)
			target_is_shambler = haunted_data.life_state == ewcfg.life_state_shambler
			target_is_inhabitted = haunted_data.id_user == user_data.get_inhabitee()


			if user_data.life_state != ewcfg.life_state_corpse:
				# Only dead players can haunt.
				response = "You can't haunt now. Try {}.".format(ewcfg.cmd_suicide)
			elif haunted_data.life_state == ewcfg.life_state_kingpin:
				# Disallow haunting of generals.
				response = "He is too far from the sewers in his ivory tower, and thus cannot be haunted."
			elif (time_now - user_data.time_lasthaunt) < ewcfg.cd_haunt:
				# Disallow haunting if the user has haunted too recently.
				response = "You're being a little TOO spooky lately, don't you think? Try again in {} seconds.".format(int(ewcfg.cd_haunt-(time_now-user_data.time_lasthaunt)))
			elif ewutils.channel_name_is_poi(cmd.message.channel.name) == False:
				response = "You can't commit violence from here."
			elif target_poi.pvp == False:
			#Require the target to be in a PvP area, and flagged if it's a remote haunt
				response = "{} is not mired in the ENDLESS WAR right now.".format(member.display_name)
			elif haunted_data.life_state == ewcfg.life_state_corpse:
				# Dead players can't be haunted.
				response = "{} is already dead.".format(member.display_name)
			elif haunted_data.life_state == ewcfg.life_state_grandfoe:
				# Grand foes can't be haunted.
				response = "{} is invulnerable to ghosts.".format(member.display_name)
			elif haunted_data.life_state == ewcfg.life_state_enlisted or haunted_data.life_state == ewcfg.life_state_juvenile or haunted_data.life_state == ewcfg.life_state_shambler:
				haunt_power_multiplier = 1

				# power to the ancients
				ghost_age = time_now - user_data.time_lastdeath
				if ghost_age > 60 * 60 * 24 * 7: # dead for longer than
					if ghost_age > 60 * 60 * 24 * 365: # one friggin year
						haunt_power_multiplier *= 2.5
					if ghost_age > 60 * 60 * 24 * 90: # three months
						haunt_power_multiplier *= 2
					elif ghost_age > 60 * 60 * 24 * 30: # one month
						haunt_power_multiplier *= 1.5
					else: # one week
						haunt_power_multiplier *= 1.25

				# vitriol as virtue
				list_ids = []
				for quadrant in ewcfg.quadrant_ids:
					quadrant_data = ewquadrants.EwQuadrant(id_server=cmd.guild.id, id_user=cmd.message.author.id, quadrant=quadrant)
					if quadrant_data.id_target != -1 and quadrant_data.check_if_onesided() is False:
						list_ids.append(quadrant_data.id_target)
					if quadrant_data.id_target2 != -1 and quadrant_data.check_if_onesided() is False:
						list_ids.append(quadrant_data.id_target2)
				if haunted_data.id_user in list_ids: # any mutual quadrants
					haunt_power_multiplier *= 1.2
				if haunted_data.faction and ((not user_data.faction) or (user_data.faction != haunted_data.faction)): # opposite faction (or no faction at all)
					haunt_power_multiplier *= 1.2
				if user_data.id_killer == haunted_data.id_user: # haunting your murderer/buster
					haunt_power_multiplier *= 1.2

				# places of power.
				if haunted_data.poi in [ewcfg.poi_id_thevoid, ewcfg.poi_id_wafflehouse, ewcfg.poi_id_blackpond]:
					haunt_power_multiplier *= 2
				elif haunted_data.poi in ewmap.get_void_connection_pois(cmd.guild.id):
					haunt_power_multiplier *= 1.25

				# glory to the vanquished
				target_kills = ewstats.get_stat(user = haunted_data, metric = ewcfg.stat_kills)
				if target_kills > 5:
					haunt_power_multiplier *= 1.25 + ((target_kills - 5) / 100) # 1% per kill after 5
				else:
					haunt_power_multiplier *= 1 + (target_kills * 5 / 100) # 5% per kill
					
				if time_now - haunted_data.time_lastkill < (60 * 15):
					haunt_power_multiplier *= 1.5 # wet hands

				# misc
				if ewcfg.weather_map.get(market_data.weather) == ewcfg.weather_foggy:
					haunt_power_multiplier *= 1.1
				if not haunted_data.has_soul:
					haunt_power_multiplier *= 1.2
				# uncomment this after moon mechanics update
				# if (market_data.day % 31 == 15 and market_data.clock >= 20) or (market_data.day % 31 == 16 and market_data.clock <= 6):
				# 	haunt_power_multiplier *= 2

				# divide haunt power by 2 if not in same area
				if user_data.poi != haunted_data.poi:
					haunt_power_multiplier /= 2

				# Double Halloween
				#haunt_power_multiplier *= 4

				haunted_slimes = int((haunted_data.slimes / ewcfg.slimes_hauntratio) * haunt_power_multiplier)
				slimes_lost = int(haunted_slimes / 5) # hauntee only loses 1/5th of what the ghost gets as antislime

				if ewcfg.mutation_id_coleblooded in target_mutations:
					haunted_slimes = -10000
					if user_data.slimes > haunted_slimes:
						haunted_slimes = user_data.slimes

				haunted_data.change_slimes(n = -slimes_lost, source = ewcfg.source_haunted)
				user_data.change_slimes(n = -haunted_slimes, source = ewcfg.source_haunter)
				market_data.negaslime -= haunted_slimes

				user_data.time_lasthaunt = time_now
				user_data.busted = False
				
				resp_cont.add_member_to_update(cmd.message.author)
				# Persist changes to the database.
				user_data.persist()
				haunted_data.persist()
				market_data.persist()

				response = "{} has been haunted by the ghost of {}! Slime has been lost! {} antislime congeals within you.".format(member.display_name, cmd.message.author.display_name, haunted_slimes)
				if ewcfg.mutation_id_coleblooded in target_mutations:
					response = "{} has been haunted by the ghost of {}! Their exorcising coleslaw blood purges {} antislime from your being! Better not do that again.".format(member.display_name, cmd.message.author.display_name, -haunted_slimes)

				haunted_channel = ewcfg.id_to_poi.get(haunted_data.poi).channel
				haunt_message = "You feel a cold shiver run down your spine"
				if cmd.tokens_count > 2:
					haunt_message_content = re.sub("<.+>" if cmd.mentions_count == 1 else "\d{17,}", "", cmd.message.content[(len(cmd.tokens[0])):]).strip()
					# Cut down really big messages so discord doesn't crash
					if len(haunt_message_content) > 500:
						haunt_message_content = haunt_message_content[:-500]
					haunt_message += " and faintly hear the words \"{}\"".format(haunt_message_content)
				haunt_message += ". {} slime evaporates from your body.".format(slimes_lost)
				if ewcfg.mutation_id_coleblooded in target_mutations:
					haunt_message += " The ghost that did it wails in agony as their ectoplasm boils in your coleslaw blood!"

				haunt_message = ewutils.formatMessage(member, haunt_message)
				resp_cont.add_channel_response(haunted_channel, haunt_message)
		else:
			# No mentions, or mentions we didn't understand.
			response = "Your spookiness is appreciated, but ENDLESS WAR didn\'t understand that name."

	# Send the response to the player.
	resp_cont.add_channel_response(cmd.message.channel.name, response)
	await resp_cont.post()
Exemplo n.º 4
0
async def xfer(cmd):
    time_now = int(time.time())

    if cmd.message.channel.name != ewcfg.channel_stockexchange:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin",
                                                        action="transfer")
        await cmd.client.send_message(
            cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))
        return

    if cmd.mentions_count != 1:
        # Must have exactly one target to send to.
        response = "Mention the player you want to send SlimeCoin to."
        await cmd.client.send_message(
            cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))
        return

    member = cmd.mentions[0]
    target_data = EwUser(member=member)

    if target_data.life_state == ewcfg.life_state_kingpin:
        # Disallow transfers to RF and CK kingpins.
        response = "You can't transfer SlimeCoin to a known criminal warlord."
        await cmd.client.send_message(
            cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))
        return

    user_data = EwUser(member=cmd.message.author)
    market_data = EwMarket(id_server=cmd.message.author.server.id)

    # Parse the slime value to send.
    value = None
    if cmd.tokens_count > 1:
        value = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)

    if value != None:
        if value < 0:
            value = user_data.slimes
        if value <= 0:
            value = None

    if value != None:
        # Cost including the 5% transfer fee.
        cost_total = int(value * 1.05)

        if user_data.slimecredit < cost_total:
            response = "You don't have enough SlimeCoin. ({:,}/{:,})".format(
                user_data.slimecredit, cost_total)
        else:
            # Do the transfer if the player can afford it.
            target_data.change_slimecredit(
                n=value, coinsource=ewcfg.coinsource_transfer)
            user_data.change_slimecredit(n=-cost_total,
                                         coinsource=ewcfg.coinsource_transfer)
            user_data.time_lastinvest = time_now

            # Persist changes
            response = "You transfer {slime:,} SlimeCoin to {target_name}. Your slimebroker takes his nominal fee of {fee:,} SlimeCoin.".format(
                slime=value,
                target_name=member.display_name,
                fee=(cost_total - value))

            user_data.persist()
            target_data.persist()
    else:
        response = ewcfg.str_exchange_specify.format(currency="SlimeCoin",
                                                     action="transfer")

    # Send the response to the player.
    await cmd.client.send_message(
        cmd.message.channel, ewutils.formatMessage(cmd.message.author,
                                                   response))
Exemplo n.º 5
0
async def haunt(cmd):
    time_now = int(time.time())
    response = ""
    resp_cont = ewutils.EwResponseContainer(id_server=cmd.guild.id)

    if cmd.mentions_count > 1:
        response = "You can only spook one person at a time. Who do you think you are, the Lord of Ghosts?"
    else:
        haunted_data = None
        member = None
        if cmd.mentions_count == 0 and cmd.tokens_count > 1:
            server = cmd.guild
            member = server.get_member(ewutils.getIntToken(cmd.tokens))
            haunted_data = EwUser(member=member)
        elif cmd.mentions_count == 1:
            member = cmd.mentions[0]
            haunted_data = EwUser(member=member)

        if member:
            # Get the user and target data from the database.
            user_data = EwUser(member=cmd.message.author)
            market_data = EwMarket(id_server=cmd.guild.id)
            target_is_shambler = haunted_data.life_state == ewcfg.life_state_shambler
            target_is_inhabitted = haunted_data.id_user == user_data.get_inhabitee(
            )

            if user_data.life_state != ewcfg.life_state_corpse:
                # Only dead players can haunt.
                response = "You can't haunt now. Try {}.".format(
                    ewcfg.cmd_suicide)
            elif haunted_data.life_state == ewcfg.life_state_kingpin:
                # Disallow haunting of generals.
                response = "He is too far from the sewers in his ivory tower, and thus cannot be haunted."
            elif (time_now - user_data.time_lasthaunt) < ewcfg.cd_haunt:
                # Disallow haunting if the user has haunted too recently.
                response = "You're being a little TOO spooky lately, don't you think? Try again in {} seconds.".format(
                    int(ewcfg.cd_haunt -
                        (time_now - user_data.time_lasthaunt)))
            elif ewutils.channel_name_is_poi(
                    cmd.message.channel.name) == False:
                response = "You can't commit violence from here."
            elif time_now > haunted_data.time_expirpvp and not (
                    target_is_shambler or target_is_inhabitted):
                # Require the target to be flagged for PvP
                response = "{} is not mired in the ENDLESS WAR right now.".format(
                    member.display_name)
            elif haunted_data.life_state == ewcfg.life_state_corpse:
                # Dead players can't be haunted.
                response = "{} is already dead.".format(member.display_name)
            elif haunted_data.life_state == ewcfg.life_state_grandfoe:
                # Grand foes can't be haunted.
                response = "{} is invulnerable to ghosts.".format(
                    member.display_name)
            elif haunted_data.life_state == ewcfg.life_state_enlisted or haunted_data.life_state == ewcfg.life_state_juvenile or haunted_data.life_state == ewcfg.life_state_shambler:
                # Target can be haunted by the player.
                haunt_power_multiplier = 1
                if user_data.poi == haunted_data.poi:
                    if user_data.poi == ewcfg.poi_id_thevoid:
                        # haunting is empowered by the void
                        haunt_power_multiplier *= 5
                    else:
                        # when haunting someone face to face, you get double the amount
                        haunt_power_multiplier *= 2
                haunted_slimes = int(
                    haunted_data.slimes /
                    ewcfg.slimes_hauntratio) * haunt_power_multiplier

                haunted_data.change_slimes(n=-haunted_slimes,
                                           source=ewcfg.source_haunted)
                user_data.change_slimes(
                    n=-min(haunted_slimes, ewcfg.slimes_hauntmax),
                    source=ewcfg.source_haunter)
                market_data.negaslime -= haunted_slimes
                user_data.time_lasthaunt = time_now
                user_data.busted = False

                user_poi = ewcfg.id_to_poi.get(user_data.poi)
                user_data.time_expirpvp = ewutils.calculatePvpTimer(
                    user_data.time_expirpvp, ewcfg.time_pvp_attack)

                resp_cont.add_member_to_update(cmd.message.author)
                # Persist changes to the database.
                user_data.persist()
                haunted_data.persist()
                market_data.persist()

                response = "{} has been haunted by the ghost of {}! Slime has been lost!".format(
                    member.display_name, cmd.message.author.display_name)

                haunted_channel = ewcfg.id_to_poi.get(haunted_data.poi).channel
                haunt_message = "You feel a cold shiver run down your spine"
                if cmd.tokens_count > 2:
                    haunt_message_content = re.sub(
                        "<.+>" if cmd.mentions_count == 1 else "\d{17,}", "",
                        cmd.message.content[(len(cmd.tokens[0])):]).strip()
                    # Cut down really big messages so discord doesn't crash
                    if len(haunt_message_content) > 500:
                        haunt_message_content = haunt_message_content[:-500]
                    haunt_message += " and faintly hear the words \"{}\"".format(
                        haunt_message_content)
                haunt_message += "."
                haunt_message = ewutils.formatMessage(member, haunt_message)
                resp_cont.add_channel_response(haunted_channel, haunt_message)
        else:
            # No mentions, or mentions we didn't understand.
            response = "Your spookiness is appreciated, but ENDLESS WAR didn\'t understand that name."

    # Send the response to the player.
    resp_cont.add_channel_response(cmd.message.channel.name, response)
    await resp_cont.post()
Exemplo n.º 6
0
async def read_book(cmd = None, dm = False):
	user_data = EwUser(member=cmd.message.author)

	if not dm:
		response = "ENDLESS WAR politely asks that you !read in his DMs."

	elif len(cmd.tokens) < 2:
		response = "What zine do you want to read?"

	else:
		if len(cmd.tokens) < 3:
			book_title = ewutils.flattenTokenListToString(cmd.tokens)
			page_number = 0
		else:
			book_title = ewutils.flattenTokenListToString(cmd.tokens[1:len(cmd.tokens) - 1])
			page_number = ewutils.getIntToken(cmd.tokens)

		book_sought = ewitem.find_item(item_search=book_title, id_user=cmd.message.author.id, id_server=cmd.message.server.id if cmd.message.server is not None else None, item_type_filter = ewcfg.it_book)

		if book_sought:
			book = EwItem(id_item = book_sought.get('id_item'))
			id_book = book.item_props.get("id_book")
			book = EwBook(id_book=id_book)

			if page_number not in range(0, book.pages+1):
				page_number = 0

			accepted = True
			if book.genre == 3:

				accepted = False
				response = "ENDLESS WAR sees you about to open up a p**n zine and wants to make sure you're 18 years or older. Use **!accept** to open or **!refuse** to abstain."

				await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))

				try:
					message = await cmd.client.wait_for_message(timeout=20, author=cmd.message.author, check=check)

					if message != None:
						if message.content.lower() == "!accept":
							accepted = True
						if message.content.lower() == "!refuse":
							accepted = False
				except:
					accepted = False

			if book.book_state < 0:
				response = "You simply can't make out the letters on the page. Maybe it's better this way."

			elif accepted:
				page_contents = get_page(id_book, page_number)

				if page_number == 0 and page_contents == "":
					page_contents = get_page(id_book, 1)

				page_text = "turn to page {}".format(page_number)

				if page_number == 0:
					page_text = "look at the cover"

				response = "You {} and begin to read.\n\n\"{} \"".format(page_text, page_contents)
				readers[user_data.id_user] = (id_book, page_number)

				if page_contents == "":
					response = "You open up to page {} only to find that it's blank!".format(page_number)

				if page_number != 0:
					response += "\n\nUse **!previouspage** to go back one page."

				if page_number != book.pages:
					response += "\n\nUse **!nextpage** to go forward one page."

			else:
				response = "You decide not to indulge yourself."

		else:
			response = "You don't have that zine. Make sure you use **!read [zine title] [page]**"

	await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 7
0
async def annex(cmd):
    user_data = EwUser(member=cmd.message.author)
    if user_data.life_state == ewcfg.life_state_shambler:
        response = "You lack the higher brain functions required to {}.".format(
            cmd.tokens[0])
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    response = ""
    resp_cont = ewutils.EwResponseContainer(id_server=cmd.message.server.id)
    time_now = int(time.time())

    poi = ewcfg.id_to_poi.get(user_data.poi)

    if user_data.life_state == ewcfg.life_state_corpse:
        response = "You ineffectively try shaking your can of spraypaint to whip up some sick graffiti. Alas, you’re all outta slime. " \
                         "They should really make these things compatible with ectoplasm."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if not (len(user_data.faction) > 0
            and user_data.life_state == ewcfg.life_state_enlisted):
        response = "Juveniles are too chickenshit to make graffiti and risk getting busted by the cops. F****n’ losers."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.poi in [
            ewcfg.poi_id_rowdyroughhouse, ewcfg.poi_id_copkilltown
    ]:
        response = "There’s no point, the rest of your gang has already covered this place in spraypaint. Focus on exporting your graffiti instead."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.poi == ewcfg.poi_id_juviesrow:
        response = "Nah, the Rowdys and Killers have both agreed this is neutral ground. You don’t want to start a diplomatic crisis, " \
                         "just stick to spraying down sick graffiti and splattering your rival gang across the pavement in the other districts."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if not user_data.poi in ewcfg.capturable_districts:
        response = "This zone cannot be captured."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    district_data = EwDistrict(id_server=user_data.id_server,
                               district=user_data.poi)

    if district_data.is_degraded():
        response = "{} has been degraded by shamblers. You can't {} here anymore.".format(
            poi.str_name, cmd.tokens[0])
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))
    if district_data.time_unlock > 0:
        response = "You can’t spray graffiti here yet, it’s too soon after your rival gang extended their own cultural dominance over it. Try again in {}.".format(
            ewutils.formatNiceTime(seconds=district_data.time_unlock,
                                   round_to_minutes=True))
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if district_data.all_neighbors_friendly():
        response = "What the hell are you doing, dude? You can’t put down any graffiti here, it’s been completely overrun by your rival gang. " \
                         "You can only spray districts that have at least one unfriendly neighbor, duh!"
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    users_in_district = district_data.get_players_in_district(
        life_states=[ewcfg.life_state_enlisted],
        ignore_offline=True,
        pvp_only=True)

    allies_in_district = district_data.get_players_in_district(
        factions=[user_data.faction],
        life_states=[ewcfg.life_state_enlisted],
        ignore_offline=True,
        pvp_only=True)

    if len(users_in_district) > len(allies_in_district):
        response = "Holy shit, deal with your rival gangsters first! You can’t spray graffiti while they’re on the prowl!"
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    mutations = user_data.get_mutations()

    slimes_spent = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)
    capture_discount = 1

    if ewcfg.mutation_id_lonewolf in mutations:
        if user_data.time_expirpvp > time_now:
            if len(users_in_district) == 1:
                capture_discount *= 0.8
        else:
            if len(users_in_district) == 0:
                capture_discount *= 0.8

    if ewcfg.mutation_id_patriot in mutations:
        capture_discount *= 0.8

    if slimes_spent == None:
        response = "How much slime do you want to spend on spraying graffiti in this district?"
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if slimes_spent < 0:
        slimes_spent = user_data.slimes

    if slimes_spent > user_data.slimes:
        response = "You don't have that much slime, retard."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    num_lock = len(allies_in_district)
    if user_data.time_expirpvp < time_now:
        num_lock += 1

    if (district_data.controlling_faction not in [
            "", user_data.faction
    ]) or (district_data.capturing_faction not in ["", user_data.faction]):
        slimes_decap = min(district_data.capture_points,
                           int(slimes_spent / capture_discount))
        decap_resp = district_data.change_capture_points(
            progress=-slimes_decap, actor=user_data.faction, num_lock=num_lock)
        resp_cont.add_response_container(decap_resp)

        user_data.change_slimes(n=-slimes_decap * capture_discount,
                                source=ewcfg.source_spending)
        slimes_spent -= slimes_decap * capture_discount

    slimes_cap = min(
        district_data.max_capture_points - district_data.capture_points,
        int(slimes_spent / capture_discount))
    cap_resp = district_data.change_capture_points(progress=slimes_cap,
                                                   actor=user_data.faction,
                                                   num_lock=num_lock)
    resp_cont.add_response_container(cap_resp)

    user_data.change_slimes(n=-slimes_cap * capture_discount,
                            source=ewcfg.source_spending)

    # Flag the user for PvP
    user_data.time_expirpvp = ewutils.calculatePvpTimer(
        user_data.time_expirpvp, ewcfg.time_pvp_annex, True)

    user_data.persist()
    district_data.persist()
    await ewrolemgr.updateRoles(client=cmd.client, member=cmd.message.author)

    return await resp_cont.post()
Exemplo n.º 8
0
async def xfer(cmd):
    resp = await ewcmd.start(cmd=cmd)
    time_now = int(time.time())

    if cmd.message.channel.name != ewcfg.channel_stockexchange:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin",
                                                        action="transfer")
        await cmd.client.edit_message(
            resp, ewutils.formatMessage(cmd.message.author, response))
        return

    if cmd.mentions_count != 1:
        # Must have exactly one target to send to.
        response = "Mention the player you want to send SlimeCoin to."
        await cmd.client.edit_message(
            resp, ewutils.formatMessage(cmd.message.author, response))
        return

    member = cmd.mentions[0]
    roles_map_target = ewutils.getRoleMap(member.roles)

    if ewcfg.role_rowdyfucker in roles_map_target or ewcfg.role_copkiller in roles_map_target:
        # Disallow transfers to RF and CK kingpins.
        response = "You can't transfer SlimeCoin to a known criminal warlord."
        await cmd.client.edit_message(
            resp, ewutils.formatMessage(cmd.message.author, response))
        return

    try:
        conn = ewutils.databaseConnect()
        cursor = conn.cursor()

        target_data = EwUser(member=member, conn=conn, cursor=cursor)
        user_data = EwUser(member=cmd.message.author, conn=conn, cursor=cursor)
        market_data = EwMarket(id_server=cmd.message.author.server.id,
                               conn=conn,
                               cursor=cursor)
    finally:
        cursor.close()
        conn.close()

    if market_data.clock >= 18 or market_data.clock < 6:
        response = ewcfg.str_exchange_closed
    else:
        # Parse the slime value to send.
        value = None
        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)

        if value != None:
            if value < 0:
                value = user_data.slimes
            if value <= 0:
                value = None

        if value != None:
            # Cost including the 5% transfer fee.
            cost_total = int(value * 1.05)

            if user_data.slimecredit < cost_total:
                response = "You don't have enough SlimeCoin. ({:,}/{:,})".format(
                    user_data.slimecredit, cost_total)
            elif user_data.time_lastinvest + ewcfg.cd_invest > time_now:
                # Limit frequency of investments.
                response = ewcfg.str_exchange_busy.format(action="transfer")
            else:
                # Do the transfer if the player can afford it.
                target_data.slimecredit += value
                user_data.slimecredit -= cost_total
                user_data.time_lastinvest = time_now

                # Persist changes
                response = "You transfer {slime:,} SlimeCoin to {target_name}. Your slimebroker takes his nominal fee of {fee:,} SlimeCoin.".format(
                    slime=value,
                    target_name=member.display_name,
                    fee=(cost_total - value))

                try:
                    conn = ewutils.databaseConnect()
                    cursor = conn.cursor()

                    user_data.persist(conn=conn, cursor=cursor)
                    target_data.persist(conn=conn, cursor=cursor)

                    conn.commit()
                finally:
                    cursor.close()
                    conn.close()
        else:
            response = ewcfg.str_exchange_specify.format(currency="SlimeCoin",
                                                         action="transfer")

    # Send the response to the player.
    await cmd.client.edit_message(
        resp, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 9
0
async def invest(cmd):
    resp = await ewcmd.start(cmd=cmd)
    time_now = int(time.time())

    if cmd.message.channel.name != ewcfg.channel_stockexchange:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="slime",
                                                        action="invest")
        await cmd.client.edit_message(
            resp, ewutils.formatMessage(cmd.message.author, response))
        return

    roles_map_user = ewutils.getRoleMap(cmd.message.author.roles)
    if ewcfg.role_rowdyfucker in roles_map_user or ewcfg.role_copkiller in roles_map_user:
        # Disallow investments by RF and CK kingpins.
        response = "You're too powerful to be playing the market."
        await cmd.client.edit_message(
            resp, ewutils.formatMessage(cmd.message.author, response))
        return

    try:
        conn = ewutils.databaseConnect()
        cursor = conn.cursor()

        user_data = EwUser(member=cmd.message.author, conn=conn, cursor=cursor)
        market_data = EwMarket(id_server=cmd.message.author.server.id,
                               conn=conn,
                               cursor=cursor)
    finally:
        cursor.close()
        conn.close()

    if market_data.clock >= 18 or market_data.clock < 6:
        response = ewcfg.str_exchange_closed
    else:
        value = None
        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)

        if value != None:
            if value < 0:
                value = user_data.slimes
            if value <= 0:
                value = None

        if value != None:
            # Apply a brokerage fee of ~5% (rate * 1.05)
            rate_exchange = (market_data.rate_exchange / 1000000.0)
            feerate = 1.05

            # The user can only buy a whole number of credits, so adjust their cost based on the actual number of credits purchased.
            gross_credits = int(value / rate_exchange)

            fee = int((gross_credits * feerate) - gross_credits)

            net_credits = gross_credits - fee

            if value > user_data.slimes:
                response = "You don't have that much slime to invest."
            elif user_data.time_lastinvest + ewcfg.cd_invest > time_now:
                # Limit frequency of investments.
                response = ewcfg.str_exchange_busy.format(action="invest")
            else:
                user_data.slimes -= value
                user_data.slimecredit += net_credits
                user_data.time_lastinvest = time_now
                market_data.slimes_casino += value

                response = "You invest {slime:,} slime and receive {credit:,} SlimeCoin. Your slimebroker takes his nominal fee of {fee:,} SlimeCoin.".format(
                    slime=value, credit=net_credits, fee=fee)

                try:
                    conn = ewutils.databaseConnect()
                    cursor = conn.cursor()

                    user_data.persist(conn=conn, cursor=cursor)
                    market_data.persist(conn=conn, cursor=cursor)

                    conn.commit()
                finally:
                    cursor.close()
                    conn.close()

        else:
            response = ewcfg.str_exchange_specify.format(currency="slime",
                                                         action="invest")

    # Send the response to the player.
    await cmd.client.edit_message(
        resp, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 10
0
async def xfer(cmd):
    time_now = round(time.time())
    user_data = EwUser(member=cmd.message.author)

    if cmd.message.channel.name != ewcfg.channel_stockexchange:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin",
                                                        action="transfer")
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if cmd.mentions_count != 1:
        # Must have exactly one target to send to.
        response = "Mention the player you want to send SlimeCoin to."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.time_lastinvest + ewcfg.cd_invest > time_now:
        # Limit frequency of transfers
        response = ewcfg.str_exchange_busy.format(action="transfer slimecoin")
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.life_state == ewcfg.life_state_corpse:
        # Disallow transfers from ghosts.
        response = "Your slimebroker can't confirm your identity while you're dead."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    member = cmd.mentions[0]
    target_data = EwUser(member=member)

    if target_data.life_state == ewcfg.life_state_kingpin:
        # Disallow transfers to RF and CK kingpins.
        response = "You can't transfer SlimeCoin to a known criminal warlord."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    market_data = EwMarket(id_server=cmd.message.author.server.id)

    if cmd.message.author.id == member.id:
        user_data.id_killer = cmd.message.author.id
        user_data.die(cause=ewcfg.cause_suicide)
        user_data.persist()

        await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(
                cmd.message.author,
                "Gaming the slimeconomy is punishable by death. SlimeCorp soldiers execute you immediately."
            ))
        await ewrolemgr.updateRoles(client=cmd.client,
                                    member=cmd.message.author)
        return

    # Parse the slime value to send.
    value = None
    if cmd.tokens_count > 1:
        value = ewutils.getIntToken(tokens=cmd.tokens)

    if value != None:
        if value < 0:
            value = user_data.slimes
        if value <= 0:
            value = None

    if value != None:
        # Cost including the 5% transfer fee.
        cost_total = round(value * 1.05)

        if user_data.slimecoin < cost_total:
            response = "You don't have enough SlimeCoin. ({:,}/{:,})".format(
                user_data.slimecoin, cost_total)
        else:
            # Do the transfer if the player can afford it.
            target_data.change_slimecoin(n=value,
                                         coinsource=ewcfg.coinsource_transfer)
            user_data.change_slimecoin(n=-cost_total,
                                       coinsource=ewcfg.coinsource_transfer)
            user_data.time_lastinvest = time_now

            # Persist changes
            response = "You transfer {slime:,} SlimeCoin to {target_name}. Your slimebroker takes his nominal fee of {fee:,} SlimeCoin.".format(
                slime=value,
                target_name=member.display_name,
                fee=(cost_total - value))

            target_data.persist()
            user_data.persist()
    else:
        response = ewcfg.str_exchange_specify.format(currency="SlimeCoin",
                                                     action="transfer")

    # Send the response to the player.
    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 11
0
async def withdraw(cmd):
    resp = await ewcmd.start(cmd=cmd)
    time_now = int(time.time())

    if cmd.message.channel.name != ewcfg.channel_stockexchange:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin",
                                                        action="withdraw")
        await cmd.client.edit_message(
            resp, ewutils.formatMessage(cmd.message.author, response))
        return

    try:
        conn = ewutils.databaseConnect()
        cursor = conn.cursor()

        user_data = EwUser(member=cmd.message.author, conn=conn, cursor=cursor)
        market_data = EwMarket(id_server=cmd.message.author.server.id,
                               conn=conn,
                               cursor=cursor)
    finally:
        cursor.close()
        conn.close()

    if market_data.clock >= 18 or market_data.clock < 6:
        response = ewcfg.str_exchange_closed
    else:
        value = None
        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)

        if value != None:
            if value < 0:
                value = user_data.slimecredit
            if value <= 0:
                value = None

        if value != None:

            rate_exchange = (market_data.rate_exchange / 1000000.0)

            credits = value
            slimes = int(value * rate_exchange)

            if value > user_data.slimecredit:
                response = "You don't have that many SlimeCoin to exchange."
            elif user_data.time_lastinvest + ewcfg.cd_invest > time_now:
                # Limit frequency of withdrawals
                response = ewcfg.str_exchange_busy.format(action="withdraw")
            else:
                user_data.slimes += slimes
                user_data.slimecredit -= credits
                user_data.time_lastinvest = time_now
                market_data.slimes_casino -= slimes

                # Flag the user for PvP
                user_data.time_expirpvp = ewutils.calculatePvpTimer(
                    user_data.time_expirpvp,
                    (int(time.time()) + ewcfg.time_pvp_invest_withdraw))

                response = "You exchange {credits:,} SlimeCoin for {slimes:,} slime.".format(
                    credits=credits, slimes=slimes)

                # Level up the player if appropriate.
                new_level = len(str(int(user_data.slimes)))
                if new_level > user_data.slimelevel:
                    response += "\n\n{} has been empowered by slime and is now a level {} slimeboi!".format(
                        cmd.message.author.display_name, new_level)
                    user_data.slimelevel = new_level

                try:
                    conn = ewutils.databaseConnect()
                    cursor = conn.cursor()

                    user_data.persist(conn=conn, cursor=cursor)
                    market_data.persist(conn=conn, cursor=cursor)

                    conn.commit()
                finally:
                    cursor.close()
                    conn.close()

                # Add the visible PvP flag role.
                await ewutils.add_pvp_role(cmd=cmd)

        else:
            response = ewcfg.str_exchange_specify.format(currency="SlimeCoin",
                                                         action="withdraw")

    # Send the response to the player.
    await cmd.client.edit_message(
        resp, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 12
0
async def donate(cmd):
    user_data = EwUser(member=cmd.message.author)
    market_data = EwMarket(id_server=user_data.id_server)

    time_now = round(time.time())

    if user_data.poi == ewcfg.poi_id_slimecorphq:
        value = None
        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)

        if value != None:
            if value < 0:
                value = user_data.slimes
            if value <= 0:
                value = None

        if value != None and value < ewcfg.slimecoin_exchangerate:
            response = "You must volunteer to donate at least %d slime to receive compensation." % ewcfg.slimecoin_exchangerate

        elif value != None:
            # Amount of slime invested.
            cost_total = round(value)
            coin_total = round(value / ewcfg.slimecoin_exchangerate)

            if user_data.slimes < cost_total:
                response = "Acid-green flashes of light and bloodcurdling screams emanate from small window of SlimeCorp HQ. Unfortunately, you did not survive the procedure. Your body is dumped down a disposal chute to the sewers."
                market_data.donated_slimes += user_data.slimes
                market_data.persist()
                user_data.die(cause=ewcfg.cause_donation)
                user_data.persist()
                # Assign the corpse role to the player. He dead.
                await ewrolemgr.updateRoles(client=cmd.client,
                                            member=cmd.message.author)
                sewerchannel = ewutils.get_channel(cmd.message.server,
                                                   ewcfg.channel_sewers)
                await ewutils.send_message(
                    cmd.client, sewerchannel,
                    "{} ".format(ewcfg.emote_slimeskull) +
                    ewutils.formatMessage(
                        cmd.message.author,
                        "You have died in a medical mishap. {}".format(
                            ewcfg.emote_slimeskull)))
            else:
                # Do the transfer if the player can afford it.
                market_data.donated_slimes += cost_total
                market_data.persist()
                user_data.change_slimes(n=-cost_total,
                                        source=ewcfg.source_spending)
                user_data.change_slimecoin(
                    n=coin_total, coinsource=ewcfg.coinsource_donation)
                user_data.slime_donations += cost_total

                # Persist changes
                user_data.persist()

                response = "You stumble out of a Slimecorp HQ vault room in a stupor. You don't remember what happened in there, but your body hurts and you've got {slimecoin:,} shiny new SlimeCoin in your pocket.".format(
                    slimecoin=coin_total)

        else:
            response = ewcfg.str_exchange_specify.format(currency="slime",
                                                         action="donate")

    elif user_data.poi == ewcfg.poi_id_slimeoidlab:
        poudrins = ewitem.find_item(item_search="slimepoudrin",
                                    id_user=cmd.message.author.id,
                                    id_server=cmd.message.server.id if
                                    cmd.message.server is not None else None)

        if poudrins == None:
            response = "You have to own a poudrin in order to donate a poudrin. Duh."

        else:
            ewitem.item_delete(
                id_item=poudrins.get('id_item'))  # Remove Poudrins
            market_data.donated_poudrins += 1
            market_data.persist()
            user_data.poudrin_donations += 1
            user_data.persist()

            response = "You hand off one of your hard-earned poudrins to the front desk receptionist, who is all too happy to collect it. Pretty uneventful, but at the very least you’re glad donating isn’t physically painful anymore."

    else:
        response = "To donate slime, go to the SlimeCorp HQ in Downtown. To donate poudrins, go to the SlimeCorp Lab in Brawlden."

    # Send the response to the player.
    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 13
0
async def withdraw(cmd):
    user_data = EwUser(member=cmd.message.author)
    time_now = round(time.time())
    market_data = EwMarket(id_server=cmd.message.author.server.id)

    if market_data.clock < 6 or market_data.clock >= 20:
        response = ewcfg.str_exchange_closed
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.poi != ewcfg.poi_id_stockexchange:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin",
                                                        action="withdraw")
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.life_state == ewcfg.life_state_corpse:
        # Disallow withdraws from ghosts.
        response = "Your slimebroker can't confirm your identity while you're dead."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    else:
        value = None
        stock = None

        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(cmd.tokens[1:], allow_all=True)

            for token in cmd.tokens[1:]:
                if token.lower() in ewcfg.stocks:
                    stock = token.lower()
                    break

        if stock != None:
            stock = EwStock(id_server=cmd.message.server.id, stock=stock)

            total_shares = getUserTotalShares(id_server=user_data.id_server,
                                              stock=stock.id_stock,
                                              id_user=user_data.id_user)

            if value != None:
                if value < 0:
                    value = total_shares
                if value <= 0:
                    value = None

            if value != None:

                if value <= total_shares:
                    exchange_rate = (stock.exchange_rate / 1000.0)

                    shares = value
                    slimecoin = round(value * exchange_rate)

                    if user_data.time_lastinvest + ewcfg.cd_invest > time_now:
                        # Limit frequency of withdrawals
                        response = ewcfg.str_exchange_busy.format(
                            action="withdraw")
                    else:
                        user_data.change_slimecoin(
                            n=slimecoin, coinsource=ewcfg.coinsource_withdraw)
                        total_shares -= shares
                        user_data.time_lastinvest = time_now
                        stock.total_shares -= shares

                        response = "You exchange {shares:,} shares in {stock} for {coins:,} SlimeCoin.".format(
                            coins=slimecoin,
                            shares=shares,
                            stock=ewcfg.stock_names.get(stock.id_stock))
                        user_data.persist()
                        stock.timestamp = round(time.time())
                        stock.persist()
                        updateUserTotalShares(id_server=user_data.id_server,
                                              stock=stock.id_stock,
                                              id_user=user_data.id_user,
                                              shares=total_shares)
                else:
                    response = "You don't have that many shares in {stock} to exchange.".format(
                        stock=ewcfg.stock_names.get(stock.id_stock))
            else:
                response = ewcfg.str_exchange_specify.format(
                    currency="SlimeCoin", action="withdraw")
        else:
            response = "That's not a valid stock name, please use a proper one, you c**t: {}".format(
                ewutils.formatNiceList(names=ewcfg.stocks))

    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 14
0
async def invest(cmd):
    user_data = EwUser(member=cmd.message.author)
    time_now = round(time.time())
    market_data = EwMarket(id_server=cmd.message.author.server.id)

    if user_data.poi != ewcfg.poi_id_stockexchange:
        # Only allowed in the stock exchange.
        response = ewcfg.str_exchange_channelreq.format(currency="SlimeCoin",
                                                        action="invest")
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if market_data.clock < 6 or market_data.clock >= 20:
        response = ewcfg.str_exchange_closed
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.time_lastinvest + ewcfg.cd_invest > time_now:
        # Limit frequency of investments.
        response = ewcfg.str_exchange_busy.format(action="invest")
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.life_state == ewcfg.life_state_corpse:
        # Disallow invests from ghosts.
        response = "Your slimebroker can't confirm your identity while you're dead."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    if user_data.life_state == ewcfg.life_state_kingpin:
        # Disallow investments by RF and CK kingpins.
        response = "You need that money to buy more videogames."
        return await ewutils.send_message(
            cmd.client, cmd.message.channel,
            ewutils.formatMessage(cmd.message.author, response))

    else:
        value = None
        stock = None

        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(cmd.tokens, allow_all=True)

            for token in cmd.tokens[1:]:
                if token.lower() in ewcfg.stocks:
                    stock = token.lower()
                    break

        if value != None:
            if value < 0:
                value = user_data.slimecoin
            if value <= 0:
                value = None

        if value != None:
            if stock != None:

                stock = EwStock(id_server=cmd.message.server.id, stock=stock)
                # basic exchange rate / 1000 = 1 share
                exchange_rate = (stock.exchange_rate / 1000.0)

                cost_total = round(value * 1.05)

                # gets the highest value possible where the player can still pay the fee
                if value == user_data.slimecoin:
                    while cost_total > user_data.slimecoin:
                        value -= cost_total - value
                        cost_total = round(value * 1.05)

                # The user can only buy a whole number of shares, so adjust their cost based on the actual number of shares purchased.
                net_shares = round(value / exchange_rate)

                if user_data.slimecoin < cost_total:
                    response = "You don't have enough SlimeCoin. ({:,}/{:,})".format(
                        user_data.slimecoin, cost_total)

                elif value > user_data.slimecoin:
                    response = "You don't have that much SlimeCoin to invest."

                elif net_shares == 0:
                    response = "You don't have enough SlimeCoin to buy a share in {stock}".format(
                        stock=ewcfg.stock_names.get(stock.id_stock))

                else:
                    user_data.change_slimecoin(
                        n=-cost_total, coinsource=ewcfg.coinsource_invest)
                    shares = getUserTotalShares(id_server=user_data.id_server,
                                                stock=stock.id_stock,
                                                id_user=user_data.id_user)
                    shares += net_shares
                    updateUserTotalShares(id_server=user_data.id_server,
                                          stock=stock.id_stock,
                                          id_user=user_data.id_user,
                                          shares=shares)
                    user_data.time_lastinvest = time_now

                    stock.total_shares += net_shares
                    response = "You invest {coin:,} SlimeCoin and receive {shares:,} shares in {stock}. Your slimebroker takes his nominal fee of {fee:,} SlimeCoin.".format(
                        coin=value,
                        shares=net_shares,
                        stock=ewcfg.stock_names.get(stock.id_stock),
                        fee=(cost_total - value))

                    user_data.persist()
                    stock.timestamp = round(time.time())
                    stock.persist()

            else:
                response = "That's not a valid stock name, please use a proper one, you c**t: {}".format(
                    ewutils.formatNiceList(names=ewcfg.stocks))

        else:
            response = ewcfg.str_exchange_specify.format(currency="SlimeCoin",
                                                         action="invest")

    # Send the response to the player.
    await ewutils.send_message(
        cmd.client, cmd.message.channel,
        ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 15
0
async def roulette(cmd):
	resp = await ewcmd.start(cmd = cmd)
	time_now = int(time.time())
	bet = ""
	all_bets = ["0", "00", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
				"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
				"32", "33", "34", "35", "36", "1strow", "2ndrow", "3rdrow", "1st12", "2nd12", "3rd12", "1to18",
				"19to36", "even", "odd", "pink", "purple", "green"]
	img_base = "https://ew.krakissi.net/img/cas/sr/"

	global last_rouletted_times
	last_used = last_rouletted_times.get(cmd.message.author.id)

	if last_used == None:
		last_used = 0

	if last_used + 5 > time_now:
		response = "**ENOUGH**"
	elif cmd.message.channel.name != ewcfg.channel_casino:
		# Only allowed in the slime casino.
		response = "You must go to the #{} to gamble your SlimeCoin.".format(ewcfg.channel_casino)
	else:
		last_rouletted_times[cmd.message.author.id] = time_now
		value = None

		if cmd.tokens_count > 1:
			value = ewutils.getIntToken(tokens = cmd.tokens[:2], allow_all = True)
			bet = ewutils.flattenTokenListToString(tokens = cmd.tokens[2:])

		if value != None:
			user_data = EwUser(member = cmd.message.author)

			if value == -1:
				value = user_data.slimecredit

			if value > user_data.slimecredit or value == 0:
				response = "You don't have enough SlimeCoin."
			elif len(bet) == 0:
				response = "You need to say what you're betting on. Options are: {}\n{}board.png".format(ewutils.formatNiceList(names = all_bets), img_base)
			elif bet not in all_bets:
				response = "The dealer didn't understand your wager. Options are: {}\n{}board.png".format(ewutils.formatNiceList(names = all_bets), img_base)
			else:
				await cmd.client.edit_message(resp, ewutils.formatMessage(
					cmd.message.author,
					img_base + "sr.gif"
				))

				await asyncio.sleep(5)

				roll = str(random.randint(1, 38))
				if roll == "37":
					roll = "0"
				if roll == "38":
					roll = "00"

				odd = ["1", "3", "5", "7", "9", "11", "13", "15", "17", "19", "21", "23", "25", "27", "29", "31", "33", "35"]
				even = ["2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "34", "36"]
				firstrow = ["1", "4", "7", "10", "13", "16", "19", "22", "25", "28", "31", "34"]
				secondrow = ["2", "5", "8", "11", "14", "17", "20", "23", "26", "29", "32", "35"]
				thirdrow = ["3", "6", "9", "12", "15", "18", "21", "24", "27", "30", "33", "36"]
				firsttwelve = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
				secondtwelve = ["13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"]
				thirdtwelve = ["25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36"]
				onetoeighteen = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"]
				nineteentothirtysix = ["19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36"]
				pink = ["2", "4", "6", "8", "10", "11", "13", "15", "17", "20", "22", "24", "26", "28", "29", "31", "33", "35"]
				purple = ["1", "3", "5", "7", "9", "12", "14", "16", "18", "19", "21", "23", "25", "27", "30", "32", "34", "36"]
				green = ["0", "00"]

				if roll == bet:
					winnings = (value * 36)
				elif bet == "1strow" and roll in firstrow:
					winnings = (value * 3)
				elif bet == "2ndrow" and roll in secondrow:
					winnings = (value * 3)
				elif bet == "3rdrow" and roll in thirdrow:
					winnings = (value * 3)
				elif bet == "1st12" and roll in firsttwelve:
					winnings = (value * 3)
				elif bet == "2nd12" and roll in secondtwelve:
					winnings = (value * 3)
				elif bet == "3rd12" and roll in thirdtwelve:
					winnings = (value * 3)
				elif bet == "1to18" and roll in onetoeighteen:
					winnings = (value * 2)
				elif bet == "19to36" and roll in nineteentothirtysix:
					winnings = (value * 2)
				elif bet == "odd" and roll in odd:
					winnings = (value * 2)
				elif bet == "even" and roll in even:
					winnings = (value * 2)
				elif bet == "pink" and roll in pink:
					winnings = (value * 2)
				elif bet == "purple" and roll in purple:
					winnings = (value * 2)
				elif bet == "green" and roll in green:
					winnings = (value * 18)
				else:
					winnings = 0

				response = "The ball landed on {}!\n".format(roll)
				if winnings > 0:
					response += " You won {} SlimeCoin!".format(winnings)
				else:
					response += " You lost your bet..."

				# Assemble image file name.
				response += "\n\n{}{}.gif".format(img_base, roll)

				# add winnings/subtract losses
				user_data.change_slimecredit(n = winnings - value, coinsource = ewcfg.coinsource_casino)
				user_data.persist()
		else:
			response = "Specify how much SlimeCoin you will wager."

	# Send the response to the player.
	await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 16
0
async def craps(cmd):
    resp = await ewcmd.start(cmd=cmd)
    time_now = int(time.time())

    global last_crapsed_times
    last_used = last_crapsed_times.get(cmd.message.author.id)

    if last_used == None:
        last_used = 0

    if last_used + 2 > time_now:
        response = "**ENOUGH**"
    elif cmd.message.channel.name != ewcfg.channel_casino:
        # Only allowed in the slime casino.
        response = "You must go to the #{} to gamble your SlimeCoin.".format(
            ewcfg.channel_casino)
    else:
        last_crapsed_times[cmd.message.author.id] = time_now
        value = None

        if cmd.tokens_count > 1:
            value = ewutils.getIntToken(tokens=cmd.tokens, allow_all=True)

        if value != None:
            try:
                conn = ewutils.databaseConnect()
                cursor = conn.cursor()

                user_data = EwUser(member=cmd.message.author,
                                   conn=conn,
                                   cursor=cursor)
                market_data = EwMarket(id_server=cmd.message.author.server.id,
                                       conn=conn,
                                       cursor=cursor)
            finally:
                cursor.close()
                conn.close()

            if ewcmd.is_casino_open(market_data.clock) == False:
                response = ewcfg.str_casino_closed
            elif value > user_data.slimecredit:
                response = "You don't have that much SlimeCoin to bet with."
            else:
                user_data.slimecredit -= value

                roll1 = random.randint(1, 6)
                roll2 = random.randint(1, 6)

                emotes_dice = [
                    ewcfg.emote_dice1, ewcfg.emote_dice2, ewcfg.emote_dice3,
                    ewcfg.emote_dice4, ewcfg.emote_dice5, ewcfg.emote_dice6
                ]

                response = " {} {}".format(emotes_dice[roll1 - 1],
                                           emotes_dice[roll2 - 1])

                if (roll1 + roll2) == 7:
                    winnings = 5 * value
                    response += "\n\n**You rolled a 7! It's your lucky day. You won {:,} SlimeCoin.**".format(
                        winnings)
                    user_data.slimecredit += winnings
                else:
                    response += "\n\nYou didn't roll 7. You lost your SlimeCoins."

                try:
                    conn = ewutils.databaseConnect()
                    cursor = conn.cursor()

                    user_data.persist(conn=conn, cursor=cursor)
                    market_data.persist(conn=conn, cursor=cursor)

                    conn.commit()
                finally:
                    cursor.close()
                    conn.close()
        else:
            response = "Specify how much SlimeCoin you will wager."

    # Send the response to the player.
    await cmd.client.edit_message(
        resp, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 17
0
async def baccarat(cmd):
	resp = await ewcmd.start(cmd = cmd)
	time_now = int(time.time())
	bet = ""
	all_bets = ["player", "dealer", "tie"]
	img_base = "https://ew.krakissi.net/img/cas/sb/"
	response = ""
	rank = ""
	suit = ""
	str_ranksuit = " the **{} of {}**. "

	global last_rouletted_times
	last_used = last_rouletted_times.get(cmd.message.author.id)

	if last_used == None:
		last_used = 0

	if last_used + 2 > time_now:
		response = "**ENOUGH**"
	elif cmd.message.channel.name != ewcfg.channel_casino:
		# Only allowed in the slime casino.
		response = "You must go to the Casino to gamble your SlimeCoin."
		await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
		await asyncio.sleep(1)
	else:
		last_rouletted_times[cmd.message.author.id] = time_now
		value = None

		if cmd.tokens_count > 1:
			value = ewutils.getIntToken(tokens = cmd.tokens[:2], allow_all = True)
			bet = ewutils.flattenTokenListToString(tokens = cmd.tokens[2:])

		if value != None:
			user_data = EwUser(member = cmd.message.author)

			if value == -1:
				value = user_data.slimecredit

			if value > user_data.slimecredit or value == 0:
				response = "You don't have enough SlimeCoin."
				await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(1)

			elif len(bet) == 0:
				response = "You must specify what hand you are betting on. Options are {}.".format(ewutils.formatNiceList(names = all_bets), img_base)
				await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(1)

			elif bet not in all_bets:
				response = "The dealer didn't understand your wager. Options are {}.".format(ewutils.formatNiceList(names = all_bets), img_base)
				await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(1)

			else:
				resp_d = await ewcmd.start(cmd = cmd)
				resp_f = await ewcmd.start(cmd = cmd)
				response = "You bet {} SlimeCoin on {}. The dealer shuffles the deck, then begins to deal.".format(str(value),str(bet))
				await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(1)

				response += "\nThe dealer deals you your first card..."

				await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(3)

				winnings = 0
				end = False
				phit = False
				d = 0
				p = 0

				drawp1 = str(random.randint(1,52))
				if drawp1 in ["1", "14", "27", "40"]:
					p += 1
				if drawp1 in ["2", "15", "28", "41"]:
					p += 2
				if drawp1 in ["3", "16", "29", "42"]:
					p += 3
				if drawp1 in ["4", "17", "30", "43"]:
					p += 4
				if drawp1 in ["5", "18", "31", "44"]:
					p += 5
				if drawp1 in ["6", "19", "32", "45"]:
					p += 6
				if drawp1 in ["7", "20", "33", "46"]:
					p += 7
				if drawp1 in ["8", "21", "34", "47"]:
					p += 8
				if drawp1 in ["9", "22", "35", "48"]:
					p += 9
				if drawp1 in ["10","11","12","13","23","24","25","26","36","37","38","39","49","50","51","52"]:
					p += 0
				lastcard = drawp1
				if lastcard in ["1", "14", "27", "40"]:
					rank = "Ace"
				if lastcard in ["2", "15", "28", "41"]:
					rank = "Two"
				if lastcard in ["3", "16", "29", "42"]:
					rank = "Three"
				if lastcard in ["4", "17", "30", "43"]:
					rank = "Four"
				if lastcard in ["5", "18", "31", "44"]:
					rank = "Five"
				if lastcard in ["6", "19", "32", "45"]:
					rank = "Six"
				if lastcard in ["7", "20", "33", "46"]:
					rank = "Seven"
				if lastcard in ["8", "21", "34", "47"]:
					rank = "Eight"
				if lastcard in ["9", "22", "35", "48"]:
					rank = "Nine"
				if lastcard in ["10", "23", "36", "49"]:
					rank = "Ten"
				if lastcard in ["11", "24", "37", "50"]:
					rank = "Jack"
				if lastcard in ["12", "25", "38", "51"]:
					rank = "Queen"
				if lastcard in ["13", "26", "39", "52"]:
					rank = "King"
				if lastcard in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]:
					suit = "Hearts"
				if lastcard in ["14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"]:
					suit = "Slugs"
				if lastcard in ["27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39"]:
					suit = "Hats"
				if lastcard in ["40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52"]:
					suit = "Shields"

				if p > 9:
					p -= 10
				if d > 9:
					d -= 10

				response += str_ranksuit.format(rank, suit)
				response += img_base + lastcard + ".png"

				await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(1)
				response += "\nThe dealer deals you your second card..."
				await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(3)

				while True:
					drawp2 = str(random.randint(1,52))
					if drawp2 != drawp1:
						break
				if drawp2 in ["1", "14", "27", "40"]:
					p += 1
				if drawp2 in ["2", "15", "28", "41"]:
					p += 2
				if drawp2 in ["3", "16", "29", "42"]:
					p += 3
				if drawp2 in ["4", "17", "30", "43"]:
					p += 4
				if drawp2 in ["5", "18", "31", "44"]:
					p += 5
				if drawp2 in ["6", "19", "32", "45"]:
					p += 6
				if drawp2 in ["7", "20", "33", "46"]:
					p += 7
				if drawp2 in ["8", "21", "34", "47"]:
					p += 8
				if drawp2 in ["9", "22", "35", "48"]:
					p += 9
				if drawp2 in ["10","11","12","13","23","24","25","26","36","37","38","39","49","50","51","52"]:
					p += 0
				lastcard = drawp2
				if lastcard in ["1", "14", "27", "40"]:
					rank = "Ace"
				if lastcard in ["2", "15", "28", "41"]:
					rank = "Two"
				if lastcard in ["3", "16", "29", "42"]:
					rank = "Three"
				if lastcard in ["4", "17", "30", "43"]:
					rank = "Four"
				if lastcard in ["5", "18", "31", "44"]:
					rank = "Five"
				if lastcard in ["6", "19", "32", "45"]:
					rank = "Six"
				if lastcard in ["7", "20", "33", "46"]:
					rank = "Seven"
				if lastcard in ["8", "21", "34", "47"]:
					rank = "Eight"
				if lastcard in ["9", "22", "35", "48"]:
					rank = "Nine"
				if lastcard in ["10", "23", "36", "49"]:
					rank = "Ten"
				if lastcard in ["11", "24", "37", "50"]:
					rank = "Jack"
				if lastcard in ["12", "25", "38", "51"]:
					rank = "Queen"
				if lastcard in ["13", "26", "39", "52"]:
					rank = "King"
				if lastcard in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]:
					suit = "Hearts"
				if lastcard in ["14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"]:
					suit = "Slugs"
				if lastcard in ["27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39"]:
					suit = "Hats"
				if lastcard in ["40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52"]:
					suit = "Shields"

				if p > 9:
					p -= 10
				if d > 9:
					d -= 10

				response += str_ranksuit.format(rank, suit)
				response += img_base + lastcard + ".png"

				await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(1)

				responsesave = response

				response = "\nThe dealer deals the house its first card..."

				await cmd.client.edit_message(resp_d, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(3)

				while True:
					drawd1 = str(random.randint(1,52))
					if drawd1 != drawp1 and drawd1 != drawp2:
						break
				if drawd1 in ["1", "14", "27", "40"]:
					d += 1
				if drawd1 in ["2", "15", "28", "41"]:
					d += 2
				if drawd1 in ["3", "16", "29", "42"]:
					d += 3
				if drawd1 in ["4", "17", "30", "43"]:
					d += 4
				if drawd1 in ["5", "18", "31", "44"]:
					d += 5
				if drawd1 in ["6", "19", "32", "45"]:
					d += 6
				if drawd1 in ["7", "20", "33", "46"]:
					d += 7
				if drawd1 in ["8", "21", "34", "47"]:
					d += 8
				if drawd1 in ["9", "22", "35", "48"]:
					d += 9
				if drawd1 in ["10","11","12","13","23","24","25","26","36","37","38","39","49","50","51","52"]:
					d += 0
				lastcard = drawd1
				if lastcard in ["1", "14", "27", "40"]:
					rank = "Ace"
				if lastcard in ["2", "15", "28", "41"]:
					rank = "Two"
				if lastcard in ["3", "16", "29", "42"]:
					rank = "Three"
				if lastcard in ["4", "17", "30", "43"]:
					rank = "Four"
				if lastcard in ["5", "18", "31", "44"]:
					rank = "Five"
				if lastcard in ["6", "19", "32", "45"]:
					rank = "Six"
				if lastcard in ["7", "20", "33", "46"]:
					rank = "Seven"
				if lastcard in ["8", "21", "34", "47"]:
					rank = "Eight"
				if lastcard in ["9", "22", "35", "48"]:
					rank = "Nine"
				if lastcard in ["10", "23", "36", "49"]:
					rank = "Ten"
				if lastcard in ["11", "24", "37", "50"]:
					rank = "Jack"
				if lastcard in ["12", "25", "38", "51"]:
					rank = "Queen"
				if lastcard in ["13", "26", "39", "52"]:
					rank = "King"
				if lastcard in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]:
					suit = "Hearts"
				if lastcard in ["14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"]:
					suit = "Slugs"
				if lastcard in ["27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39"]:
					suit = "Hats"
				if lastcard in ["40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52"]:
					suit = "Shields"

				if p > 9:
					p -= 10
				if d > 9:
					d -= 10

				response += str_ranksuit.format(rank, suit)
				response += img_base + lastcard + ".png"

				await cmd.client.edit_message(resp_d, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(1)
				response += "\nThe dealer deals the house its second card..."
				await cmd.client.edit_message(resp_d, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(3)

				while True:
					drawd2 = str(random.randint(1,52))
					if drawd2 != drawp1 and drawd2 != drawp2 and drawd2 != drawd1:
						break
				if drawd2 in ["1", "14", "27", "40"]:
					d += 1
				if drawd2 in ["2", "15", "28", "41"]:
					d += 2
				if drawd2 in ["3", "16", "29", "42"]:
					d += 3
				if drawd2 in ["4", "17", "30", "43"]:
					d += 4
				if drawd2 in ["5", "18", "31", "44"]:
					d += 5
				if drawd2 in ["6", "19", "32", "45"]:
					d += 6
				if drawd2 in ["7", "20", "33", "46"]:
					d += 7
				if drawd2 in ["8", "21", "34", "47"]:
					d += 8
				if drawd2 in ["9", "22", "35", "48"]:
					d += 9
				if drawd2 in ["10","11","12","13","23","24","25","26","36","37","38","39","49","50","51","52"]:
					d += 0
				lastcard = drawd2
				if lastcard in ["1", "14", "27", "40"]:
					rank = "Ace"
				if lastcard in ["2", "15", "28", "41"]:
					rank = "Two"
				if lastcard in ["3", "16", "29", "42"]:
					rank = "Three"
				if lastcard in ["4", "17", "30", "43"]:
					rank = "Four"
				if lastcard in ["5", "18", "31", "44"]:
					rank = "Five"
				if lastcard in ["6", "19", "32", "45"]:
					rank = "Six"
				if lastcard in ["7", "20", "33", "46"]:
					rank = "Seven"
				if lastcard in ["8", "21", "34", "47"]:
					rank = "Eight"
				if lastcard in ["9", "22", "35", "48"]:
					rank = "Nine"
				if lastcard in ["10", "23", "36", "49"]:
					rank = "Ten"
				if lastcard in ["11", "24", "37", "50"]:
					rank = "Jack"
				if lastcard in ["12", "25", "38", "51"]:
					rank = "Queen"
				if lastcard in ["13", "26", "39", "52"]:
					rank = "King"
				if lastcard in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]:
					suit = "Hearts"
				if lastcard in ["14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"]:
					suit = "Slugs"
				if lastcard in ["27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39"]:
					suit = "Hats"
				if lastcard in ["40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52"]:
					suit = "Shields"

				if p > 9:
					p -= 10
				if d > 9:
					d -= 10

				response += str_ranksuit.format(rank, suit)
				response += img_base + lastcard + ".png"

				await cmd.client.edit_message(resp_d, ewutils.formatMessage(cmd.message.author, response))
				await asyncio.sleep(1)
				responsesave_d = response

				if d in [8, 9] or p in [8, 9]:
					end = True

				drawp3 = ""
				if (p <= 5) and (end != True):

					response = responsesave
					response += "\nThe dealer deals you another card..."

					await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
					await asyncio.sleep(3)

					phit = True
					while True:
						drawp3 = str(random.randint(1,52))
						if drawp3 != drawp1 and drawp3 != drawp2 and drawp3 != drawd1 and drawp3 != drawd2:
							break
					if drawp3 in ["1", "14", "27", "40"]:
						p += 1
					if drawp3 in ["2", "15", "28", "41"]:
						p += 2
					if drawp3 in ["3", "16", "29", "42"]:
						p += 3
					if drawp3 in ["4", "17", "30", "43"]:
						p += 4
					if drawp3 in ["5", "18", "31", "44"]:
						p += 5
					if drawp3 in ["6", "19", "32", "45"]:
						p += 6
					if drawp3 in ["7", "20", "33", "46"]:
						p += 7
					if drawp3 in ["8", "21", "34", "47"]:
						p += 8
					if drawp3 in ["9", "22", "35", "48"]:
						p += 9
					if drawp3 in ["10","11","12","13","23","24","25","26","36","37","38","39","49","50","51","52"]:
						p += 0
					lastcard = drawp3
					if lastcard in ["1", "14", "27", "40"]:
						rank = "Ace"
					if lastcard in ["2", "15", "28", "41"]:
						rank = "Two"
					if lastcard in ["3", "16", "29", "42"]:
						rank = "Three"
					if lastcard in ["4", "17", "30", "43"]:
						rank = "Four"
					if lastcard in ["5", "18", "31", "44"]:
						rank = "Five"
					if lastcard in ["6", "19", "32", "45"]:
						rank = "Six"
					if lastcard in ["7", "20", "33", "46"]:
						rank = "Seven"
					if lastcard in ["8", "21", "34", "47"]:
						rank = "Eight"
					if lastcard in ["9", "22", "35", "48"]:
						rank = "Nine"
					if lastcard in ["10", "23", "36", "49"]:
						rank = "Ten"
					if lastcard in ["11", "24", "37", "50"]:
						rank = "Jack"
					if lastcard in ["12", "25", "38", "51"]:
						rank = "Queen"
					if lastcard in ["13", "26", "39", "52"]:
						rank = "King"
					if lastcard in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]:
						suit = "Hearts"
					if lastcard in ["14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"]:
						suit = "Slugs"
					if lastcard in ["27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39"]:
						suit = "Hats"
					if lastcard in ["40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52"]:
						suit = "Shields"

					if p > 9:
						p -= 10
					if d > 9:
						d -= 10

					response += str_ranksuit.format(rank, suit)
					response += img_base + lastcard + ".png"

					await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
					await asyncio.sleep(1)

				if ((phit != True and d <= 5) or (phit == True and ((d <= 2) or (d == 3 and drawp3 not in ["8", "21", "34", "47"]) or (d == 4 and drawp3 in ["2", "15", "28", "41", "3", "16", "29", "42", "4", "17", "30", "43", "5", "18", "31", "44", "6", "19", "32", "45", "7", "20", "33", "46"]) or (d == 5 and drawp3 in ["4", "17", "30", "43", "5", "18", "31", "44", "6", "19", "32", "45", "7", "20", "33", "46"]) or (d == 6 and drawp3 in ["6", "19", "32", "45", "7", "20", "33", "46"])))) and (d != 7) and (end != True):
					
					response = responsesave_d
					response += "\nThe dealer deals the house another card..."
					await cmd.client.edit_message(resp_d, ewutils.formatMessage(cmd.message.author, response))
					await asyncio.sleep(3)
					
					while True:
						drawd3 = str(random.randint(1,52))
						if drawd3 != drawp1 and drawd3 != drawp2 and drawd3 != drawd1 and drawd3 != drawd2 and drawd3 != drawp3:
							break
					if drawd3 in ["1", "14", "27", "40"]:
						d += 1
					if drawd3 in ["2", "15", "28", "41"]:
						d += 2
					if drawd3 in ["3", "16", "29", "42"]:
						d += 3
					if drawd3 in ["4", "17", "30", "43"]:
						d += 4
					if drawd3 in ["5", "18", "31", "44"]:
						d += 5
					if drawd3 in ["6", "19", "32", "45"]:
						d += 6
					if drawd3 in ["7", "20", "33", "46"]:
						d += 7
					if drawd3 in ["8", "21", "34", "47"]:
						d += 8
					if drawd3 in ["9", "22", "35", "48"]:
						d += 9
					if drawd3 in ["10","11","12","13","23","24","25","26","36","37","38","39","49","50","51","52"]:
						d += 0
					lastcard = drawd3
					if lastcard in ["1", "14", "27", "40"]:
						rank = "Ace"
					if lastcard in ["2", "15", "28", "41"]:
						rank = "Two"
					if lastcard in ["3", "16", "29", "42"]:
						rank = "Three"
					if lastcard in ["4", "17", "30", "43"]:
						rank = "Four"
					if lastcard in ["5", "18", "31", "44"]:
						rank = "Five"
					if lastcard in ["6", "19", "32", "45"]:
						rank = "Six"
					if lastcard in ["7", "20", "33", "46"]:
						rank = "Seven"
					if lastcard in ["8", "21", "34", "47"]:
						rank = "Eight"
					if lastcard in ["9", "22", "35", "48"]:
						rank = "Nine"
					if lastcard in ["10", "23", "36", "49"]:
						rank = "Ten"
					if lastcard in ["11", "24", "37", "50"]:
						rank = "Jack"
					if lastcard in ["12", "25", "38", "51"]:
						rank = "Queen"
					if lastcard in ["13", "26", "39", "52"]:
						rank = "King"
					if lastcard in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]:
						suit = "Hearts"
					if lastcard in ["14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"]:
						suit = "Slugs"
					if lastcard in ["27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39"]:
						suit = "Hats"
					if lastcard in ["40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52"]:
						suit = "Shields"

					if p > 9:
						p -= 10
					if d > 9:
						d -= 10

					response += str_ranksuit.format(rank, suit)
					response += img_base + lastcard + ".png"

					await cmd.client.edit_message(resp_d, ewutils.formatMessage(cmd.message.author, response))
					await asyncio.sleep(2)

				if p > 9:
					p -= 10
				if d > 9:
					d -= 10

				if p > d:
					response = "\n\nPlayer hand beats the dealer hand {} to {}.".format(str(p), str(d))
					result = "player"
					odds = 2
				elif d > p:
					response = "\n\nDealer hand beats the player hand {} to {}.".format(str(d), str(p))
					result = "dealer"
					odds = 2
				else: # p == d (peed lol)
					response = "\n\nPlayer hand and dealer hand tied at {}.".format(str(p))
					result = "tie"
					odds = 8

				if bet == result:
					winnings = (odds * value)
					response += "\n\n**You won {:,} SlimeCoin!**".format(winnings)
				else:
					response += "\n\n*You lost your bet.*"

				# add winnings/subtract losses
				user_data = EwUser(member = cmd.message.author)
				user_data.change_slimecredit(n = winnings - value, coinsource = ewcfg.coinsource_casino)
				user_data.persist()
				await cmd.client.edit_message(resp_f, ewutils.formatMessage(cmd.message.author, response))

		else:
			response = "Specify how much SlimeCoin you will wager."
			await cmd.client.edit_message(resp, ewutils.formatMessage(cmd.message.author, response))
Exemplo n.º 18
0
async def rate_zine(cmd):
	if len(cmd.tokens) < 2:
		response = "What zine do you want to rate?"

	else:
		if len(cmd.tokens) >= 3:
			rating = ewutils.getIntToken(cmd.tokens)
			book_title = ewutils.flattenTokenListToString(cmd.tokens[1:len(cmd.tokens) - 1])

			if rating == None:
				response = "How many f***s do you want to give the zine? (1-5)"

			elif rating not in range(1, 6):
				response = "Easy now, keep your f***s between 1 and 5."

			else:
				book_sought = ewitem.find_item(item_search=book_title, id_user=cmd.message.author.id, id_server=cmd.message.server.id if cmd.message.server is not None else None)

				if book_sought:
					book_item = EwItem(id_item=book_sought.get('id_item'))
					id_book = book_item.item_props.get("id_book")
					book = EwBook(id_book = id_book)
					sale = EwBookSale(id_book = id_book, member = cmd.message.author)

					if sale.bought == 1:
						if sale.rating == 0:
							book.rates += 1
						sale.rating = rating
						sale.persist()
						try:
							conn_info = ewutils.databaseConnect()
							conn = conn_info.get('conn')
							cursor = conn.cursor()

							cursor.execute((
									"SELECT {} FROM book_sales WHERE {} = %s AND {} = %s AND {} != 0".format(
										ewcfg.col_rating,
										ewcfg.col_id_server,
										ewcfg.col_id_user,
										ewcfg.col_rating,
									)
							), (
								cmd.message.server.id,
								cmd.message.author.id,
							))

							data = cursor.fetchall()
							ratings = []
							total_rating = 0

							if data != None:
								for row in data:
									ratings.append(row)
									total_rating += row[0]

						finally:
							# Clean up the database handles.
							cursor.close()
							ewutils.databaseClose(conn_info)

						book.rating = str(total_rating / len(ratings))[:4]

						# zine is excluded from normal browsing
						if book.book_state == 1:
							if book.rates >= 10 and float(book.rating) <= 2.0:
								book.book_state = 2
							elif book.rates >= 4 and float(book.rating) <= 1.5:
								book.book_state = 2

						# zine is included back into normal browsing
						elif book.book_state == 2:
							if float(book.rating) > 2.0 and book.rates > 10:
								book.book_state = 1
							elif float(book.rating) > 1.5 and book.rates > 5:
								book.book_state = 1

						book.persist()

						response = "{}, you carve a {} into the back of the zine in order to indicate how many f***s you give about it.".format(ewcfg.rating_flavor[rating], rating)

					else:
						response = "You've never bought this book."

				else:
					response = "You don't have that zine on you."
		else:
			response = "How many f***s do you want to give the zine? (1-5)"

	await ewutils.send_message(cmd.client, cmd.message.channel, ewutils.formatMessage(cmd.message.author, response))