Skip to content

Commit

Permalink
Merge pull request #45 from Hamziee/dev
Browse files Browse the repository at this point in the history
Add support for User Installable Commands
  • Loading branch information
Hamziee authored Nov 30, 2024
2 parents 735a94e + 6a933a3 commit a0939ab
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 52 deletions.
8 changes: 4 additions & 4 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

The following versions will receive security updates as needed:

| Version | Supported |
| ------------ | ------------------ |
| 0.8.1-beta | :white_check_mark: |
| < 0.8.1-beta | :x: |
| Version | Supported |
| ------------ | ------------------ |
| 0.10.0-beta | :white_check_mark: |
| < 0.10.0-beta | :x: |

## Reporting a Vulnerability

Expand Down
2 changes: 2 additions & 0 deletions commands/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="about", description="Some information about me!")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def about(self, interaction: discord.Interaction):
try:
embed = discord.Embed(
Expand Down
2 changes: 2 additions & 0 deletions commands/cats.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="cats", description="Get your daily dose of cats :)")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def cats(self, interaction: discord.Interaction):
if cats_enabled == False:
print(Fore.RED + Style.BRIGHT + "[!] User tried to run cats command.\nPlease provide your thecatapi key in config.py.\nThe cats command will not work without it.\nGet your own free key at https://thecatapi.com/\n\nIf you wish to hide this error, please put cats.py in the disabled_commands folder." + Fore.RESET)
Expand Down
2 changes: 2 additions & 0 deletions commands/dogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="dogs", description="Get your daily dose of dogs :)")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def dogs(self, interaction: discord.Interaction):
try:
async with httpx.AsyncClient() as client:
Expand Down
4 changes: 3 additions & 1 deletion commands/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Fun(commands.Cog):
def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="ball", description="Get the truth of your question.")
@app_commands.command(name="8ball", description="Get the truth of your world breaking question.")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def ball(self, interaction: discord.Interaction, question: str):
try:
responses = [
Expand Down
26 changes: 13 additions & 13 deletions commands/headpats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ def __init__(self, client: commands.Bot):

@app_commands.command(name="headpats", description="Give headpats to your friend/lover!")
@app_commands.rename(member='person')
async def headpats(self, interaction: discord.Interaction, member: discord.Member):
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def headpats(self, interaction: discord.Interaction, member: discord.User):
try:
async with httpx.AsyncClient() as client:
response = await client.get("https://api.hamzie.site/v1/gifs/headpats")
response.raise_for_status()
data = response.json()
image_url = data["link"]
desctxt = f"{interaction.user.mention} gives head pats to {member.mention}"
if member.id == interaction.user.id:
desctxt = "You can't give head pats to yourself! But here, let me give you some head pats! <:AVA_headpat:1245509705703362560>"
if member.id == config.BOT_ID:
desctxt = "Here, let me give you some head pats! <:AVA_headpat:1245509705703362560>"
if member.bot:
desctxt = "Bots don't need head pats! But you do, so here are some headpats for you! <:AVA_headpat:1245509705703362560>"
embed = discord.Embed(
color=discord.Colour.blurple()
color=discord.Colour.blurple(),
description=desctxt
)
embed.set_image(url=image_url)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} - Image by: hamzie.site/api", icon_url=config.FOOTER_ICON)

