aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/bot.py75
-rw-r--r--bot/cogs/clickup.py12
-rw-r--r--bot/formatter.py18
3 files changed, 66 insertions, 39 deletions
diff --git a/bot/cogs/bot.py b/bot/cogs/bot.py
index 600285cf6..f4f91ce33 100644
--- a/bot/cogs/bot.py
+++ b/bot/cogs/bot.py
@@ -88,7 +88,7 @@ class Bot:
"""
if msg.count("\n") >= 3:
# Filtering valid Python codeblocks and exiting if a valid Python codeblock is found
- if re.search("```(python|py)\n((?:.*\n*)+)```", msg, re.IGNORECASE):
+ if re.search("```(?:py|python)\n(.*?)```", msg, re.IGNORECASE | re.DOTALL):
log.trace("Someone wrote a message that was already a "
"valid Python syntax highlighted code block. No action taken.")
return None
@@ -115,44 +115,45 @@ class Bot:
return content
async def on_message(self, msg: Message):
- if msg.channel.id in self.channel_cooldowns:
- on_cooldown = time.time() - self.channel_cooldowns[msg.channel.id] < 300
- if not on_cooldown or msg.channel.id == DEVTEST_CHANNEL:
- try:
- content = self.codeblock_stripping(msg.content)
- if not content:
- return
-
- # Attempts to parse the message into an AST node.
- # Invalid Python code will raise a SyntaxError.
- tree = ast.parse(content)
-
- # Multiple lines of single words could be interpreted as expressions.
- # This check is to avoid all nodes being parsed as expressions.
- # (e.g. words over multiple lines)
- if not all(isinstance(node, ast.Expr) for node in tree.body):
- codeblock_tag = await self.bot.get_cog("Tags").get_tag_data("codeblock")
-
- if codeblock_tag == {}:
- log.warning(f"{msg.author} posted something that needed to be put inside Python "
- "code blocks, but the 'codeblock' tag was not in the tags database!")
+ if not msg.author.bot:
+ if msg.channel.id in self.channel_cooldowns:
+ on_cooldown = time.time() - self.channel_cooldowns[msg.channel.id] < 300
+ if not on_cooldown or msg.channel.id == DEVTEST_CHANNEL:
+ try:
+ content = self.codeblock_stripping(msg.content)
+ if not content:
return
- log.debug(f"{msg.author} posted something that needed to be put inside python code blocks. "
- "Sending the user some instructions.")
- howto = (f"Hey {msg.author.mention}!\n\n"
- "I noticed you were trying to paste code into this channel.\n\n"
- f"{codeblock_tag['tag_content']}")
-
- howto_embed = Embed(description=howto)
- await msg.channel.send(embed=howto_embed)
- self.channel_cooldowns[msg.channel.id] = time.time()
-
- except SyntaxError:
- log.trace(f"{msg.author} posted in a help channel, and when we tried to parse it as Python code, "
- "ast.parse raised a SyntaxError. This probably just means it wasn't Python code. "
- f"The message that was posted was:\n\n{msg.content}\n\n")
- pass
+ # Attempts to parse the message into an AST node.
+ # Invalid Python code will raise a SyntaxError.
+ tree = ast.parse(content)
+
+ # Multiple lines of single words could be interpreted as expressions.
+ # This check is to avoid all nodes being parsed as expressions.
+ # (e.g. words over multiple lines)
+ if not all(isinstance(node, ast.Expr) for node in tree.body):
+ codeblock_tag = await self.bot.get_cog("Tags").get_tag_data("codeblock")
+
+ if codeblock_tag == {}:
+ log.warning(f"{msg.author} posted something that needed to be put inside Python "
+ "code blocks, but the 'codeblock' tag was not in the tags database!")
+ return
+
+ log.debug(f"{msg.author} posted something that needed to be put inside python code blocks. "
+ "Sending the user some instructions.")
+ howto = (f"Hey {msg.author.mention}!\n\n"
+ "I noticed you were trying to paste code into this channel.\n\n"
+ f"{codeblock_tag['tag_content']}")
+
+ howto_embed = Embed(description=howto)
+ await msg.channel.send(embed=howto_embed)
+ self.channel_cooldowns[msg.channel.id] = time.time()
+
+ except SyntaxError:
+ log.trace(f"{msg.author} posted in a help channel, and when we tried to parse it as Python "
+ f"code, ast.parse raised a SyntaxError. This probably just means it wasn't Python "
+ f"code. The message that was posted was:\n\n{msg.content}\n\n")
+ pass
def setup(bot):
diff --git a/bot/cogs/clickup.py b/bot/cogs/clickup.py
index 03c1238f6..12572fd6a 100644
--- a/bot/cogs/clickup.py
+++ b/bot/cogs/clickup.py
@@ -131,6 +131,9 @@ class ClickUp:
Get a task and return information specific to it
"""
+ if task_id.startswith("#"):
+ task_id = task_id[1:]
+
embed = Embed(colour=Colour.blurple())
embed.set_author(
name=f"ClickUp Task: #{task_id}",
@@ -180,7 +183,12 @@ class ClickUp:
lines = [first_line]
if task.get("text_content"):
- lines.append(task["text_content"])
+ text = task["text_content"]
+
+ if len(text) >= 1500:
+ text = text[:1497] + "..."
+
+ lines.append(text)
if task.get("assignees"):
assignees = ", ".join(user["username"] for user in task["assignees"])
@@ -189,7 +197,7 @@ class ClickUp:
)
log.debug(f"{ctx.author} requested the task '#{task_id}'. Returning the task data.")
- return await LinePaginator.paginate(lines, ctx, embed, max_size=750)
+ return await LinePaginator.paginate(lines, ctx, embed, max_size=1500)
return await ctx.send(embed=embed)
@command(name="clickup.team()", aliases=["clickup.team", "team", "list_team"])
diff --git a/bot/formatter.py b/bot/formatter.py
index 5b75d6a03..1722dbf3c 100644
--- a/bot/formatter.py
+++ b/bot/formatter.py
@@ -60,6 +60,11 @@ class Formatter(HelpFormatter):
self._paginator = Paginator(prefix="```py")
if isinstance(self.command, Command):
+ # string used purely to make logs a teensy bit more readable
+ cog_string = f" from {self.command.cog_name}" if self.command.cog_name else ""
+
+ log.trace(f"Help command is on specific command {self.command.name}{cog_string}.")
+
# strip the command off bot. and ()
stripped_command = self.command.name.replace(HELP_PREFIX, "").replace("()", "")
@@ -71,6 +76,8 @@ class Formatter(HelpFormatter):
# discord.ext.commands.context.Context -> Context
arguments = arguments.replace(f"{annotation.__module__}.", "")
+ log.trace(f"Acquired arguments for command: '{arguments}' ")
+
# manipulate the argspec to make it valid python when 'calling' the do_<command>
args_no_type_hints = argspec.args
for kwarg in argspec.kwonlyargs:
@@ -101,6 +108,10 @@ class Formatter(HelpFormatter):
self._paginator.add_line(docstring)
self._paginator.add_line(invocation)
+ log.trace(f"Help for {self.command.name}{cog_string} added to paginator.")
+
+ log.debug(f"Help for {self.command.name}{cog_string} generated.")
+
return self._paginator.pages
max_width = self.max_name_size
@@ -113,16 +124,23 @@ class Formatter(HelpFormatter):
command_list = await self.filter_command_list()
data = sorted(command_list, key=category_check)
+ log.trace(f"Acquired command list and sorted by cog name: {[command[1].name for command in data]}")
+
for category, commands in itertools.groupby(data, key=category_check):
commands = sorted(commands)
if len(commands) > 0:
self._paginator.add_line(f"class {category}:")
self._add_subcommands_to_page(max_width, commands)
+ log.trace("Added cog and command names to the paginator.")
+
self._paginator.add_line()
ending_note = self.get_ending_note()
# make the ending note appear as comments
ending_note = "# "+ending_note.replace("\n", "\n# ")
self._paginator.add_line(ending_note)
+ log.trace("Added ending note to paginator.")
+ log.debug("General or Cog help generated.")
+
return self._paginator.pages