from nonebot import on_command, get_plugin_config,logger
from nonebot.rule import fullmatch
from .config import Config
import os
from nonebot_plugin_saa import Text, Image, MessageFactory
from nonebot.adapters.onebot.v11.event import GroupMessageEvent
import random
import asyncio

async def rule_fun(e:GroupMessageEvent):
    id = e.group_id
    if id in [621016172]:
        return True
    return False

plugin_config = get_plugin_config(Config)

help = on_command("帮助", rule=rule_fun and fullmatch(('帮助','help')), aliases={"help"}, priority=1, block=True)
@help.handle()
async def _():
    # 获取当前脚本所在目录的绝对路径
    current_dir = os.path.dirname(__file__)
    # 构造图片的绝对路径
    image_path = os.path.join(current_dir, "img", "帮助菜单.jpg")
    # 发送图片
    with open(image_path, "rb") as f:
        image_bytes = f.read()
    await asyncio.sleep(random.uniform(2, 3))
    await MessageFactory([Image(image_bytes)]).send(
            at_sender=True, reply=True
        )

downdload = on_command("下载", rule=rule_fun and fullmatch(('下载',"dl","downdload")), aliases={"dl","downdload"}, priority=1, block=True)
@downdload.handle()
async def _():
    await asyncio.sleep(random.uniform(2, 3))
    await downdload.finish(plugin_config.DowndLoadStr)

wd = on_command("帮助文档", rule=rule_fun and fullmatch(('帮助文档',"wd")), aliases={"wd"}, priority=1, block=True)
@wd.handle()
async def _():
    await asyncio.sleep(random.uniform(2, 3))
    await wd.finish("https://www.danding.vip")


free = on_command("公益版", rule=rule_fun and fullmatch(('公益版',"free","gyb")), aliases={"free","gyb"}, priority=1, block=True)
@free.handle()
async def _():
    await asyncio.sleep(random.uniform(2, 3))
    await help.finish(plugin_config.FreeStr)

pro = on_command("正式版", rule=rule_fun and fullmatch(('正式版',"pro","zsb")), aliases={"pro","zsb"}, priority=1, block=True)
@pro.handle()
async def _():
    await asyncio.sleep(random.uniform(2, 3))
    await help.finish(plugin_config.ProStr)

dyh = on_command("正式版御魂双开", rule=rule_fun and fullmatch(('正式版御魂双开',"dyh")), aliases={"dyh"}, priority=1, block=True)
@dyh.handle()
async def _():
    # 获取当前脚本所在目录的绝对路径
    current_dir = os.path.dirname(__file__)
    # 构造图片的绝对路径
    image_path = os.path.join(current_dir, "img", "御魂双开方法.jpg")
    # 发送图片
    with open(image_path, "rb") as f:
        image_bytes = f.read()
    await asyncio.sleep(random.uniform(2, 3))
    await MessageFactory([Text("御魂双开方法见下图"),Image(image_bytes)]).send(
            at_sender=True, reply=True
        )
    

htr = on_command("正式版如何运行", rule=rule_fun and fullmatch(('正式版如何运行',"htr")), aliases={"htr"}, priority=1, block=True)
@htr.handle()
async def _():
    # 获取当前脚本所在目录的绝对路径
    current_dir = os.path.dirname(__file__)
    # 构造图片的绝对路径
    image_path = os.path.join(current_dir, "img", "开软件教程.jpg")
    # 发送图片
    with open(image_path, "rb") as f:
        image_bytes = f.read()
    await asyncio.sleep(random.uniform(2, 3))
    await MessageFactory([Text("How To Run? Look!"),Image(image_bytes)]).send(
            at_sender=True, reply=True
        )
    
order = on_command("下单", rule=rule_fun and fullmatch(('下单',"xd")), aliases={"xd"}, priority=1, block=True)
@order.handle()
async def _():
    await asyncio.sleep(random.uniform(2, 3))
    await order.finish(plugin_config.OrderStr)

daily_trial = on_command("每日试用", rule=rule_fun and fullmatch(('每日试用',"mrss")), aliases={"mrss"}, priority=1, block=True)
@daily_trial.handle()
async def _():
    await asyncio.sleep(random.uniform(2, 3))
    await daily_trial.finish(plugin_config.DailyTrialStr)
