Skip to content

Commit 617eb8c

Browse files
authored
Update: v0.10.0
This update implements the pins feature and Kumiko's flagship economy modules. Along with that, there were a lot of fixes and code introduced in this update (around +5K, and -3K). For more info on the changes, please see the changelog - Noelle
2 parents 9e31389 + d38281c commit 617eb8c

File tree

100 files changed

+5210
-2682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+5210
-2682
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
uses: actions/checkout@v3
2727
- name: Set up Python 3.11
2828
id: setup-python
29-
uses: actions/setup-python@v4.6.1
29+
uses: actions/setup-python@v4.7.0
3030
with:
3131
python-version: '3.11'
3232
- name: Set up Poetry
@@ -36,7 +36,7 @@ jobs:
3636
uses: actions/cache@v3.3.1
3737
with:
3838
path: ~/.cache/pypoetry/virtualenvs
39-
key: ${{ runner.os }}-poetry-v3-${{ hashFiles('**/poetry.lock') }}
39+
key: ${{ runner.os }}-codeql-python-${{ hashFiles('**/poetry.lock') }}
4040
- name: Install Poetry Dependencies
4141
if: steps.cache-poetry.outputs.cache-hit != 'true'
4242
run: |

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- name: Set up Python ${{ matrix.version }}
4343
id: setup-python
44-
uses: actions/setup-python@v4.6.1
44+
uses: actions/setup-python@v4.7.0
4545
with:
4646
python-version: ${{ matrix.version }}
4747

.github/workflows/snyk.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@v3
1515
- name: Set up Python 3.11
1616
id: setup-python
17-
uses: actions/setup-python@v4.6.1
17+
uses: actions/setup-python@v4.7.0
1818
with:
1919
python-version: '3.11'
2020
- name: Set up Node.js 18
@@ -31,7 +31,7 @@ jobs:
3131
uses: actions/cache@v3.3.1
3232
with:
3333
path: ~/.cache/pypoetry/virtualenvs
34-
key: ${{ runner.os }}-poetry-v2-${{ hashFiles('**/poetry.lock') }}
34+
key: ${{ runner.os }}-synk-${{ hashFiles('**/poetry.lock') }}
3535
- name: Install Poetry Dependencies
3636
if: steps.cache-poetry.outputs.cache-hit != 'true'
3737
run: |

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
5757
- name: Set up Python
5858
id: setup-python
59-
uses: actions/setup-python@v4.6.1
59+
uses: actions/setup-python@v4.7.0
6060
with:
6161
python-version: ${{ matrix.version }}
6262

Bot/Cogs/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from pkgutil import iter_modules
2+
3+
EXTENSIONS = [module.name for module in iter_modules(__path__, f"{__package__}.")]

Bot/Cogs/dev-tools.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
from kumikocore import KumikoCore
88

99

10+
def is_nat():
11+
def pred(ctx):
12+
return (
13+
ctx.guild is not None and ctx.author.id == 1028431063321686036
14+
) # natalie's account
15+
16+
return commands.check(pred)
17+
18+
1019
class DevTools(commands.Cog, command_attrs=dict(hidden=True)):
1120
"""Tools for developing Kumiko"""
1221

@@ -19,7 +28,7 @@ def display_emoji(self) -> discord.PartialEmoji:
1928

