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:
parent
fdddc70469
commit
0babef0693
4 changed files with 52 additions and 11 deletions
|
@ -1,4 +1,14 @@
|
|||
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:
|
||||
|
@ -6,10 +16,10 @@ def escape(string: str) -> str:
|
|||
|
||||
Warning:
|
||||
Currently escapes everything, even items in code blocks."""
|
||||
url_pattern = re.compile(r"\[url=(.*?)](.*?)\[/url]")
|
||||
url_replacement = r'\2 (\1)'
|
||||
if escalating_odds(datetime.datetime(2020, 10, 17, 4, 0)):
|
||||
string = re.sub(spooky_pattern, spooky_replacement, string)
|
||||
|
||||
simple_parse = string \
|
||||
string = string \
|
||||
.replace("*", "\\*") \
|
||||
.replace("_", "\\_") \
|
||||
.replace("`", "\\`") \
|
||||
|
@ -24,6 +34,6 @@ def escape(string: str) -> str:
|
|||
.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
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
import re
|
||||
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]:
|
||||
|
@ -8,12 +18,12 @@ def escape(string: Optional[str]) -> Optional[str]:
|
|||
Warning:
|
||||
Currently escapes everything, even items in code blocks."""
|
||||
|
||||
url_pattern = re.compile(r"\[url=(.*?)](.*?)\[/url]")
|
||||
url_replacement = r'<a href="\1">\2</a>'
|
||||
string = string.replace("<", "<").replace(">", ">")
|
||||
|
||||
escaped_string = string.replace("<", "<").replace(">", ">")
|
||||
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("[i]", "<i>") \
|
||||
|
@ -25,6 +35,6 @@ def escape(string: Optional[str]) -> Optional[str]:
|
|||
.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
|
||||
|
|
|
@ -9,6 +9,7 @@ from .sleep_until import sleep_until
|
|||
from .strip_tabs import strip_tabs
|
||||
from .taskslist import TaskList
|
||||
from .urluuid import to_urluuid, from_urluuid
|
||||
from .escalating_odds import escalating_odds
|
||||
|
||||
__all__ = [
|
||||
"asyncify",
|
||||
|
@ -30,4 +31,5 @@ __all__ = [
|
|||
"strip_tabs",
|
||||
"TaskList",
|
||||
"RoyalnetProcess",
|
||||
"escalating_odds",
|
||||
]
|
||||
|
|
19
royalnet/utils/escalating_odds.py
Normal file
19
royalnet/utils/escalating_odds.py
Normal 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
|
Loading…
Reference in a new issue