Skip to content

Commit

Permalink
Misc Economy Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoz committed Aug 13, 2024
1 parent 7f82fd2 commit e87ab00
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 4 deletions.
7 changes: 5 additions & 2 deletions cogs/economy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from utils.translations import t
import random
from datetime import datetime, timedelta
import json

class EconomyCog(commands.Cog):
def __init__(self, bot):
Expand All @@ -31,11 +32,13 @@ async def load_config(self):
work_reward_max = await get_economy_setting("work_reward_max") or "10"
self.work_min = int(work_reward_min)
self.work_max = int(work_reward_max)
self.work_descriptions = await get_economy_setting("work_description") or ["You worked and earned {earned_points} {currency}."]
work_descriptions_str = await get_economy_setting("work_description") or '["You worked and earned {earned_points} {currency}."]'
self.work_descriptions = json.loads(work_descriptions_str)
self.work_timer = int(await get_economy_setting("work_timer") or 60)
self.daily_reward = int(await get_economy_setting("daily_reward") or 100)
self.daily_timer = int(await get_economy_setting("daily_timer") or 86400)
self.economy_config["role_bonuses"] = await get_economy_setting("role_bonuses") or {}
role_bonuses_str = await get_economy_setting("role_bonuses") or '{"Server Booster": 10, "Supporter": 5}'
self.economy_config["role_bonuses"] = json.loads(role_bonuses_str)

# Need to reload the settings because of memory caching
@tasks.loop(minutes=1)
Expand Down
16 changes: 15 additions & 1 deletion cogs/economy/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
update_discord_username,
get_economy_setting,
)
from utils.modals import EconomySettingsModal, TimerSettingsModal
from utils.modals import (
EconomySettingsModal,
TimerSettingsModal,
EtcEconomySettingsModal
)
from utils.translations import t

class EconomyManageCog(commands.Cog):
Expand Down Expand Up @@ -176,5 +180,15 @@ async def timer_settings(self, interaction: nextcord.Interaction):
except Exception as e:
await interaction.response.send_message(f"Unexpected error: {e}", ephemeral=True)

@economyset.subcommand(
name="misc", description=t("EconomyManageCog", "economyset.etc.description")
)
async def etc_settings(self, interaction: nextcord.Interaction):
try:
modal = EtcEconomySettingsModal()
await interaction.response.send_modal(modal)
except Exception as e:
await interaction.response.send_message(f"Unexpected error: {e}", ephemeral=True)

