diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 10578122..271c11c6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,7 +57,8 @@ repos: - id: next-lint-website name: Lint website files: ^website/ + exclude: ^website/node_modules/ types_or: [javascript, jsx, ts, tsx] - language: system + language: node pass_filenames: false - entry: bash -c "cd website && npm install && npm run lint" + entry: website/next-lint.js diff --git a/README.md b/README.md index 369724c1..e0ea65f1 100644 --- a/README.md +++ b/README.md @@ -136,3 +136,9 @@ In case you haven't done this, have already committed, and CI is failing, you ca ### Deployment Upon making a release on GitHub, all docker images are automatically built and pushed to ghcr.io. The docker images are tagged with the release version, and the `latest` tag. Further, the ansible playbook in `ansible/dev.yaml` is run to automatically deploy the built release to the dev machine. + +### Problems and Solutions + +- **I am on Ubuntu and getting `ERROR: The Compose file is invalid because:Service backend has neither an image nor a build context specified. At least one must be provided.`** + + Make sure you have an up-to-date version of docker installed, and also install `docker-compose-plugin`. See [here](https://github.com/LAION-AI/Open-Assistant/issues/208) for more details. diff --git a/discord-bot/bot/bot.py b/discord-bot/bot/bot.py index a305946f..b2a2eb25 100644 --- a/discord-bot/bot/bot.py +++ b/discord-bot/bot/bot.py @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- """Bot logic.""" +from datetime import datetime + import aiosqlite import hikari import lightbulb import miru from bot.api_client import OasstApiClient from bot.settings import Settings +from bot.utils import EMPTY, mention settings = Settings() @@ -38,3 +41,77 @@ async def on_stopping(event: hikari.StoppingEvent): """Cleanup.""" await bot.d.db.close() await bot.d.oasst_api.close() + + +async def _send_error_embed( + content: str, exception: lightbulb.errors.LightbulbError | BaseException, ctx: lightbulb.Context +) -> None: + ctx.command + embed = hikari.Embed( + 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) + + +@bot.listen(lightbulb.CommandErrorEvent) +async def on_error(event: lightbulb.CommandErrorEvent) -> None: + """Error handler for the bot.""" + # Unwrap the exception to get the original cause + exc = event.exception.__cause__ or event.exception + ctx = event.context + + if isinstance(event.exception, lightbulb.CommandInvocationError): + if not event.context.command: + await _send_error_embed("Something went wrong", exc, ctx) + else: + await _send_error_embed( + f"Something went wrong during invocation of command `{event.context.command.name}`.", exc, ctx + ) + + raise event.exception + + # Not an owner + if isinstance(exc, lightbulb.NotOwner): + await _send_error_embed("You are not the owner of this bot.", exc, ctx) + # Command is on cooldown + elif isinstance(exc, lightbulb.CommandIsOnCooldown): + await _send_error_embed(f"This command is on cooldown. Retry in `{exc.retry_after:.2f}` seconds.", exc, ctx) + # Missing permissions + elif isinstance(exc, lightbulb.errors.MissingRequiredPermission): + await _send_error_embed( + f"You do not have permission to use this command. Missing permissions: {exc.missing_perms}", exc, ctx + ) + # Missing roles + elif isinstance(exc, lightbulb.errors.MissingRequiredRole): + assert event.context.guild_id is not None # Roles only exist in guilds + await _send_error_embed( + f"You do not have the correct role to use this command. Missing role(s): {[mention(r, 'role') for r in exc.missing_roles]}", + exc, + ctx, + ) + # Only a guild command + elif isinstance(exc, lightbulb.errors.OnlyInGuild): + await _send_error_embed("This command can only be run in servers.", exc, ctx) + # Only a DM command + elif isinstance(exc, lightbulb.errors.OnlyInDM): + await _send_error_embed("This command can only be run in DMs.", exc, ctx) + # Not enough arguments + elif isinstance(exc, lightbulb.errors.NotEnoughArguments): + await _send_error_embed( + f"Not enough arguments were supplied to the command. {[opt.name for opt in exc.missing_options]}", exc, ctx + ) + # Bot missing permission + elif isinstance(exc, lightbulb.errors.BotMissingRequiredPermission): + await _send_error_embed( + f"The bot does not have the correct permission(s) to execute this command. Missing permissions: {exc.missing_perms}", + exc, + ctx, + ) + elif isinstance(exc, lightbulb.errors.MissingRequiredAttachment): + await _send_error_embed("Not enough attachemnts were supplied to this command.", exc, ctx) + else: + raise exc diff --git a/website/next-lint.js b/website/next-lint.js new file mode 100755 index 00000000..0b3a5c90 --- /dev/null +++ b/website/next-lint.js @@ -0,0 +1,24 @@ +#!/usr/bin/env node +const { spawnSync } = require("child_process"); +async function npmLint() { + const spawnOption = { + shell: true, + env: process.env, + stdio: "inherit", + cwd: "./website", + }; + let npmInstall; + let npmRunLint; + try { + npmInstall = await spawnSync("npm", ["install"], spawnOption); + if (npmInstall.status !== 0) { + process.exit(npmInstall.status); + } + npmRunLint = await spawnSync("npm", ["run lint"], spawnOption); + process.exit(npmRunLint.status); + } catch (error) { + console.error(error); + process.exit(1); + } +} +npmLint(); diff --git a/website/src/components/Footer.tsx b/website/src/components/Footer.tsx index a07ba24a..5c774398 100644 --- a/website/src/components/Footer.tsx +++ b/website/src/components/Footer.tsx @@ -20,24 +20,21 @@ export function Footer() {