mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
chore: ruff formatting
This commit is contained in:
@@ -22,10 +22,16 @@ class Fun(commands.GroupCog, name="fun"):
|
||||
embed = discord.Embed(
|
||||
title="Fun Commands",
|
||||
description="Use `.fun <subcommand>` or slash `/fun <subcommand>`.",
|
||||
color=0x7289DA
|
||||
color=0x7289DA,
|
||||
)
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
embed.add_field(
|
||||
name="Available",
|
||||
value="coinflip, 8ball, minesweeper, randomfact, rps",
|
||||
inline=False,
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
embed.add_field(name="Available", value="coinflip, 8ball, minesweeper, randomfact, rps", inline=False)
|
||||
await context.send(embed=embed)
|
||||
|
||||
async def _invoke_hybrid(self, context: Context, name: str, **kwargs):
|
||||
@@ -67,8 +73,7 @@ class Fun(commands.GroupCog, name="fun"):
|
||||
|
||||
@commands.check(_require_group_prefix)
|
||||
@commands.hybrid_command(
|
||||
name="coinflip",
|
||||
description="Make a coin flip, but give your bet before."
|
||||
name="coinflip", description="Make a coin flip, but give your bet before."
|
||||
)
|
||||
async def coinflip(self, context):
|
||||
return await coinflip_command()(self, context)
|
||||
@@ -83,8 +88,7 @@ class Fun(commands.GroupCog, name="fun"):
|
||||
|
||||
@commands.check(_require_group_prefix)
|
||||
@commands.hybrid_command(
|
||||
name="minesweeper",
|
||||
description="Play a buttoned minesweeper mini-game."
|
||||
name="minesweeper", description="Play a buttoned minesweeper mini-game."
|
||||
)
|
||||
async def minesweeper(self, context):
|
||||
return await minesweeper_command()(self, context)
|
||||
@@ -101,10 +105,11 @@ class Fun(commands.GroupCog, name="fun"):
|
||||
async def rock_paper_scissors(self, context):
|
||||
return await rps_command()(self, context)
|
||||
|
||||
|
||||
async def setup(bot) -> None:
|
||||
cog = Fun(bot)
|
||||
await bot.add_cog(cog)
|
||||
|
||||
|
||||
bot.logger.info("Loaded extension 'fun.coinflip'")
|
||||
bot.logger.info("Loaded extension 'fun.8ball'")
|
||||
bot.logger.info("Loaded extension 'fun.minesweeper'")
|
||||
|
||||
@@ -2,6 +2,7 @@ import random
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
class Choice(discord.ui.View):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
@@ -21,19 +22,19 @@ class Choice(discord.ui.View):
|
||||
self.value = "tails"
|
||||
self.stop()
|
||||
|
||||
|
||||
def coinflip_command():
|
||||
@commands.hybrid_command(
|
||||
name="coinflip",
|
||||
description="Make a coin flip, but give your bet before."
|
||||
name="coinflip", description="Make a coin flip, but give your bet before."
|
||||
)
|
||||
async def coinflip(self, context):
|
||||
buttons = Choice()
|
||||
embed = discord.Embed(
|
||||
title="Coinflip",
|
||||
description="What is your bet?",
|
||||
color=0x7289DA
|
||||
title="Coinflip", description="What is your bet?", color=0x7289DA
|
||||
)
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
message = await context.send(embed=embed, view=buttons)
|
||||
await buttons.wait()
|
||||
result = random.choice(["heads", "tails"])
|
||||
@@ -43,14 +44,18 @@ def coinflip_command():
|
||||
description=f"Correct! You guessed `{buttons.value}` and I flipped the coin to `{result}`.",
|
||||
color=0x00FF00,
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
else:
|
||||
embed = discord.Embed(
|
||||
title="Coinflip",
|
||||
description=f"Woops! You guessed `{buttons.value}` and I flipped the coin to `{result}`, better luck next time!",
|
||||
color=0xE02B2B,
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
await message.edit(embed=embed, view=None, content=None)
|
||||
|
||||
|
||||
return coinflip
|
||||
|
||||
@@ -2,6 +2,7 @@ import random
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
def eightball_command():
|
||||
@commands.hybrid_command(
|
||||
name="8ball",
|
||||
@@ -35,8 +36,10 @@ def eightball_command():
|
||||
description=f"{random.choice(answers)}",
|
||||
color=0x7289DA,
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
embed.set_footer(text=f"The question was: {question}")
|
||||
await context.send(embed=embed)
|
||||
|
||||
|
||||
return eight_ball
|
||||
|
||||
@@ -5,9 +5,12 @@ from discord.ext import commands
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
|
||||
class RowButton(discord.ui.Button):
|
||||
def __init__(self, ctx, label, custom_id, bombs, board):
|
||||
super().__init__(label=label, style=discord.ButtonStyle.grey, custom_id=custom_id)
|
||||
super().__init__(
|
||||
label=label, style=discord.ButtonStyle.grey, custom_id=custom_id
|
||||
)
|
||||
self.ctx = ctx
|
||||
self.bombs = bombs
|
||||
self.board = board
|
||||
@@ -15,16 +18,18 @@ class RowButton(discord.ui.Button):
|
||||
async def callback(self, interaction):
|
||||
assert self.view is not None
|
||||
view: MsView = self.view
|
||||
|
||||
|
||||
current_time = time.time()
|
||||
if current_time - view.last_interaction < 0.5:
|
||||
try:
|
||||
return await interaction.response.send_message("Please wait before clicking again.", ephemeral=True)
|
||||
return await interaction.response.send_message(
|
||||
"Please wait before clicking again.", ephemeral=True
|
||||
)
|
||||
except:
|
||||
return
|
||||
|
||||
|
||||
view.last_interaction = current_time
|
||||
|
||||
|
||||
try:
|
||||
await interaction.response.defer()
|
||||
except discord.errors.HTTPException as e:
|
||||
@@ -32,7 +37,7 @@ class RowButton(discord.ui.Button):
|
||||
await asyncio.sleep(1)
|
||||
return
|
||||
raise
|
||||
|
||||
|
||||
if interaction.user.id != self.ctx.author.id:
|
||||
return await interaction.followup.send(
|
||||
"You cannot interact with these buttons.", ephemeral=True
|
||||
@@ -40,12 +45,14 @@ class RowButton(discord.ui.Button):
|
||||
|
||||
b_id = self.custom_id
|
||||
if int(b_id[5:]) in view.moves:
|
||||
return await interaction.followup.send("That part is already taken.", ephemeral=True)
|
||||
|
||||
return await interaction.followup.send(
|
||||
"That part is already taken.", ephemeral=True
|
||||
)
|
||||
|
||||
if not view.bombs_generated:
|
||||
view.generate_bombs(int(b_id[5:]))
|
||||
self.bombs = view.bombs
|
||||
|
||||
|
||||
if int(b_id[5:]) in self.bombs:
|
||||
await view.RevealBombs(b_id, view.board)
|
||||
else:
|
||||
@@ -74,13 +81,13 @@ class RowButton(discord.ui.Button):
|
||||
return count
|
||||
|
||||
count = checkpos(count, rawpos, pos)
|
||||
number = 8-len(count)
|
||||
number = 8 - len(count)
|
||||
self.label = str(number) if number > 0 else "0"
|
||||
self.style = discord.ButtonStyle.green
|
||||
pos = int(b_id[5:])
|
||||
view.board[view.GetBoardRow(pos)][
|
||||
view.GetBoardPos(pos)
|
||||
] = str(number) if number > 0 else "0"
|
||||
view.board[view.GetBoardRow(pos)][view.GetBoardPos(pos)] = (
|
||||
str(number) if number > 0 else "0"
|
||||
)
|
||||
view.moves.append(pos)
|
||||
if len(view.moves) + len(self.bombs) == 25:
|
||||
await view.EndGame()
|
||||
@@ -93,6 +100,7 @@ class RowButton(discord.ui.Button):
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
class MsView(discord.ui.View):
|
||||
def __init__(self, ctx, options, bomb_count, board):
|
||||
super().__init__(timeout=300)
|
||||
@@ -106,34 +114,36 @@ class MsView(discord.ui.View):
|
||||
self.ctx = ctx
|
||||
self.message = None
|
||||
self.last_interaction = 0
|
||||
|
||||
|
||||
def generate_bombs(self, first_move_pos):
|
||||
"""Generate bombs excluding the first clicked position"""
|
||||
bombpositions = []
|
||||
excluded_positions = [0, 4, 20, 24, first_move_pos]
|
||||
|
||||
excluded_positions = [0, 4, 20, 24, first_move_pos]
|
||||
|
||||
while len(bombpositions) < self.bomb_count:
|
||||
random_index = random.randint(0, 24)
|
||||
if random_index not in bombpositions and random_index not in excluded_positions:
|
||||
if (
|
||||
random_index not in bombpositions
|
||||
and random_index not in excluded_positions
|
||||
):
|
||||
bombpositions.append(random_index)
|
||||
|
||||
|
||||
self.bombs = bombpositions
|
||||
self.bombs_generated = True
|
||||
|
||||
|
||||
for button in self.children:
|
||||
if isinstance(button, RowButton):
|
||||
button.bombs = self.bombs
|
||||
|
||||
|
||||
async def on_timeout(self):
|
||||
for button in self.children:
|
||||
button.disabled = True
|
||||
embed = discord.Embed(
|
||||
title="Minesweeper",
|
||||
description="Game timed out!",
|
||||
color=0xFF0000
|
||||
title="Minesweeper", description="Game timed out!", color=0xFF0000
|
||||
)
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
try:
|
||||
await self.message.edit(embed=embed, view=self)
|
||||
except:
|
||||
@@ -147,14 +157,14 @@ class MsView(discord.ui.View):
|
||||
button.label = "💣"
|
||||
button.style = discord.ButtonStyle.red
|
||||
self.board[self.GetBoardRow(pos)][self.GetBoardPos(pos)] = "💣"
|
||||
|
||||
|
||||
embed = discord.Embed(
|
||||
title="Minesweeper",
|
||||
description="Game Ended. You won!",
|
||||
color=0x00FF00
|
||||
title="Minesweeper", description="Game Ended. You won!", color=0x00FF00
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
|
||||
try:
|
||||
await self.message.edit(embed=embed, view=self)
|
||||
except discord.errors.HTTPException as e:
|
||||
@@ -200,7 +210,7 @@ class MsView(discord.ui.View):
|
||||
|
||||
async def RevealBombs(self, b_id, board):
|
||||
bombemo = "💣"
|
||||
|
||||
|
||||
for button in self.children:
|
||||
button.disabled = True
|
||||
if button.custom_id == b_id:
|
||||
@@ -214,17 +224,17 @@ class MsView(discord.ui.View):
|
||||
button.label = bombemo
|
||||
button.style = discord.ButtonStyle.red
|
||||
pos = int(button.custom_id[5:])
|
||||
self.board[self.GetBoardRow(pos)][
|
||||
self.GetBoardPos(pos)
|
||||
] = bombemo
|
||||
|
||||
self.board[self.GetBoardRow(pos)][self.GetBoardPos(pos)] = bombemo
|
||||
|
||||
embed = discord.Embed(
|
||||
title="Minesweeper",
|
||||
description=f"💥 BOOM! You hit a bomb. Game Over!\n-# gg {self.ctx.author.mention}",
|
||||
color=0xE02B2B
|
||||
color=0xE02B2B,
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
|
||||
try:
|
||||
await self.message.edit(embed=embed, view=self)
|
||||
except discord.errors.HTTPException as e:
|
||||
@@ -234,10 +244,10 @@ class MsView(discord.ui.View):
|
||||
raise
|
||||
self.stop()
|
||||
|
||||
|
||||
def minesweeper_command():
|
||||
@commands.hybrid_command(
|
||||
name="minesweeper",
|
||||
description="Play a buttoned minesweeper mini-game."
|
||||
name="minesweeper", description="Play a buttoned minesweeper mini-game."
|
||||
)
|
||||
async def minesweeper(self, context):
|
||||
board = [["឵឵ "] * 5 for _ in range(5)]
|
||||
@@ -253,12 +263,14 @@ def minesweeper_command():
|
||||
embed = discord.Embed(
|
||||
title="Minesweeper",
|
||||
description=f"💣 Total Bombs: `{bomb_count}`\n\nClick the buttons to reveal the grid. Avoid the bombs!",
|
||||
color=0x7289DA
|
||||
color=0x7289DA,
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
|
||||
view = MsView(context, ExtractBlocks(), bomb_count, board)
|
||||
message = await context.send(embed=embed, view=view)
|
||||
view.message = message
|
||||
|
||||
|
||||
return minesweeper
|
||||
|
||||
@@ -2,6 +2,7 @@ import aiohttp
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
def randomfact_command():
|
||||
@commands.hybrid_command(name="randomfact", description="Get a random fact.")
|
||||
async def randomfact(self, context):
|
||||
@@ -10,7 +11,9 @@ def randomfact_command():
|
||||
description="This command is currently disabled.",
|
||||
color=0xE02B2B,
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
await context.send(embed=embed)
|
||||
|
||||
|
||||
return randomfact
|
||||
|
||||
@@ -2,6 +2,7 @@ import random
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
class RockPaperScissors(discord.ui.Select):
|
||||
def __init__(self) -> None:
|
||||
options = [
|
||||
@@ -34,12 +35,14 @@ class RockPaperScissors(discord.ui.Select):
|
||||
bot_choice_index = choices[bot_choice]
|
||||
|
||||
result_embed = discord.Embed(title="Rock Paper Scissors", color=0x7289DA)
|
||||
result_embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
result_embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
|
||||
winner = (3 + user_choice_index - bot_choice_index) % 3
|
||||
|
||||
|
||||
user_mention = interaction.user.mention
|
||||
|
||||
|
||||
if winner == 0:
|
||||
result_embed.description = f"**That's a draw!** You've chosen {user_choice} and I've chosen {bot_choice}.\n-# gg {user_mention}"
|
||||
result_embed.colour = 0xF59E42
|
||||
@@ -54,11 +57,13 @@ class RockPaperScissors(discord.ui.Select):
|
||||
embed=result_embed, content=None, view=None
|
||||
)
|
||||
|
||||
|
||||
class RockPaperScissorsView(discord.ui.View):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.add_item(RockPaperScissors())
|
||||
|
||||
|
||||
def rps_command():
|
||||
@commands.hybrid_command(
|
||||
name="rps", description="Play the rock paper scissors game against the bot."
|
||||
@@ -68,9 +73,11 @@ def rps_command():
|
||||
embed = discord.Embed(
|
||||
title="Rock Paper Scissors",
|
||||
description="Please make your choice",
|
||||
color=0x7289DA
|
||||
color=0x7289DA,
|
||||
)
|
||||
embed.set_author(
|
||||
name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp"
|
||||
)
|
||||
embed.set_author(name="Fun", icon_url="https://yes.nighty.works/raw/eW5lLm.webp")
|
||||
await context.send(embed=embed, view=view)
|
||||
|
||||
|
||||
return rock_paper_scissors
|
||||
|
||||
Reference in New Issue
Block a user