Skip to content

Commit

Permalink
Merge pull request #46 from Hamziee/dev
Browse files Browse the repository at this point in the history
v0.11.0-beta
  • Loading branch information
Hamziee authored Dec 1, 2024
2 parents a0939ab + 78dffd3 commit c41b6d7
Show file tree
Hide file tree
Showing 6 changed files with 360 additions and 528 deletions.
2 changes: 1 addition & 1 deletion Ava.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import config
except:
raise ValueError(Fore.RED + Style.BRIGHT + "Config file could not be found, please refer to the setup instructions in the readme.md file!" + Fore.RESET)
if config.CONFIG_VERSION != 3:
if config.CONFIG_VERSION != 4:
raise ValueError(Fore.RED + Style.BRIGHT + "Config file version is outdated, please use the new config format and try again." + Fore.RESET)
elif config.TOKEN == 'Put your Discord bot token here.':
raise ValueError(Fore.RED + Style.BRIGHT + "Bot token is incorrect, please change it to the correct token in the config file." + Fore.RESET)
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.10.0-beta | :white_check_mark: |
| < 0.10.0-beta | :x: |
| 0.11.0-beta | :white_check_mark: |
| < 0.11.0-beta | :x: |

## Reporting a Vulnerability

Expand Down
111 changes: 111 additions & 0 deletions commands/games.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import discord
from discord.ext import commands
from discord import app_commands
import aiohttp
import random
import asyncio
import config

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

@app_commands.command(name="trivia", description="Test your knowledge with a trivia question!")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def trivia(self, interaction: discord.Interaction):
try:
async with aiohttp.ClientSession() as session:
async with session.get("https://opentdb.com/api.php?amount=1&type=multiple") as response:
data = await response.json()
if data["response_code"] != 0:
await interaction.response.send_message(content="Failed to fetch trivia question. Please try again later.")
return

question_data = data["results"][0]
question = question_data["question"]
correct_answer = question_data["correct_answer"]
incorrect_answers = question_data["incorrect_answers"]
options = incorrect_answers + [correct_answer]
random.shuffle(options)

embed = discord.Embed(
color=discord.Colour.blurple(),
title="🧠 Trivia Time!",
description=f"{question}\n\nSelect the correct option by typing the number (1-{len(options)}):"
)
for i, option in enumerate(options, 1):
embed.add_field(name=f"Option {i}", value=option, inline=False)
embed.set_footer(
text=config.FOOTER_TXT + " - You have 30 seconds to respond!",
icon_url=config.FOOTER_ICON
)
await interaction.response.send_message(embed=embed)

def check(message: discord.Message):
return (
message.author == interaction.user
and message.content.isdigit()
and 1 <= int(message.content) <= len(options)
)

try:
user_response = await self.client.wait_for("message", check=check, timeout=30.0)
user_choice = int(user_response.content) - 1
if options[user_choice] == correct_answer:
await interaction.followup.send(content=f"🎉 Correct! The answer was **{correct_answer}**.")
else:
await interaction.followup.send(content=f"❌ Wrong! The correct answer was **{correct_answer}**.")
except asyncio.TimeoutError:
await interaction.followup.send(content=f"⏰ Time's up! The correct answer was **{correct_answer}**.")

except Exception as e:
print(e)
await interaction.response.send_message(content="An error occurred while running the trivia game.")

@app_commands.command(name="typerace", description="Test your typing skills in a type race!")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def typerace(self, interaction: discord.Interaction):
try:
async with aiohttp.ClientSession() as session:
async with session.get("https://fakerapi.it/api/v1/texts?_quantity=1&_characters=150") as response:
if response.status != 200:
await interaction.response.send_message(content="Failed to fetch a typing challenge. Try again later!")
return

data = await response.json()
sentence = data["data"][0]["content"]
sentence = sentence.replace("'", "").strip()

embed = discord.Embed(
color=discord.Colour.blurple(),
title="⌨️ Type Race",
description=f"Type the following sentence as fast as you can:\n\n**{sentence}**"
)
embed.set_footer(text=config.FOOTER_TXT + " - Start typing now!")
await interaction.response.send_message(embed=embed)

def check(message: discord.Message):
return message.author == interaction.user

try:
start_time = asyncio.get_event_loop().time()
user_response = await self.client.wait_for("message", check=check, timeout=60.0)
end_time = asyncio.get_event_loop().time()

if user_response.content == sentence:
time_taken = end_time - start_time
await interaction.followup.send(content=f"🎉 Well done! You typed the sentence in **{time_taken:.2f} seconds**.")
else:
await interaction.followup.send(content="❌ Incorrect! Try again next time.")
except asyncio.TimeoutError:
await interaction.followup.send(content="⏰ Time's up! Better luck next time.")

except Exception as e:
print(e)
await interaction.response.send_message(content="An error occurred while running the type race.")


async def setup(client: commands.Bot) -> None:
await client.add_cog(Games(client))
17 changes: 7 additions & 10 deletions commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from discord.ext import commands
from discord import app_commands
import config
PREFIX = config.PREFIX
AVA_VERSION = config.AVA_VERSION

class Buttons(discord.ui.View):
Expand Down Expand Up @@ -42,6 +41,8 @@ async def fun_button(self, interaction: discord.Interaction, button: discord.ui.
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='/ball', value='Get the truth of your world breaking question.', inline=False)
embed.add_field(name='/trivia', value='Test your knowledge with a trivia question!', inline=False)
embed.add_field(name='/typerace', value='Test your typing skills in a type race!', 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 All @@ -53,15 +54,11 @@ async def music_button(self, interaction: discord.Interaction, button: discord.u
color=discord.Colour.blurple(),
title="Music | Music Commands",
description="Here is some Information about my music commands :)")
embed.add_field(name=f'{PREFIX}leave, {PREFIX}l, {PREFIX}disconnect', value='Clears the queue and leaves the voice channel.', inline=False)
embed.add_field(name=f'{PREFIX}now, {PREFIX}current, {PREFIX}playing', value='Displays the currently playing song.', inline=False)
embed.add_field(name=f'{PREFIX}pause, {PREFIX}pa', value='Pauses the currently playing song.', inline=False)
embed.add_field(name=f'{PREFIX}resume, {PREFIX}r', value='Resumes a currently paused song.', inline=False)
embed.add_field(name=f'{PREFIX}stop, {PREFIX}st, {PREFIX}close', value='Stops playing song and clears the queue.', inline=False)
embed.add_field(name=f'{PREFIX}skip, {PREFIX}s, {PREFIX}sk', value='Vote to skip a song. The requester can automatically skip.', inline=False)
embed.add_field(name=f'{PREFIX}queue, {PREFIX}q', value='Shows the queue. You can optionally specify the page to show. Each page contains 10 songs.', inline=False)
embed.add_field(name=f'{PREFIX}remove', value='Removes a song from the queue at a given index.', inline=False)
embed.add_field(name=f'{PREFIX}play, {PREFIX}p', value='Plays a song.', inline=False)
embed.add_field(name='/play <query>', value='Play a song or add it to the queue.', inline=False)
embed.add_field(name='/nowplaying', value='See what’s currently playing.', inline=False)
embed.add_field(name='/skip', value='Skip the current song.', inline=False)
embed.add_field(name='/queue [page]', value='View the current song queue. (Page is optional.)', inline=False)
embed.add_field(name='/leave', value='Leave the voice channel and clear the queue.', 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
Loading

0 comments on commit c41b6d7

Please sign in to comment.