Skip to content

Commit

Permalink
Merge pull request #39 from Hamziee/dev
Browse files Browse the repository at this point in the history
v0.7.0-beta
  • Loading branch information
Hamziee authored Sep 26, 2024
2 parents a413bb6 + 2d9565a commit e872c33
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 84 deletions.
16 changes: 16 additions & 0 deletions Ava.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import platform
from cogwatch import watch
import os
import requests
import config

try:
import config
Expand Down Expand Up @@ -46,6 +48,20 @@ async def on_ready(self):
print(prfx + " Slash CMDs Synced " + Fore.YELLOW + str(len(synced)) + " Commands")
await self.change_presence(activity=discord.Game(name=config.STATUS))
print(prfx + " Discord " + Fore.YELLOW + "Presence(s) loaded.")
# Version Checker
# Get the content from the URL
url = "https://cdn.hamzie.site/Ava/VRC/core.txt"
response = requests.get(url)

# Check if the content matches the AVA_VERSION
if response.status_code == 200: # Make sure the request was successful
remote_version = response.text.strip()
if config.AVA_VERSION == remote_version:
print("Ava up-to-date!")
else:
print(Fore.RED + Style.BRIGHT + f"Version mismatch! Local: {config.AVA_VERSION}, Remote: {remote_version}\nDownload the latest version at: https://github.com/Hamziee/Ava" + Fore.RESET)
else:
print(f"Failed to fetch latest Ava version. Status code: {response.status_code}")

client = Client()

Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ The following versions will receive security updates as needed:

| Version | Supported |
| ------------ | ------------------ |
| 0.6.3-beta | :white_check_mark: |
| < 0.6.3-beta | :x: |
| 0.7.0-beta | :white_check_mark: |
| < 0.7.0-beta | :x: |

## Reporting a Vulnerability

Expand Down
36 changes: 34 additions & 2 deletions commands/cats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@
else:
cats_enabled = True

class Buttons(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)

# Add the submit cat button with a URL
self.add_item(discord.ui.Button(label="Submit Your Cat!", style=discord.ButtonStyle.link, url="https://upload-api.hamzie.site/"))

@discord.ui.button(label="Run the command again!", style=discord.ButtonStyle.primary)
async def rerun_button(self, interaction: discord.Interaction, button: discord.ui.Button):
try:
async with httpx.AsyncClient() as client:
response = await client.get("https://api.thecatapi.com/v1/images/search", headers={"x-api-key": config.THECATAPI_KEY})
data = response.json()
image_url = data[0]['url']

embed = discord.Embed(
color=discord.Colour.blurple(),
title="Important Message:",
description="Currently Ava uses TheCatAPI which is not free to use, that's why Hamzie API (the source of most images Ava uses) is making their own cat's section, free to use for everyone. We ask you to send in your best cat pictures, for it to be used in Hamzie API, which will eventually replace TheCatAPI in this command."
)
embed.set_image(url=image_url)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} - Image by: thecatapi.com", icon_url=config.FOOTER_ICON)

await interaction.response.send_message(embed=embed, view=Buttons())
except httpx.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'An error occurred: {err}')


class cats(commands.Cog):
def __init__(self, client: commands.Bot):
self.client = client
Expand All @@ -29,12 +59,14 @@ async def cats(self, interaction: discord.Interaction):
image_url = data[0]['url']

embed = discord.Embed(
color=discord.Colour.blurple()
color=discord.Colour.blurple(),
title="Important Message:",
description="Currently the bot uses TheCatAPI which is not free to use, that's why Hamzie API (the source of most images Ava uses) is making their own cat's section, free to use for everyone. We ask you to send in your best cat pictures, for it to be used in Hamzie API, which will eventually replace TheCatAPI in this command."
)
embed.set_image(url=image_url)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} - Image by: thecatapi.com", icon_url=config.FOOTER_ICON)

await interaction.response.send_message(embed=embed)
await interaction.response.send_message(embed=embed, view=Buttons())
except Exception as e:
print(e)
await interaction.followup.send(content='Error occured.')
Expand Down
29 changes: 28 additions & 1 deletion commands/dogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@
from datetime import datetime
import config

class Buttons(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)