if member.id == interaction.user.id:
await interaction.response.send_message(content="You can't give head pats to yourself! But here, let me give you some head pats! <:AVA_headpat:1245509705703362560>", embed=embed)
return
if member.id == config.BOT_ID:
await interaction.response.send_message(content="Here, let me give you some head pats! <:AVA_headpat:1245509705703362560>", embed=embed)
return
if member.bot:
await interaction.response.send_message(content="Bots don't need head pats! But I do, so here are some headpats for you! <:AVA_headpat:1245509705703362560>", embed=embed)
return
await interaction.response.send_message(content= f"{interaction.user.mention} gives head pats to {member.mention} <:AVA_headpat:1245509705703362560>", embed=embed)
await interaction.response.send_message(embed=embed)
except httpx.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
Expand Down
5 changes: 4 additions & 1 deletion commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ async def fun_button(self, interaction: discord.Interaction, button: discord.ui.
embed.add_field(name='/hug', value='Hug your friend/lover!', inline=False)
embed.add_field(name='/kiss', value='Kiss your friend/lover!', inline=False)
embed.add_field(name='/headpats', value='Give headpats to your friend/lover!', inline=False)
embed.add_field(name='/slap', value='Slap someone who deserves it!', inline=False)
embed.add_field(name='/cats', value='Get your daily dose of cat pictures!', inline=False)
embed.add_field(name='/xiaojie', value='Get your daily dose of xiaojie cat pictures!', inline=False)
embed.add_field(name='/dogs', value='Get your daily dose of dog pictures!', inline=False)
embed.add_field(name='/8ball', value='Get the truth of your question.', inline=False)
embed.add_field(name='/ball', value='Get the truth of your world breaking question.', inline=False)
embed.set_footer(text=f"Ava | version: {AVA_VERSION}", icon_url=config.FOOTER_ICON)
await interaction.response.defer()
await interaction.edit_original_response(embed=embed, view=Buttons())
Expand Down Expand Up @@ -70,6 +71,8 @@ def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="help", description="Information about my commands.")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def help(self, interaction: discord.Interaction):
embed = discord.Embed(
color=discord.Colour.blurple(),
Expand Down
26 changes: 13 additions & 13 deletions commands/hug.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ def __init__(self, client: commands.Bot):

@app_commands.command(name="hug", description="Hug your friend/lover!")
@app_commands.rename(member='person')
async def hug(self, interaction: discord.Interaction, member: discord.Member):
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def hug(self, interaction: discord.Interaction, member: discord.User):
try:
async with httpx.AsyncClient() as client:
response = await client.get("https://api.hamzie.site/v1/gifs/hug")
response.raise_for_status()
data = response.json()
image_url = data["link"]
desctxt = f"{interaction.user.mention} hugs {member.mention} <:AVA_hug:1244799683042344970>"
if member.id == interaction.user.id:
desctxt = "You can't hug yourself! Here I will give you a big hug! <a:ava_CatCuddle:1244799986600902758>"
if member.id == config.BOT_ID:
desctxt = "Here I will give you a big hug! <a:AVA_hugg:1244799800378130472>"
if member.bot:
desctxt = "Bots don't need hugs! But I do, so here is a hug for you! <a:AVA_cats_hug:1244799755960451159>"
embed = discord.Embed(
color=discord.Colour.blurple()
color=discord.Colour.blurple(),
description=desctxt
)
embed.set_image(url=image_url)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} - Image by: hamzie.site/api", icon_url=config.FOOTER_ICON)

if member.id == interaction.user.id:
await interaction.response.send_message(content="You can't hug yourself! Here I will give you a big hug! <a:ava_CatCuddle:1244799986600902758>", embed=embed)
return
if member.id == config.BOT_ID:
await interaction.response.send_message(content="Here I will give you a big hug! <a:AVA_hugg:1244799800378130472>", embed=embed)
return
if member.bot:
await interaction.response.send_message(content="Bots don't need hugs! But I do, so here is a hug for you! <a:AVA_cats_hug:1244799755960451159>", embed=embed)
return
await interaction.response.send_message(content= f"{interaction.user.mention} hugs {member.mention} <:AVA_hug:1244799683042344970>", embed=embed)
await interaction.response.send_message(embed=embed)
except httpx.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
Expand Down
2 changes: 2 additions & 0 deletions commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="technical_information", description="Display technical information")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def info(self, interaction: discord.Interaction):
try:
# Version Checker
Expand Down
26 changes: 13 additions & 13 deletions commands/kiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ def __init__(self, client: commands.Bot):

