Skip to content

Commit

Permalink
seen: catch database write errors (fixes #2305)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Strzelecki <florian.strzelecki@gmail.com>
  • Loading branch information
SnoopJ and Exirel committed Sep 3, 2022
1 parent e45d69b commit c83da4a
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions sopel/modules/seen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
"""
from __future__ import annotations

import logging

from sqlalchemy.exc import SQLAlchemyError

from sopel import plugin
from sopel.tools.time import seconds_to_human


logger = logging.getLogger(__name__)


@plugin.command('seen')
@plugin.output_prefix('[seen] ')
def seen(bot, trigger):
Expand Down Expand Up @@ -63,9 +70,12 @@ def seen(bot, trigger):
@plugin.require_chanmsg
def note(bot, trigger):
nick = trigger.nick
# as of Sopel 8, `trigger.time` is Aware, meaning we should store its value
# for timezone safety when comparing it later
bot.db.set_nick_value(nick, 'seen_timestamp', trigger.time.timestamp())
bot.db.set_nick_value(nick, 'seen_channel', trigger.sender)
bot.db.set_nick_value(nick, 'seen_message', trigger)
bot.db.set_nick_value(nick, 'seen_action', trigger.ctcp is not None)
try:
# as of Sopel 8, `trigger.time` is Aware, meaning we should store its value
# for timezone safety when comparing it later
bot.db.set_nick_value(nick, 'seen_timestamp', trigger.time.timestamp())
bot.db.set_nick_value(nick, 'seen_channel', trigger.sender)
bot.db.set_nick_value(nick, 'seen_message', trigger)
bot.db.set_nick_value(nick, 'seen_action', trigger.ctcp is not None)
except SQLAlchemyError as error:
logger.error("Unable to save seen, database error: %s" % error)

0 comments on commit c83da4a

Please sign in to comment.