Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
OasisAkari committed Sep 18, 2024
1 parent 66c8843 commit 8f318b1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
17 changes: 16 additions & 1 deletion config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import toml

from core.exceptions import ConfigFileNotFound, ConfigValueError
from core.utils.text import isfloat, isint


config_filename = 'config.toml'
Expand All @@ -15,6 +14,22 @@
old_cfg_file_path = abspath('./config/config.cfg')


def isfloat(num_str: str) -> bool:
try:
float(num_str)
return True
except Exception:
return False


def isint(num_str: str) -> bool:
try:
int(num_str)
return True
except Exception:
return False


def convert_cfg_to_toml():
import configparser
config = configparser.ConfigParser()
Expand Down
3 changes: 2 additions & 1 deletion config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ openai_api_key =
osu_api_key =
wolfram_alpha_appid =
jwt_secret =

ff3_key = 0AF6C4788B86F4E2FB97215E6E4A5EB0
ff3_tweak = 6520BD033E2928
[cfg]
api_port = 5000
base_superuser = ["QQ|2596322644",]
Expand Down
24 changes: 24 additions & 0 deletions core/utils/text.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import random
import re
import sys
from datetime import timedelta
from typing import TypeVar
from ff3 import FF3Cipher

from config import Config


T = TypeVar("T", str, bytes, bytearray)

Expand Down Expand Up @@ -53,3 +59,21 @@ def parse_time_string(time_str: str) -> timedelta:
return timedelta(hours=hour, minutes=minute)
except Exception:
return timedelta()


def random_string(length: int) -> str:
return ''.join(random.choices("0123456789ABCDEF", k=length))


def decrypt_string(text):
key = Config('ff3_key', random_string(32))
tweak = Config('ff3_tweak', random_string(14))
c = FF3Cipher.withCustomAlphabet(key, tweak,
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
d = []
for i in range(0, len(text), 28):
d.append(text[i:i+28])
dec_text = ''.join([c.decrypt(i) for i in d])
if m :=re.match(r'^t:(.*?):e.*?$', dec_text):
return m.group(1)
return False
13 changes: 12 additions & 1 deletion modules/core/su_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from core.tos import pardon_user, warn_user
from core.utils.info import Info
from core.utils.storedata import get_stored_list, update_stored_list
from core.utils.text import isfloat, isint
from core.utils.text import isfloat, isint, decrypt_string
from database import BotDBUtil


Expand Down Expand Up @@ -562,3 +562,14 @@ async def _(msg: Bot.MessageSession, sender: str = None):
async def stop_playing_maimai(msg: Bot.MessageSession):
BotDBUtil.JobQueue.clear(0)
await msg.finish(msg.locale.t("success"))


decry = module('decrypt', required_superuser=True, base=True, doc=True)

@decry.command('<display_msg>')
async def _(msg: Bot.MessageSession):
dec = decrypt_string(msg.as_display().split(' ', 1)[1])
if dec:
await msg.finish(dec)
else:
await msg.finish(msg.locale.t("failed"))
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ inputimeout = "^1.0.4"
prompt-toolkit = "^3.0.47"
emoji = "^2.12.1"
langconv = {git = "https://github.com/OasisAkari/langconv.py.git"}
ff3 = "^1.0.2"


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 8f318b1

Please sign in to comment.