2029
@commands.hybrid_command(name="sync")
2130
@commands.guild_only()
22-
@commands.is_owner()
31+
@commands.check_any(commands.is_owner(), is_nat())
2332
async def sync(
2433
self,
2534
ctx: Context,
@@ -65,7 +74,7 @@ async def sync(
6574

6675
@commands.hybrid_command(name="dispatch")
6776
@commands.guild_only()
68-
@commands.is_owner()
77+
@commands.check_any(commands.is_owner(), is_nat())
6978
@app_commands.describe(event="The event to dispatch")
7079
async def dispatch_event(self, ctx: commands.Context, event: str) -> None:
7180
"""Dispatches an custom event
@@ -76,6 +85,16 @@ async def dispatch_event(self, ctx: commands.Context, event: str) -> None:
7685
self.bot.dispatch(event, ctx.guild, ctx.author)
7786
await ctx.send("Dispatched event")
7887

88+
@commands.check_any(commands.is_owner(), is_nat())
89+
@commands.command(name="arg-check", usage="<user: discord.Member>")
90+
async def arg_check(self, ctx: commands.Context, user: discord.Member):
91+
"""Testing arg checks
92+
93+
Args:
94+
user (discord.Member): The member to ping lol
95+
"""
96+
await ctx.send(user.name)
97+
7998

8099
async def setup(bot: KumikoCore):
81100
await bot.add_cog(DevTools(bot))

Bot/Cogs/economy.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import discord
2+
from discord.ext import commands
3+
from kumikocore import KumikoCore
4+
from Libs.cache import KumikoCache
5+
from Libs.cog_utils.economy import is_economy_enabled
6+
from Libs.ui.economy import RegisterView
7+
from Libs.ui.marketplace import ItemPages
8+
from Libs.utils import ConfirmEmbed, Embed, is_manager
9+
10+
11+
class Economy(commands.Cog):
12+
"""Trade, earn, and gamble your way to the top!
13+
14+
This is Kumiko's flagship module.
15+
"""
16+
17+
def __init__(self, bot: KumikoCore) -> None:
18+
self.bot = bot
19+
self.pool = self.bot.pool
20+
self.redis_pool = self.bot.redis_pool
21+
22+
@property
23+
def display_emoji(self) -> discord.PartialEmoji:
24+
return discord.PartialEmoji.from_str("<:upward_stonks:739614245997641740>")
25+
26+
@commands.hybrid_group(name="eco", aliases=["economy"])
27+
async def eco(self, ctx: commands.Context) -> None:
28+
if ctx.invoked_subcommand is None:
29+
await ctx.send_help(ctx.command)
30+
31+
# Throw checks on these later
32+
@is_manager()
33+
@eco.command(name="enable")
34+
async def enable(self, ctx: commands.Context) -> None:
35+
"""Enables the economy module for your server"""
36+
key = f"cache:kumiko:{ctx.guild.id}:guild_config" # type: ignore
37+
cache = KumikoCache(connection_pool=self.redis_pool)
38+
query = """
39+
UPDATE guild
40+
SET local_economy = $2
41+
WHERE id = $1;
42+
"""
43+
result = await cache.getJSONCache(key=key, path="$.local_economy")
44+
if result is True:
45+
await ctx.send("Economy is already enabled for your server!")
46+
return
47+
else:
48+
await self.pool.execute(query, ctx.guild.id, True) # type: ignore
49+
await cache.mergeJSONCache(
50+
key=key, value=True, path="$.local_economy", ttl=None
51+
)
52+
await ctx.send("Enabled economy!")
53+
return
54+
55+
@is_manager()
56+
@is_economy_enabled()
57+
@eco.command(name="disable")
58+
async def disable(self, ctx: commands.Context) -> None:
59+
"""Disables the economy module for your server"""
60+
key = f"cache:kumiko:{ctx.guild.id}:config" # type: ignore
61+
cache = KumikoCache(connection_pool=self.redis_pool)
62+
query = """
63+
UPDATE guild
64+
SET local_economy = $2
65+
WHERE id = $1;
66+
"""
67+
if await cache.cacheExists(key=key):
68+
result = await cache.getJSONCache(key=key, path=".local_economy")
69+
if result is True:
70+
await self.pool.execute(query, ctx.guild.id, False) # type: ignore
71+
await cache.mergeJSONCache(
72+
key=key, value=False, path="$.local_economy", ttl=None
73+
)
74+
await ctx.send(
75+
"Economy is now disabled for your server. Please enable it first."
76+
)
77+
return
78+
else:
79+
await ctx.send("Economy is already disabled for your server!")
80+
return
81+
82+
@is_economy_enabled()
83+
@eco.command(name="wallet", aliases=["bal", "balance"])
84+
async def wallet(self, ctx: commands.Context) -> None:
85+
"""View your eco wallet"""
86+
sql = """
87+
SELECT rank, petals, created_at
88+
FROM eco_user
89+
WHERE id = $1;
90+
"""
91+
user = await self.pool.fetchrow(sql, ctx.author.id)
92+
if user is None:
93+
await ctx.send(
94+
f"You have not created an economy account yet! Run `{ctx.prefix}eco register` to create one."
95+
)
96+
return
97+
dictUser = dict(user)
98+
embed = Embed()
99+
embed.set_author(
100+
name=f"{ctx.author.display_name}'s Balance",
101+
icon_url=ctx.author.display_avatar.url,
102+
)
103+
embed.set_footer(text="Created at")
104+
embed.timestamp = dictUser["created_at"]
105+
embed.add_field(name="Rank", value=dictUser["rank"], inline=True)
106+
embed.add_field(name="Petals", value=dictUser["petals"], inline=True)
107+
await ctx.send(embed=embed)
108+
109+
@is_economy_enabled()
110+
@eco.command(name="register")
111+
async def register(self, ctx: commands.Context) -> None:
112+
"""Register for an economy account"""
113+
view = RegisterView(self.pool)
114+
embed = ConfirmEmbed()
115+
embed.description = "Do you want to make an account? The account can only be accessed from your current guild"
116+
await ctx.send(embed=embed, view=view)
117+
118+
@is_economy_enabled()
119+
@eco.command(name="inventory", aliases=["inv"])
120+
async def inventory(self, ctx: commands.Context) -> None:
121+
"""View your inventory"""
122+
query = """
123+
SELECT eco_item.id, eco_item.name, eco_item.description, eco_item.price, eco_item.amount, eco_item.producer_id
124+
FROM eco_item_lookup
125+
INNER JOIN eco_item ON eco_item.id = eco_item_lookup.item_id
126+
WHERE eco_item.guild_id = $1 AND eco_item.owner_id = $2;
127+
"""
128+
rows = await self.pool.fetch(query, ctx.guild.id, ctx.author.id) # type: ignore
129+
if len(rows) == 0:
130+
await ctx.send("No items available")
131+
return
132+
133+
pages = ItemPages(entries=rows, ctx=ctx, per_page=1)
134+
await pages.start()
135+
136+
137+
async def setup(bot: KumikoCore) -> None:
138+
await bot.add_cog(Economy(bot))

0 commit comments

Comments
 (0)