Skip to content

Commit

Permalink
Revert strings to double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
JedHazaymeh committed Feb 1, 2024
1 parent 5063291 commit cb1d77f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from src.bot import bot

if __name__ == '__main__':
bot.run(activity=Activity(name='Webgroup issues', type=ActivityType.WATCHING))
if __name__ == "__main__":
bot.run(activity=Activity(name="Webgroup issues", type=ActivityType.WATCHING))
14 changes: 7 additions & 7 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
from src.config import DEBUG, TOKEN

if TOKEN is None:
print('TOKEN environment variable not set. Exiting.')
print("TOKEN environment variable not set. Exiting.")
sys.exit(1)

bot = hikari.GatewayBot(
token=TOKEN,
banner=None,
intents=hikari.Intents.ALL_UNPRIVILEGED | hikari.Intents.MESSAGE_CONTENT,
logs='DEBUG' if DEBUG else 'INFO',
logs="DEBUG" if DEBUG else "INFO",
)

logging.info(f'Debug mode is {DEBUG}; You can safely ignore this.')
logging.info(f"Debug mode is {DEBUG}; You can safely ignore this.")

client = arc.GatewayClient(bot, is_dm_enabled=False)
client.load_extensions_from('./src/extensions/')
client.load_extensions_from("./src/extensions/")

@client.set_error_handler
async def error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
if DEBUG:
message = f'```{exc}```'
message = f"```{exc}```"
else:
message = 'If this persists, create an issue at <https://webgroup-issues.redbrick.dcu.ie/>.'
message = "If this persists, create an issue at <https://webgroup-issues.redbrick.dcu.ie/>."

await ctx.respond(f'❌ Blockbot encountered an unhandled exception. {message}')
await ctx.respond(f"❌ Blockbot encountered an unhandled exception. {message}")
logging.error(exc)

raise exc
6 changes: 3 additions & 3 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

load_dotenv()

TOKEN = os.environ.get('TOKEN') # required
DEBUG = os.environ.get('DEBUG', False)
TOKEN = os.environ.get("TOKEN") # required
DEBUG = os.environ.get("DEBUG", False)

CHANNEL_IDS = {
'lobby': '627542044390457350'
"lobby": "627542044390457350"
}
12 changes: 6 additions & 6 deletions src/extensions/boosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from src.config import CHANNEL_IDS
from src.utils import get_guild

plugin = arc.GatewayPlugin(name='Boosts')
plugin = arc.GatewayPlugin(name="Boosts")

BOOST_TIERS: list[hikari.MessageType] = [
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1,
Expand All @@ -24,14 +24,14 @@ def build_boost_message(
) -> str:
assert message_type in BOOST_MESSAGE_TYPES

base_message = f'{booster_user.display_name} just boosted the server'
multiple_boosts_message = f' **{number_of_boosts}** times' if number_of_boosts else ''
base_message = f"{booster_user.display_name} just boosted the server"
multiple_boosts_message = f" **{number_of_boosts}** times" if number_of_boosts else ""

message = base_message + multiple_boosts_message + '!'
message = base_message + multiple_boosts_message + "!"

if (message_type in BOOST_TIERS):
count = BOOST_TIERS.index(message_type)
message += f'\n{guild.name} has reached **Level {count}!**'
message += f"\n{guild.name} has reached **Level {count}!**"

return message

Expand All @@ -48,7 +48,7 @@ async def on_message(event: hikari.GuildMessageCreateEvent):
guild=await get_guild(plugin.client, event)
)

await plugin.client.rest.create_message(CHANNEL_IDS['lobby'], content=message)
await plugin.client.rest.create_message(CHANNEL_IDS["lobby"], content=message)


@arc.loader
Expand Down
46 changes: 23 additions & 23 deletions src/extensions/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,60 @@
import arc
import hikari

plugin = arc.GatewayPlugin(name='Hello World')
plugin = arc.GatewayPlugin(name="Hello World")

@plugin.include
@arc.slash_command('hello', 'Say hello!')
@arc.slash_command("hello", "Say hello!")
async def hello(ctx: arc.GatewayContext) -> None:
"""A simple hello world command"""
await ctx.respond('Hello from hikari!')
await ctx.respond("Hello from hikari!")

group = plugin.include_slash_group('base_command', 'A base command, to expand on')
group = plugin.include_slash_group("base_command", "A base command, to expand on")

@group.include
@arc.slash_subcommand('sub_command', 'A sub command, to expand on')
@arc.slash_subcommand("sub_command", "A sub command, to expand on")
async def sub_command(ctx: arc.GatewayContext) -> None:
"""A simple sub command"""
await ctx.respond('Hello, world! This is a sub command')
await ctx.respond("Hello, world! This is a sub command")

@plugin.include
@arc.slash_command('options', 'A command with options')
@arc.slash_command("options", "A command with options")
async def options(
ctx: arc.GatewayContext,
option_str: arc.Option[str, arc.StrParams('A string option')],
option_int: arc.Option[int, arc.IntParams('An integer option')],
option_attachment: arc.Option[hikari.Attachment, arc.AttachmentParams('An attachment option')],
option_str: arc.Option[str, arc.StrParams("A string option")],
option_int: arc.Option[int, arc.IntParams("An integer option")],
option_attachment: arc.Option[hikari.Attachment, arc.AttachmentParams("An attachment option")],
) -> None:
"""A command with lots of options"""
embed = hikari.Embed(
title='There are a lot of options here',
description='Maybe too many',
title="There are a lot of options here",
description="Maybe too many",
colour=0x5865F2
)
embed.set_image(option_attachment)
embed.add_field('String option', option_str, inline=False)
embed.add_field('Integer option', str(option_int), inline=False)
embed.add_field("String option", option_str, inline=False)
embed.add_field("Integer option", str(option_int), inline=False)
await ctx.respond(embed=embed)