# Add the submit cat button with a URL
self.add_item(discord.ui.Button(label="Submit Your Cat!", style=discord.ButtonStyle.link, url="https://upload-api.hamzie.site/"))

@discord.ui.button(label="Run the command again!", style=discord.ButtonStyle.primary)
async def rerun_button(self, interaction: discord.Interaction, button: discord.ui.Button):
try:
async with httpx.AsyncClient() as client:
response = await client.get("https://dog.ceo/api/breeds/image/random")
response.raise_for_status()
data = response.json()
image_url = data["message"]
embed = discord.Embed(
color=discord.Colour.blurple()
)
embed.set_image(url=image_url)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} - Image by: dog.ceo/dog-api/", icon_url=config.FOOTER_ICON)

await interaction.response.send_message(embed=embed, view=Buttons())
except httpx.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'An error occurred: {err}')

class dogs(commands.Cog):
def __init__(self, client: commands.Bot):
self.client = client
Expand All @@ -23,7 +50,7 @@ async def dogs(self, interaction: discord.Interaction):
embed.set_image(url=image_url)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} - Image by: dog.ceo/dog-api/", icon_url=config.FOOTER_ICON)

await interaction.response.send_message(embed=embed)
await interaction.response.send_message(embed=embed, view=Buttons())
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/headpats.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def headpats(self, interaction: discord.Interaction, member: discord.Membe
color=discord.Colour.blurple()
)
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)
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)
Expand Down
2 changes: 1 addition & 1 deletion commands/hug.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def hug(self, interaction: discord.Interaction, member: discord.Member):
color=discord.Colour.blurple()
)
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)
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)
Expand Down
54 changes: 54 additions & 0 deletions commands/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import discord
from discord.ext import commands
from discord import app_commands
import config
import sys
import pkg_resources
import requests

class info(commands.Cog):
def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="technical_information", description="Display technical information")
async def info(self, interaction: discord.Interaction):
try:
# Version Checker
# Get the content from the URL
url = "https://cdn.hamzie.site/Ava/VRC/core.txt"
response = requests.get(url)

# Check if the content matches the AVA_VERSION
if response.status_code == 200: # Make sure the request was successful
remote_version = response.text.strip()
else:
remote_version = "Failed to fetch."

# TheCatAPI Check
if config.THECATAPI_KEY == 'your thecatapi key here':
cats_string = 'Disabled'
else:
cats_string = 'Enabled'

# Python Version
python_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"

# Get installed packages and format them
installed_packages = pkg_resources.working_set
package_list = "\n".join([f"{package.project_name} {package.version}" for package in installed_packages])

embed = discord.Embed(
color=discord.Colour.blurple(),
title="Technical Details",
description="If you are looking for information about the bot, run the command: '/about'")
embed.add_field(name='Core', value=f'Running Ava {config.AVA_VERSION} | (Latest: {remote_version})\nAva Config Version: {config.CONFIG_VERSION}\nPython {python_version}', inline=False)
embed.add_field(name="Python Packages", value=package_list, inline=False)
embed.add_field(name="Ava Optional Modules", value=f'AvaAI: Disabled - In Development | (Being Rewritten)\nTheCatAPI: {cats_string} | (Will be removed in favor of a new system that will be provided by Hamzie API)', inline=False)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION}", icon_url=config.FOOTER_ICON)
await interaction.response.send_message(embed=embed)
except Exception as e:
print(e)
await interaction.followup.send(content='Error occured.')

async def setup(client:commands.Bot) -> None:
await client.add_cog(info(client))
2 changes: 1 addition & 1 deletion commands/kiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def kiss(self, interaction: discord.Interaction, member: discord.Member):
color=discord.Colour.blurple()
)
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)
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)
Expand Down
60 changes: 56 additions & 4 deletions commands/xiaojie.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,48 @@
from discord.ext import commands
from discord import app_commands
import httpx
from datetime import datetime
import config
import random

class Buttons(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)

# Add the submit cat button with a URL
self.add_item(discord.ui.Button(label="Submit Your Cat!", style=discord.ButtonStyle.link, url="https://upload-api.hamzie.site/"))

# Rerun button
@discord.ui.button(label="Run the command again!",style=discord.ButtonStyle.primary)
async def rerun_button(self, interaction: discord.Interaction, button: discord.ui.Button):
try:
async with httpx.AsyncClient() as client:
response = await client.get("https://api.hamzie.site/v1/images/xiaojie")
response.raise_for_status()
data = response.json()
image_url = data["link"]

