aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/__init__.py2
-rw-r--r--bot/cogs/tags.py70
-rw-r--r--tox.ini2
3 files changed, 41 insertions, 33 deletions
diff --git a/bot/__init__.py b/bot/__init__.py
index df76215e6..071ec6c98 100644
--- a/bot/__init__.py
+++ b/bot/__init__.py
@@ -137,7 +137,7 @@ def _get_word(self) -> str:
args = ast.literal_eval(args)
# Force args into container
- if isinstance(args, str):
+ if not isinstance(args, tuple):
args = (args,)
# Type validate and format
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py
index 3e08778b1..645835f53 100644
--- a/bot/cogs/tags.py
+++ b/bot/cogs/tags.py
@@ -1,4 +1,5 @@
import logging
+import random
import time
from typing import Optional
@@ -17,6 +18,18 @@ class Tags:
Save new tags and fetch existing tags.
"""
+ FAIL_TITLES = [
+ "Please don't do that.",
+ "You have to stop.",
+ "Do you mind?",
+ "In the future, don't do that.",
+ "That was a mistake.",
+ "You blew it.",
+ "You're bad at computers.",
+ "Are you trying to kill me?",
+ "Noooooo!!"
+ ]
+
def __init__(self, bot: AutoShardedBot):
self.bot = bot
self.tag_cooldowns = {}
@@ -96,9 +109,9 @@ class Tags:
:return: A validation embed if invalid, otherwise None
"""
- def is_number(string):
+ def is_number(value):
try:
- float(string)
+ float(value)
except ValueError:
return False
else:
@@ -107,30 +120,16 @@ class Tags:
embed = Embed()
embed.colour = Colour.red()
- # Replace any special characters
- raw_name = tag_name.translate(
- {
- 0x8: "\\b", # Backspace
- 0x9: "\\t", # Horizontal tab
- 0xA: "\\n", # Linefeed
- 0xB: "\\v", # Vertical tab
- 0xC: "\\f", # Form feed
- 0xD: "\\r" # Carriage return
- }
- )
-
- # 'tag_name' has at least one special character.
- if tag_name != raw_name:
- log.warning(f"{author} tried to put a special character in a tag name. "
+ # 'tag_name' has at least one invalid character.
+ if ascii(tag_name)[1:-1] != tag_name:
+ log.warning(f"{author} tried to put an invalid character in a tag name. "
"Rejecting the request.")
- embed.title = "Please don't do that"
- embed.description = "Don't be ridiculous, special characters obviously aren't allowed in the tag name"
+ embed.description = "Don't be ridiculous, you can't use that character!"
# 'tag_content' or 'tag_name' are either empty, or consist of nothing but whitespace
elif (tag_content is not None and not tag_content) or not tag_name:
log.warning(f"{author} tried to create a tag with a name consisting only of whitespace. "
"Rejecting the request.")
- embed.title = "Please don't do that"
embed.description = "Tags should not be empty, or filled with whitespace."
# 'tag_name' is a number of some kind, we don't allow that.
@@ -138,12 +137,18 @@ class Tags:
log.error("inside the is_number")
log.warning(f"{author} tried to create a tag with a digit as its name. "
"Rejecting the request.")
- embed.title = "Please don't do that"
embed.description = "Tag names can't be numbers."
+ # 'tag_name' is longer than 127 characters
+ elif len(tag_name) > 127:
+ log.warning(f"{author} tried to request a tag name with over 127 characters. "
+ "Rejecting the request.")
+ embed.description = "Are you insane? That's way too long!"
+
else:
return None
+ embed.title = random.choice(Tags.FAIL_TITLES)
return embed
@command(name="tags()", aliases=["tags"], hidden=True)
@@ -158,7 +163,7 @@ class Tags:
return await ctx.invoke(self.bot.get_command("help"), "Tags")
@command(name="tags.get()", aliases=["tags.get", "tags.show()", "tags.show", "get_tag"])
- async def get_command(self, ctx: Context, tag_name=None):
+ async def get_command(self, ctx: Context, tag_name: str=None):
"""
Get a list of all tags or a specified tag.
@@ -198,11 +203,13 @@ class Tags:
return
tags = []
- tag_name = tag_name.lower().strip()
- validation = await self.validate(ctx.author, tag_name)
- if validation is not None:
- return await ctx.send(embed=validation)
+ if tag_name is not None:
+ tag_name = tag_name.lower().strip()
+ validation = await self.validate(ctx.author, tag_name)
+
+ if validation is not None:
+ return await ctx.send(embed=validation)
embed = Embed()
embed.colour = Colour.red()
@@ -237,14 +244,14 @@ class Tags:
if isinstance(tag_data, dict):
log.warning(f"{ctx.author} requested the tag '{tag_name}', but it could not be found.")
- embed.description = f"Unknown tag: **{tag_name}**"
+ embed.description = f"**{tag_name}** is an unknown tag name. Please check the spelling and try again."
else:
log.warning(f"{ctx.author} requested a list of all tags, but the tags database was empty!")
embed.description = "**There are no tags in the database!**"
if tag_name:
embed.set_footer(text="To show a list of all tags, use bot.tags.get().")
- embed.title = "Tag not found"
+ embed.title = "Tag not found."
# Paginate if this is a list of all tags
if tags:
@@ -270,13 +277,14 @@ class Tags:
:param tag_content: The content of the tag.
"""
- tag_name = tag_name.lower().strip()
- tag_content = tag_content.strip()
validation = await self.validate(ctx.author, tag_name, tag_content)
if validation is not None:
return await ctx.send(embed=validation)
+ tag_name = tag_name.lower().strip()
+ tag_content = tag_content.strip()
+
embed = Embed()
embed.colour = Colour.red()
tag_data = await self.post_tag_data(tag_name, tag_content)
@@ -309,12 +317,12 @@ class Tags:
:param tag_name: The name of the tag to delete.
"""
- tag_name = tag_name.lower().strip()
validation = await self.validate(ctx.author, tag_name)
if validation is not None:
return await ctx.send(embed=validation)
+ tag_name = tag_name.lower().strip()
embed = Embed()
embed.colour = Colour.red()
tag_data = await self.delete_tag_data(tag_name)
diff --git a/tox.ini b/tox.ini
index a8869d3ba..fb2176741 100644
--- a/tox.ini
+++ b/tox.ini
@@ -2,5 +2,5 @@
max-line-length=120
application_import_names=bot
exclude=.venv
-ignore=B311,W503,E226
+ignore=B311,W503,E226,S311
import-order-style=pycharm