コード例 #1
0
@bcc.receiver(
    "GroupMessage",
    dispatchers=[
        Kanata(
            [FullMatch("test full match:"),
             RequireParam("full_match_result")],
            stop_exec_if_fail=True)
    ])
def test_full_match(full_match_result, event: GroupMessage):
    print(full_match_result)


@bcc.receiver("GroupMessage",
              dispatchers=[
                  Kanata([
                      RegexMatch(r"test regex match:(.*)"),
                      RequireParam("regex_match_result")
                  ],
                         stop_exec_if_fail=True)
              ])
def test_regex_match(regex_match_result, event: GroupMessage):
    print("regex match")
    print(regex_match_result)


postGroupMessage(
    MessageChain.create([Plain("test regex match:2134e"),
                         Face(faceId=123)]), bcc)

postGroupMessage(
    MessageChain.create([
コード例 #2
0
ファイル: main.py プロジェクト: LittleSkinCommspt/commspt-bot
    if not result.existed:
        await app.sendGroupMessage(group, MessageChain.create([Plain(f'「{player_name}」不存在')]))
    else:
        skin_hash = result.skins.slim or result.skins.default
        cape_hash = result.cape
        littleskin_root = 'https://mcskin.littleservice.cn'
        preview_images: List[Image] = list()
        for texture in [skin_hash, cape_hash]:
            if skin_hash:
                preview_images.append(Image.fromUnsafeBytes(await apis.getTexturePreview(
                    littleskin_root, texture)))
    await app.sendGroupMessage(group,
                               MessageChain.create([*preview_images, Plain(f'Skin: {skin_hash[:7] if skin_hash else None} [{result.skin_type}]\nCape: {cape_hash[:7] if cape_hash else None}')]))


@bcc.receiver("GroupMessage", dispatchers=[Kanata([RegexMatch(r'^草*$')])])
async def grass_spammer(app: GraiaMiraiApplication, group: Group, msg: MessageChain):
    disable_in_groups: List[int] = [qq.littleskin_main, qq.csl_group]
    if not group.id in disable_in_groups:
        await app.sendGroupMessage(group,
                                   MessageChain.create(
                                       [Plain('\u202e草')]))


@bcc.receiver(GroupMessage, dispatchers=[Kanata([CommandMatch('revoke', False)])])
async def command_handler(app: GraiaMiraiApplication, messagechain: MessageChain):
    if Quote in messagechain:
        origin_message = messagechain[Quote][0].origin[Source][0]
        current_message = messagechain[Source][0]
        await app.revokeMessage(origin_message)
        await app.revokeMessage(current_message)
@bcc.receiver("GroupMessage", dispatchers=[Kanata([FullMatch('plugins')])])
async def plugins_manager(app: GraiaMiraiApplication, group: Group):
    plugins = platform.get_plugins()
    text = "SagiriGraiaPlatform\n\n目前已加载插件:"
    serial_number = 1
    for plugin in plugins:
        text += f"\n\n{serial_number}. {plugin['name']}:"
        text += f"\n{plugin['description']}"
        serial_number += 1
    text += "\n\n你可输入 'pluginHelp 插件序号' 命令来查看插件详情"
    await app.sendGroupMessage(group, MessageChain.create([Plain(text=text)]))


@bcc.receiver("GroupMessage",
              dispatchers=[Kanata([RegexMatch('pluginHelp ([0-9]*)')])])
async def plugins_manager(app: GraiaMiraiApplication, group: Group,
                          message: MessageChain):
    plugins = platform.get_plugins()
    target = message.asDisplay()[11:]
    if target.isdigit():
        target = int(target)
        if target > len(plugins):
            await app.sendGroupMessage(
                group, MessageChain.create([Plain(text="非法插件序号!")]))
        else:
            plugin = plugins[target - 1]
            await app.sendGroupMessage(
                group,
                MessageChain.create([
                    Plain(text=f"插件详细信息:"),
コード例 #4
0
__name__ = "HeadSplicer"
__description__ = "一个接头霸王插件,修改自 https://github.com/pcrbot/plugins-for-Hoshino/tree/master/shebot/conhead"
__author__ = "SAGIRI-kawaii"
__usage__ = "群内发送 `接头[图片]` 即可"

saya = Saya.current()
channel = Channel.current()

channel.name(__name__)
channel.description(f"{__description__}\n使用方法:{__usage__}")
channel.author(__author__)

signal: int = 0


@channel.use(ListenerSchema(listening_events=[GroupMessage], inline_dispatchers=[Kanata([RegexMatch("接头.*")])]))
async def head_splicer(app: GraiaMiraiApplication, message: MessageChain, member: Member, group: Group):
    print(globals()["signal"])
    if not os.path.exists("./modules/HeadSplicer/temp/"):
        os.mkdir("./modules/HeadSplicer/temp/")
    if "".join([plain.text for plain in message.get(Plain)]).strip() == "接头":
        if globals()["signal"] >= 2:
            try:
                await app.sendGroupMessage(group, MessageChain.create([Plain(text=f"目前有{signal}个任务正在处理,请稍后再试!")]))
            except AccountMuted:
                pass
            return None

        globals()["signal"] += 1

        if message.get(Image):
コード例 #5
0
__name__ = "SteamGameSearcher"
__description__ = "一个通过关键词搜索steam游戏的插件"
__author__ = "SAGIRI-kawaii"
__usage__ = "在群内发送 `steam 游戏名` 即可"

saya = Saya.current()
channel = Channel.current()

channel.name(__name__)
channel.description(f"{__description__}\n使用方法:{__usage__}")
channel.author(__author__)


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[Kanata([RegexMatch('steam .*')])]))
async def steam_game_searcher(app: GraiaMiraiApplication,
                              message: MessageChain, group: Group):
    keyword = message.asDisplay()[6:]
    try:
        if keyword:
            await app.sendGroupMessage(group, await
                                       get_steam_game_search(keyword))
        else:
            await app.sendGroupMessage(
                group,
                MessageChain.create([Plain(text="请输入你要搜索的关键词(英文更管用哦~)")]))
    except AccountMuted:
        pass

コード例 #6
0
__name__ = "BangumiInfoSearcher"
__description__ = "一个可以搜索番剧信息的插件"
__author__ = "SAGIRI-kawaii"
__usage__ = "发送 `番剧 番剧名` 即可"

saya = Saya.current()
channel = Channel.current()

channel.name(__name__)
channel.description(f"{__description__}\n使用方法:{__usage__}")
channel.author(__author__)


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[Kanata([RegexMatch('番剧 .*')])]))
async def bangumi_info_searcher(app: GraiaMiraiApplication,
                                message: MessageChain, group: Group,
                                member: Member):
    keyword = message.asDisplay()[3:]
    try:
        if keyword:
            await app.sendGroupMessage(
                group, await get_bangumi_info(keyword, member.id))
        else:
            await app.sendGroupMessage(
                group, MessageChain.create([Plain(text="请输入你要搜索的关键词")]))
    except AccountMuted:
        pass

コード例 #7
0
__name__ = "PornhubStyleLogoGenerator"
__description__ = "一个可以生成 pornhub style logo 的插件"
__author__ = "SAGIRI-kawaii"
__usage__ = "发送 `ph text1 text2` 即可"

saya = Saya.current()
channel = Channel.current()

channel.name(__name__)
channel.description(f"{__description__}\n使用方法:{__usage__}")
channel.author(__author__)


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[Kanata([RegexMatch('5000兆 .* .*')])]))
async def pornhub_style_logo_generator(app: GraiaMiraiApplication,
                                       message: MessageChain, group: Group):
    try:
        _, left_text, right_text = message.asDisplay().split(" ")
        try:
            try:
                genImage(word_a=left_text,
                         word_b=right_text).save("./modules/5000zhao/test.png")
            except TypeError:
                await app.sendGroupMessage(
                    group,
                    MessageChain.create([Plain(text="不支持的内容!不要给我一些稀奇古怪的东西!")]))
                return None
            await app.sendGroupMessage(
                group,
コード例 #8
0
                except (ClientResponseError, PermissionError):
                    await app.sendGroupMessage(
                        group,
                        MessageChain.create([
                            Plain(text="检测到敏感词,发生错误: 无权限"),
                            Plain(text="\n过滤后:\n"),
                            Plain(text=DFA.replace_filter_word(message_text))
                        ]),
                        quote=message[Source][0])
            except AccountMuted:
                pass


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[Kanata([RegexMatch("(打开|关闭)敏感词过滤")])]))
async def switch_modify(app: GraiaMiraiApplication, message: MessageChain,
                        group: Group, member: Member):
    if member.id == HostQQ:
        switch = 1 if message.asDisplay()[:2] == "开启" else 0
        await set_group_switch(group.id, switch)
        try:
            await app.sendGroupMessage(
                group,
                MessageChain.create(
                    [Plain(text=f"敏感词过滤已{message.asDisplay()[:2]}")]))
        except AccountMuted:
            pass
    else:
        try:
            await app.sendGroupMessage(
コード例 #9
0
                await app.sendGroupMessage(
                    group,
                    MessageChain.create([Plain(text=f"{function}图功能尚未开启~")]))
        else:
            sql = f"SELECT {function} FROM setting WHERE groupId='{group.id}'"
            if (await execute_sql(sql))[0][0]:
                await app.sendGroupMessage(group, await get_pic(function))
            else:
                await app.sendGroupMessage(
                    group,
                    MessageChain.create([Plain(text=f"{function}图功能尚未开启~")]))


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[Kanata([RegexMatch("(打开|关闭).*功能")])]))
async def switch_control(app: GraiaMiraiApplication, message: MessageChain,
                         group: Group, member: Member):
    legal_config = ("setu", "setu18", "real", "realHighq", "bizhi", "sketch")
    config = re.findall(r"(.*?)功能", message.asDisplay()[2:], re.S)[0]
    if message.asDisplay().startswith("打开"):
        new_setting_value = 1
    else:
        new_setting_value = 0
    try:
        if config in legal_config:
            admins = await get_admin(group.id)
            if member.id in admins:
                await update_setting(group.id, config, new_setting_value)
                await app.sendGroupMessage(
                    group,
コード例 #10
0
__description__ = "一个可以获取leetcode信息的插件"
__author__ = "SAGIRI-kawaii"
__usage__ = "查询用户信息:发送 leetcode userSlug (userSlug为个人唯一标识 个人主页地址 -> https://leetcode-cn.com/u/userSlug/)" \
            "\n查询每日一题:发送 leetcode每日一题 即可"

saya = Saya.current()
channel = Channel.current()

channel.name(__name__)
channel.description(f"{__description__}\n使用方法:{__usage__}")
channel.author(__author__)


@channel.use(ListenerSchema(
    listening_events=[GroupMessage],
    inline_dispatchers=[Kanata([RegexMatch("leetcode .*")])]
))
async def leetcode_user_info_crawer(app: GraiaMiraiApplication, message: MessageChain, group: Group):
    try:
        if userSlug := message.asDisplay()[9:]:
            await app.sendGroupMessage(group, await get_leetcode_user_statics(userSlug))
        else:
            await app.sendGroupMessage(
                group,
                MessageChain.create([
                    Plain(text="请输入userSlug!\nuserSlug为个人主页地址的标识(https://leetcode-cn.com/u/userSlug/)")
                ])
            )
    except AccountMuted:
        pass
コード例 #11
0
from graia.saya import Saya, Channel
from graia.application.exceptions import AccountMuted

from .utils import *

# 插件信息
__name__ = "WyySongOrderer"
__description__ = "一个(全损音质x)网易云源的点歌插件"
__author__ = "SAGIRI-kawaii"
__usage__ = "在群中发送 `点歌 歌名` 即可"

saya = Saya.current()
channel = Channel.current()


@channel.use(ListenerSchema(
    listening_events=[GroupMessage],
    inline_dispatchers=[Kanata([RegexMatch("点歌 .*")])]
))
async def wyy_song_order(app: GraiaMiraiApplication, message: MessageChain, group: Group):
    if keyword := message.asDisplay()[3:].strip():
        try:
            await app.sendGroupMessage(group, await get_song_ordered(keyword, app))
        except AccountMuted:
            pass
    else:
        try:
            await app.sendGroupMessage(group, MessageChain.create([Plain(text="你要告诉我你要搜索什么歌呐~")]))
        except AccountMuted:
            pass
コード例 #12
0
from graia.application import GraiaMiraiApplication
from graia.application.event.messages import GroupMessage
from graia.application.message.parser.kanata import Kanata
from graia.application.message.parser.signature import RegexMatch
from graia.application.message.elements.internal import Plain, At
from graia.application.message.chain import MessageChain
from graia.application.group import Group, Member
from graia.saya import Channel
from graia.saya.builtins.broadcast.schema import ListenerSchema

channel = Channel.current()

channel.name("BanMe")
channel.description("发送'禁言我'禁言(前提是有权限)")
channel.author("I_love_study")


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[Kanata([RegexMatch('.禁言我.')])]))
async def auto_ban(app: GraiaMiraiApplication, group: Group,
                   message: MessageChain, member: Member):
    try:
        await app.mute(group, member, 600)
        await app.sendGroupMessage(
            group, MessageChain.create([Plain('那我就来实现你的愿望吧!')]))
    except PermissionError:
        await app.sendGroupMessage(
            group, MessageChain.create([Plain('对不起,我没有办法实现你的愿望555~')]))