Skip to content

Commit

Permalink
V1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
parker02311 committed Apr 7, 2024
1 parent 72c0177 commit 38cb7c0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
23 changes: 21 additions & 2 deletions bot/__init__.py
Expand Up @@ -3,16 +3,18 @@
Usage: The bot's main file.
"""

from discord import Object as DiscordObject
from discord import Interaction, Embed
from discord.ext.commands import Bot as BotBase
from discord.app_commands import AppCommandError, MissingPermissions
from . import config
from .data import database
from glob import glob
import logging
import os
import datetime

_log = logging.getLogger(__name__)
__version__ = "1.0.0"
__version__ = "1.0.2"


class Bot(BotBase):
Expand All @@ -21,6 +23,8 @@ def __init__(self, *args, **kwargs):
self.ready = False
super().__init__(*args, **kwargs)

self.tree.on_error = self.on_app_command_error

async def load_extensions(self):
# Original code from pycord

Expand Down Expand Up @@ -54,3 +58,18 @@ async def on_ready(self):
await database.connect()

_log.info("Database Connected")

async def on_app_command_error(
self, interaction: Interaction, error: AppCommandError
):
if isinstance(error, MissingPermissions):
await interaction.response.send_message(
embed=Embed(
title="Error",
description="You are not allowed to use this command.",
colour=interaction.user.colour,
timestamp=datetime.datetime.now(datetime.timezone.utc),
).set_footer(text=f"Redon Hub • Version {self.version}"),
)

_log.error(error)
29 changes: 17 additions & 12 deletions bot/cogs/product.py
Expand Up @@ -2,10 +2,10 @@
File: /bot/cogs/product.py
Usage: Product related commands
"""

from discord import (
app_commands,
Interaction,
Member,
Embed,
utils,
ui,
Expand All @@ -14,13 +14,13 @@
ButtonStyle,
Role,
)
from discord.app_commands import MissingPermissions
from asyncio import TimeoutError
from discord.ext.commands import Cog
from bot.data import (
get_users,
get_products,
get_product_by_name,
get_product,
create_product,
delete_product,
get_tags,
Expand Down Expand Up @@ -817,7 +817,6 @@ def __init__(self, bot):
name="admin",
description="Product Admin Commands",
parent=product_commands,
default_permissions=None,
)

