-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rainbowshuffling and bottom encoding (#92)
* add owo.toml to gitignore * add owo.toml to gitignore * add mensa cog * mensaing * mensa command update * nyaaaa regex * add stucafé handling * small mensa cog edit * add dockerfile * small changes * remove re from requirements * nina, mvg apis, etc meow * move setup.md contents to readme * update default toml * change ssl settings so it defaults to False * increase duration for task.loop * remove duplicate toml settings * add mvg disruptions command * add thumbnail to NINA warnings * add mvg disruption levels * disable mensa menu cache due to errors * add more disruption classes * add embeddable domains * add mvg/nina toggle to settings * change logging to debug * remove evil tracking parameters * change hug logic, add img src * add context menu cogs + remove_tracking command * add bottom encoder/decoder * move purge command to admin cog * create rainbowshuffle command
- Loading branch information
Showing
4 changed files
with
194 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
''' | ||
Originally implemented in https://github.com/bottom-software-foundation/bottom-py/blob/main/bottom.py | ||
No licensing. | ||
Defined in https://github.com/bottom-software-foundation/spec | ||
''' | ||
|
||
CHARACTER_VALUES = { | ||
200: "🫂", | ||
50: "💖", | ||
10: "✨", | ||
5: "🥺", | ||
1: ",", | ||
0: "❤️" | ||
} | ||
|
||
SECTION_SEPERATOR = '👉👈' | ||
|
||
|
||
def to_bottom(text: str) -> str: | ||
out = bytearray() | ||
|
||
for char in text.encode(): | ||
while char != 0: | ||
for value, emoji in CHARACTER_VALUES.items(): | ||
if char >= value: | ||
char -= value | ||
out += emoji.encode() | ||
break | ||
|
||
out += SECTION_SEPERATOR.encode() | ||
|
||
return out.decode('utf-8') | ||
|
||
|
||
def from_bottom(text: str) -> str: | ||
out = bytearray() | ||
text = text.strip().removesuffix(SECTION_SEPERATOR) | ||
|
||
if not all(c in CHARACTER_VALUES.values() for c in text.replace(SECTION_SEPERATOR, '')): | ||
raise TypeError(f'Invalid bottom text: {text}') | ||
|
||
for char in text.split(SECTION_SEPERATOR): | ||
rev_mapping = {v: k for k, v in CHARACTER_VALUES.items()} | ||
|
||
sub = 0 | ||
for emoji in char: | ||
sub += rev_mapping[emoji] | ||
|
||
out += sub.to_bytes(1, 'big') | ||
|
||
return out.decode() |