aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Numerlor <[email protected]>2021-08-12 20:09:39 +0200
committerGravatar Numerlor <[email protected]>2021-08-12 20:14:31 +0200
commitf83dee308201ed6bddb4650f3a46e7b7d924ea54 (patch)
tree681463a431bfeaae4e7ee79ef1b2e0a25605c9a7
parentmake the tags attribute public (diff)
Use new Tags cog structure in source.py
-rw-r--r--bot/exts/info/source.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/bot/exts/info/source.py b/bot/exts/info/source.py
index ef07c77a1..723ae5aba 100644
--- a/bot/exts/info/source.py
+++ b/bot/exts/info/source.py
@@ -7,8 +7,9 @@ from discord.ext import commands
from bot.bot import Bot
from bot.constants import URLs
+from bot.exts.info.tags import TagIdentifier
-SourceType = Union[commands.HelpCommand, commands.Command, commands.Cog, str, commands.ExtensionNotLoaded]
+SourceType = Union[commands.HelpCommand, commands.Command, commands.Cog, TagIdentifier, commands.ExtensionNotLoaded]
class SourceConverter(commands.Converter):
@@ -33,8 +34,10 @@ class SourceConverter(commands.Converter):
if not tags_cog:
show_tag = False
- elif argument.lower() in tags_cog._cache:
- return argument.lower()
+ else:
+ identifier = TagIdentifier.from_string(argument.lower())
+ if identifier in tags_cog.tags:
+ return identifier
escaped_arg = utils.escape_markdown(argument)
@@ -72,9 +75,9 @@ class BotSource(commands.Cog):
source_item = inspect.unwrap(source_item.callback)
src = source_item.__code__
filename = src.co_filename
- elif isinstance(source_item, str):
+ elif isinstance(source_item, TagIdentifier):
tags_cog = self.bot.get_cog("Tags")
- filename = tags_cog._cache[source_item]["location"]
+ filename = tags_cog.tags[source_item].file_path
else:
src = type(source_item)
try:
@@ -82,7 +85,7 @@ class BotSource(commands.Cog):
except TypeError:
raise commands.BadArgument("Cannot get source for a dynamically-created object.")
- if not isinstance(source_item, str):
+ if not isinstance(source_item, TagIdentifier):
try:
lines, first_line_no = inspect.getsourcelines(src)
except OSError:
@@ -95,7 +98,7 @@ class BotSource(commands.Cog):
# Handle tag file location differently than others to avoid errors in some cases
if not first_line_no:
- file_location = Path(filename).relative_to("/bot/")
+ file_location = Path(filename).relative_to("bot/")
else:
file_location = Path(filename).relative_to(Path.cwd()).as_posix()
@@ -113,7 +116,7 @@ class BotSource(commands.Cog):
elif isinstance(source_object, commands.Command):
description = source_object.short_doc
title = f"Command: {source_object.qualified_name}"
- elif isinstance(source_object, str):
+ elif isinstance(source_object, TagIdentifier):
title = f"Tag: {source_object}"
description = ""
else: