1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

🎃 Add ⊕ substitution, scheduled for 17 Oct

This commit is contained in:
Steffo 2020-09-17 04:22:31 +02:00
parent fdddc70469
commit 0babef0693
4 changed files with 52 additions and 11 deletions

View file

@ -1,4 +1,14 @@
import re import re
from ...utils import escalating_odds
import datetime
# https://stackoverflow.com/questions/18621568/regex-replace-text-outside-html-tags
spooky_pattern = re.compile(r"o(?![^\[]*]|[^[]]*\[/)")
spooky_replacement = r''
url_pattern = re.compile(r"\[url=(.*?)](.*?)\[/url]")
url_replacement = r'\2 (\1)'
def escape(string: str) -> str: def escape(string: str) -> str:
@ -6,10 +16,10 @@ def escape(string: str) -> str:
Warning: Warning:
Currently escapes everything, even items in code blocks.""" Currently escapes everything, even items in code blocks."""
url_pattern = re.compile(r"\[url=(.*?)](.*?)\[/url]") if escalating_odds(datetime.datetime(2020, 10, 17, 4, 0)):
url_replacement = r'\2 (\1)' string = re.sub(spooky_pattern, spooky_replacement, string)
simple_parse = string \ string = string \
.replace("*", "\\*") \ .replace("*", "\\*") \
.replace("_", "\\_") \ .replace("_", "\\_") \
.replace("`", "\\`") \ .replace("`", "\\`") \
@ -24,6 +34,6 @@ def escape(string: str) -> str:
.replace("[p]", "```") \ .replace("[p]", "```") \
.replace("[/p]", "```") .replace("[/p]", "```")
advanced_parse = re.sub(url_pattern, url_replacement, simple_parse) string = re.sub(url_pattern, url_replacement, string)
return advanced_parse return string

View file

@ -1,5 +1,15 @@
import re import re
from typing import * from typing import *
from ...utils import escalating_odds
import datetime
# https://stackoverflow.com/questions/18621568/regex-replace-text-outside-html-tags
spooky_pattern = re.compile(r"o(?![^\[]*]|[^[]]*\[/)")
spooky_replacement = r''
url_pattern = re.compile(r"\[url=(.*?)](.*?)\[/url]")
url_replacement = r'<a href="\1">\2</a>'
def escape(string: Optional[str]) -> Optional[str]: def escape(string: Optional[str]) -> Optional[str]:
@ -8,12 +18,12 @@ def escape(string: Optional[str]) -> Optional[str]:
Warning: Warning:
Currently escapes everything, even items in code blocks.""" Currently escapes everything, even items in code blocks."""
url_pattern = re.compile(r"\[url=(.*?)](.*?)\[/url]") string = string.replace("<", "&lt;").replace(">", "&gt;")
url_replacement = r'<a href="\1">\2</a>'
escaped_string = string.replace("<", "&lt;").replace(">", "&gt;") if escalating_odds(datetime.datetime(2020, 10, 17, 4, 0)):
string = re.sub(spooky_pattern, spooky_replacement, string)
simple_parse = escaped_string \ string = string \
.replace("[b]", "<b>") \ .replace("[b]", "<b>") \
.replace("[/b]", "</b>") \ .replace("[/b]", "</b>") \
.replace("[i]", "<i>") \ .replace("[i]", "<i>") \
@ -25,6 +35,6 @@ def escape(string: Optional[str]) -> Optional[str]:
.replace("[p]", "<pre>") \ .replace("[p]", "<pre>") \
.replace("[/p]", "</pre>") .replace("[/p]", "</pre>")
advanced_parse = re.sub(url_pattern, url_replacement, simple_parse) string = re.sub(url_pattern, url_replacement, string)
return advanced_parse return string

View file

@ -9,6 +9,7 @@ from .sleep_until import sleep_until
from .strip_tabs import strip_tabs from .strip_tabs import strip_tabs
from .taskslist import TaskList from .taskslist import TaskList
from .urluuid import to_urluuid, from_urluuid from .urluuid import to_urluuid, from_urluuid
from .escalating_odds import escalating_odds
__all__ = [ __all__ = [
"asyncify", "asyncify",
@ -30,4 +31,5 @@ __all__ = [
"strip_tabs", "strip_tabs",
"TaskList", "TaskList",
"RoyalnetProcess", "RoyalnetProcess",
"escalating_odds",
] ]

View file

@ -0,0 +1,19 @@
import random
import datetime
import logging
log = logging.getLogger(__name__)
def escalating_odds(target_day: datetime.datetime) -> bool:
time_left: datetime.timedelta = target_day - datetime.datetime.now()
log.debug(f"Time left is {time_left}")
if time_left.total_seconds() <= 0:
log.debug("Target has passed, autorolling a success")
return True
odds = 1 / (time_left.days + 1)
result = random.uniform(0, 1) <= odds
log.debug(f"Odds are {odds}, rolled a {result}")
return result