Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit e20c7fb

Browse files
authored
Merge pull request #246 from PyBotDevs/move-isocoin-system-commands-to-cog
Move all IsoCoin commands from main file to a cog
2 parents 2e7ae50 + 0e1ba15 commit e20c7fb

2 files changed

Lines changed: 60 additions & 30 deletions

File tree

cogs/isocoin.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""The isobot cog file for the IsoCoin system."""
2+
3+
# Imports
4+
import random
5+
import json
6+
import discord
7+
from discord import ApplicationContext, SlashCommandGroup
8+
from discord.ext import commands
9+
10+
# Variables
11+
with open("database/isotokens.json", 'r', encoding="utf-8") as f: isocoins = json.load(f)
12+
13+
def save():
14+
with open("database/isotokens.json", 'w+', encoding="utf-8") as f: json.dump(isocoins, f)
15+
16+
# Functions
17+
def create_isocoin_key(user_id: int) -> int:
18+
"""Creates a new isocoin key and value for the specified user.\n\nReturns `0` if successful, returns `1` if user is already cached."""
19+
if str(user_id) not in isocoins:
20+
isocoins[str(user_id)] = 0
21+
return 0
22+
else: return 1
23+
24+
# Commands
25+
class IsoCoin(commands.Cog):
26+
def __init__(self, bot):
27+
self.bot = bot
28+
29+
isocoin_system = SlashCommandGroup("isocoin", "Commands related to the IsoCoin rewards system.")
30+
31+
@isocoin_system.command(
32+
name="balance",
33+
description="See your IsoCoin balances"
34+
)
35+
async def isocoin_balance(self, ctx: ApplicationContext):
36+
localembed = discord.Embed(description=f"You currently have **{isocoins[str(ctx.author.id)]}** IsoCoins.")
37+
await ctx.respond(embed=localembed)
38+
39+
@isocoin_system.command(
40+
name="daily",
41+
description="Collect your daily reward of IsoCoins"
42+
)
43+
@commands.cooldown(1, 86400, commands.BucketType.user)
44+
async def isocoin_daily(self, ctx: ApplicationContext):
45+
isocoins_reward = random.randint(2500, 5000)
46+
isocoins[str(ctx.author.id)] += isocoins_reward
47+
save()
48+
await ctx.respond(f"You have earned {isocoins_reward} IsoCoins from this daily. Come back in 24 hours for the next one!")
49+
50+
@isocoin_system.command(
51+
name="shop",
52+
description="See all the items that you can buy using your IsoCoins."
53+
)
54+
async def isocoin_shop(self, ctx: ApplicationContext):
55+
await ctx.respond("IsoCoin shop is coming soon! Check back later for new items.")
56+
57+
# Cog Initialization
58+
def setup(bot): bot.add_cog(IsoCoin(bot))

main.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from discord.ext import commands
2525
from discord.ext.commands import *
2626
from cogs.economy import get_wallet, get_bank, new_bank, new_wallet
27+
from cogs.isocoin import create_isocoin_key
2728

2829
# Slash option types:
2930
# Just use variable types to define option types.
@@ -136,7 +137,7 @@ async def on_ready():
136137
async def on_message(ctx):
137138
new_wallet(ctx.author.id)
138139
new_bank(ctx.author.id)
139-
if str(ctx.author.id) not in isocoins: isocoins[str(ctx.author.id)] = 0
140+
create_isocoin_key(ctx.author.id)
140141
if str(ctx.guild.id) not in warnings: warnings[str(ctx.guild.id)] = {}
141142
if str(ctx.author.id) not in warnings[str(ctx.guild.id)]: warnings[str(ctx.guild.id)][str(ctx.author.id)] = []
142143
if str(ctx.author.id) not in items: items[str(ctx.author.id)] = {}
@@ -301,35 +302,6 @@ async def reload(ctx: ApplicationContext, cog: str):
301302
await ctx.respond(embed=discord.Embed(description=f"{cog} cog successfully reloaded.", color=discord.Color.green()))
302303
except: await ctx.respond(embed=discord.Embed(description=f"{cog} cog not found.", color=discord.Color.red()))
303304

304-
# IsoCoins commands
305-
isocoin_system = client.create_group("isocoin", "Commands related to the IsoCoin rewards system.")
306-
307-
isocoin_system.command(
308-
name="balance",
309-
description="See your IsoCoin balances"
310-
)
311-
async def isocoin_balance(ctx: ApplicationContext):
312-
localembed = discord.Embed(description=f"You currently have **{isocoins[str(ctx.author.id)]}** IsoCoins.")
313-
await ctx.respond(embed=localembed)
314-
315-
isocoin_system.command(
316-
name="daily",
317-
description="Collect your daily reward of IsoCoins"
318-
)
319-
@commands.cooldown(1, 86400, commands.BucketType.user)
320-
async def isocoin_daily(ctx: ApplicationContext):
321-
isocoins_reward = random.randint(2500, 5000)
322-
isocoins[str(ctx.author.id)] += isocoins_reward
323-
save()
324-
await ctx.respond(f"You have earned {isocoins_reward} IsoCoins from this daily. Come back in 24 hours for the next one!")
325-
326-
isocoin_system.command(
327-
name="shop",
328-
description="See all the items that you can buy using your IsoCoins."
329-
)
330-
async def isocoin_shop(ctx: ApplicationContext):
331-
await ctx.respond("IsoCoin shop is coming soon! Check back later for new items.")
332-
333305
# Initialization
334306
active_cogs = [
335307
"economy",

0 commit comments

Comments
 (0)