Fix code style issues with Black

This commit is contained in:
Lint Action
2021-09-05 21:34:20 +00:00
parent a23dae8604
commit 7513c2138f
108 changed files with 5369 additions and 4858 deletions

View File

@@ -6,13 +6,12 @@ import discord
class Bot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=commands.when_mentioned_or('$'),
intents=discord.Intents(guilds=True, messages=True)
command_prefix=commands.when_mentioned_or("$"), intents=discord.Intents(guilds=True, messages=True)
)
async def on_ready(self):
print(f'Logged in as {self.user} (ID: {self.user.id})')
print('------')
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
# Define a simple View that gives us a confirmation menu
@@ -24,16 +23,16 @@ class Confirm(discord.ui.View):
# When the confirm button is pressed, set the inner value to `True` and
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label='Confirm', style=discord.ButtonStyle.green)
@discord.ui.button(label="Confirm", style=discord.ButtonStyle.green)
async def confirm(self, button: discord.ui.Button, interaction: discord.Interaction):
await interaction.response.send_message('Confirming', ephemeral=True)
await interaction.response.send_message("Confirming", ephemeral=True)
self.value = True
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label='Cancel', style=discord.ButtonStyle.grey)
@discord.ui.button(label="Cancel", style=discord.ButtonStyle.grey)
async def cancel(self, button: discord.ui.Button, interaction: discord.Interaction):
await interaction.response.send_message('Cancelling', ephemeral=True)
await interaction.response.send_message("Cancelling", ephemeral=True)
self.value = False
self.stop()
@@ -46,15 +45,15 @@ async def ask(ctx: commands.Context):
"""Asks the user a question to confirm something."""
# We create the view and assign it to a variable so we can wait for it later.
view = Confirm()
await ctx.send('Do you want to continue?', view=view)
await ctx.send("Do you want to continue?", view=view)
# Wait for the View to stop listening for input...
await view.wait()
if view.value is None:
print('Timed out...')
print("Timed out...")
elif view.value:
print('Confirmed...')
print("Confirmed...")
else:
print('Cancelled...')
print("Cancelled...")
bot.run('token')
bot.run("token")

View File

@@ -6,13 +6,12 @@ import discord
class CounterBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=commands.when_mentioned_or('$'),
intents=discord.Intents(guilds=True, messages=True)
command_prefix=commands.when_mentioned_or("$"), intents=discord.Intents(guilds=True, messages=True)
)
async def on_ready(self):
print(f'Logged in as {self.user} (ID: {self.user.id})')
print('------')
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
# Define a simple View that gives us a counter button
@@ -22,7 +21,7 @@ class Counter(discord.ui.View):
# When pressed, this increments the number displayed until it hits 5.
# When it hits 5, the counter button is disabled and it turns green.
# note: The name of the function does not matter to the library
@discord.ui.button(label='0', style=discord.ButtonStyle.red)
@discord.ui.button(label="0", style=discord.ButtonStyle.red)
async def count(self, button: discord.ui.Button, interaction: discord.Interaction):
number = int(button.label) if button.label else 0
if number + 1 >= 5:
@@ -40,7 +39,7 @@ bot = CounterBot()
@bot.command()
async def counter(ctx: commands.Context):
"""Starts a counter for pressing."""
await ctx.send('Press!', view=Counter())
await ctx.send("Press!", view=Counter())
bot.run('token')
bot.run("token")

View File

@@ -9,22 +9,22 @@ class Dropdown(discord.ui.Select):
# Set the options that will be presented inside the dropdown
options = [
discord.SelectOption(label='Red', description='Your favourite colour is red', emoji='🟥'),
discord.SelectOption(label='Green', description='Your favourite colour is green', emoji='🟩'),
discord.SelectOption(label='Blue', description='Your favourite colour is blue', emoji='🟦')
discord.SelectOption(label="Red", description="Your favourite colour is red", emoji="🟥"),
discord.SelectOption(label="Green", description="Your favourite colour is green", emoji="🟩"),
discord.SelectOption(label="Blue", description="Your favourite colour is blue", emoji="🟦"),
]
# The placeholder is what will be shown when no option is chosen
# The min and max values indicate we can only pick one of the three options
# The options parameter defines the dropdown options. We defined this above
super().__init__(placeholder='Choose your favourite colour...', min_values=1, max_values=1, options=options)
super().__init__(placeholder="Choose your favourite colour...", min_values=1, max_values=1, options=options)
async def callback(self, interaction: discord.Interaction):
# Use the interaction object to send a response message containing
# the user's favourite colour or choice. The self object refers to the
# Select object, and the values attribute gets a list of the user's
# Select object, and the values attribute gets a list of the user's
# selected options. We only want the first one.
await interaction.response.send_message(f'Your favourite colour is {self.values[0]}')
await interaction.response.send_message(f"Your favourite colour is {self.values[0]}")
class DropdownView(discord.ui.View):
@@ -38,15 +38,14 @@ class DropdownView(discord.ui.View):
class Bot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=commands.when_mentioned_or('$'),
intents=discord.Intents(guilds=True, messages=True)
command_prefix=commands.when_mentioned_or("$"), intents=discord.Intents(guilds=True, messages=True)
)
async def on_ready(self):
print(f'Logged in as {self.user} (ID: {self.user.id})')
print('------')
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
bot = Bot()
@@ -58,7 +57,7 @@ async def colour(ctx):
view = DropdownView()
# Sending a message containing our view
await ctx.send('Pick your favourite colour:', view=view)
await ctx.send("Pick your favourite colour:", view=view)
bot.run('token')
bot.run("token")

