Compare commits
No commits in common. "1dfa03bc175d259b01ebe26ee80fa0fcce1aac5d" and "663abf56bca44f966538bcfeb6e32f0775020f17" have entirely different histories.
1dfa03bc17
...
663abf56bc
2 changed files with 53 additions and 57 deletions
|
|
@ -128,10 +128,7 @@ class BaseModel(peewee.Model):
|
|||
|
||||
@classmethod
|
||||
def bulk_update(
|
||||
cls,
|
||||
model_list: Iterable[Self],
|
||||
fields: Iterable[peewee.Field | str],
|
||||
batch_size: int | None = None,
|
||||
cls, model_list: Iterable[Self], fields: Iterable, batch_size: int | None = None
|
||||
):
|
||||
def lazy(models: Iterable[Self]) -> Iterable[Self]:
|
||||
now = datetime.now()
|
||||
|
|
|
|||
105
src/bot/main.py
105
src/bot/main.py
|
|
@ -81,8 +81,7 @@ def setup_bot() -> commands.Bot:
|
|||
]
|
||||
|
||||
description = "\n\n".join(
|
||||
" ".join(line.strip() for line in paragraph.split("\n"))
|
||||
for paragraph in desc_paragraphs
|
||||
" ".join(line.strip() for line in paragraph) for paragraph in desc_paragraphs
|
||||
)
|
||||
|
||||
command_prefix = Environment.bot_prefix()
|
||||
|
|
@ -111,70 +110,70 @@ def read_token_file() -> str:
|
|||
raise e
|
||||
|
||||
|
||||
# Note: pyright will complain about the async functions below not being accessed;
|
||||
# this is a false positive, as the @bot.event decorators actually register and
|
||||
# use the functions just fine. Unfortunately, it's not possible to silence the
|
||||
# warning, so I'll have to deal with it.
|
||||
#
|
||||
# ruff doesn't complain, though.
|
||||
def register_event_handlers(bot: commands.Bot):
|
||||
@bot.event
|
||||
async def on_error(event: str, *args, **kwargs):
|
||||
_log.error(
|
||||
f"Encountered unexpected exception while processing event {event} ({args = }; {kwargs = }):",
|
||||
exc_info=sys.exc_info(),
|
||||
)
|
||||
bot = setup_bot()
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
_log.info("Ready: Connected to Discord")
|
||||
|
||||
@bot.event
|
||||
async def on_resumed():
|
||||
_log.info("Resumed: Session with Discord resumed")
|
||||
@bot.event
|
||||
async def on_error(event: str, *args, **kwargs):
|
||||
_log.error(
|
||||
f"Encountered unexpected exception while processing event {event} ({args = }; {kwargs = }):",
|
||||
exc_info=sys.exc_info(),
|
||||
)
|
||||
|
||||
@bot.event
|
||||
async def on_shard_ready(shard_id: int):
|
||||
_log.info(f"Ready: Shard ID {shard_id} connected to Discord")
|
||||
|
||||
@bot.event
|
||||
async def on_shard_resumed(shard_id: int):
|
||||
_log.info(f"Resumed: Shard ID {shard_id} resumed session with Discord")
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
_log.info("Ready: Connected to Discord")
|
||||
|
||||
@bot.event
|
||||
async def on_message(message: discord.Message):
|
||||
_log.debug(f"Read message ({message.id = }): {message.content}")
|
||||
|
||||
@bot.event
|
||||
async def on_command(ctx: commands.Context):
|
||||
_log.debug(
|
||||
f"Command invoked:"
|
||||
f" {ctx.command = }; {ctx.message.author = }; {ctx.message.id = }"
|
||||
)
|
||||
@bot.event
|
||||
async def on_resumed():
|
||||
_log.info("Resumed: Session with Discord resumed")
|
||||
|
||||
@bot.event
|
||||
async def on_command_completion(ctx: commands.Context):
|
||||
_log.debug(
|
||||
f"Command completed:"
|
||||
f" {ctx.command = }; {ctx.message.author = }; {ctx.message.id = }"
|
||||
)
|
||||
|
||||
@bot.event
|
||||
async def on_command_error(ctx: commands.Context, error: commands.CommandError):
|
||||
_log.error(
|
||||
f"Failed to run command:"
|
||||
f" {ctx.command = }; {ctx.message.author = }; {ctx.message.id = }",
|
||||
exc_info=error,
|
||||
)
|
||||
@bot.event
|
||||
async def on_shard_ready(shard_id: int):
|
||||
_log.info(f"Ready: Shard ID {shard_id} connected to Discord")
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_shard_resumed(shard_id: int):
|
||||
_log.info(f"Resumed: Shard ID {shard_id} resumed session with Discord")
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_message(message: discord.Message):
|
||||
_log.debug(f"Read message ({message.id = }): {message.content}")
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_command(ctx: commands.Context):
|
||||
_log.debug(
|
||||
f"Command invoked:"
|
||||
f" {ctx.command = }; {ctx.message.author = }; {ctx.message.id = }"
|
||||
)
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_command_completion(ctx: commands.Context):
|
||||
_log.debug(
|
||||
f"Command completed:"
|
||||
f" {ctx.command = }; {ctx.message.author = }; {ctx.message.id = }"
|
||||
)
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_command_error(ctx: commands.Context, error: commands.CommandError):
|
||||
_log.error(
|
||||
f"Failed to run command:"
|
||||
f" {ctx.command = }; {ctx.message.author = }; {ctx.message.id = }",
|
||||
exc_info=error,
|
||||
)
|
||||
|
||||
|
||||
async def main():
|
||||
_log.debug("Entered main()")
|
||||
|
||||
bot = setup_bot()
|
||||
|
||||
register_event_handlers(bot)
|
||||
|
||||
token = read_token_file()
|
||||
|
||||
async with bot:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue