コード例 #1
0
        def decorator(func: Callable):
            @wraps(func)
            @self._pre_check(only_to_me=only_to_me)
            async def wrapper(bot: Bot, event: Event, state: T_State):
                logger.debug(state)
                await func(bot, event)
                logger.info(
                    f'消息{event.get_session_id()}已被on_startswith处理器{func.__name__}处理。'
                )
                # await matcher.finish()

            for pfx in prefix:
                matcher = on_startswith(pfx, **kwargs)
                matcher.handle()(wrapper)
            return wrapper
コード例 #2
0
ファイル: love.py プロジェクト: lcy1317/QQrobot
from nonebot import on_command, on_startswith
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message

love = on_startswith(msg="love you", priority=4)

# 识别参数 并且给state 赋值


@love.handle()
async def love_rev(bot: Bot, event: Event, state: dict):
    await love.finish(message="love you too~", at_sender=True)


loves = on_startswith(msg="我爱你", priority=4)

# 识别参数 并且给state 赋值


@loves.handle()
async def loves_rev(bot: Bot, event: Event, state: dict):
    await loves.finish(message="我也爱你!mua~", at_sender=True)
コード例 #3
0
        str(event.message).replace("\n", "").replace("\r", ""),
    )
    if receive:
        file = receive.group("file")
        draw_text = receive.group("text")
        if draw_text:
            draw_text_list = char_to_pixels(draw_text)
            # print(draw_text_list)
            draw_text = ""
            for item in draw_text_list:
                draw_text += item[1]
            if await ascii_art(file=file,
                               draw_string=draw_text,
                               save_path=save_path):
                reply = f"[CQ:image,file=file:///{save_path}/temp.ascii.png]"
            else:
                reply = "error:生成图片失败"
        else:
            if await ascii_art(file=file, save_path=save_path):
                reply = f"[CQ:image,file=file:///{save_path}/temp.ascii.png]"
            else:
                reply = "error:生成图片失败"

    else:
        reply = "error:缺少图片"
    # print(reply)
    await bot.send(event, Message(reply))


ascii_art_cmd = on_startswith("字符画", handlers=[main])
コード例 #4
0
import requests
from nonebot import on_command, on_startswith
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message
import random

tiangou = on_startswith("舔狗日记", priority=3)
#love = on_keyword("土味情话",priority=3)

# 识别参数 并且给state 赋值


@tiangou.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
    tiangoudiary = await get_soil_sentence()
    await tiangou.finish(tiangoudiary)


async def get_soil_sentence():
    res = requests.get('https://v1.alapi.cn/api/dog?format=text')
    sentence = res.text
    return sentence
コード例 #5
0
ファイル: __init__.py プロジェクト: lcy1317/QQrobot
from nonebot import on_command,on_startswith
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message
import random
from . import data
love = on_startswith(msg="网抑", priority=2)
import requests


# 识别参数 并且给state 赋值


@love.handle()
async def love_rev(bot: Bot, event: Event, state: dict):
#    res = requests.get("https://chp.shadiao.app/api.php?from=sunbelife")
#    await love.finish(message = res.text, at_sender = True)
    seed = random.randint(0,len(data.kuakua)-1)
    await love.finish(message=data.kuakua[seed], at_sender=True)
コード例 #6
0
ファイル: soillove.py プロジェクト: lcy1317/QQrobot
import requests
from nonebot import on_command, on_startswith
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message
import random

love = on_startswith("土味情话", priority=3)
#love = on_keyword("土味情话",priority=3)

# 识别参数 并且给state 赋值


@love.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
    soillove = await get_soil_sentence()
    await love.finish(soillove)


async def get_soil_sentence():
    url = 'https://api.lovelive.tools/api/SweetNothings'
    res = requests.get(url)
    content_s = res.text
    return content_s
コード例 #7
0
ファイル: daily.py プロジェクト: lcy1317/QQrobot
import requests
from nonebot import on_command, on_startswith
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message
import random

love = on_startswith("每日一句", priority=3)
#love = on_keyword("土味情话",priority=3)

# 识别参数 并且给state 赋值


@love.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
    soillove = await get_soil_sentence()
    await love.finish(soillove[0])


async def get_soil_sentence():
    url = 'http://open.iciba.com/dsapi/'
    res = requests.get(url)
    content_e = res.json()['content']
    content_c = res.json()['note']
    return [content_c, content_e]
コード例 #8
0
ファイル: dujitang.py プロジェクト: lcy1317/QQrobot
from nonebot import on_startswith
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event
import requests
import json

weather = on_startswith("毒鸡汤", priority=2)


@weather.handle()
async def handle_first_receive(bot: Bot, event: Event, state: dict):
    se = await get_dujitang()
    await weather.finish(se)


async def get_dujitang():
    default_sentence = "我没见过一个煤矿工人靠挖煤又快又多当上了煤老板。"
    url = "http://rainbow.ilibrary.me/api/rainbow/random"
    headers = {
        "Accept":
        "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "Accept-Encoding":
        "gzip, deflate",
        "Accept-Language":
        "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        "Cache-Control":
        "max-age=0",
        "Cookie":
        "__gads=ID=2259474e6918a12c-223a528558c500b4:T=1608995008:RT=1608995008:S=ALNI_MYh2OIippuk5f3eJPNegsv62cABAg; UM_distinctid=1769f937360bc4-05f0488b1c204b-5a301e44-1fa400-1769f937361b5c",
        "Host":
        "rainbow.ilibrary.me",
コード例 #9
0
ファイル: __init__.py プロジェクト: 138436724/coup
# 游戏是否开始
game_flag = False
# 玩家数据
players = {}
# 身份牌
identities = ['公爵 ', '队长 ', '夫人 ', '刺客 ', '大使 '] * 4
# 身份牌墓地
card_graveyard = []

help_documentation = on_command("帮助", rule=to_me(), priority=0)

start_game = on_command("开始", rule=to_me(), priority=1)
draw_cards = on_endswith("人", rule=to_me(), priority=1)
give_cards = on_regex("^[1-7一二三四五六七两俩]", rule=to_me(), priority=2)
change_cards = on_startswith("换牌", rule=to_me(), priority=2)
die_cards = on_startswith("死亡", rule=to_me(), priority=2)
end_game = on_command("结束", rule=to_me(), priority=1)


@help_documentation.handle()
async def _(bot: Bot, event: Event):
    text = '请先呼我名\n' \
           '创建房间命令是”开始“\n' \
           '选择人数命令是“n人”\n' \
           '加入房间的命令是“n“\n' \
           '换牌命令是”换牌第n张“\n' \
           '死亡命令是”死亡第n张“\n' \
           '支持命令”结束“快速结束\n' \
           '详情规则参考http://www.yihubg.com/rule-details/7f81295f-7160-4261-b436-d385395b9b22'
    await help_documentation.finish(text)
コード例 #10
0
ファイル: gongneng.py プロジェクト: lcy1317/QQrobot
from nonebot import on_command, on_startswith
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message
import random

love = on_startswith(msg="功能", priority=1)

# 识别参数 并且给state 赋值


@love.handle()
async def love_rev(bot: Bot, event: Event, state: dict):
    await love.finish(
        message=
        "\n1.每日一句\n2.祖安/骂人\n3.夸夸\n4.人品\n5.舔狗日记\n6.土味情话\n7.网抑\n8.毒鸡汤\n9.查天气\n10.盛乐恒语录\n11.每日健康申报打卡,请私聊机器人发送健康申报查看详情",
        at_sender=True)
コード例 #11
0
ファイル: love.py プロジェクト: anlen123/my_nonebot2
from nonebot import on_command,on_startswith,on_keyword,on_message
from nonebot.plugin import on_notice, on_regex
from nonebot.rule import Rule, regex, to_me
from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message, message
from nonebot.typing import T_State
# def bool_img() -> Rule:
#     async def bool_img_(bot: "Bot", event: "Event", state: T_State) -> bool:
#         if event.get_type() != "message":
#             return False
#         return [ s.data['file'] for s in event.get_message() if s.type=="image" and "file" in s.data]
#     return Rule(bool_img_)
# 识别参数 并且给state 赋值

# love = on_regex(pattern="^love$",rule=to_me())
# love = on_message(rule=bool_img())

love = on_startswith(msg="love", rule=to_me())

@love.handle()
async def love_rev(bot: Bot, event: Event, state: dict):
    print(event.get_message())
    await love.finish(message="我也爱你"+Message("[CQ:face,id=214][CQ:face,id=66]"), at_sender=True)
    # await love.finish(message="我也爱你"+Message("[CQ:face,id=214]"), at_sender=True)
    # await love.finish(message="我也爱你"+MessageSegment.face(214),at_sender=True)
    # await bot.send(message="我也爱你"+Message("[CQ:face,id=214]"),at_sender=True)
コード例 #12
0
from nonebot import on_command, on_startswith
from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message
import sys
import os

sys.path.insert(0, os.getcwd())
print(sys.path)
import tiquzhilian

lanzouyun = on_startswith(msg="lanzouyun")


# 识别参数 并且给state 赋值

@lanzouyun.handle()
async def lanzouyun_rev(bot: Bot, event: Event, state: dict):
    msg = str(event.message).strip().split(" ")[1]
    print(msg)
    url = tiquzhilian.main(msg)
    # url = "12333"
    if url:
        await lanzouyun.finish(message=url, at_sender=True)
    else:
        await lanzouyun.finish(messages="解析出错", at_sender=True)
コード例 #13
0
ファイル: __init__.py プロジェクト: lcy1317/QQrobot
from nonebot import on_command, on_startswith
from nonebot.rule import to_me
from nonebot.adapters.cqhttp import Bot, Event, MessageSegment, Message
import random
from . import data
from . import namelist
love = on_startswith(msg="骂人", priority=2)
zuan = on_startswith(msg="祖安", priority=2)
import requests

# 识别参数 并且给state 赋值


@love.handle()
async def love_rev(bot: Bot, event: Event, state: dict):
    #print(event.__event__,type(event))
    if (event.__event__ == "message.group"):
        if (event.group_id in namelist.black_list_group): return
        if (namelist.white_list_group_on
                and event.group_id not in namelist.white_list_group):
            return
    elif (event.__event__ == "message.private"):
        if (event.user_id in namelist.black_list_private): return
        if (namelist.white_list_private_on
                and event.user_id not in namelist.white_list_private):
            return
    else:
        pass
    res = requests.get(
        "https://nmsl.shadiao.app/api.php?level=min&lang=zh_cn&from=sunbelife")
    await love.finish(message=res.text)