Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/better messages #318

Merged
merged 6 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion discord-bot/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BOT_TOKEN=<discord bot token>
DECLARE_GLOBAL_COMMANDS=<testing guild id>
OWNER_IDS=[<your user id>, <other user ids>]
PREFIX="/" # Don't change, this allows for slash commands in DMs
PREFIX="/" # DO NOT LEAVE EMPTY, slash command prefix in DMs

OASST_API_URL="http://localhost:8080" # No trailing '/'
OASST_API_KEY=""
19 changes: 13 additions & 6 deletions discord-bot/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lightbulb
import miru
from bot.settings import Settings
from bot.utils import EMPTY, mention
from bot.utils import mention
from oasst_shared.api_client import OasstApiClient

settings = Settings()
Expand Down Expand Up @@ -34,8 +34,11 @@ async def on_starting(event: hikari.StartingEvent):

bot.d.oasst_api = OasstApiClient(settings.oasst_api_url, settings.oasst_api_key)

# A set of user id's that are currently doing work.
bot.d.currently_working = set()
# A `dict[hikari.Message | None, UUID | None]]` that maps user IDs to (task msg ID, task UUIDs).
# Either both are `None` or both are not `None`.
# If both are `None`, the user is not currently selecting a task.
# TODO: Grow this on startup so we don't have to re-allocate memory every time it needs to grow
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in general not necessary (premature optimization).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it's just a reminder for the future. Should I change "TODO" to some other word?

bot.d.currently_working = {}


@bot.listen()
Expand All @@ -50,13 +53,13 @@ async def _send_error_embed(
) -> None:
ctx.command
embed = hikari.Embed(
title=f"`{exception.__class__.__name__}` Error{f' in `{ctx.command.name}`' if ctx.command else '' }",
title=f"`{exception.__class__.__name__}` Error{f' in `/{ctx.command.name}`' if ctx.command else '' }",
description=content,
color=0xFF0000,
timestamp=datetime.now().astimezone(),
).set_author(name=ctx.author.username, url=str(ctx.author.avatar_url))

await ctx.respond(EMPTY, embed=embed)
await ctx.respond(embed=embed)


@bot.listen(lightbulb.CommandErrorEvent)
Expand All @@ -65,6 +68,8 @@ async def on_error(event: lightbulb.CommandErrorEvent) -> None:
# Unwrap the exception to get the original cause
exc = event.exception.__cause__ or event.exception
ctx = event.context
if not ctx.bot.rest.is_alive:
return

if isinstance(event.exception, lightbulb.CommandInvocationError):
if not event.context.command:
Expand Down Expand Up @@ -114,6 +119,8 @@ async def on_error(event: lightbulb.CommandErrorEvent) -> None:
ctx,
)
elif isinstance(exc, lightbulb.errors.MissingRequiredAttachment):
await _send_error_embed("Not enough attachemnts were supplied to this command.", exc, ctx)
await _send_error_embed("Not enough attachments were supplied to this command.", exc, ctx)
elif isinstance(exc, lightbulb.errors.CommandNotFound):
await ctx.respond(f"`/{exc.invoked_with}` is not a valid command. Use `/help` to see a list of commands.")
else:
raise exc
1 change: 0 additions & 1 deletion discord-bot/bot/extensions/guild_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ async def log_channel(ctx: lightbulb.SlashContext) -> None:

# if the bot's permissions for this channel don't contain SEND_MESSAGE
# This will also filter out categories and voice channels
print(permissions_in(ch, own_member) & hikari.Permissions.SEND_MESSAGES)
AlexanderHott marked this conversation as resolved.
Show resolved Hide resolved
if not permissions_in(ch, own_member) & hikari.Permissions.SEND_MESSAGES:
await ctx.respond(f"I don't have permission to send messages in {ch.mention}.")
return
Expand Down
5 changes: 2 additions & 3 deletions discord-bot/bot/extensions/text_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import miru
from aiosqlite import Connection
from bot.db.schemas import GuildSettings
from bot.utils import EMPTY
from loguru import logger

plugin = lightbulb.Plugin(
Expand Down Expand Up @@ -74,7 +73,7 @@ async def callback(self, context: miru.ModalContext) -> None:
)
channel = await context.bot.rest.fetch_channel(guild_settings.log_channel_id)
assert isinstance(channel, hikari.TextableChannel)
await channel.send(EMPTY, embed=embed)
await channel.send(embed=embed)


class LabelSelect(miru.View):
Expand Down Expand Up @@ -164,7 +163,7 @@ async def label_message_text(ctx: lightbulb.MessageContext):
msg.content,
timeout=60,
)
resp = await ctx.respond(EMPTY, embed=embed, components=label_select_view, flags=hikari.MessageFlag.EPHEMERAL)
resp = await ctx.respond(embed=embed, components=label_select_view, flags=hikari.MessageFlag.EPHEMERAL)

await label_select_view.start(await resp.message())
await label_select_view.wait()
Expand Down