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

Remove majikoins ENTIRELY.

This commit is contained in:
wlinator 2024-03-14 21:30:58 +01:00
parent 58497f67d9
commit 66fb739d2e
20 changed files with 92 additions and 409 deletions

View file

@ -42,8 +42,6 @@ docker compose up -d --build
- `OWNER_ID`: the Discord user ID of the person who will act as owner of this bot.
- `XP_GAIN`: a comma-seperated list of XP gain values, Racu randomly picks one on each message.
- `COOLDOWN`: a comma-seperated list of cooldown times, this is to prevent botting XP.
- `CASH_BALANCE_NAME`: the name of your "cash", e.g. "racu coin".
- `SPECIAL_BALANCE_NAME`: the name of the level-up currency that is exchangable for cash.
- The values with "DBX" can be ignored unless you plan to make database backups with Dropbox. In that case enter your Dropbox API credentials.
- `MARIADB_USER`: the username for your MariaDB database.
- `MARIADB_PASSWORD`: the password for your database.

View file

@ -89,13 +89,6 @@ class XPHandler:
except Exception as error:
logs.error(f"[XpHandler] Assign level role FAILED; {error}")
"""
AWARD CURRENY_SPECIAL ON LEVEL-UP
"""
user_currency = Currency(user_id)
user_currency.add_special(1)
user_currency.push()
logs.debug(f"[XpHandler] {message.author.name} leveled up to lv {xp.level}.")
else:

45
modules/award.py Normal file
View file

@ -0,0 +1,45 @@
import json
import logging
import discord
from discord.ext import commands
from dotenv import load_dotenv
from services.Currency import Currency
from lib import checks
load_dotenv('.env')
logs = logging.getLogger('Racu.Core')
with open("config/economy.json") as file:
json_data = json.load(file)
class AwardCog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.slash_command(
name="award",
description="Award currency - owner only command.",
guild_only=True
)
@commands.check(checks.channel)
@commands.check(checks.bot_owner)
async def award(self, ctx, *, user: discord.Option(discord.Member), amount: discord.Option(int)):
# Currency handler
curr = Currency(user.id)
curr.add_balance(amount)
curr.push()
embed = discord.Embed(
color=discord.Color.green(),
description=f"Awarded **${Currency.format(amount)}** to {user.name}."
)
await ctx.respond(embed=embed)
def setup(client):
client.add_cog(AwardCog(client))

View file

@ -1,6 +1,3 @@
import json
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
@ -10,9 +7,6 @@ from lib import checks
load_dotenv('.env')
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
cash_balance_name = os.getenv("CASH_BALANCE_NAME")
class BalanceCog(commands.Cog):
def __init__(self, client):
@ -28,19 +22,15 @@ class BalanceCog(commands.Cog):
# Currency handler
ctx_currency = Currency(ctx.author.id)
cash_balance = Currency.format(ctx_currency.cash)
special_balance = Currency.format(ctx_currency.special)
balance = Currency.format(ctx_currency.balance)
embed = discord.Embed(
color=discord.Color.embed_background(),
description=f"**Cash**: {cash_balance_name}{cash_balance}\n"
f"**{special_balance_name.capitalize()}**: {special_balance}"
description=f"**Cash**: ${balance}"
)
embed.set_author(name=f"{ctx.author.name}'s wallet", icon_url=ctx.author.avatar.url)
embed.set_footer(text=f"Level up to earn {special_balance_name}!")
await ctx.respond(embed=embed)
def setup(client):
client.add_cog(BalanceCog(client))

View file