View File

@@ -2,16 +2,17 @@ from discord.ext import commands
import discord
class EphemeralCounterBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=commands.when_mentioned_or('$'),
intents=discord.Intents(guilds=True, messages=True)
command_prefix=commands.when_mentioned_or("$"), intents=discord.Intents(guilds=True, messages=True)
)
async def on_ready(self):
print(f'Logged in as {self.user} (ID: {self.user.id})')
print('------')
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
# Define a simple View that gives us a counter button
class Counter(discord.ui.View):
@@ -20,7 +21,7 @@ class Counter(discord.ui.View):
# When pressed, this increments the number displayed until it hits 5.
# When it hits 5, the counter button is disabled and it turns green.
# note: The name of the function does not matter to the library
@discord.ui.button(label='0', style=discord.ButtonStyle.red)
@discord.ui.button(label="0", style=discord.ButtonStyle.red)
async def count(self, button: discord.ui.Button, interaction: discord.Interaction):
number = int(button.label) if button.label else 0
if number + 1 >= 5:
@@ -31,20 +32,24 @@ class Counter(discord.ui.View):
# Make sure to update the message with our updated selves
await interaction.response.edit_message(view=self)
# Define a View that will give us our own personal counter button
class EphemeralCounter(discord.ui.View):
# When this button is pressed, it will respond with a Counter view that will
# give the button presser their own personal button they can press 5 times.
@discord.ui.button(label='Click', style=discord.ButtonStyle.blurple)
@discord.ui.button(label="Click", style=discord.ButtonStyle.blurple)
async def receive(self, button: discord.ui.Button, interaction: discord.Interaction):
# ephemeral=True makes the message hidden from everyone except the button presser
await interaction.response.send_message('Enjoy!', view=Counter(), ephemeral=True)
await interaction.response.send_message("Enjoy!", view=Counter(), ephemeral=True)
bot = EphemeralCounterBot()
@bot.command()
async def counter(ctx: commands.Context):
"""Starts a counter for pressing."""
await ctx.send('Press!', view=EphemeralCounter())
await ctx.send("Press!", view=EphemeralCounter())
bot.run('token')
bot.run("token")

View File

@@ -3,16 +3,16 @@ from discord.ext import commands
import discord
from urllib.parse import quote_plus
class GoogleBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=commands.when_mentioned_or('$'),
intents=discord.Intents(guilds=True, messages=True)
command_prefix=commands.when_mentioned_or("$"), intents=discord.Intents(guilds=True, messages=True)
)
async def on_ready(self):
print(f'Logged in as {self.user} (ID: {self.user.id})')
print('------')
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
# Define a simple View that gives us a google link button.
@@ -22,12 +22,12 @@ class Google(discord.ui.View):
super().__init__()
# we need to quote the query string to make a valid url. Discord will raise an error if it isn't valid.
query = quote_plus(query)
url = f'https://www.google.com/search?q={query}'
url = f"https://www.google.com/search?q={query}"
# Link buttons cannot be made with the decorator
# Therefore we have to manually create one.
# We add the quoted url to the button, and add the button to the view.
self.add_item(discord.ui.Button(label='Click Here', url=url))
self.add_item(discord.ui.Button(label="Click Here", url=url))
bot = GoogleBot()
@@ -36,7 +36,7 @@ bot = GoogleBot()
@bot.command()
async def google(ctx: commands.Context, *, query: str):
"""Returns a google link for a query"""
await ctx.send(f'Google Result for: `{query}`', view=Google(query))
await ctx.send(f"Google Result for: `{query}`", view=Google(query))
bot.run()

View File

