mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 18:03:12 +00:00
Add streak icon and rework JSON caching
This commit is contained in:
parent
0f8d0fc115
commit
e5d095138a
24 changed files with 96 additions and 201 deletions
|
@ -1,9 +1,11 @@
|
|||
{
|
||||
"emotes_guild_id": 1038051105642401812,
|
||||
"rc_guild_id": 719227135151046699,
|
||||
"daily_reward": 500,
|
||||
"exchange_rate": 75000,
|
||||
"bet_limit": 1000000,
|
||||
"icons": {
|
||||
"racu_exclam": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_exclam.png",
|
||||
"racu_question": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_question.png",
|
||||
"racu_streak": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_streak.png"
|
||||
},
|
||||
"blackjack": {
|
||||
"emotes": {
|
||||
"hit": "<:hit:1119262723285467156>",
|
|
@ -1,44 +0,0 @@
|
|||
import json
|
||||
import logging
|
||||
|
||||
logs = logging.getLogger('Racu.Core')
|
||||
|
||||
|
||||
def load_strings(path="config/strings.en-US.json"):
|
||||
with open(path, 'r') as file:
|
||||
data = json.load(file)
|
||||
|
||||
logs.debug(f"{path} was loaded.")
|
||||
return data
|
||||
|
||||
|
||||
def load_levels(path="config/levels.en-US.json"):
|
||||
with open(path, 'r') as file:
|
||||
data = json.load(file)
|
||||
|
||||
logs.debug(f"{path} was loaded.")
|
||||
return data
|
||||
|
||||
|
||||
def load_economy_config(path="config/economy.json"):
|
||||
with open(path, 'r') as file:
|
||||
data = json.load(file)
|
||||
|
||||
logs.debug(f"{path} was loaded.")
|
||||
return data
|
||||
|
||||
|
||||
def load_reactions(path="config/reactions.json"):
|
||||
with open(path, 'r') as file:
|
||||
data = json.load(file)
|
||||
|
||||
logs.debug(f"{path} was loaded.")
|
||||
return data
|
||||
|
||||
|
||||
def load_birthday(path="config/birthday.json"):
|
||||
with open(path, 'r') as file:
|
||||
data = json.load(file)
|
||||
|
||||
logs.debug(f"{path} was loaded.")
|
||||
return data
|
18
config/parser.py
Normal file
18
config/parser.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import json
|
||||
import logging
|
||||
|
||||
logs = logging.getLogger('Racu.Core')
|
||||
|
||||
|
||||
class JsonCache:
|
||||
_cache = {}
|
||||
|
||||
@staticmethod
|
||||
def read_json(path):
|
||||
"""Read and cache the JSON data if not already cached."""
|
||||
if path not in JsonCache._cache:
|
||||
with open(f"config/JSON/{path}.json", 'r') as file:
|
||||
JsonCache._cache[path] = json.load(file)
|
||||
logs.info(f"{path}.json was loaded and cached.")
|
||||
|
||||
return JsonCache._cache[path]
|
|
@ -1,12 +1,13 @@
|
|||
import random
|
||||
|
||||
from config.parser import JsonCache
|
||||
from lib import checks
|
||||
|
||||
|
||||
class ReactionHandler:
|
||||
def __init__(self, reactions):
|
||||
self.eightball = reactions["eightball"]
|
||||
self.full_content_reactions = reactions["full_content_reactions"]
|
||||
def __init__(self):
|
||||
self.reactions = JsonCache.read_json("reactions")
|
||||
self.eightball = self.reactions["eightball"]
|
||||
self.full_content_reactions = self.reactions["full_content_reactions"]
|
||||
|
||||
async def handle_message(self, message):
|
||||
content = message.content.lower()
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import logging
|
||||
import random
|
||||
import time
|
||||
|
||||
import discord
|
||||
|
||||
from config import json_loader
|
||||
from services.Currency import Currency
|
||||
from services.Xp import Xp
|
||||
from services.GuildConfig import GuildConfig
|
||||
from config.parser import JsonCache
|
||||
from lib import formatter
|
||||
from services.GuildConfig import GuildConfig
|
||||
from services.Xp import Xp
|
||||
|
||||
strings = JsonCache.read_json("strings")
|
||||
level_messages = JsonCache.read_json("levels")
|
||||
logs = logging.getLogger('Racu.Core')
|
||||
strings = json_loader.load_strings()
|
||||
level_messages = json_loader.load_levels()
|
||||
|
||||
|
||||
class XPHandler:
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
import discord
|
||||
import pytz
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv('.env')
|
||||
est = pytz.timezone('US/Eastern')
|
||||
|
||||
with open("config/economy.json") as file:
|
||||
json_data = json.load(file)
|
||||
|
||||
|
||||
def give_bot_error():
|
||||
embed = discord.Embed(
|
||||
color=discord.Color.red(),
|
||||
description=f"You can't give money to a bot, silly."
|
||||
)
|
||||
return embed
|
||||
|
||||
|
||||
def already_playing(game):
|
||||
embed = discord.Embed(
|
||||
color=discord.Color.red(),
|
||||
description=f"You're already playing {game}. Please finish this game first."
|
||||
)
|
||||
return embed
|
||||
|
||||
|
||||
def not_enough_cash():
|
||||
embed = discord.Embed(
|
||||
color=discord.Color.red(),
|
||||
description="Oops! Your current cash balance isn't sufficient to do that."
|
||||
)
|
||||
return embed
|
|
@ -1,11 +1,13 @@
|
|||
import random
|
||||
|
||||
from main import economy_config
|
||||
from config.parser import JsonCache
|
||||
|
||||
resources = JsonCache.read_json("resources")
|
||||
|
||||
|
||||
def blackjack_get_new_deck():
|
||||
suits = economy_config["blackjack"]["deck_suits"]
|
||||
ranks = economy_config["blackjack"]["deck_ranks"]
|
||||
suits = resources["blackjack"]["deck_suits"]
|
||||
ranks = resources["blackjack"]["deck_ranks"]
|
||||
deck = []
|
||||
for suit in suits:
|
||||
for rank in ranks:
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import discord
|
||||
|
||||
from config.parser import JsonCache
|
||||
from lib import formatter
|
||||
|
||||
question_icon = "https://i.imgur.com/8xccUws.png"
|
||||
exclam_icon = "https://i.imgur.com/vitwMUu.png"
|
||||
resources = JsonCache.read_json("resources")
|
||||
|
||||
question_icon = resources["icons"]["racu_question"]
|
||||
exclam_icon = resources["icons"]["racu_exclam"]
|
||||
|
||||
|
||||
def clean_error_embed(ctx):
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import discord
|
||||
|
||||
from config.parser import JsonCache
|
||||
from lib import formatter
|
||||
|
||||
question_icon = "https://i.imgur.com/8xccUws.png"
|
||||
exclam_icon = "https://i.imgur.com/vitwMUu.png"
|
||||
resources = JsonCache.read_json("resources")
|
||||
|
||||
question_icon = resources["icons"]["racu_question"]
|
||||
exclam_icon = resources["icons"]["racu_exclam"]
|
||||
|
||||
|
||||
class Greet:
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
import discord
|
||||
|
||||
from config.parser import JsonCache
|
||||
from lib import formatter
|
||||
|
||||
question_icon = "https://i.imgur.com/8xccUws.png"
|
||||
exclam_icon = "https://i.imgur.com/vitwMUu.png"
|
||||
resources = JsonCache.read_json("resources")
|
||||
|
||||
question_icon = resources["icons"]["racu_question"]
|
||||
exclam_icon = resources["icons"]["racu_exclam"]
|
||||
streak_icon = resources["icons"]["racu_streak"]
|
||||
|
||||
|
||||
def clean_info_embed(ctx):
|
||||
|
@ -22,7 +27,7 @@ class EconInfo:
|
|||
|
||||
if streak > 1:
|
||||
embed.set_footer(text=f"You're on a streak of {streak} days",
|
||||
icon_url=exclam_icon)
|
||||
icon_url=streak_icon)
|
||||
|
||||
return embed
|
||||
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
import discord
|
||||
|
||||
footer_icon = "https://i.imgur.com/8xccUws.png"
|
||||
|
||||
|
||||
def get_prefix(ctx):
|
||||
"""
|
||||
Attempt to get the prefix, if the command was used as a SlashCommand, return "/"
|
||||
"""
|
||||
try:
|
||||
prefix = ctx.clean_prefix
|
||||
except (discord.ApplicationCommandInvokeError, AttributeError):
|
||||
prefix = "/"
|
||||
|
||||
return prefix
|
||||
|
||||
|
||||
def MissingBet(ctx):
|
||||
"""
|
||||
See MissingRequiredArgument
|
||||
"""
|
||||
embed = discord.Embed(
|
||||
color=discord.Color.red(),
|
||||
description=f"**{ctx.author.name}** please enter a bet.",
|
||||
)
|
||||
embed.set_footer(text=f"For more info do '{get_prefix(ctx)}help {ctx.command}'",
|
||||
icon_url=footer_icon)
|
||||
return embed
|
||||
|
||||
|
||||
def BadBetArgument(ctx):
|
||||
"""
|
||||
See BadArgument
|
||||
"""
|
||||
embed = discord.Embed(
|
||||
color=discord.Color.red(),
|
||||
description=f"**{ctx.author.name}** the bet you entered is invalid.",
|
||||
)
|
||||
embed.set_footer(text=f"For more info do '{get_prefix(ctx)}help {ctx.command}'",
|
||||
icon_url=footer_icon)
|
||||
return embed
|
||||
|
||||
|
||||
def InsufficientBalance(ctx):
|
||||
"""
|
||||
Error message for when the entered value exceeds the user's balance.
|
||||
"""
|
||||
embed = discord.Embed(
|
||||
color=discord.Color.red(),
|
||||
description=f"**{ctx.author.name}** you don't have enough cash.",
|
||||
)
|
||||
embed.set_footer(text=f"Do '{get_prefix(ctx)}balance' to see how much you can spend.",
|
||||
icon_url=footer_icon)
|
||||
return embed
|
16
main.py
16
main.py
|
@ -1,17 +1,15 @@
|
|||
import os
|
||||
|
||||
import discord
|
||||
from discord.ext import bridge
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from lib.embeds.greet import Greet
|
||||
from config import json_loader
|
||||
from handlers import LoggingHandler, ErrorHandler
|
||||
from handlers.ReactionHandler import ReactionHandler
|
||||
from handlers.XPHandler import XPHandler
|
||||
from handlers import LoggingHandler, ErrorHandler
|
||||
from lib.embeds.greet import Greet
|
||||
from services.Client import RacuBot
|
||||
from services.GuildConfig import GuildConfig
|
||||
from services.Help import RacuHelp
|
||||
from services.Client import RacuBot
|
||||
|
||||
load_dotenv('.env')
|
||||
instance = os.getenv("INSTANCE")
|
||||
|
@ -49,7 +47,7 @@ async def on_message(message):
|
|||
xp_handler = XPHandler()
|
||||
await xp_handler.process_xp(message)
|
||||
|
||||
reaction_handler = ReactionHandler(reactions)
|
||||
reaction_handler = ReactionHandler()
|
||||
await reaction_handler.handle_message(message)
|
||||
|
||||
except Exception as error:
|
||||
|
@ -117,12 +115,6 @@ async def on_error(event: str, *args, **kwargs) -> None:
|
|||
await ErrorHandler.on_error(event, *args, **kwargs)
|
||||
|
||||
|
||||
# load all json
|
||||
strings = json_loader.load_strings()
|
||||
economy_config = json_loader.load_economy_config()
|
||||
reactions = json_loader.load_reactions()
|
||||
|
||||
|
||||
def load_modules():
|
||||
|
||||
module_list = [d for d in os.listdir("modules") if os.path.isdir(os.path.join("modules", d))]
|
||||
|
|
|
@ -5,7 +5,7 @@ import random
|
|||
import discord
|
||||
from discord.ext import commands, tasks, bridge
|
||||
|
||||
from config import json_loader
|
||||
from config.parser import JsonCache
|
||||
from lib import time, checks
|
||||
from lib.embeds.error import BdayErrors
|
||||
from modules.birthdays import upcoming, birthday
|
||||
|
@ -13,7 +13,7 @@ from services.Birthday import Birthday
|
|||
from services.GuildConfig import GuildConfig
|
||||
|
||||
logs = logging.getLogger('Racu.Core')
|
||||
data = json_loader.load_birthday()
|
||||
data = JsonCache.read_json("birthday")
|
||||
month_mapping = data["month_mapping"]
|
||||
messages = data["birthday_messages"]
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import logging
|
||||
|
||||
import discord
|
||||
from discord.ext import commands, bridge
|
||||
from discord.commands import SlashCommandGroup
|
||||
from services.GuildConfig import GuildConfig
|
||||
from discord.ext import commands, bridge
|
||||
|
||||
from config.parser import JsonCache
|
||||
from lib import formatter, embeds_old
|
||||
from modules.config import config, prefix
|
||||
from lib.embeds.error import MiscErrors
|
||||
import main
|
||||
|
||||
from main import strings
|
||||
from modules.config import config, prefix
|
||||
from services.GuildConfig import GuildConfig
|
||||
|
||||
strings = JsonCache.read_json("strings")
|
||||
logs = logging.getLogger('Racu.Core')
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import discord
|
||||
|
||||
from config.parser import JsonCache
|
||||
from services.GuildConfig import GuildConfig
|
||||
from main import strings
|
||||
|
||||
strings = JsonCache.read_json("strings")
|
||||
|
||||
|
||||
async def cmd(self, ctx):
|
||||
|
|
|
@ -9,10 +9,11 @@ from handlers.ItemHandler import ItemHandler
|
|||
from lib import economy_functions, interaction
|
||||
from lib.embeds.error import EconErrors
|
||||
from lib.embeds.error import GenericErrors
|
||||
from main import economy_config
|
||||
from config.parser import JsonCache
|
||||
from services.BlackJackStats import BlackJackStats
|
||||
from services.Currency import Currency
|
||||
|
||||
resources = JsonCache.read_json("resources")
|
||||
logs = logging.getLogger('Racu.Core')
|
||||
load_dotenv('.env')
|
||||
est = pytz.timezone('US/Eastern')
|
||||
|
@ -46,12 +47,6 @@ async def cmd(ctx, bet: int):
|
|||
elif bet <= 0:
|
||||
return await ctx.respond(embed=EconErrors.bad_bet_argument(ctx))
|
||||
|
||||
# check if the bet exceeds the bet limit
|
||||
# bet_limit = int(economy_config["bet_limit"])
|
||||
# if abs(bet) > bet_limit:
|
||||
# message = strings["bet_limit"].format(ctx.author.name, Currency.format_human(bet_limit))
|
||||
# return await ctx.respond(content=message)
|
||||
|
||||
active_blackjack_games[ctx.author.id] = True
|
||||
|
||||
try:
|
||||
|
@ -59,7 +54,7 @@ async def cmd(ctx, bet: int):
|
|||
player_hand = []
|
||||
dealer_hand = []
|
||||
deck = economy_functions.blackjack_get_new_deck()
|
||||
multiplier = float(economy_config["blackjack"]["reward_multiplier"])
|
||||
multiplier = float(resources["blackjack"]["reward_multiplier"])
|
||||
|
||||
# deal initial cards (player draws two & dealer one)
|
||||
player_hand.append(economy_functions.blackjack_deal_card(deck))
|
||||
|
|
|
@ -8,10 +8,11 @@ import pytz
|
|||
|
||||
from handlers.ItemHandler import ItemHandler
|
||||
from lib.embeds.error import EconErrors
|
||||
from main import economy_config
|
||||
from config.parser import JsonCache
|
||||
from services.Currency import Currency
|
||||
from services.SlotsStats import SlotsStats
|
||||
|
||||
resources = JsonCache.read_json("resources")
|
||||
est = pytz.timezone('US/Eastern')
|
||||
|
||||
|
||||
|
@ -27,7 +28,7 @@ async def cmd(self, ctx, bet):
|
|||
return await ctx.respond(embed=EconErrors.bad_bet_argument(ctx))
|
||||
|
||||
# # check if the bet exceeds the bet limit
|
||||
# bet_limit = int(economy_config["bet_limit"])
|
||||
# bet_limit = int(resources["bet_limit"])
|
||||
# if abs(bet) > bet_limit:
|
||||
# message = strings["bet_limit"].format(ctx.author.name, Currency.format_human(bet_limit))
|
||||
# return await ctx.respond(content=message)
|
||||
|
@ -88,7 +89,7 @@ async def cmd(self, ctx, bet):
|
|||
|
||||
|
||||
def get_emotes(client):
|
||||
decoration = economy_config["slots"]["emotes"]
|
||||
decoration = resources["slots"]["emotes"]
|
||||
emojis = {name: client.get_emoji(emoji_id) for name, emoji_id in decoration.items()}
|
||||
return emojis
|
||||
|
||||
|
@ -96,7 +97,7 @@ def get_emotes(client):
|
|||
def calculate_slots_results(bet, results):
|
||||
type = None
|
||||
multiplier = None
|
||||
rewards = economy_config["slots"]["reward_multipliers"]
|
||||
rewards = resources["slots"]["reward_multipliers"]
|
||||
|
||||
# count occurrences of each item in the list
|
||||
counts = Counter(results)
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
from main import strings, economy_config
|
||||
from config.parser import JsonCache
|
||||
from services.BlackJackStats import BlackJackStats
|
||||
from services.Currency import Currency
|
||||
from services.SlotsStats import SlotsStats
|
||||
|
||||
strings = JsonCache.read_json("strings")
|
||||
resources = JsonCache.read_json("resources")
|
||||
|
||||
async def cmd(self, ctx, game):
|
||||
output = ""
|
||||
|
@ -32,10 +34,10 @@ async def cmd(self, ctx, game):
|
|||
output = strings["stats_slots"].format(stats["amount_of_games"], total_bet, total_payout)
|
||||
output += "\n\n"
|
||||
|
||||
pair_emote = self.client.get_emoji(economy_config["slots"]["emotes"]["slots_0_id"])
|
||||
three_emote = self.client.get_emoji(economy_config["slots"]["emotes"]["slots_4_id"])
|
||||
diamonds_emote = self.client.get_emoji(economy_config["slots"]["emotes"]["slots_5_id"])
|
||||
seven_emote = self.client.get_emoji(economy_config["slots"]["emotes"]["slots_6_id"])
|
||||
pair_emote = self.client.get_emoji(resources["slots"]["emotes"]["slots_0_id"])
|
||||
three_emote = self.client.get_emoji(resources["slots"]["emotes"]["slots_4_id"])
|
||||
diamonds_emote = self.client.get_emoji(resources["slots"]["emotes"]["slots_5_id"])
|
||||
seven_emote = self.client.get_emoji(resources["slots"]["emotes"]["slots_6_id"])
|
||||
|
||||
output += f"{pair_emote} | **{stats['games_won_pair']}** pairs.\n"
|
||||
output += f"{three_emote} | **{stats['games_won_three_of_a_kind']}** three-of-a-kinds.\n"
|
||||
|
|
|
@ -3,8 +3,9 @@ import logging
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
from main import strings
|
||||
from config.parser import JsonCache
|
||||
|
||||
strings = JsonCache.read_json("strings")
|
||||
logs = logging.getLogger('Racu.Core')
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytz
|
||||
|
||||
from services.Currency import Currency
|
||||
from db import database
|
||||
from config.parser import JsonCache
|
||||
from services.Currency import Currency
|
||||
|
||||
with open("config/economy.json") as file:
|
||||
json_data = json.load(file)
|
||||
resources = JsonCache.read_json("resources")
|
||||
|
||||
|
||||
class Dailies:
|
||||
|
@ -30,7 +29,7 @@ class Dailies:
|
|||
|
||||
def refresh(self):
|
||||
if self.amount == 0:
|
||||
self.amount = json_data["daily_reward"]
|
||||
self.amount = resources["daily_reward"]
|
||||
|
||||
query = """
|
||||
INSERT INTO dailies (user_id, amount, claimed_at, streak)
|
||||
|
|
Loading…
Reference in a new issue