Skip to content

Commit

Permalink
Update: v0.10.0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
No767 committed Jul 25, 2023
2 parents 9e31389 + d38281c commit 617eb8c
Show file tree
Hide file tree
Showing 100 changed files with 5,210 additions and 2,682 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: actions/checkout@v3
- name: Set up Python 3.11
id: setup-python
uses: actions/setup-python@v4.6.1
uses: actions/setup-python@v4.7.0
with:
python-version: '3.11'
- name: Set up Poetry
Expand All @@ -36,7 +36,7 @@ jobs:
uses: actions/cache@v3.3.1
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-v3-${{ hashFiles('**/poetry.lock') }}
key: ${{ runner.os }}-codeql-python-${{ hashFiles('**/poetry.lock') }}
- name: Install Poetry Dependencies
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- name: Set up Python ${{ matrix.version }}
id: setup-python
uses: actions/setup-python@v4.6.1
uses: actions/setup-python@v4.7.0
with:
python-version: ${{ matrix.version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/snyk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v3
- name: Set up Python 3.11
id: setup-python
uses: actions/setup-python@v4.6.1
uses: actions/setup-python@v4.7.0
with:
python-version: '3.11'
- name: Set up Node.js 18
Expand All @@ -31,7 +31,7 @@ jobs:
uses: actions/cache@v3.3.1
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-v2-${{ hashFiles('**/poetry.lock') }}
key: ${{ runner.os }}-synk-${{ hashFiles('**/poetry.lock') }}
- name: Install Poetry Dependencies
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Set up Python
id: setup-python
uses: actions/setup-python@v4.6.1
uses: actions/setup-python@v4.7.0
with:
python-version: ${{ matrix.version }}

Expand Down
3 changes: 3 additions & 0 deletions Bot/Cogs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pkgutil import iter_modules

EXTENSIONS = [module.name for module in iter_modules(__path__, f"{__package__}.")]
23 changes: 21 additions & 2 deletions Bot/Cogs/dev-tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
from kumikocore import KumikoCore


def is_nat():
def pred(ctx):
return (
ctx.guild is not None and ctx.author.id == 1028431063321686036
) # natalie's account

return commands.check(pred)


class DevTools(commands.Cog, command_attrs=dict(hidden=True)):
"""Tools for developing Kumiko"""

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

@commands.hybrid_command(name="sync")
@commands.guild_only()
@commands.is_owner()
@commands.check_any(commands.is_owner(), is_nat())
async def sync(
self,
ctx: Context,
Expand Down Expand Up @@ -65,7 +74,7 @@ async def sync(

@commands.hybrid_command(name="dispatch")
@commands.guild_only()
@commands.is_owner()
@commands.check_any(commands.is_owner(), is_nat())
@app_commands.describe(event="The event to dispatch")
async def dispatch_event(self, ctx: commands.Context, event: str) -> None:
"""Dispatches an custom event
Expand All @@ -76,6 +85,16 @@ async def dispatch_event(self, ctx: commands.Context, event: str) -> None:
self.bot.dispatch(event, ctx.guild, ctx.author)
await ctx.send("Dispatched event")

@commands.check_any(commands.is_owner(), is_nat())
@commands.command(name="arg-check", usage="<user: discord.Member>")
async def arg_check(self, ctx: commands.Context, user: discord.Member):
"""Testing arg checks
Args:
user (discord.Member): The member to ping lol
"""
await ctx.send(user.name)


async def setup(bot: KumikoCore):
await bot.add_cog(DevTools(bot))
138 changes: 138 additions & 0 deletions Bot/Cogs/economy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import discord
from discord.ext import commands
from kumikocore import KumikoCore
from Libs.cache import KumikoCache
from Libs.cog_utils.economy import is_economy_enabled
from Libs.ui.economy import RegisterView
from Libs.ui.marketplace import ItemPages
from Libs.utils import ConfirmEmbed, Embed, is_manager


class Economy(commands.Cog):
"""Trade, earn, and gamble your way to the top!
This is Kumiko's flagship module.
"""

def __init__(self, bot: KumikoCore) -> None:
self.bot = bot
self.pool = self.bot.pool
self.redis_pool = self.bot.redis_pool

@property
def display_emoji(self) -> discord.PartialEmoji:
return discord.PartialEmoji.from_str("<:upward_stonks:739614245997641740>")

@commands.hybrid_group(name="eco", aliases=["economy"])
async def eco(self, ctx: commands.Context) -> None:
if ctx.invoked_subcommand is None:
await ctx.send_help(ctx.command)

# Throw checks on these later
@is_manager()
@eco.command(name="enable")
async def enable(self, ctx: commands.Context) -> None:
"""Enables the economy module for your server"""
key = f"cache:kumiko:{ctx.guild.id}:guild_config" # type: ignore
cache = KumikoCache(connection_pool=self.redis_pool)
query = """
UPDATE guild
SET local_economy = $2
WHERE id = $1;
"""
result = await cache.getJSONCache(key=key, path="$.local_economy")
if result is True:
await ctx.send("Economy is already enabled for your server!")
return
else:
await self.pool.execute(query, ctx.guild.id, True) # type: ignore
await cache.mergeJSONCache(
key=key, value=True, path="$.local_economy", ttl=None
)
await ctx.send("Enabled economy!")
return

@is_manager()
@is_economy_enabled()
@eco.command(name="disable")
async def disable(self, ctx: commands.Context) -> None:
"""Disables the economy module for your server"""
key = f"cache:kumiko:{ctx.guild.id}:config" # type: ignore
cache = KumikoCache(connection_pool=self.redis_pool)
query = """
UPDATE guild
SET local_economy = $2
WHERE id = $1;
"""
if await cache.cacheExists(key=key):
result = await cache.getJSONCache(key=key, path=".local_economy")
if result is True:
await self.pool.execute(query, ctx.guild.id, False) # type: ignore
await cache.mergeJSONCache(
key=key, value=False, path="$.local_economy", ttl=None
)
await ctx.send(
"Economy is now disabled for your server. Please enable it first."
)
return
else:
await ctx.send("Economy is already disabled for your server!")
return

@is_economy_enabled()
@eco.command(name="wallet", aliases=["bal", "balance"])
async def wallet(self, ctx: commands.Context) -> None:
"""View your eco wallet"""
sql = """
SELECT rank, petals, created_at
FROM eco_user
WHERE id = $1;
"""
user = await self.pool.fetchrow(sql, ctx.author.id)
if user is None:
await ctx.send(
f"You have not created an economy account yet! Run `{ctx.prefix}eco register` to create one."
)
return
dictUser = dict(user)
embed = Embed()
embed.set_author(
name=f"{ctx.author.display_name}'s Balance",
icon_url=ctx.author.display_avatar.url,
)
embed.set_footer(text="Created at")
embed.timestamp = dictUser["created_at"]
embed.add_field(name="Rank", value=dictUser["rank"], inline=True)
embed.add_field(name="Petals", value=dictUser["petals"], inline=True)
await ctx.send(embed=embed)

@is_economy_enabled()
@eco.command(name="register")
async def register(self, ctx: commands.Context) -> None:
"""Register for an economy account"""
view = RegisterView(self.pool)
embed = ConfirmEmbed()
embed.description = "Do you want to make an account? The account can only be accessed from your current guild"
await ctx.send(embed=embed, view=view)

@is_economy_enabled()
@eco.command(name="inventory", aliases=["inv"])
async def inventory(self, ctx: commands.Context) -> None:
"""View your inventory"""
query = """
SELECT eco_item.id, eco_item.name, eco_item.description, eco_item.price, eco_item.amount, eco_item.producer_id
FROM eco_item_lookup
INNER JOIN eco_item ON eco_item.id = eco_item_lookup.item_id
WHERE eco_item.guild_id = $1 AND eco_item.owner_id = $2;
"""
rows = await self.pool.fetch(query, ctx.guild.id, ctx.author.id) # type: ignore
if len(rows) == 0:
await ctx.send("No items available")
return

pages = ItemPages(entries=rows, ctx=ctx, per_page=1)
await pages.start()


async def setup(bot: KumikoCore) -> None:
await bot.add_cog(Economy(bot))
Loading

0 comments on commit 617eb8c

Please sign in to comment.