@@ -14,24 +14,23 @@ class PersistentView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
@discord.ui.button(label='Green', style=discord.ButtonStyle.green, custom_id='persistent_view:green')
@discord.ui.button(label="Green", style=discord.ButtonStyle.green, custom_id="persistent_view:green")
async def green(self, button: discord.ui.Button, interaction: discord.Interaction):
await interaction.response.send_message('This is green.', ephemeral=True)
await interaction.response.send_message("This is green.", ephemeral=True)
@discord.ui.button(label='Red', style=discord.ButtonStyle.red, custom_id='persistent_view:red')
@discord.ui.button(label="Red", style=discord.ButtonStyle.red, custom_id="persistent_view:red")
async def red(self, button: discord.ui.Button, interaction: discord.Interaction):
await interaction.response.send_message('This is red.', ephemeral=True)
await interaction.response.send_message("This is red.", ephemeral=True)
@discord.ui.button(label='Grey', style=discord.ButtonStyle.grey, custom_id='persistent_view:grey')
@discord.ui.button(label="Grey", style=discord.ButtonStyle.grey, custom_id="persistent_view:grey")
async def grey(self, button: discord.ui.Button, interaction: discord.Interaction):
await interaction.response.send_message('This is grey.', ephemeral=True)
await interaction.response.send_message("This is grey.", ephemeral=True)
class PersistentViewBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=commands.when_mentioned_or('$'),
intents=discord.Intents(guilds=True, messages=True)
command_prefix=commands.when_mentioned_or("$"), intents=discord.Intents(guilds=True, messages=True)
)
self.persistent_views_added = False
@@ -46,8 +45,8 @@ class PersistentViewBot(commands.Bot):
self.add_view(PersistentView())
self.persistent_views_added = True
print(f'Logged in as {self.user} (ID: {self.user.id})')
print('------')
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
bot = PersistentViewBot()
@@ -64,4 +63,4 @@ async def prepare(ctx: commands.Context):
await ctx.send("What's your favourite colour?", view=PersistentView())
bot.run('token')
bot.run("token")

View File

@@ -5,13 +5,13 @@ import discord
# Defines a custom button that contains the logic of the game.
# The ['TicTacToe'] bit is for type hinting purposes to tell your IDE or linter
# what the type of `self.view` is. It is not required.
class TicTacToeButton(discord.ui.Button['TicTacToe']):
class TicTacToeButton(discord.ui.Button["TicTacToe"]):
def __init__(self, x: int, y: int):
# A label is required, but we don't need one so a zero-width space is used
# The row parameter tells the View which row to place the button under.
# A View can only contain up to 5 rows -- each row can only have 5 buttons.
# Since a Tic Tac Toe grid is 3x3 that means we have 3 rows and 3 columns.
super().__init__(style=discord.ButtonStyle.secondary, label='\u200b', row=y)
super().__init__(style=discord.ButtonStyle.secondary, label="\u200b", row=y)
self.x = x
self.y = y
@@ -26,14 +26,14 @@ class TicTacToeButton(discord.ui.Button['TicTacToe']):
if view.current_player == view.X:
self.style = discord.ButtonStyle.danger
self.label = 'X'
self.label = "X"
self.disabled = True
view.board[self.y][self.x] = view.X
view.current_player = view.O
content = "It is now O's turn"
else:
self.style = discord.ButtonStyle.success
self.label = 'O'
self.label = "O"
self.disabled = True
view.board[self.y][self.x] = view.O
view.current_player = view.X
@@ -42,9 +42,9 @@ class TicTacToeButton(discord.ui.Button['TicTacToe']):
winner = view.check_board_winner()
if winner is not None:
if winner == view.X:
content = 'X won!'
content = "X won!"
elif winner == view.O:
content = 'O won!'
content = "O won!"
else:
content = "It's a tie!"
@@ -121,13 +121,12 @@ class TicTacToe(discord.ui.View):
class TicTacToeBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=commands.when_mentioned_or('$'),
intents=discord.Intents(guilds=True, messages=True)
command_prefix=commands.when_mentioned_or("$"), intents=discord.Intents(guilds=True, messages=True)
)
async def on_ready(self):
print(f'Logged in as {self.user} (ID: {self.user.id})')
print('------')
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
bot = TicTacToeBot()
@@ -136,7 +135,7 @@ bot = TicTacToeBot()
@bot.command()
async def tic(ctx: commands.Context):
"""Starts a tic-tac-toe game with yourself."""
await ctx.send('Tic Tac Toe: X goes first', view=TicTacToe())
await ctx.send("Tic Tac Toe: X goes first", view=TicTacToe())
bot.run('token')
bot.run("token")