@app_commands.command(
Expand Down Expand Up @@ -893,6 +892,7 @@ async def get_product_info_command_autocomplete(
@product_admin.command(
name="stats", description="Get statistics on a specific product"
)
@app_commands.checks.has_permissions(administrator=True)
async def get_product_stats_info_command(
self, interaction: Interaction, product_name: str
):
Expand Down Expand Up @@ -939,10 +939,12 @@ async def get_product_stats_info_command_autocomplete(
]

@product_admin.command(name="create", description="Create a new product")
@app_commands.checks.has_permissions(administrator=True)
async def create_product_command(self, interaction: Interaction):
await interaction.response.send_modal(createProduct(bot=self.bot))

@product_admin.command(name="delete", description="Delete a product")
@app_commands.checks.has_permissions(administrator=True)
async def delete_product_command(self, interaction: Interaction, product_name: str):
try:
product = await get_product_by_name(product_name)
Expand Down Expand Up @@ -1033,17 +1035,19 @@ async def update_product_command_autocomplete(
]

@product_admin.command(name="clear", description="Delete all products")
@app_commands.checks.has_permissions(administrator=True)
async def clear_products_command(self, interaction: Interaction):
if interaction.user.id not in config.Bot.Owners:
await interaction.response.send_message(
embed=Embed(
title="Error",
description="You are not allowed to use this command.",
colour=interaction.user.colour,
timestamp=utils.utcnow(),
).set_footer(text=f"Redon Hub • Version {self.bot.version}"),
)
return
# await interaction.response.send_message(
# embed=Embed(
# title="Error",
# description="You are not allowed to use this command.",
# colour=interaction.user.colour,
# timestamp=utils.utcnow(),
# ).set_footer(text=f"Redon Hub • Version {self.bot.version}"),
# )
# return
raise MissingPermissions("Bot Owner")

try:
products = await get_products()
Expand Down Expand Up @@ -1114,6 +1118,7 @@ async def clear_products_command(self, interaction: Interaction):
)

@product_admin.command(name="update", description="Update a product")
@app_commands.checks.has_permissions(administrator=True)
async def update_product_command(self, interaction: Interaction, product_name: str):
await interaction.response.defer()

Expand Down
7 changes: 4 additions & 3 deletions bot/cogs/tag.py
Expand Up @@ -2,15 +2,14 @@
File: /bot/cogs/tags.py
Usage: Tag related commands
"""

from discord import (
app_commands,
Interaction,
Embed,
utils,
ui,
TextStyle,
SelectOption,
ButtonStyle,
)
from discord.ext.commands import Cog
from bot.data import get_tag, get_tag_by_name, get_tags, create_tag, delete_tag, Tag
Expand Down Expand Up @@ -192,7 +191,6 @@ def __init__(self, bot):
name="admin",
description="Tag Admin Commands",
parent=tag_commands,
default_permissions=None,
)

@app_commands.command(name="tags", description="View all the tags this server has")
Expand Down Expand Up @@ -260,10 +258,12 @@ async def get_tag_info_command_autocomplete(
]

@tag_admin.command(name="create", description="Create a new tag")
@app_commands.checks.has_permissions(administrator=True)
async def create_tag_command(self, interaction: Interaction):
await interaction.response.send_modal(createTag(bot=self.bot))

@tag_admin.command(name="delete", description="Delete a tag")
@app_commands.checks.has_permissions(administrator=True)
async def delete_tag_command(self, interaction: Interaction):
await interaction.response.defer()

Expand All @@ -280,6 +280,7 @@ async def delete_tag_command(self, interaction: Interaction):
)

@tag_admin.command(name="update", description="Update a tag")
@app_commands.checks.has_permissions(administrator=True)
async def update_tag_command(self, interaction: Interaction, tag_name: str):
try:
tag = await get_tag_by_name(tag_name)
Expand Down
15 changes: 13 additions & 2 deletions bot/cogs/user.py
Expand Up @@ -2,7 +2,15 @@
File: /bot/cogs/user.py
Usage: User related commands
"""
from discord import app_commands, Interaction, Member, Embed, utils, Forbidden

from discord import (
app_commands,
Interaction,
Member,
Embed,
utils,
Forbidden,
)
from discord.ext.commands import Cog
from bot.data import (
get_user_by_discord_id,
Expand All @@ -27,7 +35,6 @@ def __init__(self, bot):
name="admin",
description="User Admin Commands",
parent=user_commands,
default_permissions=None,
)

@app_commands.command(name="profile", description="View a user's profile")
Expand Down Expand Up @@ -391,6 +398,7 @@ async def user_transfer_autocomplete(
]

@user_admin.command(name="give", description="Give a user a product")
@app_commands.checks.has_permissions(administrator=True)
async def user_admin_give(
self, interaction: Interaction, product_name: str, member: Member
):
Expand Down Expand Up @@ -483,6 +491,7 @@ async def user_admin_give(
)

@user_admin_give.autocomplete("product_name")
@app_commands.checks.has_permissions(administrator=True)
async def user_admin_give_autocomplete(
self, interaction: Interaction, current_product_name: str
):
Expand All @@ -498,6 +507,7 @@ async def user_admin_give_autocomplete(
]

@user_admin.command(name="revoke", description="Revoke a product from a user")
@app_commands.checks.has_permissions(administrator=True)
async def user_admin_revoke(
self, interaction: Interaction, product_name: str, member: Member
):
Expand Down Expand Up @@ -572,6 +582,7 @@ async def user_admin_revoke(
)

@user_admin_revoke.autocomplete("product_name")
@app_commands.checks.has_permissions(administrator=True)
async def user_admin_revoke_autocomplete(
self, interaction: Interaction, current_product_name: str
):
Expand Down

0 comments on commit 38cb7c0

Please sign in to comment.