diff --git a/bot/notification.py b/bot/notification.py index b69a496..ea544e2 100644 --- a/bot/notification.py +++ b/bot/notification.py @@ -1,9 +1,6 @@ -import traceback -from typing import Dict, Any - -from config import NOTIFICATION_BATCH_SIZE, USE_WHITELIST +from config import USE_WHITELIST from parsing import parse_notification -from db_utils import get_config, set_config, is_whitelisted, is_player_banned +from db_utils import is_whitelisted, is_player_banned from response import generate_response from custom_types import BotResponse from fediverse_factory import get_fediverse_service @@ -71,61 +68,3 @@ def process_fediverse_notification(notification: FediverseNotification, fedivers file_ids=file_ids # visible_user_ids=[] # TODO: write actual visible users ids so pleromers can use the bot privately ) - - -def process_notifications(client: misskey.Misskey) -> bool: - '''Processes a batch of unread notifications. Returns False if there are - no more notifications to process.''' - - last_seen_id = get_config('last_seen_notif_id') - # process_notification writes to last_seen_id, so make a copy - new_last_seen_id = last_seen_id - - try: - notifications = client.i_notifications( - # Fetch notifications we haven't seen yet. This option is a bit - # tempermental, sometimes it'll include since_id, sometimes it - # won't. We need to keep track of what notifications we've - # already processed. - since_id=last_seen_id, - # Let misskey handle the filtering - include_types=['mention', 'reply'], - # And handle the batch size while we're at it - limit=NOTIFICATION_BATCH_SIZE - ) - - # No notifications. Wait the poll period. - if not notifications: - return False - - # Iterate oldest to newest - for notification in notifications: - try: - # Skip if we've processed already - notif_id = notification.get('id', '') - if notif_id <= last_seen_id: - continue - - # Update new_last_seen_id and process - new_last_seen_id = notif_id - process_notification(client, notification) - - except Exception as e: - print(f'An exception has occured while processing a \ -notification: {e}') - print(traceback.format_exc()) - - # If we got as many notifications as we requested, there are probably - # more in the queue - return len(notifications) == NOTIFICATION_BATCH_SIZE - - except MisskeyAPIException as e: - print(f'An exception has occured while reading notifications: {e}\n') - print(traceback.format_exc()) - finally: - # Quality jank right here, but finally lets us update the last_seen_id - # even if we hit an exception or return early - if new_last_seen_id > last_seen_id: - set_config('last_seen_notif_id', new_last_seen_id) - - return False