@ -18,8 +18,6 @@ load_dotenv('.env')
est = pytz.timezone('US/Eastern')
active_blackjack_games = {}
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
cash_balance_name = os.getenv("CASH_BALANCE_NAME")
def blackjack_show(ctx, bet, player_hand, dealer_hand, player_hand_value, dealer_hand_value):
@ -44,7 +42,7 @@ def blackjack_show(ctx, bet, player_hand, dealer_hand, player_hand_value, dealer
f"*Hand: {' + '.join(dealer_hand)}*"
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar.url)
embed.set_footer(text=f"Bet {cash_balance_name}{bet} • deck shuffled • Today at {current_time}",
embed.set_footer(text=f"Bet ${bet} • deck shuffled • Today at {current_time}",
icon_url="https://i.imgur.com/96jPPXO.png")
if thumbnail_url:
@ -144,8 +142,8 @@ class BlackJackCog(commands.Cog):
ctx_currency = Currency(ctx.author.id)
# check if the user has enough cash
player_cash_balance = ctx_currency.cash
if bet > player_cash_balance or bet <= 0:
player_balance = ctx_currency.balance
if bet > player_balance or bet <= 0:
await ctx.respond(embed=economy_embeds.not_enough_cash())
return
@ -250,7 +248,7 @@ class BlackJackCog(commands.Cog):
# change balance
# if status == 1 or status == 4:
if not is_won:
ctx_currency.take_cash(bet)
ctx_currency.take_balance(bet)
ctx_currency.push()
# push stats (low priority)
@ -266,11 +264,11 @@ class BlackJackCog(commands.Cog):
elif status == 6:
await ctx.send(embed=economy_embeds.out_of_time(), content=ctx.author.mention)
ctx_currency.take_cash(bet)
ctx_currency.take_balance(bet)
ctx_currency.push()
else:
ctx_currency.add_cash(payout)
ctx_currency.add_balance(payout)
ctx_currency.push()
# push stats (low priority)

View file

@ -13,9 +13,6 @@ from lib import checks
load_dotenv('.env')
active_blackjack_games = {}
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
with open("config/economy.json") as file:
json_data = json.load(file)

View file

@ -1,91 +0,0 @@
import os
import random
import discord
from discord.ext import commands
from dotenv import load_dotenv
from services.Currency import Currency
from main import economy_config
from lib import economy_embeds, checks, interaction
load_dotenv('.env')
cash_balance_name = os.getenv("CASH_BALANCE_NAME")
class GamblingCog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.slash_command(
name="duel",
description="Challenge another player to a fight.",
guild_only=True
)
@commands.check(checks.channel)
async def duel(self, ctx, *, opponent: discord.Option(discord.Member), bet: discord.Option(int)):
challenger = ctx.author
if challenger.id == opponent.id:
return await ctx.respond(content="You cannot duel yourself.")
elif opponent.bot:
return await ctx.respond(content="You cannot duel a bot.")
# Currency handler
challenger_currency = Currency(ctx.author.id)
opponent_currency = Currency(opponent.id)
# check if challenger has enough cash
challenger_cash_balance = challenger_currency.cash
if bet > challenger_cash_balance or bet <= 0:
return await ctx.respond(embed=economy_embeds.not_enough_cash())
# if opponent doesn't have sufficient money, the bet will become the opponent's cash
opponent_cash_balance = opponent_currency.cash
all_in = ""
if opponent_cash_balance <= 0:
return await ctx.respond(f"Woops, you can't do that because **{opponent.name}** has no money.")
elif bet > opponent_cash_balance:
bet = opponent_cash_balance
all_in = " | opponent's all-in"
# challenge message
view = interaction.DuelChallenge(opponent)
await ctx.respond(
content=f"**{challenger.name}** challenges {opponent.mention} to a duel ({cash_balance_name}{Currency.format(bet)}{all_in})\n"
f"Use the buttons to accept/deny (challenge expires after 60s)", view=view)
await view.wait()
if view.clickedConfirm:
winner = random.choice([challenger, opponent])
loser = opponent if winner == challenger else challenger
combat_message = random.choice(economy_config["duel"]["combat_messages"]).format(f"**{winner.name}**",
f"**{loser.name}**")
await ctx.respond(content=f"{combat_message}\n\n"
f"{winner.mention} wins **{cash_balance_name}{Currency.format(bet)}**\n"
f"{loser.mention} loses this bet.")
# payouts
if winner == challenger:
challenger_currency.add_cash(bet)
opponent_currency.take_cash(bet)
elif winner == opponent:
opponent_currency.add_cash(bet)
challenger_currency.take_cash(bet)
elif view.clickedDeny:
await ctx.edit(content=f"**{opponent.name}** canceled the duel.")
else:
await ctx.edit(content=f"Time ran out.")
challenger_currency.push()
opponent_currency.push()
def setup(client):
client.add_cog(GamblingCog(client))

View file

@ -1,5 +1,4 @@
import json
import os
import discord
from discord.ext import commands
@ -10,14 +9,11 @@ from lib import economy_embeds, checks
load_dotenv('.env')
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
cash_balance_name = os.getenv("CASH_BALANCE_NAME")
with open("config/economy.json") as file:
json_data = json.load(file)
class AwardCog(commands.Cog):
class GiveCog(commands.Cog):
def __init__(self, client):
self.client = client
@ -47,19 +43,19 @@ class AwardCog(commands.Cog):
target_currency = Currency(user.id)
try:
author_cash_balance = ctx_currency.cash
author_balance = ctx_currency.balance
if author_cash_balance < amount or author_cash_balance <= 0:
if author_balance < amount or author_balance <= 0:
return await ctx.respond(embed=economy_embeds.not_enough_cash())
target_currency.add_cash(amount)
ctx_currency.take_cash(amount)
target_currency.add_balance(amount)
ctx_currency.take_balance(amount)
ctx_currency.push()
target_currency.push()
except Exception as e:
await ctx.channel.respond("Something funky happened.. Sorry about that.", ephemeral=True)
await ctx.respond("Something funky happened.. Sorry about that.", ephemeral=True)
print(e)
return
@ -71,42 +67,6 @@ class AwardCog(commands.Cog):
await ctx.respond(embed=embed)
@commands.slash_command(
name="award",
description="Award currency - owner only command.",
guild_only=True
)
@commands.check(checks.channel)
@commands.check(checks.bot_owner)
async def award(self, ctx, *,
user: discord.Option(discord.Member),
currency: discord.Option(choices=["cash_balance", "special_balance"]),
amount: discord.Option(int)):
# Currency handler
target_currency = Currency(user.id)
try:
if currency == "cash_balance":
target_currency.add_cash(amount)
else:
target_currency.add_special(amount)
target_currency.push()
except Exception as e:
await ctx.channel.respond("Something went wrong. Check console.", ephemeral=True)
print(e)
return
embed = discord.Embed(
color=discord.Color.green(),
description=f"Awarded **${Currency.format(amount)}** to {user.name}."
)
await ctx.respond(embed=embed)
def setup(client):
client.add_cog(AwardCog(client))
client.add_cog(GiveCog(client))

View file

@ -10,10 +10,6 @@ from lib import checks
load_dotenv('.env')
active_blackjack_games = {}
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
cash_balance_name = os.getenv("CASH_BALANCE_NAME")
with open("config/economy.json") as file:
json_data = json.load(file)
@ -54,7 +50,6 @@ class InventoryCog(commands.Cog):
embed.add_field(name=f"{emote} {item.display_name.capitalize()}",
value=f"*— amount: `{quantity}`*",
inline=False)
embed.set_footer(text="for more info do /item")
await ctx.respond(embed=embed)

View file

@ -1,108 +0,0 @@
import json
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
from services.Currency import Currency
from services.Inventory import Inventory
from services.Item import Item
from services.ShopItem import ShopItem
from lib import checks
load_dotenv('.env')
active_blackjack_games = {}
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
cash_balance_name = os.getenv("CASH_BALANCE_NAME")
with open("config/economy.json") as file:
json_data = json.load(file)
class ItemCog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.slash_command(
name="item",
description="View the information about a specific item.",
guild_only=True
)
@commands.check(checks.channel)
async def item_command(self, ctx, *, item: discord.Option(choices=Item.get_all_item_names())):
# create item object from choice
item = Item.get_item_by_display_name(item)
amount = item.get_quantity(ctx.author.id)
shop_item = ShopItem(item)
price = "can't be bought" if shop_item.price <= 0 else f"${Currency.format(shop_item.price)}"
worth = "can't be sold" if shop_item.worth <= 0 else f"${Currency.format(shop_item.worth)}"
if shop_item.price_special > 0:
if price == "can't be bought":
price = f"{shop_item.price_special} {special_balance_name}"
else:
price += f" or {shop_item.price_special} {special_balance_name}"
emote = self.client.get_emoji(item.emote_id)
amount_string = f"You have this item {amount} time"
if amount > 1:
amount_string += "s"
elif amount < 1:
amount_string = f"You don't have this item"
if item.quote is None or item.quote == "":
description = amount_string
else:
description = f"> *{item.quote}*\n\n{amount_string}"
embed = discord.Embed(
color=discord.Color.embed_background(),
title=f"{emote} {item.display_name.capitalize()}",
description=description
)
embed.add_field(name="Value", value=f"`/shop` price: **{price}**\n`/sell` value: **{worth}**", inline=False)
embed.add_field(name="Description", value=item.description, inline=False)
embed.set_thumbnail(url=item.image_url)
embed.set_footer(text=f"type: {item.type}")
return await ctx.respond(embed=embed)
items = discord.SlashCommandGroup(name="items", guild_only=True)
@items.command(
name="gift",
description="Award items to someone."
)
@commands.check(checks.bot_owner)
async def gift(self, ctx, *,
user: discord.Option(discord.Member),
item: discord.Option(choices=Item.get_all_item_names()),
quantity: discord.Option(int)):
try:
item = Item.get_item_by_display_name(item)
target_inventory = Inventory(user.id)
target_inventory.add_item(item, quantity)
except Exception as e:
await ctx.channel.respond("Something went wrong. Check console.", ephemeral=True)
print(e)
return
embed = discord.Embed(
color=discord.Color.embed_background(),
description=f"Awarded **{abs(quantity)} {item.name}** to {user.name}."
)
await ctx.respond(embed=embed)
def setup(client):
client.add_cog(ItemCog(client))

View file

@ -167,7 +167,7 @@ class LeaderboardCommandView(discord.ui.View):
embed.set_thumbnail(url="https://i.imgur.com/wFsgSnr.png")
value = ""
for i, (user_id, cash_balance, special_balance, rank) in enumerate(cash_lb[:5], start=1):
for i, (user_id, balance, rank) in enumerate(cash_lb[:5], start=1):
try:
member = await self.ctx.guild.fetch_member(user_id)
name = member.name
@ -178,7 +178,7 @@ class LeaderboardCommandView(discord.ui.View):
embed.add_field(
name=f"#{rank} - {name}",
value=f"cash: **${Currency.format(cash_balance)}**\nmajikoins: `{special_balance}`",
value=f"cash: **${Currency.format(balance)}**",
inline=False
)

View file

@ -14,7 +14,6 @@ from lib import interaction, checks
logs = logging.getLogger('Racu.Core')
load_dotenv('.env')
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
class SellCommandOptions(discord.ui.Select):
@ -185,7 +184,7 @@ class SellCog(commands.Cog):
if view.clickedConfirm:
try:
currency.cash += total
currency.balance += total
currency.push()
inv.take_item(item, amount_to_sell)

View file

@ -170,8 +170,8 @@ class SlotsCog(commands.Cog):
ctx_currency = Currency(ctx.author.id)
# check if the user has enough cash
player_cash_balance = ctx_currency.cash
if bet > player_cash_balance or bet <= 0:
player_balance = ctx_currency.balance
if bet > player_balance or bet <= 0:
await ctx.respond(embed=economy_embeds.not_enough_cash())
return
@ -216,9 +216,9 @@ class SlotsCog(commands.Cog):
# user payout
if payout > 0:
ctx_currency.add_cash(payout)
ctx_currency.add_balance(payout)
else:
ctx_currency.take_cash(bet)
ctx_currency.take_balance(bet)
# item_reward = ItemHandler(ctx)
# await item_reward.rave_coin(is_won=is_won, bet=bet)

View file

@ -11,10 +11,6 @@ from lib import checks
load_dotenv('.env')
active_blackjack_games = {}
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
cash_balance_name = os.getenv("CASH_BALANCE_NAME")
with open("config/economy.json") as file:
json_data = json.load(file)

View file

@ -13,10 +13,6 @@ from lib import checks
load_dotenv('.env')
active_blackjack_games = {}
special_balance_name = os.getenv("SPECIAL_BALANCE_NAME")
cash_balance_name = os.getenv("CASH_BALANCE_NAME")
with open("config/economy.json") as file:
json_data = json.load(file)

View file

@ -14,7 +14,7 @@ class BlackJackStats:
def push(self):
query = """
INSERT INTO stats_bj (user_id, is_won, bet, payout, hand_player, hand_dealer)
INSERT INTO blackjack (user_id, is_won, bet, payout, hand_player, hand_dealer)
VALUES (%s, %s, %s, %s, %s, %s)
"""
@ -31,7 +31,7 @@ class BlackJackStats:
SUM(payout) AS total_payout,
SUM(CASE WHEN is_won = 1 THEN 1 ELSE 0 END) AS winning,
SUM(CASE WHEN is_won = 0 THEN 1 ELSE 0 END) AS losing
FROM stats_bj
FROM blackjack
WHERE user_id = %s;
"""
(amount_of_games, total_bet,

View file

@ -6,73 +6,63 @@ from db import database
class Currency:
def __init__(self, user_id):
self.user_id = user_id
(self.cash, self.special) = Currency.fetch_or_create_balance(self.user_id)
self.balance = Currency.fetch_or_create_balance(self.user_id)
def add_cash(self, amount):
self.cash += abs(amount)
def add_balance(self, amount):
self.balance += abs(amount)
def add_special(self, amount):
self.special += abs(amount)
def take_balance(self, amount):
self.balance -= abs(amount)
def take_cash(self, amount):
self.cash -= abs(amount)
if self.cash < 0:
self.cash = 0
def take_special(self, amount):
self.special -= abs(amount)
if self.special < 0:
self.special = 0
if self.balance < 0:
self.balance = 0
def push(self):
query = """
UPDATE currency
SET cash_balance = %s, special_balance = %s
SET balance = %s
WHERE user_id = %s
"""
database.execute_query(query, (round(self.cash), round(self.special), self.user_id))
database.execute_query(query, (round(self.balance), self.user_id))
@staticmethod
def fetch_or_create_balance(user_id):
query = """
SELECT cash_balance, special_balance
SELECT balance
FROM currency
WHERE user_id = %s
"""
try:
(cash_balance, special_balance) = database.select_query(query, (user_id,))[0]
balance = database.select_query_one(query, (user_id,))
except (IndexError, TypeError):
(cash_balance, special_balance) = (None, None)
balance = None
# if the user doesn't have a balance yet -> create one
# additionally if for some reason a balance becomes Null
# re-generate the user's balance as fallback.
if cash_balance is None or special_balance is None:
if balance is None:
query = """
INSERT INTO currency (user_id, cash_balance, special_balance)
VALUES (%s, 50, 3)
INSERT INTO currency (user_id, balance)
VALUES (%s, 50)
"""
database.execute_query(query, (user_id,))
return 50, 3
return 50
return cash_balance, special_balance
return balance
@staticmethod
def load_leaderboard():
query = "SELECT user_id, cash_balance, special_balance FROM currency ORDER BY cash_balance DESC"
query = "SELECT user_id, balance FROM currency ORDER BY balance DESC"
data = database.select_query(query)
leaderboard = []
rank = 1
for row in data:
row_user_id = row[0]
cash_balance = row[1]
special_balance = row[2]
leaderboard.append((row_user_id, cash_balance, special_balance, rank))
balance = row[1]
leaderboard.append((row_user_id, balance, rank))
rank += 1
return leaderboard

View file

@ -40,7 +40,7 @@ class Dailies:
database.execute_query(query, values)
cash = Currency(self.user_id)
cash.add_cash(self.amount)
cash.add_balance(self.amount)
cash.push()
def can_be_claimed(self):

View file

@ -1,75 +0,0 @@
from services.Item import Item
from db import database
class ShopItem:
"""
Unused as of v1.5
"""
def __init__(self, item: Item):
self.item = item
self.price = None
self.price_special = None
self.worth = None
self.description = None
self.fetch_or_create_shopitem()
"""
if either price, price_special or worth equal "0",
this will be interpreted as no-buy or no-sell.
"""
def set_price(self, price):
query = "UPDATE ShopItem SET price = %s WHERE item_id = %s"
database.execute_query(query, (price, self.item.id))
self.price = price
def set_price_special(self, price_special):
query = "UPDATE ShopItem SET price_special = %s WHERE item_id = %s"
database.execute_query(query, (price_special, self.item.id))
self.price_special = price_special
def set_worth(self, worth):
query = "UPDATE ShopItem SET worth = %s WHERE item_id = %s"
database.execute_query(query, (worth, self.item.id))
self.worth = worth
def set_description(self, description):
query = "UPDATE ShopItem SET description = %s WHERE item_id = %s"
database.execute_query(query, (description, self.item.id))
self.description = description
def fetch_or_create_shopitem(self):
query = """
SELECT price, price_special, worth, description
FROM ShopItem
WHERE item_id = %s
"""
try:
(price, price_special, worth, description) = database.select_query(query, (self.item.id,))[0]
except (IndexError, TypeError):
query = """
INSERT INTO ShopItem (item_id, price, price_special, worth, description)
VALUES (%s, 0, 0, 0, "placeholder_descr")
"""
database.execute_query(query, (self.item.id,))
(price, price_special, worth, description) = 0, 0, 0, "placeholder_descr"
self.price = price
self.price_special = price_special
self.worth = worth
self.description = description
@staticmethod
def get_shop_all():
query = "SELECT item_id FROM ShopItem WHERE price != 0 OR price_special != 0;"
shop_items = database.select_query(query)
shop_items = [item[0] for item in shop_items]
list = []
for item_id in shop_items:
list.append(ShopItem(Item(item_id)))
return list

View file

@ -20,7 +20,7 @@ class SlotsStats:
Insert the services from any given slots game into the database
"""
query = """
INSERT INTO stats_slots (user_id, is_won, bet, payout, spin_type, icons)
INSERT INTO slots (user_id, is_won, bet, payout, spin_type, icons)
VALUES (%s, %s, %s, %s, %s, %s)
"""
@ -42,7 +42,7 @@ class SlotsStats:
SUM(CASE WHEN spin_type = 'three_of_a_kind' AND is_won = 1 THEN 1 ELSE 0 END) AS games_won_three_of_a_kind,
SUM(CASE WHEN spin_type = 'three_diamonds' AND is_won = 1 THEN 1 ELSE 0 END) AS games_won_three_diamonds,
SUM(CASE WHEN spin_type = 'jackpot' AND is_won = 1 THEN 1 ELSE 0 END) AS games_won_jackpot
FROM stats_slots
FROM slots
WHERE user_id = %s
"""