aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar rohanjnr <[email protected]>2020-04-14 18:57:39 +0530
committerGravatar rohanjnr <[email protected]>2020-04-14 18:57:39 +0530
commit7195a928952c1550a82d27706a57165606aa5f4a (patch)
tree431444a5ce77f0704bde5917094101b8d41de963
parentRemove unnecessary variable creation and join two if statements (diff)
Feature now is cross-platform
Instead of using string methods to split the file path at `/` which is not cross-platform, I am now entirely using pathlib methods to get the parent folder and restrict the tags.
-rw-r--r--bot/cogs/tags.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py
index bb74ab1ca..a59d28600 100644
--- a/bot/cogs/tags.py
+++ b/bot/cogs/tags.py
@@ -38,7 +38,7 @@ class Tags(Cog):
cache = {}
tag_files = Path("bot", "resources", "tags").glob("**/*")
for file in tag_files:
- file_path = str(file).split("/")
+
if file.is_file():
tag_title = file.stem
tag = {
@@ -48,8 +48,9 @@ class Tags(Cog):
},
"restricted_to": "developers"
}
- if len(file_path) == 5:
- tag["restricted_to"] = file_path[3]
+ parent_folder = file.parent.stem
+ if parent_folder != "tags":
+ tag["restricted_to"] = parent_folder
cache[tag_title] = tag
return cache
@@ -212,11 +213,13 @@ class Tags(Cog):
return
if tag_name is not None:
- founds = self._get_tag(tag_name)
+ temp_founds = self._get_tag(tag_name)
+
+ founds = []
- for found_tag in founds:
- if not self.check_accessibility(ctx.author, found_tag):
- founds.remove(found_tag)
+ for found_tag in temp_founds:
+ if self.check_accessibility(ctx.author, found_tag):
+ founds.append(found_tag)
if len(founds) == 1:
tag = founds[0]