Skip to content

Commit

Permalink
Simplify SubscribedMessage load method
Browse files Browse the repository at this point in the history
Co-authored-by: Will Barber <[email protected]>
  • Loading branch information
raccube and WillB97 committed Aug 16, 2024
1 parent e4f8b15 commit 8792a30
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/commands/stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# file to store messages being dynamically updated between reboots
import json
from typing import Any, Dict, List, Union, NamedTuple, TYPE_CHECKING
from typing import Any, Dict, NamedTuple, TYPE_CHECKING

import discord
from discord import app_commands
Expand All @@ -23,17 +23,9 @@ class SubscribedMessage(NamedTuple):
stats: bool = False

@classmethod
def load(cls, dct: Dict[str, Any]) -> Union['SubscribedMessage', Dict[str, Any]]: # type:ignore
def load(cls, dct: Dict[str, Any]) -> 'SubscribedMessage': # type:ignore[misc]
"""Load a SubscribedMessage object from a dictionary."""
if tuple(dct.keys()) == cls._fields:
return cls(
dct['channel_id'],
dct['message_id'],
dct['members'],
dct['warnings'],
dct['stats']
)
return dct
return cls(**dct)

def __eq__(self, comp: object) -> bool:
if not isinstance(comp, SubscribedMessage):
Expand Down

0 comments on commit 8792a30

Please sign in to comment.