diff --git a/config/command.yml b/config/command.yml index ca75567..551f3e4 100644 --- a/config/command.yml +++ b/config/command.yml @@ -30,30 +30,12 @@ setu: getsetu1: (色图|涩图|setu)\s*(\S+)?\s*$ getsetu2: 来(\d)*[张份点]?(\S+)*\s*(的)?\s*[色涩涉]图\s*$ -tenhou: - thpt: (thpt|天凤pt|天凤分数)\s*(\S+)\s*(\S+)?\s*$ - addwatch: (thadd|天凤添加关注)\s*(\S+)\s*$ - delwatch: (thdel|天凤删除关注)\s*(\S+)\s*$ - getwatch: (thgetwatch|天凤获取本群关注)\s*$ - clearwatch: (thclearwatch|天凤清除本群关注)\s*$ - - - tagon: (thtagon|天凤添加标记)\s*(\S+)\s*(\S+)\s*$ - tagoff: (thtagoff|天凤删除标记)\s*(\S+)\s*(\S+)?\s*$ - taglist: (qhtaglist)\s*(\S+)?\s*$ - -jupai: - jupai: 举牌\s*(\S+)\s*$ - reply: jida: ([\w\d]+)鸡打\s*\. wochao: 我超(\w+)\s*\. kisskiss: (亲|亲亲)\s*@?(\w+)?\s* touchhead: (摸|摸摸|摸头)\s*@?(\w+)?\s*$ -imgoperation: - bw: bw\s*(\S+)\s*$ - remake: remake: (重开|remake)\s*(\d+)?\s*(\w+)?\s*$ diff --git a/config/config.yml b/config/config.yml index aa04427..a1a2961 100644 --- a/config/config.yml +++ b/config/config.yml @@ -49,6 +49,12 @@ welcomeinfo: # 新人入群欢迎词,%ps%为新人名字,%gn%为群聊名 whitelist: - 0 # 白名单 +trash_folders: # 需要清理垃圾的文件夹 + - './images/MajSoulInfo' + - './images/PetPet' + - './images/Remake' + - './images/ImgGenerator' + settings: # 功能开关 autogetpaipu: true # 自动获取雀魂牌谱 autowelcome: true # 自动欢迎新人 diff --git a/core/__init__.py b/core/__init__.py index 945dd85..14b9621 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -2,5 +2,6 @@ from core.config import * from core.bot import bot, bot_cfg from core.scheduler import * +from core.help import * from core.fun import * diff --git a/core/config.py b/core/config.py index eb29697..83cc41e 100644 --- a/core/config.py +++ b/core/config.py @@ -7,17 +7,16 @@ """ import sys -from utils import text_to_image from utils.cfg_loader import * __all__ = ['config', 'replydata', 'admin', 'master', 'commandpre', 'commands_map', 'load_replydata', 'load_commands', - 'load_config', 'create_helpimg', 'create_init_config'] + 'load_config', 'create_init_config'] config = {} replydata = {} _syskey = {'admin', 'whitelist', 'blacklist', 'settings', 'welcomeinfo', 'alarmclockgroup', 'commandpre', 'botconfig', - 'silencegroup', 'nudgeconfig', 'loglevel', 'master', 'mutegrouplist', - 'welcomeinfo', 'replyimgpath'} + 'silencegroup', 'nudgeconfig', 'loglevel', 'master', 'mutegrouplist', 'trash_folders', 'welcomeinfo', + 'replyimgpath'} def load_config() -> dict: @@ -81,19 +80,12 @@ def load_commands() -> dict: print(f"发生未知错误{_e}") -def create_helpimg(): - """生成帮助图片""" - _help = read_file(r'./data/sys/help.yml') - grouphelp = _help['grouphelp'] - friendhelp = _help['friendhelp'] - text_to_image(text=grouphelp, path='grouphelp.png') - text_to_image(text=friendhelp, path='friendhelp.png') - - def create_init_config(): """生成默认配置""" sys_config = dict(admin=[0], whitelist=[0], blacklist=[0], mutegrouplist=[0], welcomeinfo=["欢迎%ps%加入%gn%"], alarmclockgroup=[0], + trash_folders=['./images/MajSoulInfo', './images/PetPet', './images/Remake', + './images/ImgGenerator'], silencegroup=[0], disnudgegroup=[0], commandpre="", master=0, loglevel="INFO", replyimgpath='fox', botconfig=dict(qq=123456, botname=""), nudgeconfig=dict(disnudgegroup=[0], sendnudgechance=0.3, supernudgequantity=10, @@ -101,7 +93,7 @@ def create_init_config(): adapter=dict(verify_key='NekoRabi', host='localhost', port=17280), settings=dict(autowelcome=True, help=True, r18talk=True, nudgereply=True, - silence=False, saveflashimg=True)) + silence=False, saveflashimg=True)) write_file(sys_config, r'./config/config.yml') diff --git a/core/help.py b/core/help.py new file mode 100644 index 0000000..182d561 --- /dev/null +++ b/core/help.py @@ -0,0 +1,67 @@ +""" +:Author: NekoRabi +:Create: 2022/9/23 13:34 +:Update: / +:Describe: "帮助"生成功能 +:Version: 0.0.1 +""" +from typing import Union + +from utils import read_file, text_to_image + +__all__ = ['add_help', 'create_helpimg', 'get_help_list'] + +_help = read_file(r'./data/sys/help.yml') +all_help = dict(friendhelp=_help['friendhelp'], grouphelp=_help['grouphelp'], adminhelp=[], masterhelp=[]) + + +def add_help(event_type: str, data: Union[set, list, str, tuple, dict]): + """ + 向全局帮助添加文本 + + Args: + event_type: 消息事件或身份, friend,gropu,admin,master + data: 帮助内容, 适配 str,list,set,tuple,dict 类型 + + Returns: + + """ + if event_type.lower().startswith('friend'): + event = 'friendhelp' + elif event_type.lower().startswith('group'): + event = 'grouphelp' + elif event_type.lower().startswith('admin'): + event = 'adminhelp' + elif event_type.lower().startswith('master'): + event = 'masterhelp' + else: + raise ValueError("帮助添加失败,无效参数") + + if type(data) == str: + if not data.endswith('\n'): + data = f'{data}\n' + all_help[event].append(data) + elif type(data) in [set, list, tuple]: + for _item in data: + if not f'{_item}'.endswith('\n'): + all_help[event].append(f'{_item}\n') + else: + all_help[event].append(f'{_item}') + elif type(data) == dict: + for _k, _v in data.items(): + if not f'{_v}'.endswith('\n'): + all_help[event].append(f'{_k} : {_v}\n') + else: + all_help[event].append(f'{_k} : {_v}') + else: + raise TypeError('帮助添加失败,添加的帮助内容的类型不匹配') + + +def get_help_list(): + return all_help + + +def create_helpimg(): + """生成帮助""" + text_to_image(text=all_help['grouphelp'], path='grouphelp.png') + text_to_image(text=all_help['friendhelp'], path='friendhelp.png') diff --git a/data/sys/help.yml b/data/sys/help.yml index 39d8080..6d46384 100644 --- a/data/sys/help.yml +++ b/data/sys/help.yml @@ -1,36 +1,10 @@ grouphelp: - "指令帮助 ()内为可选项,[]为必选项,{}为可用参数,<>为类型:\n" - - "qhpt / 雀魂分数 / 雀魂pt [玩家名] (3/4) (序号):查询该玩家的段位分\n" - - "qhsl / 雀魂十连 (限时/常驻) :来一次模拟雀魂十连\n" - - "qhadd / 雀魂添加关注 [玩家名] :将一个玩家添加至雀魂自动查询,有新对局记录时会广播\n" - - "qhgetwatch / 雀魂获取本群关注 :获取本群所有的雀魂关注的玩家\n" - - "getmyqhsl / 我的雀魂十连 : 获取你的抽卡总结" - - "qhdel / 雀魂删除关注 [玩家名] :将一个玩家从雀魂自动查询中移除,不再自动广播对局记录\n" - - "qhpaipu / 雀魂最近对局 [玩家名] (3/4) ({1-10}) :查询一个玩家最近n场3/4人对局记录\n" - - "qhinfo / 雀魂玩家详情 [玩家名] (3/4) ({基本/立直/血统/all}):查询一个玩家的详细数据\n" - - "qhyb / 雀魂月报 [玩家名] (3/4) [yyyy-mm] :查询一个玩家yy年mm月的3/4麻对局月报\n" - - "thpt / 天凤pt / 天凤分数 [玩家名] : 查询玩家的天凤pt ( 但该功能还存在问题\n" - - "thadd / 天凤添加关注 [玩家名] :将一个玩家添加指天凤的自动查询,有新对局会广播\n" - - "thdel / 天凤删除关注 [玩家名] :将一个玩家从天凤自动查询中移除,不再自动广播对局记录\n" - - "thgetwatch / 天凤获取本群关注 :获取本群所有的天凤关注的玩家\n" - - "牌理[114514p1919m810s4z] : 天凤一般型牌理分析\n" - - "举牌 [<文本>] :将文本写在举牌小人上发出来,最多40字\n" - - "亲/亲亲 @用户 : 两人互亲\n" - - "[A]鸡打. / 我超[A]. : 返回一段主体为A发病文\n" + - "项目地址 : 获取机器人链接\n" + - "[A]鸡打. / 我超[A]. : 返回一段主体为A发病文\n" - "摸/摸摸/摸头 @群友 : 摸某人头\n" - - "逮捕(我自己) @群友 : 逮捕某人\n" - - "(我是)小可爱 @群友 : 可爱群友\n" - - "丢(我自己) @群友 : 把群友丢出去\n " - - "吃掉 @群友 : 把群友吃了\n" - - "重开 / remake : 异世界转生\n" - - "bw [<文本>] [<图片>] : 返回一张黑白处理后的图片,底部有一行文字\n" - - "截图 <回复消息> : 将一条文本聊天记录截图\n" - - "击杀[<文本> 或 @群友] : 击杀群友\n" - - "签到 : 顾名思义,就是签到\n" - - "(1-9张)塔罗牌: 抽n张塔罗牌\n" - - "我的塔罗牌 : 获取你的塔罗牌记录\n" - - "抽老婆 : 返回一张算法随机生成的老婆\n" - - "项目地址 : 获取项目链接\n" + - "签到 : 签到获取积分\n" + - "获取当前积分 : 获取积分\n" friendhelp: - "私聊指令:\n" diff --git a/plugin/KissKiss/KissFrames/1.png b/plugin/ImgGenerator/KissKiss/KissFrames/1.png similarity index 100% rename from plugin/KissKiss/KissFrames/1.png rename to plugin/ImgGenerator/KissKiss/KissFrames/1.png diff --git a/plugin/KissKiss/KissFrames/10.png b/plugin/ImgGenerator/KissKiss/KissFrames/10.png similarity index 100% rename from plugin/KissKiss/KissFrames/10.png rename to plugin/ImgGenerator/KissKiss/KissFrames/10.png diff --git a/plugin/KissKiss/KissFrames/11.png b/plugin/ImgGenerator/KissKiss/KissFrames/11.png similarity index 100% rename from plugin/KissKiss/KissFrames/11.png rename to plugin/ImgGenerator/KissKiss/KissFrames/11.png diff --git a/plugin/KissKiss/KissFrames/12.png b/plugin/ImgGenerator/KissKiss/KissFrames/12.png similarity index 100% rename from plugin/KissKiss/KissFrames/12.png rename to plugin/ImgGenerator/KissKiss/KissFrames/12.png diff --git a/plugin/KissKiss/KissFrames/13.png b/plugin/ImgGenerator/KissKiss/KissFrames/13.png similarity index 100% rename from plugin/KissKiss/KissFrames/13.png rename to plugin/ImgGenerator/KissKiss/KissFrames/13.png diff --git a/plugin/KissKiss/KissFrames/2.png b/plugin/ImgGenerator/KissKiss/KissFrames/2.png similarity index 100% rename from plugin/KissKiss/KissFrames/2.png rename to plugin/ImgGenerator/KissKiss/KissFrames/2.png diff --git a/plugin/KissKiss/KissFrames/3.png b/plugin/ImgGenerator/KissKiss/KissFrames/3.png similarity index 100% rename from plugin/KissKiss/KissFrames/3.png rename to plugin/ImgGenerator/KissKiss/KissFrames/3.png diff --git a/plugin/KissKiss/KissFrames/4.png b/plugin/ImgGenerator/KissKiss/KissFrames/4.png similarity index 100% rename from plugin/KissKiss/KissFrames/4.png rename to plugin/ImgGenerator/KissKiss/KissFrames/4.png diff --git a/plugin/KissKiss/KissFrames/5.png b/plugin/ImgGenerator/KissKiss/KissFrames/5.png similarity index 100% rename from plugin/KissKiss/KissFrames/5.png rename to plugin/ImgGenerator/KissKiss/KissFrames/5.png diff --git a/plugin/KissKiss/KissFrames/6.png b/plugin/ImgGenerator/KissKiss/KissFrames/6.png similarity index 100% rename from plugin/KissKiss/KissFrames/6.png rename to plugin/ImgGenerator/KissKiss/KissFrames/6.png diff --git a/plugin/KissKiss/KissFrames/7.png b/plugin/ImgGenerator/KissKiss/KissFrames/7.png similarity index 100% rename from plugin/KissKiss/KissFrames/7.png rename to plugin/ImgGenerator/KissKiss/KissFrames/7.png diff --git a/plugin/KissKiss/KissFrames/8.png b/plugin/ImgGenerator/KissKiss/KissFrames/8.png similarity index 100% rename from plugin/KissKiss/KissFrames/8.png rename to plugin/ImgGenerator/KissKiss/KissFrames/8.png diff --git a/plugin/KissKiss/KissFrames/9.png b/plugin/ImgGenerator/KissKiss/KissFrames/9.png similarity index 100% rename from plugin/KissKiss/KissFrames/9.png rename to plugin/ImgGenerator/KissKiss/KissFrames/9.png diff --git a/plugin/KissKiss/KissFrames/Kiss.gif b/plugin/ImgGenerator/KissKiss/KissFrames/Kiss.gif similarity index 100% rename from plugin/KissKiss/KissFrames/Kiss.gif rename to plugin/ImgGenerator/KissKiss/KissFrames/Kiss.gif diff --git a/plugin/KissKiss/Kisskiss.py b/plugin/ImgGenerator/KissKiss/Kisskiss.py similarity index 85% rename from plugin/KissKiss/Kisskiss.py rename to plugin/ImgGenerator/KissKiss/Kisskiss.py index a0987ba..c9e84b9 100644 --- a/plugin/KissKiss/Kisskiss.py +++ b/plugin/ImgGenerator/KissKiss/Kisskiss.py @@ -1,3 +1,10 @@ +""" +:Author: NekoRabi +:Create: 2022/9/23 14:07 +:Update: / +:Describe: 亲亲群友 +:Version: 0.0.1 +""" import re import numpy import aiohttp @@ -11,8 +18,8 @@ from core import bot, commands_map, commandpre from utils.MessageChainBuilder import messagechain_builder -if not os.path.exists("./images/KissKiss"): - os.mkdir("./images/KissKiss") +if not os.path.exists("./images/ImgGenerator/KissKiss"): + os.mkdir("./images/ImgGenerator/KissKiss") __all__ = ['on_kiss'] @@ -28,7 +35,7 @@ async def kiss_make_frame(operator, target, i): operator_y = [64, 40, 105, 110, 82, 96, 80, 55, 65, 100, 80, 65, 65] target_x = [58, 62, 42, 50, 56, 18, 28, 54, 46, 60, 35, 20, 40] target_y = [90, 95, 100, 100, 100, 120, 110, 100, 100, 100, 115, 120, 96] - bg = IMG.open(f"./plugin/KissKiss/KissFrames/{i}.png") + bg = IMG.open(f"./plugin/ImgGenerator/KissKiss/KissFrames/{i}.png") gif_frame = IMG.new('RGB', (200, 200), (255, 255, 255)) gif_frame.paste(bg, (0, 0)) gif_frame.paste(target, (target_x[i - 1], target_y[i - 1]), target) @@ -37,10 +44,6 @@ async def kiss_make_frame(operator, target, i): async def kiss(operator_id, target_id) -> None: - if not os.path.exists("./images/KissKiss"): - os.mkdir("./images/KissKiss") - if not os.path.exists("./images/KissKiss/temp"): - os.mkdir("./images/KissKiss/temp") operator_url = f'http://q1.qlogo.cn/g?b=qq&nk={operator_id}&s=640' target_url = f'http://q1.qlogo.cn/g?b=qq&nk={target_id}&s=640' gif_frames = [] @@ -76,7 +79,7 @@ async def kiss(operator_id, target_id) -> None: for i in range(1, 14): gif_frames.append(await kiss_make_frame(operator, target, i)) - await save_gif(gif_frames, f'./images/KissKiss/temp/tempKiss-{operator_id}-{target_id}.gif', fps=25) + await save_gif(gif_frames, f'./images/ImgGenerator/KissKiss/tempKiss-{operator_id}-{target_id}.gif', fps=25) # 亲亲 @@ -94,4 +97,4 @@ async def on_kiss(event: GroupMessage): else: await kiss(operator_id=operator_id, target_id=target_id) await bot.send(event, messagechain_builder( - imgpath=f'./images/KissKiss/temp/tempKiss-{operator_id}-{target_id}.gif')) + imgpath=f'./images/ImgGenerator/KissKiss/tempKiss-{operator_id}-{target_id}.gif')) diff --git a/plugin/ImgGenerator/KissKiss/__init__.py b/plugin/ImgGenerator/KissKiss/__init__.py new file mode 100644 index 0000000..ff67935 --- /dev/null +++ b/plugin/ImgGenerator/KissKiss/__init__.py @@ -0,0 +1 @@ +from plugin.ImgGenerator.KissKiss.Kisskiss import * diff --git a/plugin/ImgOperation/MiSans-Bold.ttf b/plugin/ImgGenerator/MiSans-Bold.ttf similarity index 100% rename from plugin/ImgOperation/MiSans-Bold.ttf rename to plugin/ImgGenerator/MiSans-Bold.ttf diff --git a/plugin/ImgGenerator/__init__.py b/plugin/ImgGenerator/__init__.py new file mode 100644 index 0000000..406595d --- /dev/null +++ b/plugin/ImgGenerator/__init__.py @@ -0,0 +1,32 @@ +import os + +from core.help import add_help +from plugin.ImgGenerator.bwimg import * +from plugin.ImgGenerator.csgokill import * +from plugin.ImgGenerator.groupmember_imgoperation import * + +if not os.path.exists('./images/ImgGenerator'): + os.mkdir(f'./images/ImgGenerator') +if os.path.exists(r'./main.exe'): + from plugin.ImgGenerator.KissKiss import * + from plugin.ImgGenerator.jupai import * + from plugin.ImgGenerator.prank_on_groupmember import * +else: + _plugins = os.listdir(r'./plugin/ImgGenerator') + for path in _plugins: + if os.path.isdir(f'./plugin/ImgGenerator/{path}'): + if os.path.exists(f'./plugin/ImgGenerator/{path}/__init__.py'): + exec(f'from plugin.ImgGenerator.{path} import *') + + +add_help('group', [ + "举牌 [<文本>] :将文本写在举牌小人上发出来,最多40字\n", + "亲 / 亲亲 @群友 : 两人互亲\n", + "逮捕(我自己) @群友 : 逮捕某人\n", + "(我是)小可爱 @群友 : 可爱群友\n", + "丢/举(我自己)@群友 : 把群友丢出去/举起来\n ", + "吃掉 @群友 : 把群友吃了\n", + "bw [<文本>] [<图片>] : 返回一张黑白处理后的图片,底部有一行文字\n", + "截图 <回复消息> : 将一条文本聊天记录截图\n", + "击杀[<文本> 或 @群友] : 击杀群友\n" +]) diff --git a/plugin/ImgOperation/bwimg.py b/plugin/ImgGenerator/bwimg.py similarity index 74% rename from plugin/ImgOperation/bwimg.py rename to plugin/ImgGenerator/bwimg.py index c3c3b3c..72d9b44 100644 --- a/plugin/ImgOperation/bwimg.py +++ b/plugin/ImgGenerator/bwimg.py @@ -1,65 +1,65 @@ -import os -import re -from PIL import Image as IMG, ImageDraw, ImageFont -from mirai import GroupMessage, Plain, Image, MessageChain -from core import bot, commandpre, commands_map - -__all__ = ['bwimg'] - -if not os.path.exists("./images/ImgOperation"): - os.mkdir("./images/ImgOperation") - - -def makebwimg(imgname, text: str = ""): - filename = os.path.splitext(imgname)[0] - suffixname = os.path.splitext(imgname)[-1] - if suffixname == '.jpg': - suffixname = '.jpeg' - img = IMG.open(f'./images/tempimg/{filename}{suffixname}').convert('L') - width = img.width - height = img.height - if width > height: - fontsize = height // 10 - else: - fontsize = width // 10 - textlength = len(text) - if textlength == 0: - textlength = 1 - if fontsize > width / textlength: - fontsize = width // textlength - font = ImageFont.truetype( - font='./plugin/ImgOperation/MiSans-Bold.ttf', size=fontsize) - bgimg = IMG.new('RGB', (width, height + 30 + fontsize), (0, 0, 0)) - bgimg.paste(img, (0, 0, width, height)) - textdraw = ImageDraw.Draw(bgimg) - textdraw.text(((width - font.getsize(text)[0]) / 2, height + 10), text=f'{text}', font=font, fill=(255, 255, 255)) - bgimg.save(f'./images/ImgOperation/{filename}{os.path.splitext(imgname)[-1]}') - - -def deletesource(imgname): - filename = os.path.splitext(imgname)[0] - suffixname = os.path.splitext(imgname)[-1] - if suffixname == '.jpg': - suffixname = '.jpeg' - if os.path.exists(f'./images/ImgOperation/{filename}{suffixname}'): - os.remove(f'./images/ImgOperation/{filename}{suffixname}') - if os.path.exists(f'./images/ImgOperation/{imgname}'): - os.remove(f'./images/ImgOperation/{imgname}') - - -@bot.on(GroupMessage) -async def bwimg(event: GroupMessage): - msg = "".join(map(str, event.message_chain[Plain])) - m = re.match( - fr"^{commandpre}{commands_map['imgoperation']['bw']}", msg.strip()) - if m and event.message_chain.has(Image): - # try: - img = event.message_chain.get_first(Image) - imgname = img.image_id - await img.download(filename=f'./images/tempimg/{imgname}') - makebwimg(imgname, m.group(1)) - await bot.send(event, MessageChain([Image(path=f'./images/ImgOperation/{imgname}')])) - deletesource(imgname) - # except Exception as e: - # print(e) - # rootLogger.exception(e) +import os +import re +from PIL import Image as IMG, ImageDraw, ImageFont +from mirai import GroupMessage, Plain, Image, MessageChain +from core import bot, commandpre, commands_map + +__all__ = ['bwimg'] + +if not os.path.exists("./images/ImgGenerator"): + os.mkdir("./images/ImgGenerator") + + +def makebwimg(imgname, text: str = ""): + filename = os.path.splitext(imgname)[0] + suffixname = os.path.splitext(imgname)[-1] + if suffixname == '.jpg': + suffixname = '.jpeg' + img = IMG.open(f'./images/tempimg/{filename}{suffixname}').convert('L') + width = img.width + height = img.height + if width > height: + fontsize = height // 10 + else: + fontsize = width // 10 + textlength = len(text) + if textlength == 0: + textlength = 1 + if fontsize > width / textlength: + fontsize = width // textlength + font = ImageFont.truetype( + font='./plugin/ImgGenerator/MiSans-Bold.ttf', size=fontsize) + bgimg = IMG.new('RGB', (width, height + 30 + fontsize), (0, 0, 0)) + bgimg.paste(img, (0, 0, width, height)) + textdraw = ImageDraw.Draw(bgimg) + textdraw.text(((width - font.getsize(text)[0]) / 2, height + 10), text=f'{text}', font=font, fill=(255, 255, 255)) + bgimg.save(f'./images/ImgGenerator/{filename}{os.path.splitext(imgname)[-1]}') + + +def deletesource(imgname): + filename = os.path.splitext(imgname)[0] + suffixname = os.path.splitext(imgname)[-1] + if suffixname == '.jpg': + suffixname = '.jpeg' + if os.path.exists(f'./images/ImgGenerator/{filename}{suffixname}'): + os.remove(f'./images/ImgGenerator/{filename}{suffixname}') + if os.path.exists(f'./images/ImgGenerator/{imgname}'): + os.remove(f'./images/ImgGenerator/{imgname}') + + +@bot.on(GroupMessage) +async def bwimg(event: GroupMessage): + msg = "".join(map(str, event.message_chain[Plain])) + m = re.match( + fr"^{commandpre}\s*bw\s*(\S+)\s*$", msg.strip()) + if m and event.message_chain.has(Image): + # try: + img = event.message_chain.get_first(Image) + imgname = img.image_id + await img.download(filename=f'./images/tempimg/{imgname}') + makebwimg(imgname, m.group(1)) + await bot.send(event, MessageChain([Image(path=f'./images/ImgGenerator/{imgname}')])) + deletesource(imgname) + # except Exception as e: + # print(e) + # rootLogger.exception(e) diff --git a/plugin/ImgOperation/csgokill.py b/plugin/ImgGenerator/csgokill.py similarity index 86% rename from plugin/ImgOperation/csgokill.py rename to plugin/ImgGenerator/csgokill.py index 0455764..c39245b 100644 --- a/plugin/ImgOperation/csgokill.py +++ b/plugin/ImgGenerator/csgokill.py @@ -1,3 +1,10 @@ +""" +:Author: NekoRabi +:Create: 2022/9/23 14:07 +:Update: / +:Describe: 生成CSGO的击杀图片 +:Version: 0.0.1 +""" import base64 import random import re @@ -5,7 +12,6 @@ from io import BytesIO from PIL import Image as IMG, ImageFont, ImageDraw from mirai import GroupMessage, Plain, At -# from plugin.preinit.create_bot import bot from core import bot __all__ = ['cskill'] @@ -19,12 +25,12 @@ async def jisha(user: str, target: str, headshot=None, penetrate=None): target: 击杀目标 击杀图片生成消息链 """ - gun_file = random.choice(os.listdir(f'./plugin/ImgOperation/image/cs/')).replace('.png', '') + gun_file = random.choice(os.listdir(f'./plugin/ImgGenerator/image/cs/')).replace('.png', '') while gun_file in ['headshot', 'penetrate']: - gun_file = random.choice(os.listdir(f'./plugin/ImgOperation/image/cs/')).replace('.png', '') + gun_file = random.choice(os.listdir(f'./plugin/ImgGenerator/image/cs/')).replace('.png', '') # gun_file = random.choice(['ak47', 'awp', 'knife', 'm4a1', 'p90', 'deagle', 'fn57', 'hegrenade', 'usp']) - gun = f'./plugin/ImgOperation/image/cs/{gun_file}.png' - font = ImageFont.truetype('./plugin/ImgOperation/MiSans-Bold.ttf', 30) + gun = f'./plugin/ImgGenerator/image/cs/{gun_file}.png' + font = ImageFont.truetype('./plugin/ImgGenerator/MiSans-Bold.ttf', 30) headshot = random.random() headshot_img = None himg_a = None @@ -34,9 +40,9 @@ async def jisha(user: str, target: str, headshot=None, penetrate=None): if gun_file not in ['hegrenade', 'defuser', 'flashbang', 'diversion', 'fists', 'inferno', 'headshot', 'penetrate']: if not gun_file.startswith('knife'): if headshot < 0.1: - headshot_img = IMG.open(f'./plugin/ImgOperation/image/cs/headshot.png') + headshot_img = IMG.open(f'./plugin/ImgGenerator/image/cs/headshot.png') if penetrate < 0.1: - penetrate_img = IMG.open(f'./plugin/ImgOperation/image/cs/penetrate.png') + penetrate_img = IMG.open(f'./plugin/ImgGenerator/image/cs/penetrate.png') width, height = font.getsize(user) width2, height2 = font.getsize(target) img_gun = IMG.open(gun) diff --git a/plugin/ImgOperation/groupmember_imgoperation.py b/plugin/ImgGenerator/groupmember_imgoperation.py similarity index 91% rename from plugin/ImgOperation/groupmember_imgoperation.py rename to plugin/ImgGenerator/groupmember_imgoperation.py index 6213e84..e674dec 100644 --- a/plugin/ImgOperation/groupmember_imgoperation.py +++ b/plugin/ImgGenerator/groupmember_imgoperation.py @@ -1,3 +1,10 @@ +""" +:Author: NekoRabi +:Create: 2022/9/23 14:08 +:Update: / +:Describe: 群成员图片制作 +:Version: 0.0.1 +""" import random from utils.MessageChainBuilder import * @@ -11,8 +18,8 @@ import os import base64 -if not os.path.exists("./images/ImgOperation"): - os.mkdir("./images/ImgOperation") +if not os.path.exists("./images/ImgGenerator"): + os.mkdir("./images/ImgGenerator") __all__ = ['xka', 'daiburen', 'diuren', 'chiren', 'juren'] @@ -34,7 +41,7 @@ def addfont(img: Image, text, position=(0, 0), fontcolor=(0, 0, 0), fontsize=Non fontsize = min(maxs, fontsize) draw = ImageDraw.Draw(img) fontstyle = ImageFont.truetype( - font='./plugin/ImgOperation/MiSans-Bold.ttf', size=fontsize) + font='./plugin/ImgGenerator/MiSans-Bold.ttf', size=fontsize) if center: pxlength = fontstyle.getsize(text)[0] pos_x = (img.width - pxlength) // 2 @@ -81,7 +88,7 @@ async def get_head_sculpture(userid) -> Image: async def makedaibu(userid): avatar = await get_head_sculpture(userid) ima = avatar.resize((130, 130), Image.ANTIALIAS) - bgk = Image.open('./plugin/ImgOperation/image/daibu.png').convert("RGBA") + bgk = Image.open('./plugin/ImgGenerator/image/daibu.png').convert("RGBA") bgk.paste(ima, (68, 85, 68 + ima.width, 85 + ima.height)) return img_to_base64(bgk) @@ -102,13 +109,13 @@ async def makesmalllove(userid, username, sex: str = None): addfont(bgk, text=f'你们看到{username}了吗?', maxsize=(300, 30)) addfont(bgk, text=f'非常可爱,简直就是小天使', maxsize=(50, 20), position=(0, 250)) addfont(bgk, text=f'{sex}没失踪也没怎么样,我只是觉得你们都该看一下', position=(0, 280)) - bgk.save(fp=f'./images/ImgOperation/xiaokeai_{userid}.png') + bgk.save(fp=f'./images/ImgGenerator/xiaokeai_{userid}.png') async def throwpeople(userid): headimg = await get_head_sculpture(userid) headimg = circle_corner(headimg.resize((160, 160), Image.ANTIALIAS), 80) - bgk = Image.open('./plugin/ImgOperation/image/diu.png').convert("RGBA") + bgk = Image.open('./plugin/ImgGenerator/image/diu.png').convert("RGBA") bgk.paste(headimg, (10, 170, 10 + headimg.width, 170 + headimg.height), mask=headimg.split()[3]) return img_to_base64(bgk) @@ -116,7 +123,7 @@ async def throwpeople(userid): async def eatpeople(userid): headimg = await get_head_sculpture(userid) headimg = circle_corner(headimg.resize((160, 160), Image.ANTIALIAS), 80) - bgkimg = Image.open('./plugin/ImgOperation/image/eat.png').convert("RGBA") + bgkimg = Image.open('./plugin/ImgGenerator/image/eat.png').convert("RGBA") bgk = Image.new('RGB', bgkimg.size, (255, 255, 255)) bgk.paste(headimg, (90, 350, 90 + headimg.width, 350 + headimg.height), mask=headimg.split()[3]) bgk.paste(bgkimg, (0, 0), mask=bgkimg.split()[3]) @@ -126,7 +133,7 @@ async def eatpeople(userid): async def holdup(userid): headimg = await get_head_sculpture(userid) headimg = circle_corner(headimg.resize((240, 240), Image.ANTIALIAS), 120) - bgkimg = Image.open('./plugin/ImgOperation/image/ju.png').convert("RGBA") + bgkimg = Image.open('./plugin/ImgGenerator/image/ju.png').convert("RGBA") bgk = Image.new('RGB', bgkimg.size, (255, 255, 255)) bgk.paste(headimg, (80, 10, 80 + headimg.width, 10 + headimg.height), mask=headimg.split()[3]) bgk.paste(bgkimg, (0, 0), mask=bgkimg.split()[3]) @@ -147,7 +154,7 @@ async def daiburen(event: GroupMessage): userid = event.message_chain.get_first(At).target if userid: # await makedaibu(userid) - # return bot.send(event, messagechain_builder(imgpath=f'./images/ImgOperation/daibu_{userid}.png')) + # return bot.send(event, messagechain_builder(imgpath=f'./images/ImgGenerator/daibu_{userid}.png')) return await bot.send(event, messagechain_builder(imgbase64=await makedaibu(userid))) @@ -170,7 +177,7 @@ async def xka(event: GroupMessage): await makesmalllove(userid, memberinfo.member_name, member_profile.sex) else: await makesmalllove(userid, member_profile.nickname, member_profile.sex) - await bot.send(event, messagechain_builder(imgpath=f'./images/ImgOperation/xiaokeai_{userid}.png')) + await bot.send(event, messagechain_builder(imgpath=f'./images/ImgGenerator/xiaokeai_{userid}.png')) except Exception as e: print(e) pass diff --git a/plugin/ImgOperation/image/cs/ak47.png b/plugin/ImgGenerator/image/cs/ak47.png similarity index 100% rename from plugin/ImgOperation/image/cs/ak47.png rename to plugin/ImgGenerator/image/cs/ak47.png diff --git a/plugin/ImgOperation/image/cs/awp.png b/plugin/ImgGenerator/image/cs/awp.png similarity index 100% rename from plugin/ImgOperation/image/cs/awp.png rename to plugin/ImgGenerator/image/cs/awp.png diff --git a/plugin/ImgOperation/image/cs/deagle.png b/plugin/ImgGenerator/image/cs/deagle.png similarity index 100% rename from plugin/ImgOperation/image/cs/deagle.png rename to plugin/ImgGenerator/image/cs/deagle.png diff --git a/plugin/ImgOperation/image/cs/defuser.png b/plugin/ImgGenerator/image/cs/defuser.png similarity index 100% rename from plugin/ImgOperation/image/cs/defuser.png rename to plugin/ImgGenerator/image/cs/defuser.png diff --git a/plugin/ImgOperation/image/cs/diversion.png b/plugin/ImgGenerator/image/cs/diversion.png similarity index 100% rename from plugin/ImgOperation/image/cs/diversion.png rename to plugin/ImgGenerator/image/cs/diversion.png diff --git a/plugin/ImgOperation/image/cs/dronegun.png b/plugin/ImgGenerator/image/cs/dronegun.png similarity index 100% rename from plugin/ImgOperation/image/cs/dronegun.png rename to plugin/ImgGenerator/image/cs/dronegun.png diff --git a/plugin/ImgOperation/image/cs/fistspng.png b/plugin/ImgGenerator/image/cs/fistspng.png similarity index 100% rename from plugin/ImgOperation/image/cs/fistspng.png rename to plugin/ImgGenerator/image/cs/fistspng.png diff --git a/plugin/ImgOperation/image/cs/flashbang.png b/plugin/ImgGenerator/image/cs/flashbang.png similarity index 100% rename from plugin/ImgOperation/image/cs/flashbang.png rename to plugin/ImgGenerator/image/cs/flashbang.png diff --git a/plugin/ImgOperation/image/cs/fn57.png b/plugin/ImgGenerator/image/cs/fn57.png similarity index 100% rename from plugin/ImgOperation/image/cs/fn57.png rename to plugin/ImgGenerator/image/cs/fn57.png diff --git a/plugin/ImgOperation/image/cs/headshot.png b/plugin/ImgGenerator/image/cs/headshot.png similarity index 100% rename from plugin/ImgOperation/image/cs/headshot.png rename to plugin/ImgGenerator/image/cs/headshot.png diff --git a/plugin/ImgOperation/image/cs/hegrenade.png b/plugin/ImgGenerator/image/cs/hegrenade.png similarity index 100% rename from plugin/ImgOperation/image/cs/hegrenade.png rename to plugin/ImgGenerator/image/cs/hegrenade.png diff --git a/plugin/ImgOperation/image/cs/inferno.png b/plugin/ImgGenerator/image/cs/inferno.png similarity index 100% rename from plugin/ImgOperation/image/cs/inferno.png rename to plugin/ImgGenerator/image/cs/inferno.png diff --git a/plugin/ImgOperation/image/cs/knife.png b/plugin/ImgGenerator/image/cs/knife.png similarity index 100% rename from plugin/ImgOperation/image/cs/knife.png rename to plugin/ImgGenerator/image/cs/knife.png diff --git a/plugin/ImgOperation/image/cs/knife_butterfly.png b/plugin/ImgGenerator/image/cs/knife_butterfly.png similarity index 100% rename from plugin/ImgOperation/image/cs/knife_butterfly.png rename to plugin/ImgGenerator/image/cs/knife_butterfly.png diff --git a/plugin/ImgOperation/image/cs/m249.png b/plugin/ImgGenerator/image/cs/m249.png similarity index 100% rename from plugin/ImgOperation/image/cs/m249.png rename to plugin/ImgGenerator/image/cs/m249.png diff --git a/plugin/ImgOperation/image/cs/m4a1.png b/plugin/ImgGenerator/image/cs/m4a1.png similarity index 100% rename from plugin/ImgOperation/image/cs/m4a1.png rename to plugin/ImgGenerator/image/cs/m4a1.png diff --git a/plugin/ImgOperation/image/cs/m4a1_silencer.png b/plugin/ImgGenerator/image/cs/m4a1_silencer.png similarity index 100% rename from plugin/ImgOperation/image/cs/m4a1_silencer.png rename to plugin/ImgGenerator/image/cs/m4a1_silencer.png diff --git a/plugin/ImgOperation/image/cs/p90.png b/plugin/ImgGenerator/image/cs/p90.png similarity index 100% rename from plugin/ImgOperation/image/cs/p90.png rename to plugin/ImgGenerator/image/cs/p90.png diff --git a/plugin/ImgOperation/image/cs/penetrate.png b/plugin/ImgGenerator/image/cs/penetrate.png similarity index 100% rename from plugin/ImgOperation/image/cs/penetrate.png rename to plugin/ImgGenerator/image/cs/penetrate.png diff --git a/plugin/ImgOperation/image/cs/usp.png b/plugin/ImgGenerator/image/cs/usp.png similarity index 100% rename from plugin/ImgOperation/image/cs/usp.png rename to plugin/ImgGenerator/image/cs/usp.png diff --git a/plugin/ImgOperation/image/daibu.png b/plugin/ImgGenerator/image/daibu.png similarity index 100% rename from plugin/ImgOperation/image/daibu.png rename to plugin/ImgGenerator/image/daibu.png diff --git a/plugin/ImgOperation/image/diu.png b/plugin/ImgGenerator/image/diu.png similarity index 100% rename from plugin/ImgOperation/image/diu.png rename to plugin/ImgGenerator/image/diu.png diff --git a/plugin/ImgOperation/image/eat.png b/plugin/ImgGenerator/image/eat.png similarity index 100% rename from plugin/ImgOperation/image/eat.png rename to plugin/ImgGenerator/image/eat.png diff --git a/plugin/ImgOperation/image/ju.png b/plugin/ImgGenerator/image/ju.png similarity index 100% rename from plugin/ImgOperation/image/ju.png rename to plugin/ImgGenerator/image/ju.png diff --git a/plugin/ImgGenerator/jupai/__init__.py b/plugin/ImgGenerator/jupai/__init__.py new file mode 100644 index 0000000..7bb6dde --- /dev/null +++ b/plugin/ImgGenerator/jupai/__init__.py @@ -0,0 +1 @@ +from plugin.ImgGenerator.jupai.holdup import * diff --git a/plugin/jupai/fonts/shs_and_emoji.ttf b/plugin/ImgGenerator/jupai/fonts/shs_and_emoji.ttf similarity index 100% rename from plugin/jupai/fonts/shs_and_emoji.ttf rename to plugin/ImgGenerator/jupai/fonts/shs_and_emoji.ttf diff --git a/plugin/jupai/holdup.py b/plugin/ImgGenerator/jupai/holdup.py similarity index 81% rename from plugin/jupai/holdup.py rename to plugin/ImgGenerator/jupai/holdup.py index 67694e6..3791e14 100644 --- a/plugin/jupai/holdup.py +++ b/plugin/ImgGenerator/jupai/holdup.py @@ -1,88 +1,87 @@ -import re - -from PIL import ImageFont, ImageDraw, Image as IMG -import os -import random -import numpy as np -from mirai import GroupMessage, Plain, MessageChain, Image - -from core import bot, commandpre, commands_map - -if not os.path.exists("./images/jupai"): - os.mkdir("./images/jupai") - -__all__ = ['jupai'] - -def find_coeffs(pa, pb): - matrix = [] - for p1, p2 in zip(pa, pb): - matrix.append([p1[0], p1[1], 1, 0, 0, 0, -p2[0] * p1[0], -p2[0] * p1[1]]) - matrix.append([0, 0, 0, p1[0], p1[1], 1, -p2[1] * p1[0], -p2[1] * p1[1]]) - - A = np.matrix(matrix, dtype=np.float) - B = np.array(pb).reshape(8) - - res = np.dot(np.linalg.inv(A.T * A) * A.T, B) - return np.array(res).reshape(8) - - -def imgoutput(senderid: int, textMessage='拉克丝真可爱'): - print(f"开始创建图片,内容为:{textMessage}") - try: - font = ImageFont.truetype('./plugin/jupai/fonts/shs_and_emoji.ttf', 40) - text = textMessage[0:40] - pic_list = [] - for i in text: - width, height = font.getsize(i) - back = random.choice(os.listdir('./plugin/jupai/jupai')) - path = f'./plugin/jupai/jupai/{back}' - img = IMG.open(path) - # img = img.rotate(23, resample=IMG.BICUBIC, expand=True) - word = IMG.new('RGBA', (63, 42), (255, 255, 255, 1)) - draw = ImageDraw.Draw(word) - draw.text((20 - width / 2, 20 - height / 2), i, font=font, fill=(0, 0, 0)) - # word = word.resize((30, 40), IMG.ANTIALIAS) - # word = word.rotate(-30, resample=IMG.BICUBIC, expand=True) - coeffs = find_coeffs([(29, 0), (63, 14), (34, 42), (0, 28)], [(0, 0), (63, 0), (63, 42), (0, 42)]) - word = word.transform((63, 42), IMG.PERSPECTIVE, coeffs, IMG.BICUBIC) - img.paste(word, (14, 9), word) - pic_list.append(img) - text_num = len(pic_list) - 1 - lines = int(text_num / 8) - last = text_num % 8 - if lines == 0: - x = last * 55 + 80 - y = last * 21 + 165 - else: - x = lines * 45 + 465 - y = max(lines * 45 + last * 21 + 165, (lines - 1) * 45 + 312) - out = IMG.new('RGB', (x, y), (255, 255, 255)) - k = 0 - for i in pic_list: - no_x = k % 8 - no_y = int(k / 8) - out.paste(i, (no_x * 55 + (lines - no_y) * 45, no_y * 45 + no_x * 21), i) - k += 1 - # out = out.rotate(-23, resample=IMG.BICUBIC, expand=True) - out.save(f"./images/jupai/{senderid}.png") - except OSError: - print(OSError) - - - - -@bot.on(GroupMessage) -async def jupai(event: GroupMessage): - """创建举牌文字""" - msg = "".join(map(str, event.message_chain[Plain])) - m = re.match( - fr'''^{commandpre}{commands_map['jupai']['jupai']}''', msg.strip()) - if m: - - if len(m.group(1)) > 40: - await bot.send(event, "最多支持做40个字的举牌哦~") - imgoutput(event.sender.id, (m.group(1))) - message_chain = MessageChain([ - await Image.from_local(f'./images/jupai/{event.sender.id}.png') - ]) - await bot.send(event, message_chain) +import os +import random +import re + +import numpy as np +from PIL import ImageFont, ImageDraw, Image as IMG +from mirai import GroupMessage, Plain, MessageChain, Image + +from core import bot, commandpre + +if not os.path.exists("./images/ImgGenerator/jupai"): + os.mkdir("./images/ImgGenerator/jupai") + +__all__ = ['jupai'] + + +def find_coeffs(pa, pb): + matrix = [] + for p1, p2 in zip(pa, pb): + matrix.append([p1[0], p1[1], 1, 0, 0, 0, -p2[0] * p1[0], -p2[0] * p1[1]]) + matrix.append([0, 0, 0, p1[0], p1[1], 1, -p2[1] * p1[0], -p2[1] * p1[1]]) + + A = np.matrix(matrix, dtype=np.float) + B = np.array(pb).reshape(8) + + res = np.dot(np.linalg.inv(A.T * A) * A.T, B) + return np.array(res).reshape(8) + + +def imgoutput(senderid: int, textMessage='拉克丝真可爱'): + print(f"开始创建图片,内容为:{textMessage}") + try: + font = ImageFont.truetype('./plugin/ImgGenerator/jupai/fonts/shs_and_emoji.ttf', 40) + text = textMessage[0:40] + pic_list = [] + for i in text: + width, height = font.getsize(i) + back = random.choice(os.listdir('./plugin/ImgGenerator/jupai/jupai')) + path = f'./plugin/ImgGenerator/jupai/jupai/{back}' + img = IMG.open(path) + # img = img.rotate(23, resample=IMG.BICUBIC, expand=True) + word = IMG.new('RGBA', (63, 42), (255, 255, 255, 1)) + draw = ImageDraw.Draw(word) + draw.text((20 - width / 2, 20 - height / 2), i, font=font, fill=(0, 0, 0)) + # word = word.resize((30, 40), IMG.ANTIALIAS) + # word = word.rotate(-30, resample=IMG.BICUBIC, expand=True) + coeffs = find_coeffs([(29, 0), (63, 14), (34, 42), (0, 28)], [(0, 0), (63, 0), (63, 42), (0, 42)]) + word = word.transform((63, 42), IMG.PERSPECTIVE, coeffs, IMG.BICUBIC) + img.paste(word, (14, 9), word) + pic_list.append(img) + text_num = len(pic_list) - 1 + lines = int(text_num / 8) + last = text_num % 8 + if lines == 0: + x = last * 55 + 80 + y = last * 21 + 165 + else: + x = lines * 45 + 465 + y = max(lines * 45 + last * 21 + 165, (lines - 1) * 45 + 312) + out = IMG.new('RGB', (x, y), (255, 255, 255)) + k = 0 + for i in pic_list: + no_x = k % 8 + no_y = int(k / 8) + out.paste(i, (no_x * 55 + (lines - no_y) * 45, no_y * 45 + no_x * 21), i) + k += 1 + # out = out.rotate(-23, resample=IMG.BICUBIC, expand=True) + out.save(f"./images/ImgGenerator/jupai/{senderid}.png") + except OSError: + print(OSError) + + +@bot.on(GroupMessage) +async def jupai(event: GroupMessage): + """创建举牌文字""" + msg = "".join(map(str, event.message_chain[Plain])) + m = re.match( + fr'''^{commandpre}举牌\s*(\S+)\s*$''', msg.strip()) + if m: + + if len(m.group(1)) > 40: + await bot.send(event, "最多支持做40个字的举牌哦~") + imgoutput(event.sender.id, (m.group(1))) + message_chain = MessageChain([ + await Image.from_local(f'./images/ImgGenerator/jupai/{event.sender.id}.png') + ]) + await bot.send(event, message_chain) diff --git a/plugin/jupai/jupai/QP4a5rvW_0.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_0.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_0.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_0.png diff --git a/plugin/jupai/jupai/QP4a5rvW_1.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_1.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_1.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_1.png diff --git a/plugin/jupai/jupai/QP4a5rvW_10.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_10.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_10.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_10.png diff --git a/plugin/jupai/jupai/QP4a5rvW_11.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_11.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_11.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_11.png diff --git a/plugin/jupai/jupai/QP4a5rvW_12.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_12.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_12.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_12.png diff --git a/plugin/jupai/jupai/QP4a5rvW_13.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_13.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_13.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_13.png diff --git a/plugin/jupai/jupai/QP4a5rvW_14.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_14.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_14.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_14.png diff --git a/plugin/jupai/jupai/QP4a5rvW_15.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_15.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_15.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_15.png diff --git a/plugin/jupai/jupai/QP4a5rvW_16.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_16.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_16.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_16.png diff --git a/plugin/jupai/jupai/QP4a5rvW_17.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_17.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_17.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_17.png diff --git a/plugin/jupai/jupai/QP4a5rvW_18.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_18.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_18.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_18.png diff --git a/plugin/jupai/jupai/QP4a5rvW_19.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_19.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_19.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_19.png diff --git a/plugin/jupai/jupai/QP4a5rvW_2.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_2.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_2.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_2.png diff --git a/plugin/jupai/jupai/QP4a5rvW_20.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_20.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_20.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_20.png diff --git a/plugin/jupai/jupai/QP4a5rvW_21.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_21.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_21.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_21.png diff --git a/plugin/jupai/jupai/QP4a5rvW_22.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_22.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_22.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_22.png diff --git a/plugin/jupai/jupai/QP4a5rvW_23.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_23.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_23.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_23.png diff --git a/plugin/jupai/jupai/QP4a5rvW_24.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_24.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_24.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_24.png diff --git a/plugin/jupai/jupai/QP4a5rvW_25.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_25.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_25.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_25.png diff --git a/plugin/jupai/jupai/QP4a5rvW_26.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_26.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_26.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_26.png diff --git a/plugin/jupai/jupai/QP4a5rvW_27.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_27.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_27.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_27.png diff --git a/plugin/jupai/jupai/QP4a5rvW_28.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_28.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_28.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_28.png diff --git a/plugin/jupai/jupai/QP4a5rvW_29.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_29.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_29.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_29.png diff --git a/plugin/jupai/jupai/QP4a5rvW_3.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_3.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_3.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_3.png diff --git a/plugin/jupai/jupai/QP4a5rvW_30.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_30.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_30.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_30.png diff --git a/plugin/jupai/jupai/QP4a5rvW_31.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_31.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_31.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_31.png diff --git a/plugin/jupai/jupai/QP4a5rvW_32.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_32.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_32.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_32.png diff --git a/plugin/jupai/jupai/QP4a5rvW_33.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_33.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_33.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_33.png diff --git a/plugin/jupai/jupai/QP4a5rvW_34.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_34.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_34.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_34.png diff --git a/plugin/jupai/jupai/QP4a5rvW_35.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_35.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_35.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_35.png diff --git a/plugin/jupai/jupai/QP4a5rvW_36.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_36.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_36.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_36.png diff --git a/plugin/jupai/jupai/QP4a5rvW_37.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_37.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_37.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_37.png diff --git a/plugin/jupai/jupai/QP4a5rvW_38.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_38.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_38.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_38.png diff --git a/plugin/jupai/jupai/QP4a5rvW_39.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_39.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_39.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_39.png diff --git a/plugin/jupai/jupai/QP4a5rvW_4.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_4.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_4.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_4.png diff --git a/plugin/jupai/jupai/QP4a5rvW_40.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_40.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_40.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_40.png diff --git a/plugin/jupai/jupai/QP4a5rvW_5.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_5.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_5.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_5.png diff --git a/plugin/jupai/jupai/QP4a5rvW_6.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_6.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_6.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_6.png diff --git a/plugin/jupai/jupai/QP4a5rvW_7.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_7.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_7.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_7.png diff --git a/plugin/jupai/jupai/QP4a5rvW_8.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_8.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_8.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_8.png diff --git a/plugin/jupai/jupai/QP4a5rvW_9.png b/plugin/ImgGenerator/jupai/jupai/QP4a5rvW_9.png similarity index 100% rename from plugin/jupai/jupai/QP4a5rvW_9.png rename to plugin/ImgGenerator/jupai/jupai/QP4a5rvW_9.png diff --git a/plugin/prank_on_groupmember/MiSans-Bold.ttf b/plugin/ImgGenerator/prank_on_groupmember/MiSans-Bold.ttf similarity index 100% rename from plugin/prank_on_groupmember/MiSans-Bold.ttf rename to plugin/ImgGenerator/prank_on_groupmember/MiSans-Bold.ttf diff --git a/plugin/ImgGenerator/prank_on_groupmember/__init__.py b/plugin/ImgGenerator/prank_on_groupmember/__init__.py new file mode 100644 index 0000000..8db3845 --- /dev/null +++ b/plugin/ImgGenerator/prank_on_groupmember/__init__.py @@ -0,0 +1 @@ +from plugin.ImgGenerator.prank_on_groupmember.persecute_groupmenber import * diff --git a/plugin/prank_on_groupmember/persecute_groupmenber.py b/plugin/ImgGenerator/prank_on_groupmember/persecute_groupmenber.py similarity index 99% rename from plugin/prank_on_groupmember/persecute_groupmenber.py rename to plugin/ImgGenerator/prank_on_groupmember/persecute_groupmenber.py index 8536bef..39f42d6 100644 --- a/plugin/prank_on_groupmember/persecute_groupmenber.py +++ b/plugin/ImgGenerator/prank_on_groupmember/persecute_groupmenber.py @@ -1,3 +1,9 @@ +""" +:Author: NekoRabi +:Create: 2022/8/13 20:13 +:Update: / +:Describe: 一个'迫害'群友的插件 +""" import base64 import re import aiohttp @@ -11,12 +17,7 @@ default_fontsize = 48 default_maxwidth = default_fontsize * 15 -""" -:Author: NekoRabi -:Create: 2022/8/13 20:13 -:Update: / -:Describe: 一个'迫害'群友的插件 -""" + __all__ = ['groupmessage_screenshot'] diff --git a/plugin/prank_on_groupmember/shs_and_emoji.ttf b/plugin/ImgGenerator/prank_on_groupmember/shs_and_emoji.ttf similarity index 100% rename from plugin/prank_on_groupmember/shs_and_emoji.ttf rename to plugin/ImgGenerator/prank_on_groupmember/shs_and_emoji.ttf diff --git a/plugin/ImgOperation/__init__.py b/plugin/ImgOperation/__init__.py deleted file mode 100644 index beee212..0000000 --- a/plugin/ImgOperation/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from plugin.ImgOperation.bwimg import * -from plugin.ImgOperation.groupmember_imgoperation import * -from plugin.ImgOperation.csgokill import * diff --git a/plugin/KissKiss/__init__.py b/plugin/KissKiss/__init__.py deleted file mode 100644 index b61795b..0000000 --- a/plugin/KissKiss/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from plugin.KissKiss.Kisskiss import * diff --git a/plugin/MajSoulInfo/file_init.py b/plugin/MajSoulInfo/file_init.py index 76ba320..7d0cca3 100644 --- a/plugin/MajSoulInfo/file_init.py +++ b/plugin/MajSoulInfo/file_init.py @@ -1,6 +1,7 @@ import os import sqlite3 +from core.help import add_help from utils.cfg_loader import write_file if not os.path.exists("./database/MajSoulInfo"): @@ -142,3 +143,17 @@ def db_init(): db_init() + +_qhhelp = [ + "qhpt / 雀魂分数 / 雀魂pt [玩家名] (3/4) (序号):查询该玩家的段位分\n", + "qhsl / 雀魂十连 (限时/常驻) :来一次模拟雀魂十连\n", + "qhadd / 雀魂添加关注 [玩家名] :将一个玩家添加至雀魂自动查询,有新对局记录时会广播\n", + "qhgetwatch / 雀魂获取本群关注 :获取本群所有的雀魂关注的玩家\n", + "getmyqhsl / 我的雀魂十连 : 获取你的抽卡总结\n", + "qhdel / 雀魂删除关注 [玩家名] :将一个玩家从雀魂自动查询中移除,不再自动广播对局记录\n", + "qhpaipu / 雀魂最近对局 [玩家名] (3/4) ({1-10}) :查询一个玩家最近n场3/4人对局记录\n", + "qhinfo / 雀魂玩家详情 [玩家名] (3/4) ({基本/立直/血统/all}):查询一个玩家的详细数据\n", + "qhyb / 雀魂月报 [玩家名] (3/4) [yyyy-mm] :查询一个玩家yy年mm月的3/4麻对局月报\n" +] + +add_help('group', _qhhelp) diff --git a/plugin/MajSoulInfo/majsoulinfo.py b/plugin/MajSoulInfo/majsoulinfo.py index 9d2ddf4..ebb80c0 100644 --- a/plugin/MajSoulInfo/majsoulinfo.py +++ b/plugin/MajSoulInfo/majsoulinfo.py @@ -22,7 +22,7 @@ from utils.MessageChainBuilder import messagechain_builder from utils.cfg_loader import read_file from utils.text_to_img import text_to_image - +fontsize=36, asytimeout = aiohttp.ClientTimeout(total=60) levellist = [[1200, 1400, 2000], [2800, 3200, 3600], [4000, 6000, 9000]] @@ -266,7 +266,7 @@ async def getplayerdetail(self, playername: str, selecttype: str, selectlevel: l if _broadcast_type in ['txt', 'text', 'str']: return messagechain_builder(text=msg) else: - return messagechain_builder(imgbase64=text_to_image(text=msg, needtobase64=True)) + return messagechain_builder(imgbase64=text_to_image(fontsize=36, text=msg, needtobase64=True)) async def getsomeqhpaipu(self, playername: str, type="4", counts=5) -> MessageChain: """ @@ -351,11 +351,11 @@ async def asyrecordsrequest(_playerid, _type, _counts) -> list: return messagechain_builder(text=paipuInfo) elif _broadcast_type in ['mix', 'mixed']: return messagechain_builder(text=_paipu_link, - imgbase64=text_to_image(text=paipuInfo, needtobase64=True)) + imgbase64=text_to_image(fontsize=36, text=paipuInfo, needtobase64=True)) else: - # text_to_image(path=f"MajsoulInfo/qhpt{username}.png", text=prtmsg) - return messagechain_builder(imgbase64=text_to_image(text=paipuInfo, needtobase64=True)) - # result['img64'] = text_to_image(text=paipuInfo, needtobase64=True) + # text_to_image(fontsize=36, path=f"MajsoulInfo/qhpt{username}.png", text=prtmsg) + return messagechain_builder(imgbase64=text_to_image(fontsize=36, text=paipuInfo, needtobase64=True)) + # result['img64'] = text_to_image(fontsize=36, text=paipuInfo, needtobase64=True) return result def drawcards(self, userid: int, up=None) -> dict: @@ -752,7 +752,7 @@ def getrank(playerinfo: dict): _broadcast_type = _config.get('broadcast', 'image').lower() if _broadcast_type in ['txt', 'text', 'str']: return messagechain_builder(text=msg) - return messagechain_builder(imgbase64=text_to_image(text=msg, needtobase64=True)) + return messagechain_builder(imgbase64=text_to_image(fontsize=36, text=msg, needtobase64=True)) def removewatch(self, playername: str, groupid: int) -> str: """雀魂取消关注""" @@ -902,8 +902,8 @@ async def query(self, username: str, selecttype: str = "", selectindex: int = 1) if _broadcast_type in ['txt', 'text', 'str']: return messagechain_builder(text=prtmsg) else: - # text_to_image(path=f"MajsoulInfo/qhpt{username}.png", text=prtmsg) - return messagechain_builder(imgbase64=text_to_image(text=prtmsg, needtobase64=True)) + # text_to_image(fontsize=36, path=f"MajsoulInfo/qhpt{username}.png", text=prtmsg) + return messagechain_builder(imgbase64=text_to_image(fontsize=36, text=prtmsg, needtobase64=True)) # return dict(msg=prtmsg, error=False) async def getcertaininfo(self, username: str, selecttype: str = "4", selectindex: int = 1) -> MessageChain: @@ -980,8 +980,8 @@ async def getcertaininfo(self, username: str, selecttype: str = "4", selectindex if _broadcast_type in ['txt', 'text', 'str']: return messagechain_builder(text=prtmsg) else: - # text_to_image(path=f"MajsoulInfo/qhpt{username}.png", text=prtmsg) - return messagechain_builder(imgbase64=text_to_image(text=prtmsg, needtobase64=True)) + # text_to_image(fontsize=36, path=f"MajsoulInfo/qhpt{username}.png", text=prtmsg) + return messagechain_builder(imgbase64=text_to_image(fontsize=36, text=prtmsg, needtobase64=True)) def tagonplayer(self, playername, tagname, userid, groupid): """ diff --git a/plugin/Remake/remake.py b/plugin/Remake/remake.py index 26916a0..f7de218 100644 --- a/plugin/Remake/remake.py +++ b/plugin/Remake/remake.py @@ -10,11 +10,10 @@ import os from PIL import ImageDraw, ImageFont, Image as IMG from mirai import GroupMessage, Plain, MessageChain, Image -from core import bot, commandpre, commands_map +from core import bot, commandpre, commands_map, add_help from utils.MessageChainBuilder import messagechain_builder from utils.bufferpool import * - if not os.path.exists("./images/Remake"): os.mkdir("./images/Remake") @@ -166,3 +165,6 @@ async def getremakeimg(event: GroupMessage): worlddifficulty=worlddifficulty) await bot.send(event, MessageChain(Image(path=f'./images/Remake/{senderid}.png'))) return + + +add_help('group', "重开 / remake : 异世界转生\n") diff --git a/plugin/Tarot/tarot.py b/plugin/Tarot/tarot.py index 5beca87..b4eaed3 100644 --- a/plugin/Tarot/tarot.py +++ b/plugin/Tarot/tarot.py @@ -16,11 +16,14 @@ from PIL import Image, ImageDraw, ImageFont from mirai import GroupMessage, Plain from mirai.models import ForwardMessageNode, Forward -from core import bot, commandpre, commands_map +from core import bot, commandpre, commands_map,add_help from utils.MessageChainBuilder import messagechain_builder from utils.MessageChainSender import messagechain_sender from utils.cfg_loader import write_file - +add_help('group', [ + "(1-9张)塔罗牌: 抽n张塔罗牌\n", + "我的塔罗牌 : 获取你的塔罗牌记录\n" +]) __all__ = ['getsometarots', 'getmytarots', 'tarotcards'] diff --git a/plugin/TenHouPlugin/file_init.py b/plugin/TenHouPlugin/file_init.py index a8bf0cd..61cc27c 100644 --- a/plugin/TenHouPlugin/file_init.py +++ b/plugin/TenHouPlugin/file_init.py @@ -1,5 +1,6 @@ import os import sqlite3 + from utils.cfg_loader import write_file, read_file @@ -82,8 +83,6 @@ def file_init(): cx.commit() cursor.close() cx.close() - - commands = read_file(r'./config/command.yml') thcmds = { "thpt": r"(thpt|天凤pt|天凤分数)\s*(\S+)\s*(\S+)?\s*$", "addwatch": r"(thadd|天凤添加关注)\s*(\S+)\s*$", @@ -94,25 +93,11 @@ def file_init(): "tagoff": r"(thtagoff|天凤删除标记)\s*(\S+)\s*(\S+)?\s*$", "taglist": r"(qhtaglist)\s*(\S+)?\s*$" } - if commands.get('tenhou', None): - for key in ['thpt', 'addwatch', 'delwatch', 'getwatch', 'clearwatch', 'tagon', 'tagoff', 'taglist']: - if key not in commands.get('tenhou').keys(): - commands['tenhou'] = thcmds - write_file(commands, path=r'./config/command.yml') - break - else: - commands['tenhou'] = thcmds - write_file(commands, path=r'./config/command.yml') - # if not os.path.exists(r'./config/TenHouPlugin/command.yml'): - # w_cfg_to_file(thcmds, path=r'./config/command.yml') - # else: - # commands = loadcfg_from_file(r'./config/TenHouPlugin/command.yml') - # for key in ['thpt', 'addwatch', 'delwatch', 'getwatch', 'clearwatch', 'tagon', 'tagoff', 'taglist']: - # if key not in commands.keys(): - # commands['tenhou'] = thcmds - # w_cfg_to_file(commands, path=r'./config/command.yml') - # break + if not os.path.exists(r'./config/TenHouPlugin/command.yml'): + write_file(thcmds, path=r'./config/TenHouPlugin/command.yml') + file_init() + diff --git a/plugin/TenHouPlugin/th_bot.py b/plugin/TenHouPlugin/th_bot.py index 2919e9a..caa7c39 100644 --- a/plugin/TenHouPlugin/th_bot.py +++ b/plugin/TenHouPlugin/th_bot.py @@ -3,36 +3,42 @@ :Create: 2022/9/5 16:45 :Update: / :Describe: 天凤与机器人交互组件 -:Version: 0.0.1 +:Version: 0.0.3 """ import datetime import re from mirai import GroupMessage, Plain -from core import bot, commandpre, commands_map, scheduler +from core import bot, commandpre, scheduler, add_help from plugin.TenHouPlugin.TenHou import tenhou from utils.cfg_loader import read_file - -__all__ = ['ranktenhouplayer', 'asyth_all', 'addtenhouwatch', 'deltenhouwatcher', 'cleartenhouwatcher', - 'gettenhouwatcher'] - from utils import text_to_image - from utils.MessageChainBuilder import messagechain_builder - from utils.MessageChainSender import messagechain_sender - from utils.bufferpool import * from utils.get_groupmember_authority import is_having_admin_permission +add_help('group', [ + "thpt / 天凤pt / 天凤分数 [玩家名] : 查询玩家的天凤pt \n", + "thadd / 天凤添加关注 [玩家名] :将一个玩家添加指天凤的自动查询,有新对局会广播\n", + "thdel / 天凤删除关注 [玩家名] :将一个玩家从天凤自动查询中移除,不再自动广播对局记录\n", + "thgetwatch / 天凤获取本群关注 :获取本群所有的天凤关注的玩家\n", + "牌理[114514p1919m810s4z] : 天凤一般型牌理分析\n" +]) +__all__ = ['ranktenhouplayer', 'asyth_all', 'addtenhouwatch', 'deltenhouwatcher', 'cleartenhouwatcher', + 'gettenhouwatcher'] + + _cfg = read_file(r'./config/TenHouPlugin/config.yml') +_cmd = read_file(r'./config/TenHouPlugin/command.yml') + @bot.on(GroupMessage) async def ranktenhouplayer(event: GroupMessage): msg = "".join(map(str, event.message_chain[Plain])) - m = re.match(fr"^{commandpre}{commands_map['tenhou']['thpt']}", msg.strip()) + m = re.match(fr"^{commandpre}{_cmd.get('thpt')}", msg.strip()) if m: if not cmdbuffer.updategroupcache(GroupCommand(event.group.id, event.sender.id, 'thpt')): return messagechain_sender(event=event, @@ -57,7 +63,7 @@ async def ranktenhouplayer(event: GroupMessage): @bot.on(GroupMessage) async def addtenhouwatch(event: GroupMessage): msg = "".join(map(str, event.message_chain[Plain])) - m = re.match(fr"^{commandpre}{commands_map['tenhou']['addwatch']}", msg.strip()) + m = re.match(fr"^{commandpre}{_cmd.get('addwatch')}", msg.strip()) if m: if is_having_admin_permission(event): await messagechain_sender(event=event, @@ -69,7 +75,7 @@ async def addtenhouwatch(event: GroupMessage): @bot.on(GroupMessage) async def deltenhouwatcher(event: GroupMessage): msg = "".join(map(str, event.message_chain[Plain])) - m = re.match(fr"^{commandpre}{commands_map['tenhou']['delwatch']}", msg.strip()) + m = re.match(fr"^{commandpre}{_cmd.get('delwatch')}", msg.strip()) if m: if is_having_admin_permission(event): await bot.send(event, @@ -81,7 +87,7 @@ async def deltenhouwatcher(event: GroupMessage): @bot.on(GroupMessage) async def cleartenhouwatcher(event: GroupMessage): msg = "".join(map(str, event.message_chain[Plain])) - m = re.match(fr"^{commandpre}{commands_map['tenhou']['clearwatch']}", msg.strip()) + m = re.match(fr"^{commandpre}{_cmd.get('clearwatch')}", msg.strip()) if m: if is_having_admin_permission(event): await bot.send(event, tenhou.clearthwatch(groupid=event.group.id)) @@ -93,7 +99,7 @@ async def cleartenhouwatcher(event: GroupMessage): async def gettenhouwatcher(event: GroupMessage): msg = "".join(map(str, event.message_chain[Plain])) # 匹配指令 - m = re.match(fr"^{commandpre}{commands_map['tenhou']['getwatch']}", msg.strip()) + m = re.match(fr"^{commandpre}{_cmd.get('getwatch')}", msg.strip()) if m: await bot.send(event, tenhou.getthwatch(event.group.id)) @@ -102,7 +108,7 @@ async def gettenhouwatcher(event: GroupMessage): # @bot.on(GroupMessage) # async def thaddtag(event: GroupMessage): # msg = "".join(map(str, event.message_chain[Plain])) -# m = re.match(fr"^{commandpre}{commands_map['tenhou']['tagon']}", msg.strip()) +# m = re.match(fr"^{commandpre}{_cmd.get('tagon')}", msg.strip()) # if m: # if not m.group(3): # return await sendMsgChain(event=event, msg=messagechain_builder(text='请输入你要添加tag哦')) @@ -119,7 +125,7 @@ async def gettenhouwatcher(event: GroupMessage): # @bot.on(GroupMessage) # async def thdeltag(event: GroupMessage): # msg = "".join(map(str, event.message_chain[Plain])) -# m = re.match(fr"^{commandpre}{commands_map['tenhou']['tagoff']}", msg.strip()) +# m = re.match(fr"^{commandpre}{_cmd.get('tagoff')}", msg.strip()) # if m: # if is_havingadmin(event): # tagnames = None @@ -135,7 +141,7 @@ async def gettenhouwatcher(event: GroupMessage): # @bot.on(GroupMessage) # async def thtagoperate(event: GroupMessage): # msg = "".join(map(str, event.message_chain[Plain])) -# m = re.match(fr"^{commandpre}{commands_map['tenhou']['tagopeartion']}", msg.strip()) +# m = re.match(fr"^{commandpre}{_cmd.get('tagopeartion')}", msg.strip()) # ope_type = 'add' # p1 = 'xyshu' # p2 = '帅哥' @@ -161,7 +167,7 @@ async def gettenhouwatcher(event: GroupMessage): # @bot.on(GroupMessage) # async def thlisttag(event: GroupMessage): # msg = "".join(map(str, event.message_chain[Plain])) -# m = re.match(fr"^{commandpre}{commands_map['tenhou']['taglist']}", msg.strip()) +# m = re.match(fr"^{commandpre}{_cmd.get('taglist')}", msg.strip()) # if m: # target = m.group(2) # searchtype = 'playername' diff --git a/plugin/__init__.py b/plugin/__init__.py index 4c871cd..d76d873 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -25,13 +25,10 @@ # from plugin.AutoReply import * # from plugin.BilibiliPlugin import * # from plugin.draw_wife import * -# from plugin.ImgOperation import * -# from plugin.jupai import * -# from plugin.KissKiss import * +# from plugin.ImgGenerator import * # from plugin.MajSoulInfo import * # from plugin.paili_analysis import * # from plugin.Petpet import * -# from plugin.prank_on_groupmember import * # from plugin.Remake import * # from plugin.Setu import * # from plugin.Tarot import * diff --git a/plugin/draw_wife/drawwife.py b/plugin/draw_wife/drawwife.py index 7f290a7..6c63c4c 100644 --- a/plugin/draw_wife/drawwife.py +++ b/plugin/draw_wife/drawwife.py @@ -5,7 +5,7 @@ from io import BytesIO from mirai import GroupMessage, Plain -from core import bot +from core import bot, add_help from utils.MessageChainBuilder import messagechain_builder from PIL import Image, ImageDraw @@ -24,6 +24,7 @@ __all__ = ['drawwife'] + async def download_img(url): async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False), timeout=asytimeout, headers={'User-Agent': random.choice(user_agent_list)}) as session: @@ -55,3 +56,6 @@ async def drawwife(event: GroupMessage): img = await download_img(f'https://www.thiswaifudoesnotexist.net/example-{index}.jpg') return await bot.send(event, messagechain_builder(at=event.sender.id, imgbase64=img)) + + +add_help('group', "抽老婆 : 返回一张算法随机生成的老婆\n") diff --git a/plugin/jupai/__init__.py b/plugin/jupai/__init__.py deleted file mode 100644 index 667e9b9..0000000 --- a/plugin/jupai/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from plugin.jupai.holdup import * \ No newline at end of file diff --git a/plugin/prank_on_groupmember/__init__.py b/plugin/prank_on_groupmember/__init__.py deleted file mode 100644 index e6bfb26..0000000 --- a/plugin/prank_on_groupmember/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from plugin.prank_on_groupmember.persecute_groupmenber import * diff --git a/utils/cfg_loader.py b/utils/cfg_loader.py index 62bf068..193d8bc 100644 --- a/utils/cfg_loader.py +++ b/utils/cfg_loader.py @@ -6,7 +6,6 @@ :Version: 0.0.1 """ import os - import yaml import json diff --git a/utils/file_cleaner.py b/utils/file_cleaner.py index 03bba38..06581c7 100644 --- a/utils/file_cleaner.py +++ b/utils/file_cleaner.py @@ -9,17 +9,22 @@ __all__ = ['cleaner', 'FileCleaner'] +from utils.cfg_loader import read_file + class FileCleaner: def __init__(self, foldernames: list): - self.target = foldernames + self.target_folders = foldernames self.do_clean() + print(f'需要清理垃圾的文件路径为{self.target_folders}') def do_clean(self): + if len(self.target_folders) == 0: + return _allfile = [] print("开始清理文件") - for folderpath in self.target: + for folderpath in self.target_folders: if os.path.exists(folderpath): _allfile.extend(list_allfile(path=folderpath)) try: @@ -30,6 +35,18 @@ def do_clean(self): except FileNotFoundError as e: print(f"清理失败\t{e}") + def addtarget(self, folder_path: str or list): + if type(folder_path) is list: + for path in folder_path: + try: + self.target_folders.append(f'{path}') + except Exception as _e: + print(_e) + elif type(folder_path) is str: + self.target_folders.append(folder_path) + else: + raise TypeError('垃圾文件夹路径类型无效,仅接受str和list') + def list_allfile(path, all_files=None): if all_files is None: @@ -37,7 +54,7 @@ def list_allfile(path, all_files=None): if os.path.exists(path): files = os.listdir(path) else: - # print('文件不存在') + # print('路径不存在') return all_files for file in files: if os.path.isdir(os.path.join(path, file)): @@ -47,8 +64,6 @@ def list_allfile(path, all_files=None): return all_files -# TODO 垃圾清理的路径自定义,而不是通过代码写死 +_folders = read_file(r'./config/config.yml').get('trash_folders', []) -cleaner = FileCleaner( - ['./images/KissKiss', './images/jupai', './images/MajSoulInfo', './images/PetPet', './images/Remake', - './images/ImgOperation', './images/daibu']) +cleaner = FileCleaner(_folders)