@plugin.include
@arc.slash_command('components', 'A command with components')
@arc.slash_command("components", "A command with components")
async def components(ctx: arc.GatewayContext) -> None:
"""A command with components"""
builder = ctx.client.rest.build_message_action_row()
select_menu = builder.add_text_menu(
'select_me',
placeholder='I wonder what this does',
"select_me",
placeholder="I wonder what this does",
min_values=1,
max_values=2
)
for opt in ('Select me!', 'No, select me!', 'Select me too!'):
for opt in ("Select me!", "No, select me!", "Select me too!"):
select_menu.add_option(opt, opt)

button = ctx.client.rest.build_message_action_row().add_interactive_button(
hikari.ButtonStyle.PRIMARY, 'click_me', label='Click me!'
hikari.ButtonStyle.PRIMARY, "click_me", label="Click me!"
)

await ctx.respond('Here are some components', components=[builder, button])
await ctx.respond("Here are some components", components=[builder, button])

@plugin.listen()
async def on_interaction(event: hikari.InteractionCreateEvent) -> None:
Expand All @@ -68,12 +68,12 @@ async def on_interaction(event: hikari.InteractionCreateEvent) -> None:
if not isinstance(interaction, hikari.ComponentInteraction):
return

if interaction.custom_id == 'click_me':
if interaction.custom_id == "click_me":
await interaction.create_initial_response(
hikari.ResponseType.MESSAGE_CREATE,
f'{interaction.user.mention}, you clicked me!'
f"{interaction.user.mention}, you clicked me!"
)
elif interaction.custom_id == 'select_me':
elif interaction.custom_id == "select_me":
await interaction.create_initial_response(
hikari.ResponseType.MESSAGE_CREATE,
f"{interaction.user.mention}, you selected {' '.join(interaction.values)}",
Expand Down
32 changes: 16 additions & 16 deletions src/extensions/user_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@

from src.utils import role_mention

plugin = arc.GatewayPlugin(name='User Roles')
plugin = arc.GatewayPlugin(name="User Roles")

role = plugin.include_slash_group('role', 'Get/remove assignable roles.')
role = plugin.include_slash_group("role", "Get/remove assignable roles.")

role_choices = [
hikari.CommandChoice(name='Webgroup', value='1166751688598761583'),
hikari.CommandChoice(name='Gamez', value='1089204642241581139'),
hikari.CommandChoice(name='Croomer', value='1172696659097047050'),
hikari.CommandChoice(name="Webgroup", value="1166751688598761583"),
hikari.CommandChoice(name="Gamez", value="1089204642241581139"),
hikari.CommandChoice(name="Croomer", value="1172696659097047050"),
]

@role.include
@arc.slash_subcommand('add', 'Add an assignable role.')
@arc.slash_subcommand("add", "Add an assignable role.")
async def add_role(
ctx: arc.GatewayContext,
role: arc.Option[str, arc.StrParams('The role to add.', choices=role_choices)]
role: arc.Option[str, arc.StrParams("The role to add.", choices=role_choices)]
) -> None:
assert ctx.guild_id
assert ctx.member

if int(role) in ctx.member.role_ids:
return await ctx.respond(
f'You already have the {role_mention(role)} role.',
f"You already have the {role_mention(role)} role.",
flags=hikari.MessageFlag.EPHEMERAL
)

await ctx.client.rest.add_role_to_member(
ctx.guild_id, ctx.author, int(role), reason='Self-service role.'
ctx.guild_id, ctx.author, int(role), reason="Self-service role."
)
await ctx.respond(
f'Done! Added {role_mention(role)} to your roles.',
f"Done! Added {role_mention(role)} to your roles.",
flags=hikari.MessageFlag.EPHEMERAL
)

@role.include
@arc.slash_subcommand('remove', 'Remove an assignable role.')
@arc.slash_subcommand("remove", "Remove an assignable role.")
async def remove_role(
ctx: arc.GatewayContext,
role: arc.Option[str, arc.StrParams('The role to remove.', choices=role_choices)]
role: arc.Option[str, arc.StrParams("The role to remove.", choices=role_choices)]
) -> None:
assert ctx.guild_id
assert ctx.member
Expand All @@ -52,21 +52,21 @@ async def remove_role(
)

await ctx.client.rest.remove_role_from_member(
ctx.guild_id, ctx.author, int(role), reason=f'{ctx.author} removed role.'
ctx.guild_id, ctx.author, int(role), reason=f"{ctx.author} removed role."
)
await ctx.respond(
f'Done! Removed {role_mention(role)} from your roles.',
f"Done! Removed {role_mention(role)} from your roles.",
flags=hikari.MessageFlag.EPHEMERAL
)

@role.set_error_handler
async def role_error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
role = ctx.get_option('role', arc.OptionType.STRING)
role = ctx.get_option("role", arc.OptionType.STRING)
assert role is not None

if isinstance(exc, hikari.ForbiddenError):
return await ctx.respond(
f'❌ Blockbot is not permitted to self-service the {role_mention(role)} role.',
f"❌ Blockbot is not permitted to self-service the {role_mention(role)} role.",
flags=hikari.MessageFlag.EPHEMERAL
)

Expand Down
2 changes: 1 addition & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
async def get_guild(client: GatewayClient, event: hikari.GuildMessageCreateEvent):
return event.get_guild() or await client.rest.fetch_guild(event.guild_id)

def role_mention(role: hikari.Snowflake | str): return f'<@&{role}>'
def role_mention(role: hikari.Snowflake | str): return f"<@&{role}>"

0 comments on commit cb1d77f

Please sign in to comment.