diff options
author | 2021-08-02 20:38:09 +0200 | |
---|---|---|
committer | 2021-08-02 20:38:09 +0200 | |
commit | 359a17c00bb036f9a90fe7681592dee29f84c806 (patch) | |
tree | d3b0351c8356cca1ad6f7d6bb7547938eb38e27a | |
parent | Change if to elif to indicate it's exclusive with the above if (diff) |
Move tag identifier creation method to a TagIdentifier constructor
-rw-r--r-- | bot/exts/backend/error_handler.py | 2 | ||||
-rw-r--r-- | bot/exts/info/tags.py | 18 |
2 files changed, 10 insertions, 10 deletions
diff --git a/bot/exts/backend/error_handler.py b/bot/exts/backend/error_handler.py index 78822aece..51b6bc660 100644 --- a/bot/exts/backend/error_handler.py +++ b/bot/exts/backend/error_handler.py @@ -155,7 +155,7 @@ class ErrorHandler(Cog): return try: - tag_identifier = tags.extract_tag_identifier(ctx.message.content) + tag_identifier = tags.TagIdentifier.from_string(ctx.message.content) if tag_identifier.group is not None: tag_name = await TagNameConverter.convert(ctx, tag_identifier.name) tag_name_or_group = await TagNameConverter.convert(ctx, tag_identifier.group) diff --git a/bot/exts/info/tags.py b/bot/exts/info/tags.py index f2b5c0823..c05528daf 100644 --- a/bot/exts/info/tags.py +++ b/bot/exts/info/tags.py @@ -68,6 +68,15 @@ class TagIdentifier(NamedTuple): else: return self.name + @classmethod + def from_string(cls, string: str) -> TagIdentifier: + """Create a `TagIdentifier` instance from the beginning of `string`.""" + split_string = string.removeprefix(constants.Bot.prefix).split(" ", maxsplit=2) + if len(split_string) == 1: + return cls(None, split_string[0]) + else: + return cls(split_string[0], split_string[1]) + class Tag: """Provide an interface to a tag from resources with `file_content`.""" @@ -404,12 +413,3 @@ class Tags(Cog): def setup(bot: Bot) -> None: """Load the Tags cog.""" bot.add_cog(Tags(bot)) - - -def extract_tag_identifier(string: str) -> TagIdentifier: - """Create a `TagIdentifier` instance from the beginning of `string`.""" - split_string = string.removeprefix(constants.Bot.prefix).split(" ", maxsplit=2) - if len(split_string) == 1: - return TagIdentifier(None, split_string[0]) - else: - return TagIdentifier(split_string[0], split_string[1]) |