-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae20f61
commit 75e8b69
Showing
8 changed files
with
182 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
"""Entrypoint script to load extensions and start the client.""" | ||
import hikari | ||
from hikari import Activity, ActivityType | ||
|
||
from src.bot import bot | ||
|
||
if __name__ == "__main__": | ||
bot.run(activity=hikari.Activity(name="Webgroup issues", type=hikari.ActivityType.WATCHING)) | ||
bot.run(activity=Activity(name="Webgroup issues", type=ActivityType.WATCHING)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from datetime import datetime | ||
|
||
import arc | ||
|
||
start_time = datetime.now() | ||
|
||
plugin = arc.GatewayPlugin("Blockbot Uptime") | ||
|
||
@plugin.include | ||
@arc.slash_command("uptime", "Show formatted uptime of Blockbot") | ||
async def uptime(ctx): | ||
up_time = datetime.now() - start_time | ||
d = up_time.days | ||
h, ms = divmod(up_time.seconds, 3600) | ||
m, s = divmod(ms, 60) | ||
|
||
format = lambda val, str: f"{val} {str}{'s' if val != 1 else ''}" | ||
message_parts = [(d, "day"), (h, "hour"), (m, "minute"), (s, "second")] | ||
formatted_parts = [format(val, str) for val, str in message_parts if val] | ||
|
||
await ctx.respond(f"Uptime: **{', '.join(formatted_parts)}**") | ||
|
||
@arc.loader | ||
def loader(client): | ||
client.add_plugin(plugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import arc | ||
import hikari | ||
|
||
from src.utils import role_mention | ||
from src.config import ROLE_IDS | ||
|
||
plugin = arc.GatewayPlugin("User Roles") | ||
|
||
role = plugin.include_slash_group("role", "Get/remove assignable roles.") | ||
|
||
ROLE_CHOICES = [hikari.CommandChoice(name=name, value=value) for name,value in ROLE_IDS] # ROLE_IDS <- ROLE_CHOICES into CommandChoice-es; thus ROLE_CHOICES can just store easy-to-update tuples | ||
|
||
@role.include | ||
@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)] | ||
) -> 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.", | ||
flags=hikari.MessageFlag.EPHEMERAL | ||
) | ||
|
||
await ctx.client.rest.add_role_to_member( | ||
ctx.guild_id, ctx.author, int(role), reason="Self-service role." | ||
) | ||
await ctx.respond( | ||
f"Done! Added {role_mention(role)} to your roles.", | ||
flags=hikari.MessageFlag.EPHEMERAL | ||
) | ||
|
||
@role.include | ||
@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)] | ||
) -> None: | ||
assert ctx.guild_id | ||
assert ctx.member | ||
|
||
if int(role) not in ctx.member.role_ids: | ||
return await ctx.respond( | ||
f"You don't have the {role_mention(role)} role.", | ||
flags=hikari.MessageFlag.EPHEMERAL | ||
) | ||
|
||
await ctx.client.rest.remove_role_from_member( | ||
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.", | ||
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) | ||
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.", | ||
flags=hikari.MessageFlag.EPHEMERAL | ||
) | ||
|
||
if isinstance(exc, hikari.NotFoundError): | ||
return await ctx.respond( | ||
f"❌ Blockbot can't find that role.", | ||
flags=hikari.MessageFlag.EPHEMERAL | ||
) | ||
|
||
raise exc | ||
|
||
@arc.loader | ||
def loader(client: arc.GatewayClient) -> None: | ||
client.add_plugin(plugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import hikari | ||
from arc import GatewayClient | ||
|
||
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_id: hikari.Snowflake | int | str): | ||
return f"<@&{role_id}>" |