mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
Add url support
This commit is contained in:
parent
02789649d9
commit
f4abd6c3d0
4 changed files with 32 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
|||
import royalnet
|
||||
import royalnet.version
|
||||
from royalnet.commands import *
|
||||
|
||||
|
||||
|
@ -10,9 +10,9 @@ class VersionCommand(Command):
|
|||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||
# noinspection PyUnreachableCode
|
||||
if __debug__:
|
||||
message = f"ℹ️ Royalnet {royalnet.__version__} (debug)\n"
|
||||
message = f"ℹ️ Royalnet [url=https://github.com/Steffo99/royalnet/]Unreleased[/url]\n"
|
||||
else:
|
||||
message = f"ℹ️ Royalnet {royalnet.__version__}\n"
|
||||
if "69" in message:
|
||||
message = f"ℹ️ Royalnet [url=https://github.com/Steffo99/royalnet/releases/tag/{royalnet.version.semantic}]{royalnet.version.semantic}[/url]\n"
|
||||
if "69" in royalnet.version.semantic:
|
||||
message += "(Nice.)"
|
||||
await data.reply(message)
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
import re
|
||||
|
||||
|
||||
def escape(string: str) -> str:
|
||||
"""Escape a string to be sent through Discord, and format it using RoyalCode.
|
||||
|
||||
Warning:
|
||||
Currently escapes everything, even items in code blocks."""
|
||||
return string.replace("*", "\\*") \
|
||||
url_pattern = re.compile(r"\[url=(.*?)](.*?)\[/url]")
|
||||
url_replacement = r'\2 (\1)'
|
||||
|
||||
escaped_string = string.replace("<", "<").replace(">", ">")
|
||||
|
||||
simple_parse = escaped_string \
|
||||
.replace("*", "\\*") \
|
||||
.replace("_", "\\_") \
|
||||
.replace("`", "\\`") \
|
||||
.replace("[b]", "**") \
|
||||
|
@ -16,3 +25,7 @@ def escape(string: str) -> str:
|
|||
.replace("[/c]", "`") \
|
||||
.replace("[p]", "```") \
|
||||
.replace("[/p]", "```")
|
||||
|
||||
advanced_parse = re.sub(url_pattern, url_replacement, simple_parse)
|
||||
|
||||
return advanced_parse
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
import re
|
||||
|
||||
|
||||
def escape(string: str) -> str:
|
||||
"""Escape a string to be sent through Telegram (as HTML), and format it using RoyalCode.
|
||||
|
||||
Warning:
|
||||
Currently escapes everything, even items in code blocks."""
|
||||
return string.replace("<", "<") \
|
||||
.replace(">", ">") \
|
||||
url_pattern = re.compile(r"\[url=(.*?)](.*?)\[/url]")
|
||||
url_replacement = r'<a href="\1">\2</a>'
|
||||
|
||||
escaped_string = string.replace("<", "<").replace(">", ">")
|
||||
|
||||
simple_parse = escaped_string \
|
||||
.replace("[b]", "<b>") \
|
||||
.replace("[/b]", "</b>") \
|
||||
.replace("[i]", "<i>") \
|
||||
|
@ -15,3 +22,7 @@ def escape(string: str) -> str:
|
|||
.replace("[/c]", "</code>") \
|
||||
.replace("[p]", "<pre>") \
|
||||
.replace("[/p]", "</pre>")
|
||||
|
||||
advanced_parse = re.sub(url_pattern, url_replacement, simple_parse)
|
||||
|
||||
return advanced_parse
|
||||
|
|
|
@ -1 +1 @@
|
|||
semantic = "5.7.4"
|
||||
semantic = "5.7.5"
|
||||
|
|
Loading…
Reference in a new issue