1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 22:23:13 +00:00

Fix exchange bug and increase rate

This commit is contained in:
wlinator 2023-07-20 15:26:00 -04:00
parent 19780ed10f
commit 6eefd69e3d
4 changed files with 64 additions and 51 deletions

View file

@ -2,6 +2,7 @@
"emotes_guild_id": 1038051105642401812, "emotes_guild_id": 1038051105642401812,
"rc_guild_id": 719227135151046699, "rc_guild_id": 719227135151046699,
"daily_reward": 50, "daily_reward": 50,
"exchange_rate": 75000,
"blackjack": { "blackjack": {
"emotes": { "emotes": {
"hit": "<:hit:1119262723285467156>", "hit": "<:hit:1119262723285467156>",

View file

@ -6,11 +6,10 @@ from discord.ext import commands
from dotenv import load_dotenv from dotenv import load_dotenv
from data.Currency import Currency from data.Currency import Currency
from sb_tools import economy_embeds, universal, interaction from sb_tools import economy_embeds, universal
load_dotenv('.env') load_dotenv('.env')
active_blackjack_games = {}
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME") special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
cash_balance_name = os.getenv("CASH_BALANCE_NAME") cash_balance_name = os.getenv("CASH_BALANCE_NAME")
@ -95,37 +94,6 @@ class EconomyCog(commands.Cog):
await ctx.respond(embed=economy_embeds.give(ctx, user, currency, Currency.format(amount))) await ctx.respond(embed=economy_embeds.give(ctx, user, currency, Currency.format(amount)))
@commands.slash_command(
name="exchange",
description=f"Exchange {special_balance_name} for cash.",
guild_only=True
)
@commands.check(universal.channel_check)
async def exchange(self, ctx, *, amount: discord.Option(int)):
# Currency handler
ctx_currency = Currency(ctx.author.id)
author_special_balance = ctx_currency.special
if author_special_balance < amount or author_special_balance <= 0:
return await ctx.respond(embed=economy_embeds.not_enough_special_balance())
view = interaction.ExchangeConfirmation(ctx)
await ctx.respond(embed=economy_embeds.exchange_confirmation(Currency.format(amount)), view=view)
await view.wait()
if view.clickedConfirm:
exchange_rate = 1000
ctx_currency.add_cash(amount * exchange_rate)
ctx_currency.take_special(amount)
ctx_currency.push()
return await ctx.edit(embed=economy_embeds.exchange_done(Currency.format(amount)))
await ctx.edit(embed=economy_embeds.exchange_stopped())
@commands.slash_command( @commands.slash_command(
name="award", name="award",
description="Award currency - owner only command.", description="Award currency - owner only command.",

62
modules/exchange.py Normal file
View file

@ -0,0 +1,62 @@
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
from data.Currency import Currency
from main import economy_config
from sb_tools import economy_embeds, universal, interaction
load_dotenv('.env')
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
cash_balance_name = os.getenv("CASH_BALANCE_NAME")
class ExchangeCog(commands.Cog):
def __init__(self, sbbot):
self.bot = sbbot
@commands.slash_command(
name="exchange",
description=f"Exchange {special_balance_name} for cash.",
guild_only=True
)
@commands.check(universal.channel_check)
async def exchange(self, ctx, *, amount: discord.Option(int)):
# Currency handler
ctx_currency = Currency(ctx.author.id)
author_special_balance = ctx_currency.special
exchange_rate = economy_config["exchange_rate"]
total = amount * exchange_rate
if author_special_balance < amount or author_special_balance <= 0:
return await ctx.respond(embed=economy_embeds.not_enough_special_balance())
view = interaction.ExchangeConfirmation(ctx)
embed = discord.Embed(
description=f"You're about to sell **{amount} {special_balance_name}** for **{cash_balance_name}{Currency.format(total)}**. "
f"Are you absolutely sure about this?"
)
await ctx.respond(embed=embed, view=view)
await view.wait()
if view.clickedConfirm:
ctx_currency.add_cash(total)
ctx_currency.take_special(amount)
ctx_currency.push()
embed = discord.Embed(
color=discord.Color.green(),
description=f"You successfully exchanged **{amount} {special_balance_name}** "
f"for **{cash_balance_name}{Currency.format(total)}**."
)
return await ctx.edit(embed=embed)
await ctx.edit(embed=economy_embeds.exchange_stopped())
def setup(sbbot):
sbbot.add_cog(ExchangeCog(sbbot))

View file

@ -93,24 +93,6 @@ def out_of_time():
return embed return embed
def exchange_confirmation(amount):
embed = discord.Embed(
description=f"You're about to sell {amount} {special_balance_name} for {cash_balance_name}{amount * 1000}. "
f"Are you absolutely sure about this? Keep in mind that repurchasing {special_balance_name} "
f"later is considerably more expensive."
)
return embed
def exchange_done(amount):
embed = discord.Embed(
color=discord.Color.green(),
description=f"You successfully exchanged **{amount} {special_balance_name}** "
f"for **{cash_balance_name}{amount * 1000}**."
)
return embed
def exchange_stopped(): def exchange_stopped():
embed = discord.Embed( embed = discord.Embed(
color=discord.Color.red(), color=discord.Color.red(),