|
| 1 | +from dependency_injector.wiring import inject, Provide |
| 2 | +from loguru import logger |
| 3 | +from nextcord.ext import commands |
| 4 | + |
| 5 | +from novelsave.containers import Application |
| 6 | +from novelsave.core.services.source import BaseSourceService |
| 7 | +from .. import checks, mfmt |
| 8 | +from ..bot import bot |
| 9 | + |
| 10 | + |
| 11 | +@bot.command() |
| 12 | +async def dm(ctx: commands.Context): |
| 13 | + """Send a direct message to you""" |
| 14 | + await ctx.author.send( |
| 15 | + f"Hello, {ctx.author.name}.\n" |
| 16 | + f" Send `{ctx.clean_prefix}help` to get usage instructions." |
| 17 | + ) |
| 18 | + |
| 19 | + |
| 20 | +@bot.command() |
| 21 | +@commands.check(checks.direct_only) |
| 22 | +@inject |
| 23 | +async def sources( |
| 24 | + ctx: commands.Context, |
| 25 | + *args, |
| 26 | + source_service: BaseSourceService = Provide[Application.services.source_service], |
| 27 | +): |
| 28 | + """List all the sources supported""" |
| 29 | + with ctx.typing(): |
| 30 | + await ctx.send( |
| 31 | + f"The sources currently supported include (v{source_service.current_version}):" |
| 32 | + ) |
| 33 | + |
| 34 | + source_list = "\n".join( |
| 35 | + f"• `{'🔍' if gateway.is_search_capable else ' '}` <{gateway.base_url}>" |
| 36 | + for gateway in sorted( |
| 37 | + source_service.get_novel_sources(), key=lambda g: g.base_url |
| 38 | + ) |
| 39 | + ) |
| 40 | + |
| 41 | + await ctx.send(source_list) |
| 42 | + await ctx.send( |
| 43 | + "You can request a new source by creating an issue at " |
| 44 | + "<https://github.com/mensch272/novelsave/issues/new/choose>" |
| 45 | + ) |
| 46 | + |
| 47 | + |
| 48 | +@sources.error |
| 49 | +async def sources_error(ctx: commands.Context, error: Exception): |
| 50 | + if isinstance(error, commands.CommandError): |
| 51 | + await ctx.send(mfmt.error(str(error))) |
| 52 | + |
| 53 | + logger.exception(repr(error)) |
0 commit comments