bot.exts.info.code_snippets
#
Get snippets of code.
Module Contents#
Classes#
Cog that parses and sends code snippets to Discord. |
Functions#
|
Load the CodeSnippets cog. |
Attributes#
- class bot.exts.info.code_snippets.CodeSnippets(bot: bot.bot.Bot)[source]#
Bases:
discord.ext.commands.Cog
Cog that parses and sends code snippets to Discord.
Matches each message against a regex and prints the contents of all matched snippets.
- async _fetch_response(url: str, response_format: str, **kwargs: dict) str | dict | None [source]#
Make http requests using aiohttp.
- _find_ref(path: str, refs: tuple) tuple [source]#
Loop through all branches and tags to find the required ref.
- async _fetch_github_snippet(repo: str, path: str, start_line: str, end_line: str) str [source]#
Fetch a snippet from a GitHub repo.
- async _fetch_github_gist_snippet(gist_id: str, revision: str, file_path: str, start_line: str, end_line: str) str [source]#
Fetch a snippet from a GitHub gist.
- async _fetch_gitlab_snippet(repo: str, path: str, start_line: str, end_line: str) str [source]#
Fetch a snippet from a GitLab repo.
- async _fetch_bitbucket_snippet(repo: str, ref: str, file_path: str, start_line: str, end_line: str) str [source]#
Fetch a snippet from a BitBucket repo.
- _snippet_to_codeblock(file_contents: str, file_path: str, start_line: str, end_line: str) str [source]#
Given the entire file contents and target lines, creates a code block.
First, we split the file contents into a list of lines and then keep and join only the required ones together.
We then dedent the lines to look nice, and replace all ` characters with ` to prevent markdown injection.
Finally, we surround the code with ``` characters.
- async bot.exts.info.code_snippets.setup(bot: bot.bot.Bot) None [source]#
Load the CodeSnippets cog.