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

seen: catch database write errors #2338

Merged
merged 1 commit into from
Sep 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)