aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers.py (unfollow)
Commit message (Collapse)AuthorLines
2020-06-13Code block: fix missing newline before generic exampleGravatar MarkKoz-1/+1
2020-06-13Move some functions into a new channel utility moduleGravatar MarkKoz-37/+54
* Change `is_help_channel` to`internally use `is_in_category`
2020-06-13Code block: document the cogGravatar MarkKoz-7/+42
* Add docstrings for modules * Rephrase some docstrings and comments * Fix the grammar of some comments
2020-06-13Code block: fix wrong message shown for bad ticks with a valid languageGravatar MarkKoz-1/+1
When the code block had invalid ticks, instructions for syntax highlighting were being shown despite the code block having a valid language.
2020-06-13Code block: don't return bad language instructions if nothing's wrongGravatar MarkKoz-14/+19
2020-06-13Code block: join bad language instructions by spacesGravatar MarkKoz-9/+11
It was a mistake to join them by newlines in the first place. It looks and reads better as a paragraph. * Remove extra space after bad ticks instructions
2020-06-13Code block: fix message content being edited instead of the embedGravatar MarkKoz-1/+1
2020-06-13Code block: add function to create the instructions embedGravatar MarkKoz-2/+7
While it may be simple now, if the embed needs to changed later, it won't need to be done in multiple places since everything can rely on this function to create the embed.
2020-06-13Code block: use regex to parse incorrect languagesGravatar MarkKoz-18/+51
Regex is simpler and more versatile in this case. The functions in the `instructions` module should be more focused on formatting than parsing, so the parsing was moved to the `parsing` module. * Move _PY_LANG_CODES to the `parsing` module * Create a separate function in the `parsing` module to parse bad languages
2020-06-13Code block: create a function to format the example code blocksGravatar MarkKoz-17/+23
First, this reduces code redundancy. Furthermore, it moves the relatively big block of code for checking the language away from `_get_bad_ticks_message` and into its own, smaller unit.
2020-06-13Code block: rename some things to be "private"Gravatar MarkKoz-26/+26
2020-06-13Code block: refactor `send_guide_embed`Gravatar MarkKoz-4/+4
* Rename to `send_instructions` to be consistent with the use of "instructions" rather than "guide" elsewhere * Rename the `description` parameter to `instructions`
2020-06-13Code block: fix error retrieving a deleted instructions messageGravatar MarkKoz-4/+17
2020-06-13Code block: clarify log messages in message edit eventGravatar MarkKoz-9/+6
If statement was separated so there could be separate messages that are more specific. The message ID was also included to distinguish events.
2020-06-13Code block: edit instructions if edited message is still invalidGravatar MarkKoz-5/+7
Editing instructions means the user will always see what is currently relevant to them. Sometimes an incorrect edit could result in a different problem that was not mentioned in the original instructions. This change also fixes detection of fixed messages by using the same detection logic as the original `on_message`. Previously, it considered an edited message without code blocks to be fixed.
2020-06-13Code block: move bot message retrieval to a separate functionGravatar MarkKoz-16/+11
This bot message retrieval is the actual part of `remove_instructions` that will soon get re-used elsewhere. * Remove `remove_instructions` since it became a bit too simple given the separation of bot message retrieval.
2020-06-13Code block: move instructions retrieval to a separate functionGravatar MarkKoz-26/+37
Not only is it cleaner and more testable, but it allows for other functions to also retrieve instructions.
2020-06-13Code block: move instructions deletion to a separate functionGravatar MarkKoz-7/+16
2020-06-13Code block: fix valid code block being parsed as a missing blockGravatar MarkKoz-6/+9
`find_code_blocks` was returning an empty tuple if there was at least one valid code block. However, the caller could not distinguish between that case and simply no code blocks being found. Therefore, None is explicitly returned to distinguish it from a lack of results.
2020-06-13Code block: add trace loggingGravatar MarkKoz-6/+48
2020-06-13Code block: use same lang specifier as the user for the py exampleGravatar MarkKoz-5/+5
Keeping examples consistent will hopefully make things clearer to the user.
2020-06-13Code block: fix formatting of the additional messageGravatar MarkKoz-2/+2
The newlines should be replaced with a space rather than with 1 newline. To separate the two issues, a double newline is prepended to the entire additional message.
2020-06-13Code block: fix missing space between words in messageGravatar MarkKoz-1/+1
2020-06-13Code block: fix formatting of example code blocksGravatar MarkKoz-4/+4
2020-06-13Code block: fix find_code_blocks iteration and missing returnGravatar MarkKoz-11/+16
* Add named capture groups to the regex
2020-06-13Code block: load the extensionGravatar MarkKoz-0/+1
2020-06-13Code block: use find_code_blocks to check if an edited msg was fixedGravatar MarkKoz-16/+8
* Remove has_bad_ticks - it's obsolete
2020-06-13Code block: use new formatting functions in on_messageGravatar MarkKoz-17/+20
2020-06-13Code block: remove truncate functionGravatar MarkKoz-14/+0
No longer used anywhere.
2020-06-13Code block: rework the instruction formatting functionsGravatar MarkKoz-65/+113
A new module, `instructions`, was created to house the functions. 4 ways in which code blocks can be incorrect are considered: 1. The code is not within a code block at all 2. Incorrect characters are used for back ticks 3. A language is not specified 4. A language is specified incorrectly Splitting it up into these 4 cases allows for more specific and relevant instructions to be shown to users. If a message has both incorrect back ticks and an issue with the language specifier, the instructions for fixing both issues are combined. The instructions show a generic code example rather than using the original code from the message. This circumvents any ambiguities when parsing their message and trying to fix it. The escaped code block also failed to preserve indentation. This was a problem because some users would copy it anyway and end up with poorly formatted code. By using a simple example that doesn't rely on indentation, it makes it clear the example is not meant to be copied. Finally, the new examples are shorter and thus make the embed not as giant.
2020-06-13Code block: move parsing functions to a separate moduleGravatar MarkKoz-119/+126
This reduces clutter in the cog. The cog should only have Discord- related functionality.
2020-06-13Code block: remove obsolete functionsGravatar MarkKoz-108/+1
The user's original code will not be displayed in the output so there is no longer a need for the functions which format their code.
2020-06-13Code block: add function to check if REPL code existsGravatar MarkKoz-17/+10
The `repl_stripping` function was re-purposed. The plan going forward is to not show the user's code in the output so actual stripping is no longer necessary.
2020-06-13Code block: exclude code blocks 3 lines or shorterGravatar MarkKoz-1/+3
2020-06-13Code block: add function to check for valid Python codeGravatar MarkKoz-29/+43
2020-06-13Code block: add function to truncate contentGravatar MarkKoz-21/+16
The code was duplicated in each of the format message functions. The function also ensures content is truncated to 10 lines. Previously, code could have skipped truncating by being 100 lines long but under 204 characters in length.
2020-06-13Code block: return code blocks with valid ticks but no langGravatar MarkKoz-11/+8
Such code block will be useful down the road for sending information on including a language specified if the content successfully parses as valid Python.
2020-06-13Code block: add function to find invalid code blocksGravatar MarkKoz-2/+32
* Create a `NamedTuple` representing a code block
2020-06-13Code block: add regex to search for any code blocksGravatar MarkKoz-12/+25
This regex supports both valid and invalid ticks. The ticks are in a group so it's later possible to detect if valid ones were used.
2020-06-13Code block: fix code block language regexGravatar MarkKoz-1/+1
It was missing a quantifier to match more than 1 character.
2020-06-13Code block: use a more efficient line count checkGravatar MarkKoz-57/+59
2020-06-13Code block: ignore if code block has *any* languageGravatar MarkKoz-5/+3
If the code was valid Python syntax, the guide embed would be sent despite a non-Python language being explicitly specified for the code block by the message author. * Make the code block language regex a compiled pattern constant Fixes #829
2020-06-13Code block: simplify log messageGravatar MarkKoz-3/+2
2020-06-13Code block: make invalid backticks a constant setGravatar MarkKoz-9/+16
A set should be faster since it's being used to test for membership. A constant just means it won't need to be redefined every time the function is called. * Make `has_bad_ticks` a static method * Add comments describing characters represented by the Unicode escapes
2020-06-13Code block: move standard guide message creation to a new functionGravatar MarkKoz-50/+55
* Rename `howto` variable to `description`
2020-06-13Code block: move bad ticks message creation to a new functionGravatar MarkKoz-33/+37
2020-06-13Code block: move final send/cooldown code outside the try-exceptGravatar MarkKoz-9/+6
Reduces nesting for improved readability. The code would have never thrown a syntax error in the manner expected anyway.
2020-06-13Code block: add helper function to send the embedGravatar MarkKoz-7/+15
2020-06-13Code block: invert conditions to reduce nestingGravatar MarkKoz-102/+107
2020-06-13Code block: add helper function to check for channel cooldownGravatar MarkKoz-2/+9