Skip to content

Commit

Permalink
Merge pull request #183 from DogeisCut/patch-1
Browse files Browse the repository at this point in the history
Compression macros
  • Loading branch information
balt-dev authored Sep 11, 2024
2 parents 78b4782 + ddb62f0 commit ff9bf24
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/cogs/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from typing import Optional, Callable
import json
import time
import base64
import zlib

from .. import constants, errors
from ..types import Bot, BuiltinMacro
Expand Down Expand Up @@ -456,6 +458,32 @@ def upper(text: str):
def title(text: str):
return text.title()

@builtin("base64.encode")
def base64encode(string: str):
text_bytes = string.encode('utf-8')
base64_bytes = base64.b64encode(text_bytes)
return base64_bytes.decode('utf-8')

@builtin("base64.decode")
def base64decode(string: str):
base64_bytes = string.encode('utf-8')
text_bytes = base64.b64decode(base64_bytes)
return text_bytes.decode('utf-8')

@builtin("zlib.compress")
def zlibcompress(data: str):
text_bytes = data.encode('utf-8')
compressed_bytes = zlib.compress(text_bytes)
base64_compressed = base64.b64encode(compressed_bytes)
return base64_compressed.decode('utf-8')

@builtin("zlib.decompress")
def zlibdecompress(data: str):
base64_compressed = data.encode('utf-8')
compressed_bytes = base64.b64decode(base64_compressed)
text_bytes = zlib.decompress(compressed_bytes)
return text_bytes.decode('utf-8')

self.builtins = dict(sorted(self.builtins.items(), key=lambda tup: tup[0]))

def parse_macros(self, objects: str, debug_info: bool, macros=None, cmd="x", init=True) -> tuple[Optional[str], Optional[list[str]]]:
Expand Down

0 comments on commit ff9bf24

Please sign in to comment.