Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Aug 2, 2021
1 parent afb0c86 commit 03b80d6
Show file tree
Hide file tree
Showing 10 changed files with 1,111 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ENVIRONMENT=prod
COMMAND_START=["", "."]
PORT=10219
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
src/static
.idea
.code
venv
__pycache__
37 changes: 37 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import defaultdict

import nonebot
from nonebot.adapters.cqhttp import Bot as CQHTTPBot


# Custom your logger
#
# from nonebot.log import logger, default_format
# logger.add("error.log",
# rotation="00:00",
# diagnose=False,
# level="ERROR",
# format=default_format)

# You can pass some keyword args config to init function
nonebot.init()
# nonebot.load_builtin_plugins()
app = nonebot.get_asgi()

driver = nonebot.get_driver()
driver.register_adapter("cqhttp", CQHTTPBot)
driver.config.help_text = {}


nonebot.load_plugins("src/plugins")

# Modify some config / config depends on loaded configs
#
# config = driver.config
# do something...


if __name__ == "__main__":
nonebot.run(app="bot:app")
52 changes: 52 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
aiohttp==3.7.4.post0
arrow==1.1.1
async-timeout==3.0.1
attrs==21.2.0
binaryornot==0.4.4
certifi==2021.5.30
chardet==4.0.0
charset-normalizer==2.0.4
click==7.1.2
colorama==0.4.4
cookiecutter==1.7.3
fastapi==0.63.0
h11==0.12.0
httpcore==0.12.3
httpx==0.17.1
idna==3.2
Jinja2==3.0.1
jinja2-time==0.2.0
loguru==0.5.3
MarkupSafe==2.0.1
multidict==5.1.0
nb-cli==0.4.2
nonebot-adapter-cqhttp==2.0.0a13
nonebot2==2.0.0a13.post1
Pillow==8.3.1
poyo==0.5.0
prompt-toolkit==1.0.14
pydantic==1.8.2
pyfiglet==0.8.post1
Pygments==2.9.0
pygtrie==2.4.2
PyInquirer==1.0.3
python-dateutil==2.8.2
python-dotenv==0.19.0
python-slugify==5.0.2
PyYAML==5.4.1
regex==2021.7.6
requests==2.26.0
rfc3986==1.5.0
six==1.16.0
sniffio==1.2.0
starlette==0.13.6
text-unidecode==1.3
tomlkit==0.7.2
typing-extensions==3.10.0.0
urllib3==1.26.6
uvicorn==0.13.4
watchgod==0.7
wcwidth==0.2.5
websockets==8.1
win32-setctime==1.0.3
yarl==1.6.3
49 changes: 49 additions & 0 deletions src/libraries/image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import base64
from io import BytesIO

from PIL import ImageFont, ImageDraw, Image


path = 'src/static/high_eq_image.png'
fontpath = "src/static/msyh.ttc"


def draw_text(img_pil, text, offset_x):
draw = ImageDraw.Draw(img_pil)
font = ImageFont.truetype(fontpath, 48)
width, height = draw.textsize(text, font)
x = 5
if width > 390:
font = ImageFont.truetype(fontpath, int(390 * 48 / width))
width, height = draw.textsize(text, font)
else:
x = int((400 - width) / 2)
draw.rectangle((x + offset_x - 2, 360, x + 2 + width + offset_x, 360 + height * 1.2), fill=(0, 0, 0, 255))
draw.text((x + offset_x, 360), text, font=font, fill=(255, 255, 255, 255))


def text_to_image(text):
font = ImageFont.truetype(fontpath, 24)
padding = 10
margin = 4
text_list = text.split('\n')
max_width = 0
for text in text_list:
w, h = font.getsize(text)
max_width = max(max_width, w)
wa = max_width + padding * 2
ha = h * len(text_list) + margin * (len(text_list) - 1) + padding * 2
i = Image.new('RGB', (wa, ha), color=(255, 255, 255))
draw = ImageDraw.Draw(i)
for j in range(len(text_list)):
text = text_list[j]
draw.text((padding, padding + j * (margin + h)), text, font=font, fill=(0, 0, 0))
return i


def image_to_base64(img, format='PNG'):
output_buffer = BytesIO()
img.save(output_buffer, format)
byte_data = output_buffer.getvalue()
base64_str = base64.b64encode(byte_data)
return base64_str
Loading

0 comments on commit 03b80d6

Please sign in to comment.