Skip to content

Commit

Permalink
Economy Update aiosqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoz committed Aug 1, 2024
1 parent e051730 commit f86ccc9
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 182 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@
- **Steam API Integration**: Seamlessly integrate with the Steam API to fetch player profiles and enhance server management with detailed user insights.
- **Economy System**: Enhance your server's gameplay with a fully integrated economy system. Players can earn currency through various activities, trade with others, and purchase kits containing exclusive items, pals, and eggs. This system encourages player engagement and adds a new layer of strategy to your server's ecosystem.

## Upcoming Features
- **Economy**: Earn points in discord to redeem them for kits. When a kit is purchased it will send the items to the player in-game.
- **Steam Auth**: This will allow you to authenticate your steam account with discord. This will be required to redeem points for rewards in-game.

## Guides:
Please check our [wiki](https://github.com/dkoz/palworld-bot/wiki) for all guides related to the bot.
28 changes: 14 additions & 14 deletions cogs/economy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class EconomyCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
init_db()
self.bot.loop.create_task(init_db())
self.load_config()
self.work_cooldown = {}
self.daily_cooldown = {}
Expand Down Expand Up @@ -87,7 +87,7 @@ def format_time(seconds):
)
async def toppoints(self, interaction: nextcord.Interaction):
try:
top_points = get_top_points()
top_points = await get_top_points()
embed = nextcord.Embed(
title=f"Top {self.currency}", color=nextcord.Color.blurple()
)
Expand Down Expand Up @@ -120,19 +120,19 @@ async def transferpoints(
):
user_id = str(interaction.user.id)
user_name = interaction.user.display_name
user_name, user_points = get_points(user_id, user_name)
user_name, user_points = await get_points(user_id, user_name)
recipient_id = str(recipient.id)
recipient_name = recipient.display_name
recipient_name, recipient_points = get_points(recipient_id, recipient_name)
recipient_name, recipient_points = await get_points(recipient_id, recipient_name)
if user_points < points:
await interaction.response.send_message(
f"You do not have enough {self.currency} to transfer.", ephemeral=True
)
return
new_user_points = user_points - points
new_recipient_points = recipient_points + points
set_points(user_id, user_name, new_user_points)
set_points(recipient_id, recipient_name, new_recipient_points)
await set_points(user_id, user_name, new_user_points)
await set_points(recipient_id, recipient_name, new_recipient_points)
embed = nextcord.Embed(
title=f"{self.currency} Transfer",
description=f"Transferred {points} {self.currency} to {recipient_name}.",
Expand All @@ -144,7 +144,7 @@ async def transferpoints(
async def balance(self, interaction: nextcord.Interaction):
user_id = str(interaction.user.id)
user_name = interaction.user.display_name
user_name, points = get_points(user_id, user_name)
user_name, points = await get_points(user_id, user_name)
embed = nextcord.Embed(
title=f"Your {self.currency} Balance",
description=f"You have {str(points)} {self.currency} in your account.",
Expand All @@ -156,8 +156,8 @@ async def balance(self, interaction: nextcord.Interaction):
async def profile(self, interaction: nextcord.Interaction):
user_id = str(interaction.user.id)
user_name = interaction.user.display_name
user_name, points = get_points(user_id, user_name)
steam_id = get_steam_id(user_id)
user_name, points = await get_points(user_id, user_name)
steam_id = await get_steam_id(user_id)
embed = nextcord.Embed(
title=f"{user_name}'s Profile", color=nextcord.Color.blurple()
)
Expand All @@ -173,7 +173,7 @@ async def profile(self, interaction: nextcord.Interaction):
name="topinvites", description="Display the top invite leaderboard."
)
async def inviteleaderboard(self, interaction: nextcord.Interaction):
top_invites = get_top_invites()
top_invites = await get_top_invites()
embed = nextcord.Embed(title="Top Invites", color=nextcord.Color.blurple())
if top_invites:
for i, (user_name, invite_count) in enumerate(top_invites, start=1):
Expand Down Expand Up @@ -242,11 +242,11 @@ async def work(self, interaction: nextcord.Interaction):
)
return
user_name = interaction.user.display_name
user_name, points = get_points(user_id, user_name)
user_name, points = await get_points(user_id, user_name)
base_points = random.randint(self.work_min, self.work_max)
earned_points = await self.apply_bonus(base_points, interaction.user)
new_points = points + earned_points
set_points(user_id, user_name, new_points)
await set_points(user_id, user_name, new_points)
desc_text = random.choice(self.work_descriptions).format(
earned_points=earned_points, currency=self.currency
)
Expand Down Expand Up @@ -281,11 +281,11 @@ async def daily(self, interaction: nextcord.Interaction):
return

user_name = interaction.user.display_name
user_name, points = get_points(user_id, user_name)
user_name, points = await get_points(user_id, user_name)
base_points = self.daily_reward
earned_points = await self.apply_bonus(base_points, interaction.user)
new_points = points + earned_points
set_points(user_id, user_name, new_points)
await set_points(user_id, user_name, new_points)

embed = nextcord.Embed(
title="Daily Reward",
Expand Down
4 changes: 2 additions & 2 deletions cogs/economy/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ async def on_member_join(self, member):
print(
f"Member {member.display_name} joined using invite from {invite.inviter.display_name}."
)
add_points(
await add_points(
str(invite.inviter.id),
invite.inviter.display_name,
self.invite_payment,
)
add_invite(str(invite.inviter.id), invite.inviter.display_name)
await add_invite(str(invite.inviter.id), invite.inviter.display_name)
break
self.invites[guild.id] = new_invites

Expand Down
10 changes: 5 additions & 5 deletions cogs/economy/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def addpoints(
):
user_id = str(user.id)
user_name = user.display_name
add_points(user_id, user_name, points)
await add_points(user_id, user_name, points)
emebd = nextcord.Embed(
title=f"Added {self.currency}",
description=f"Added {points} {self.currency} to {user_name}.",
Expand All @@ -54,7 +54,7 @@ async def checkpoints(
):
user_id = str(user.id)
user_name = user.display_name
user_name, points = get_points(user_id, user_name)
user_name, points = await get_points(user_id, user_name)

embed = nextcord.Embed(
title=f"Check {self.currency}",
Expand All @@ -75,7 +75,7 @@ async def setpoints(
):
user_id = str(user.id)
user_name = user.display_name
set_points(user_id, user_name, points)
await set_points(user_id, user_name, points)
embed = nextcord.Embed(
title=f"Set {self.currency}",
description=f"Set {user_name}'s {self.currency} to {points}.",
Expand Down Expand Up @@ -113,15 +113,15 @@ async def removepoints(
):
user_id = str(user.id)
user_name = user.display_name
user_name, current_points = get_points(user_id, user_name)
user_name, current_points = await get_points(user_id, user_name)
if current_points < points:
await interaction.response.send_message(
f"{user_name} does not have enough {self.currency} to remove.",
ephemeral=True,
)
return
new_points = current_points - points
set_points(user_id, user_name, new_points)
await set_points(user_id, user_name, new_points)
embed = nextcord.Embed(
title=f"Removed {self.currency}",
description=f"Removed {points} {self.currency} from {user_name}.",
Expand Down
6 changes: 3 additions & 3 deletions cogs/economy/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ async def redeem(
user_id = str(interaction.user.id)
user_name = interaction.user.display_name

data = get_points(user_id, user_name)
data = await get_points(user_id, user_name)
if not data:
await interaction.followup.send(
"There was an error retrieving your data.", ephemeral=True
)
return

user_name, points = data
steam_id = get_steam_id(user_id)
steam_id = await get_steam_id(user_id)

if steam_id is None:
await interaction.followup.send("No Steam ID linked.", ephemeral=True)
Expand All @@ -145,7 +145,7 @@ async def redeem(
return

new_points = points - item["price"]
set_points(user_id, user_name, new_points)
await set_points(user_id, user_name, new_points)

for command_template in item["commands"]:
command = command_template.format(steamid=steam_id)
Expand Down
6 changes: 3 additions & 3 deletions cogs/economy/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ async def claim_reward(self, steam_id):
@nextcord.slash_command(name="claimreward", description="Claim your vote reward.")
async def votereward(self, interaction: nextcord.Interaction):
user_id = str(interaction.user.id)
steam_id = get_steam_id(user_id)
steam_id = await get_steam_id(user_id)
if steam_id is None:
await interaction.response.send_message("Your Steam ID is not linked.", ephemeral=True)
return

vote_status = await self.vote_status(steam_id)
if vote_status == "1":
await self.claim_reward(steam_id)
add_points(user_id, interaction.user.display_name, self.vote_reward)
await add_points(user_id, interaction.user.display_name, self.vote_reward)
await interaction.response.send_message(f"Thank you for voting! Your reward of {self.vote_reward} {self.currency} has been claimed.", ephemeral=True)
elif vote_status == "2":
await interaction.response.send_message("You have already claimed your reward.", ephemeral=True)
Expand All @@ -65,7 +65,7 @@ async def votereward(self, interaction: nextcord.Interaction):
@nextcord.slash_command(name="claimkit", description="Claim a kit as a vote reward.")
async def claim_kit(self, interaction: nextcord.Interaction, kit_name: str = nextcord.SlashOption(description="Select a kit", autocomplete=True), server: str = nextcord.SlashOption(description="Select a server", autocomplete=True)):
user_id = str(interaction.user.id)
steam_id = get_steam_id(user_id)
steam_id = await get_steam_id(user_id)
if steam_id is None:
await interaction.response.send_message("Your Steam ID is not linked.", ephemeral=True)
return
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ nextcord==2.6.0
python-dotenv==1.0.1
gamercon-async==1.0.6
aiohttp==3.9.5
aiosqlite==0.20.0
pytz==2024.1
steam==1.4.4
Loading

0 comments on commit f86ccc9

Please sign in to comment.