# Define the two descriptions
description_options = [
("115 **new** images of Xiaojie have been added! In total, Hamzie API stores 295 images of the cute Xiaojie cat. Have you seen every one?", "Fun Fact"),
("Currently Ava uses TheCatAPI which is not free to use, that's why Hamzie API (the source of most images Ava uses) is making their own cat's section, free to use for everyone. We ask you to send in your best cat pictures, for it to be used in Hamzie API, which will eventually replace TheCatAPI in this command.", "Important Announcement")
]

# Randomly choose one of the description strings
random_description, random_title = random.choice(description_options)

embed = discord.Embed(
color=discord.Colour.blurple(),
title=random_title,
description=random_description
)
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)

await interaction.response.send_message(embed=embed, view=Buttons())
except httpx.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'An error occurred: {err}')

class xiaojie(commands.Cog):
def __init__(self, client: commands.Bot):
Expand All @@ -17,13 +57,25 @@ async def xiaojie(self, interaction: discord.Interaction):
response.raise_for_status()
data = response.json()
image_url = data["link"]

# Define the two descriptions
description_options = [
("115 **new** images of Xiaojie have been added! In total, Hamzie API stores 295 images of the cute Xiaojie cat. Have you seen every one?", "Fun Fact:"),
("Currently Ava uses TheCatAPI for the /cats command, which is not free to use. That's why Hamzie API (the source of most images Ava uses) is making their own cat's section, free to use for everyone. We ask you to send in your best cat pictures, for it to be used in Hamzie API, which will eventually replace TheCatAPI in this command.", "Important Announcement")
]

# Randomly choose one of the description strings
random_description, random_title = random.choice(description_options)

embed = discord.Embed(
color=discord.Colour.blurple()
color=discord.Colour.blurple(),
title=random_title,
description=random_description
)
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)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} - Image by: hamzie.site/api", icon_url=config.FOOTER_ICON)

await interaction.response.send_message(embed=embed)
await interaction.response.send_message(embed=embed, view=Buttons())
except httpx.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
Expand Down
50 changes: 50 additions & 0 deletions disabled commands/ChatAI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

# IMPORTANT NOTE:
# AvaAI is closed source for now. ChatAI will NOT work for you unless you make your function for this command to process! If you do not know what that means then don't bother getting this to work, I might add an example script to use OpenAI in the future.
# This script calls for ChatReponse() to respond with a message.


# This is in progress of begin rewritten

import discord
from discord.ext import commands
from discord import app_commands
import config
from extraConfigs.ChatAIConfig import *

class chat(commands.Cog):
def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="chat", description="Chat with me!")
@app_commands.rename(message='message')
@app_commands.describe(message='Type the message you wish to send to Ava.')
async def chat(self, interaction: discord.Interaction, message: str):
try:
embed = discord.Embed(
color=discord.Colour.blurple(),
title="AvaAI 💬",
description="Ava is thinking... <:AVA_CuteThink:1211038099086512199>")
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} | Keep in mind that Ava can make mistakes.", icon_url=config.FOOTER_ICON)
await interaction.response.send_message(embed=embed)
response = await ChatReponse(message)
try:
embed = discord.Embed(
color=discord.Colour.blurple(),
title="AvaAI 💬",
description=response)
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} | Keep in mind that Ava can make mistakes.", icon_url=config.FOOTER_ICON)
await interaction.edit_original_response(embed=embed)
except:
embed = discord.Embed(
color=discord.Colour.blurple(),
title="AvaAI <:Ava_Error:1211046596373123174>",
description="Ava's response overwhelmed Discord with its size. Could you please ask her to provide a shorter response?")
embed.set_footer(text=f"Ava | version: {config.AVA_VERSION} | Keep in mind that Ava can make mistakes.", icon_url=config.FOOTER_ICON)
await interaction.edit_original_response(embed=embed)
except Exception as e:
print(e)
await interaction.followup.send(content='Error occured.')

async def setup(client:commands.Bot) -> None:
await client.add_cog(chat(client))
Loading

0 comments on commit e872c33

Please sign in to comment.