@app_commands.command(name="kiss", description="Kiss your friend/lover!")
@app_commands.rename(member='person')
async def kiss(self, interaction: discord.Interaction, member: discord.Member):
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def kiss(self, interaction: discord.Interaction, member: discord.User):
try:
async with httpx.AsyncClient() as client:
response = await client.get("https://api.hamzie.site/v1/gifs/kiss")
response.raise_for_status()
data = response.json()
image_url = data["link"]
desctxt = f"{interaction.user.mention} kisses {member.mention} <:AVA_hug:1244799683042344970>"
if member.id == interaction.user.id:
desctxt="You can't kiss yourself! Here I will give you a big kiss! <a:ava_CatCuddle:1244799986600902758>"
if member.id == config.BOT_ID:
desctxt="Here I will give you a big kiss! <a:AVA_hugg:1244799800378130472>"
if member.bot:
desctxt="Bots don't need kisses! But I do, so here is a kiss for you! <a:AVA_cats_hug:1244799755960451159>"
embed = discord.Embed(
color=discord.Colour.blurple()
color=discord.Colour.blurple(),
description=desctxt
)
embed.set_image(url=image_url)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} - Image by: hamzie.site/api", icon_url=config.FOOTER_ICON)

if member.id == interaction.user.id:
await interaction.response.send_message(content="You can't kiss yourself! Here I will give you a big kiss! <a:ava_CatCuddle:1244799986600902758>", embed=embed)
return
if member.id == config.BOT_ID:
await interaction.response.send_message(content="Here I will give you a big kiss! <a:AVA_hugg:1244799800378130472>", embed=embed)
return
if member.bot:
await interaction.response.send_message(content="Bots don't need kisses! But I do, so here is a kiss for you! <a:AVA_cats_hug:1244799755960451159>", embed=embed)
return
await interaction.response.send_message(content= f"{interaction.user.mention} kisses {member.mention} <:AVA_hug:1244799683042344970>", embed=embed)
await interaction.response.send_message(embed=embed)
except httpx.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
Expand Down
2 changes: 1 addition & 1 deletion commands/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ async def _skip(self, ctx: commands.Context):

elif voter.id == config.OWNER_ID:
await ctx.message.add_reaction('⬆️')
await ctx.send('Master skip vote, skipping.')
await ctx.send('Master skip vote, skipping...')
ctx.voice_state.skip()

elif voter.id not in ctx.voice_state.skip_votes:
Expand Down
2 changes: 2 additions & 0 deletions commands/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="ping", description="Calculate current latency.")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def ping(self, interaction: discord.Interaction):
try:
start = time.time()
Expand Down
13 changes: 8 additions & 5 deletions commands/slap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ class Slap(commands.Cog):
def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="slap", description="Slap your friend/lover!")
@app_commands.command(name="slap", description="Slap someone who deserves it!")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
@app_commands.rename(member='person')
async def slap(self, interaction: discord.Interaction, member: discord.Member):
async def slap(self, interaction: discord.Interaction, member: discord.User):
try:
async with httpx.AsyncClient() as client:
if member.id == interaction.user.id:
Expand Down Expand Up @@ -43,15 +45,16 @@ async def slap(self, interaction: discord.Interaction, member: discord.Member):
data = response.json()
image_url = data["link"]
embed = discord.Embed(
color=discord.Colour.blurple()
color=discord.Colour.blurple(),
description=f"{interaction.user.mention} slaps {member.mention}"
)
embed.set_image(url=image_url)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} - Image by: api.hamzie.site", icon_url=config.FOOTER_ICON)
await interaction.response.send_message(content=f"{interaction.user.mention} slaps {member.mention}", embed=embed)
await interaction.response.send_message(embed=embed)
except httpx.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'An error occurred: {err}')

async def setup(client: commands.Bot) -> None:
await client.add_cog(Slap(client))
2 changes: 2 additions & 0 deletions commands/xiaojie.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="xiaojie", description="Get your daily dose of xiaojie cat pictures :)")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def xiaojie(self, interaction: discord.Interaction):
try:
async with httpx.AsyncClient() as client:
Expand Down
2 changes: 1 addition & 1 deletion ex_config (change me to config.py).py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AVA_VERSION = 'v0.9.1-beta' # Do not change this, it will help with troubleshooting later
AVA_VERSION = 'v0.10.0-beta' # Do not change this, it will help with troubleshooting later
CONFIG_VERSION = 3 # Do not change this, it will help with troubleshooting later

# Required Bot Configuration
Expand Down

0 comments on commit a0939ab

Please sign in to comment.