def setup(bot):
bot.add_cog(EconomyManageCog(bot))
28 changes: 28 additions & 0 deletions i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@
"success": "Wirtschaftseinstellungen erfolgreich aktualisiert.",
"error": "Unerwarteter Fehler: {error}"
},
"etceconomysettings": {
"title": "Wirtschaftseinstellungen",
"work_description": {
"label": "Arbeitsbeschreibung",
"placeholder": "['Du hast gearbeitet und {earned_points} {currency} verdient!']"
},
"role_bonuses": {
"label": "Rollen Namen",
"placeholder": "{'Server Booster': 10, 'Supporter': 5}"
},
"vote_slug": {
"label": "Vote-Slug",
"placeholder": "servername-123456"
},
"vote_apikey": {
"label": "Vote-API-Schlüssel",
"placeholder": "1234567890"
},
"vote_reward": {
"label": "Belohnung für Abstimmung",
"placeholder": "100"
},
"success": "Wirtschaftseinstellungen erfolgreich aktualisiert.",
"error": "Unerwarteter Fehler: {error}"
},
"timersettings": {
"title": "Timer-Einstellungen",
"work_timer": {
Expand Down Expand Up @@ -420,6 +445,9 @@
},
"timers": {
"description": "Bearbeite die Wirtschaftstimer"
},
"etc": {
"description": "Zusätzliche Wirtschaftseinstellungen bearbeiten"
}
}
},
Expand Down
28 changes: 28 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@
"success": "Economy settings updated successfully.",
"error": "Unexpected error: {error}"
},
"etceconomysettings": {
"title": "Economy Settings",
"work_description": {
"label": "Work Description",
"placeholder": "['You worked and earned {earned_points} {currency}!']"
},
"role_bonuses": {
"label": "Role Names",
"placeholder": "{'Server Booster': 10, 'Supporter': 5}"
},
"vote_slug": {
"label": "Vote Slug",
"placeholder": "servername-123456"
},
"vote_apikey": {
"label": "Vote API Key",
"placeholder": "1234567890"
},
"vote_reward": {
"label": "Vote Reward",
"placeholder": "100"
},
"success": "Economy settings updated successfully.",
"error": "Unexpected error: {error}"
},
"timersettings": {
"title": "Timer Settings",
"work_timer": {
Expand Down Expand Up @@ -420,6 +445,9 @@
},
"timers": {
"description": "Edit the economy timers"
},
"etc": {
"description": "Edit additional economy settings"
}
}
},
Expand Down
28 changes: 28 additions & 0 deletions i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@
"success": "Configuración de la economía actualizada exitosamente.",
"error": "Error inesperado: {error}"
},
"etceconomysettings": {
"title": "Configuraciones de Economía",
"work_description": {
"label": "Descripción del Trabajo",
"placeholder": "['Has trabajado y ganado {earned_points} {currency}!']"
},
"role_bonuses": {
"label": "Nombres de Roles",
"placeholder": "{'Server Booster': 10, 'Supporter': 5}"
},
"vote_slug": {
"label": "Identificador de Voto",
"placeholder": "servername-123456"
},
"vote_apikey": {
"label": "Clave API de Voto",
"placeholder": "1234567890"
},
"vote_reward": {
"label": "Recompensa por Votar",
"placeholder": "100"
},
"success": "Configuraciones de economía actualizadas con éxito.",
"error": "Error inesperado: {error}"
},
"timersettings": {
"title": "Configuración de Temporizadores",
"work_timer": {
Expand Down Expand Up @@ -420,6 +445,9 @@
},
"timers": {
"description": "Editar los temporizadores de la economía"
},
"etc": {
"description": "Editar configuraciones adicionales de economía"
}
}
},
Expand Down
7 changes: 6 additions & 1 deletion utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ async def init_db():
"work_reward_max": "50",
"work_timer": "360",
"daily_reward": "200",
"daily_timer": "86400"
"daily_timer": "86400",
"work_description": '["Your Pals butchered the invaders and earned {earned_points} {currency}!", "Anubis stumbled upon {earned_points} {currency} in the hot tub!"]',
"role_bonuses": '{"Server Booster": 10, "Supporter": 5}',
"vote_slug": "",
"vote_apikey": "",
"vote_reward": "100"
}
for key, value in default_settings.items():
await db.execute('''
Expand Down
53 changes: 53 additions & 0 deletions utils/modals.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,56 @@ async def callback(self, interaction: Interaction):
t("Modals", "timersettings.error").format(error=e),
ephemeral=True
)

class EtcEconomySettingsModal(ui.Modal):
def __init__(self):
super().__init__(title=t("Modals", "etceconomysettings.title"))

self.work_description = ui.TextInput(
label=t("Modals", "etceconomysettings.work_description.label"),
placeholder=t("Modals", "etceconomysettings.work_description.placeholder"),
style=nextcord.TextInputStyle.paragraph
)
self.role_bonuses = ui.TextInput(
label=t("Modals", "etceconomysettings.role_bonuses.label"),
placeholder=t("Modals", "etceconomysettings.role_bonuses.placeholder"),
style=nextcord.TextInputStyle.paragraph
)
self.vote_slug = ui.TextInput(
label=t("Modals", "etceconomysettings.vote_slug.label"),
placeholder=t("Modals", "etceconomysettings.vote_slug.placeholder"),
required=False
)
self.vote_apikey = ui.TextInput(
label=t("Modals", "etceconomysettings.vote_apikey.label"),
placeholder=t("Modals", "etceconomysettings.vote_apikey.placeholder"),
required=False
)
self.vote_reward = ui.TextInput(
label=t("Modals", "etceconomysettings.vote_reward.label"),
placeholder=t("Modals", "etceconomysettings.vote_reward.placeholder"),
required=False
)

self.add_item(self.work_description)
self.add_item(self.role_bonuses)
self.add_item(self.vote_slug)
self.add_item(self.vote_apikey)
self.add_item(self.vote_reward)

async def callback(self, interaction: Interaction):
try:
await update_economy_setting("work_description", self.work_description.value)
await update_economy_setting("role_bonuses", self.role_bonuses.value)
await update_economy_setting("vote_slug", self.vote_slug.value)
await update_economy_setting("vote_apikey", self.vote_apikey.value)
await update_economy_setting("vote_reward", self.vote_reward.value)
await interaction.response.send_message(
t("Modals", "etceconomysettings.success"),
ephemeral=True
)
except Exception as e:
await interaction.response.send_message(
t("Modals", "etceconomysettings.error").format(error=e),
ephemeral=True
)

0 comments on commit e87ab00

Please sign in to comment.