-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
100 changed files
with
5,210 additions
and
2,682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -36,7 +36,7 @@ jobs: | |
uses: actions/[email protected] | ||
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: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -31,7 +31,7 @@ jobs: | |
uses: actions/[email protected] | ||
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: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__}.")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Oops, something went wrong.