Added an error checking in case a tag was provided in the incorrect format
This commit is contained in:
parent
c907f76ac8
commit
567162268b
1 changed files with 8 additions and 3 deletions
11
cogs/tags.py
11
cogs/tags.py
|
@ -34,11 +34,16 @@ class Tags:
|
||||||
async def add_tag(self, ctx, *, result: str):
|
async def add_tag(self, ctx, *, result: str):
|
||||||
"""Use this to add a new tag that can be used in this server
|
"""Use this to add a new tag that can be used in this server
|
||||||
Format to add a tag is !tag add <tag> - <result>"""
|
Format to add a tag is !tag add <tag> - <result>"""
|
||||||
tag = result[0:result.find('-')].strip()
|
try:
|
||||||
tag_result = result[result.find('-') + 2:].strip()
|
tag = re.search("(.*) - (.*)",result).group(1).strip()
|
||||||
if len(tag) == 0 or len(result) == 0:
|
tag_result = "(.*) - (.*)",result).group(2).strip()
|
||||||
|
except AttributeError:
|
||||||
await self.bot.say("Please provide the format for the tag in: !tag add <tag> - <result>")
|
await self.bot.say("Please provide the format for the tag in: !tag add <tag> - <result>")
|
||||||
return
|
return
|
||||||
|
if len(tag) == 0 or len(tag_result) == 0:
|
||||||
|
await self.bot.say("Please provide the format for the tag in: !tag add <tag> - <result>")
|
||||||
|
return
|
||||||
|
|
||||||
tags = config.getContent('tags')
|
tags = config.getContent('tags')
|
||||||
for t in tags:
|
for t in tags:
|
||||||
if t['tag'] == tag and t['server_id'] == ctx.message.server.id:
|
if t['tag'] == tag and t['server_id'] == ctx.message.server.id:
|
||||||
|
|
Loading…
Reference in a new issue