Exemple #1
0
channel = Channel.current()

channel.name("QrcodeGenerator")
channel.author("SAGIRI-kawaii")
channel.description("一个生成二维码的插件,在群中发送 `qrcode 内容` 即可(文字)")


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([FullMatch("qrcode"),
                      RegexMatch(r"[^\s]+$") @ "content"])
        ],
        decorators=[
            FrequencyLimit.require("qrcode_generator", 1),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def qrcode_generator(app: Ariadne, message: MessageChain, group: Group,
                           content: RegexResult):
    content = content.result.asDisplay()
    qrcode_img = qrcode.make(content)
    bytes_io = BytesIO()
    qrcode_img.save(bytes_io)
    await app.sendGroupMessage(group,
                               MessageChain(
                                   [Image(data_bytes=bytes_io.getvalue())]),
                               quote=message.getFirst(Source))
Exemple #2
0
from sagiri_bot.control import FrequencyLimit, Function, BlackListControl, UserCalledCountControl

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

channel.name("RandomWife")
channel.author("SAGIRI-kawaii")
channel.description("生成随机老婆图片的插件,在群中发送 `[来个老婆|随机老婆]`")


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[Twilight([RegexMatch(r"(来个老婆|随机老婆)$")])],
        decorators=[
            FrequencyLimit.require("random_wife", 4),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def random_wife(app: Ariadne, message: MessageChain, group: Group):
    await app.sendGroupMessage(
        group,
        MessageChain([
            Image(
                url=
                f"https://www.thiswaifudoesnotexist.net/example-{random.randint(1, 100000)}.jpg"
            )
        ]),
        quote=message.getFirst(Source))
with open(str(Path(__file__).parent.joinpath("food.json")),
          "r",
          encoding="utf-8") as r:
    food = json.loads(r.read())


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           RegexMatch(r"[随隨][机機]"),
                           UnionMatch("早餐", "午餐", "晚餐") @ "option"
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("random_food", 2),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def random_meal(app: Ariadne, message: MessageChain, group: Group,
                      option: MatchResult):
    option = option.result.asDisplay()
    main_amount = 1 if option == "早餐" else 2
    dish = []
    if randrange(101) < 5:
        return "没得吃!"
    if randrange(2) if option != "午餐" else 1:
        dish.append(random.choice(food[option]["drink"]))
    if randrange(2) if option != "午餐" else 1:
proxy = config.proxy if config.proxy != "proxy" else ''
SAUCENAO_API_KEY = config.functions.get("saucenao_api_key", None)


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                UnionMatch("搜图", "识图", "以图搜图"),
                RegexMatch(r"[\s]+", optional=True),
                ElementMatch(Image, optional=True) @ "image"
            ])
        ],
        decorators=[
            FrequencyLimit.require("image_searcher", 3),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]
    )
)
async def image_searcher(app: Ariadne, message: MessageChain, group: Group, member: Member, image: ElementResult):

    @Waiter.create_using_function(listening_events=[GroupMessage])
    async def image_waiter(
        waiter_group: Group, waiter_member: Member, waiter_message: MessageChain
    ):
        if waiter_group.id == group.id and waiter_member.id == member.id:
            if waiter_message.has(Image):
                return waiter_message.getFirst(Image).url
from graia.ariadne.message.parser.twilight import Twilight
from graia.ariadne.message.parser.twilight import FullMatch
from graia.ariadne.event.message import Group, GroupMessage
from graia.saya.builtins.broadcast.schema import ListenerSchema

from statics.pero_dog_contents import pero_dog_contents
from sagiri_bot.control import FrequencyLimit, Function, BlackListControl, UserCalledCountControl

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

channel.name("PeroDog")
channel.author("SAGIRI-kawaii")
channel.description("一个获取舔狗日记的插件,在群中发送 `舔` 即可")


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[Twilight([FullMatch("舔")])],
        decorators=[
            FrequencyLimit.require("pero_dog", 1),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]
    )
)
async def pero_dog(app: Ariadne, group: Group):
    await app.sendGroupMessage(group, MessageChain(random.choice(pero_dog_contents).replace('*', '')))
Exemple #6
0
with open(os.path.join(FILE_PATH, 'gid_pool.json'), 'r',
          encoding='UTF-8') as f:
    group_pool = json.load(f)


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           RegexMatch(r"原神"),
                           RegexMatch(r"(10|90|180)") @ "count",
                           RegexMatch(r"连?抽?") @ "suffix"
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("gacha", 1),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
@switch()
@blacklist()
@frequency_limit_require_weight_free(1)
async def gacha(app: Ariadne, group: Group, message: MessageChain,
                member: Member, count: RegexResult):
    gid = group.id
    user_id = member.id
    count = int(count.result.asDisplay())
    if all([
            count == 10 and not daily_limiter_10.check(user_id), count == 90
Exemple #7
0
with open(f"{os.getcwd()}/statics/cp_data.json", "r", encoding="utf-8") as r:
    cp_data = json.loads(r.read())


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           FullMatch("/cp"),
                           RegexMatch(r"[^\s]+") @ "attack",
                           RegexMatch(r"[^\s]+") @ "defence"
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("cp_generator", 1),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def cp_generator(app: Ariadne, message: MessageChain, group: Group,
                       attack: RegexResult, defence: RegexResult):
    attack = attack.result.asDisplay()
    defence = defence.result.asDisplay()
    template = random.choice(cp_data["data"])
    content = template.replace("<攻>", attack).replace("<受>", defence)
    await app.sendGroupMessage(group,
                               MessageChain(content),
                               quote=message.getFirst(Source))

@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           FullMatch("彩色", optional=True) @ "colorful",
                           FullMatch("幻影"),
                           RegexMatch(r'[\s]?', optional=True),
                           ElementMatch(Image) @ "img1",
                           RegexMatch(r'[\s]?', optional=True),
                           ElementMatch(Image) @ "img2"
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("phantom_tank", 3),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def phantom_tank(app: Ariadne, message: MessageChain, group: Group,
                       colorful: RegexResult, img1: ElementResult,
                       img2: ElementResult):
    async with get_running(Adapter).session.get(url=img1.result.url) as resp:
        display_img = PIL.Image.open(BytesIO(await resp.read()))
    async with get_running(Adapter).session.get(url=img2.result.url) as resp:
        hide_img = PIL.Image.open(BytesIO(await resp.read()))
    if colorful.matched:
        msg = MessageChain([
            Image(data_bytes=await PhantomTank.colorful_tank(
@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                FullMatch("营销号#"),
                RegexMatch(r"[^\s]+") @ "somebody",
                FullMatch("#"),
                RegexMatch(r"[^\s]+") @ "something",
                FullMatch("#"),
                RegexMatch(r"[^\s]+") @ "other_word"
            ])
        ],
        decorators=[
            FrequencyLimit.require("marketing_content_generator", 1),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def marketing_content_generator(app: Ariadne, message: MessageChain,
                                      group: Group, somebody: RegexResult,
                                      something: RegexResult,
                                      other_word: RegexResult):
    somebody = somebody.result.asDisplay()
    something = something.result.asDisplay()
    other_word = other_word.result.asDisplay()
    content = f"{somebody}{something}是怎么回事呢?" \
              f"{somebody}相信大家都很熟悉,但是{somebody}{something}是怎么回事呢,下面就让小编带大家一起了解下吧。\n" \
              f"{somebody}{something},其实就是{somebody}{other_word},大家可能会很惊讶{somebody}怎么会{something}呢?" \
              f"但事实就是这样,小编也感到非常惊讶。\n" \
channel.name("MessageMerger")
channel.author("SAGIRI-kawaii")
channel.description("将收到的消息合并为图片,在群中发送 `/merge 文字/图片`")


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           FullMatch("/merge"),
                           WildcardMatch().flags(re.S) @ "msg_to_merge"
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("message_merger", 2),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def message_merger(app: Ariadne, message: MessageChain, group: Group,
                         msg_to_merge: RegexResult):
    await app.sendGroupMessage(
        group,
        MessageChain([
            Image(data_bytes=TextEngine([GraiaAdapter(msg_to_merge.result)],
                                        min_width=1080).draw())
        ]),
        quote=message.getFirst(Source))
channel.author("SAGIRI-kawaii")
channel.description("一个网络编译器插件,在群中发送 `super language\\n code`即可")


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           FullMatch("super"),
                           RegexMatch(r"[^\s]+") @ "language",
                           RegexMatch(r"[\s]+", optional=True),
                           RegexMatch(r"[\s\S]+") @ "code"
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("network_compiler", 2),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def network_compiler(app: Ariadne, message: MessageChain, group: Group,
                           language: RegexResult, code: RegexResult):
    if not await group_setting.get_setting(group.id, Setting.compile):
        await app.sendGroupMessage(group,
                                   MessageChain("网络编译器功能关闭了呐~去联系管理员开启吧~"))
        return
    language = language.result.asDisplay()
    code = code.result.asDisplay()
    result = await get_result(language, code)
    if isinstance(result, str):
Exemple #12
0
max_size = 2073600
mutex = Semaphore(1)


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           FullMatch("/超分"),
                           FullMatch("-resize", optional=True) @ "resize",
                           FullMatch("\n", optional=True) @ "enter",
                           ElementMatch(Image, optional=True) @ "image"
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("super_resolution", 5),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def super_resolution(app: Ariadne, message: MessageChain, group: Group,
                           member: Member, image: ElementResult,
                           resize: RegexResult):
    if result := await SuperResolution.handle(app, message, group, member,
                                              image, resize):
        await MessageSender(result.strategy).send(app, result.message, message,
                                                  group, member)


class SuperResolution(AbstractHandler):
Exemple #13
0
core = AppCore.get_core_instance()
config = core.get_config()
proxy = config.proxy if config.proxy != "proxy" else ''


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           FullMatch("pdf").space(SpacePolicy.FORCE),
                           RegexMatch(r".+") @ "keyword"
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("pdf_searcher", 4),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.SEARCH)
                   ]))
async def pdf_searcher(app: Ariadne, message: MessageChain, group: Group,
                       keyword: RegexResult):
    base_url = "https://zh.sg1lib.org"
    keyword = keyword.result.asDisplay().strip()
    url = f"{base_url}/s/?q={keyword}"
    async with aiohttp.ClientSession(connector=TCPConnector(
            verify_ssl=False)) as session:
        async with session.get(url=url, proxy=proxy) as resp:
            html = await resp.read()
    soup = BeautifulSoup(html, "html.parser")
Exemple #14
0
channel.name("GenshinMaterialRemind")
channel.author("SAGIRI-kawaii")
channel.description("一个可以查询原神每日可获取素材的插件,在群中发送 `原神今日素材` 即可")

core = AppCore.get_core_instance()
config = core.get_config()
proxy = config.proxy if config.proxy != "proxy" else ''
IMAGE_PATH = Path.cwd() / "statics" / "genshin" / "material"


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[Twilight([FullMatch("原神今日素材")])],
                   decorators=[
                       FrequencyLimit.require("genshin_material_remind", 2),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def genshin_material_remind(
    app: Ariadne,
    message: MessageChain,
    group: Group,
):
    if time.strftime("%w") == "0":
        await app.sendGroupMessage(group,
                                   MessageChain("今天是周日,所有材料副本都开放了。"),
                                   quote=message.getFirst(Source))
        return
    "在群中发送 `leetcode userslug` 可查询个人资料(userslug为个人主页地址最后的唯一识别代码)\n"
    "在群中发送 `leetcode每日一题` 可查询每日一题")


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                UnionMatch("leetcode", "力扣"),
                RegexMatch("每日一题$", optional=True) @ "daily_question",
                RegexMatch(r"\S+", optional=True) @ "user_slug"
            ])
        ],
        decorators=[
            FrequencyLimit.require("leetcode_info", 1),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def leetcode_info(app: Ariadne, group: Group,
                        daily_question: RegexResult, user_slug: RegexResult):
    if not daily_question.matched and not user_slug.matched or daily_question.matched and user_slug.matched:
        return
    if daily_question.matched:
        await app.sendGroupMessage(group, await get_leetcode_daily_question())
    else:
        await app.sendGroupMessage(
            group, await
            get_leetcode_user_statics(user_slug.result.asDisplay()))
Exemple #16
0
channel.name("AbstractMessageTransformer")
channel.author("SAGIRI-kawaii")
channel.description("一个普通话转抽象话的插件,在群中发送 `/抽象 文字` 即可")


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                FullMatch("/抽象 "),
                RegexMatch(r".*").help("要转抽象的内容") @ "content"
            ])
        ],
        decorators=[
            FrequencyLimit.require("abstract_message_transformer", 1),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]
    )
)
async def abstract_message_transformer(app: Ariadne, message: MessageChain, group: Group, content: RegexResult):
    result = ""
    content = content.result.asDisplay()
    length = len(content)
    index = 0
    while index < length:
        if index < length - 1 and (get_pinyin(content[index]) + get_pinyin(content[index + 1])) in emoji:
            result += emoji[get_pinyin(content[index]) + get_pinyin(content[index + 1])]
            index += 1
Exemple #17
0
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                FullMatch("我"),
                RegexMatch(r"有一?个", optional=True),
                FullMatch("朋友"),
                RegexMatch(
                    r"(想问问|说|让我问问|想问|让我问|想知道|让我帮他问问|让我帮他问|让我帮忙问|让我帮忙问问|问)"),
                FullMatch(" ", optional=True),
                FullMatch("-dark", optional=True) @ "dark",
                ElementMatch(At, optional=True) @ "target",
                RegexMatch(".+", optional=True) @ "content"
            ])
        ],
        decorators=[
            FrequencyLimit.require("i_have_a_friend", 2),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def i_have_a_friend(app: Ariadne, message: MessageChain, group: Group,
                          member: Member, content: RegexResult,
                          target: ElementResult, dark: RegexResult):
    if content.matched and content.result.asDisplay().strip():
        content = content.result.asDisplay()
        if target.matched:
            target = target.result.target
            member = await app.getMember(group, target)
            if not member:
                await app.sendGroupMessage(group,
                                           MessageChain("获取成员信息失败!"),
channel.author("SAGIRI-kawaii")
channel.description("一个接入WolframAlpha的插件,在群中发送 `/solve {content}` 即可")

api_key = AppCore.get_core_instance().get_config().functions.get(
    "wolfram_alpha_key", None)


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([FullMatch("/solve"),
                      RegexMatch(".+") @ "content"])
        ],
        decorators=[
            FrequencyLimit.require("wolfram_alpha", 4),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def wolfram_alpha(app: Ariadne, message: MessageChain, group: Group,
                        content: RegexResult):
    question = content.result.asDisplay()
    if not api_key or api_key == "wolfram_alpha_key":
        return MessageItem(
            MessageChain.create([Plain(text="尚未配置wolfram_alpha_key!")]),
            QuoteSource())
    url = f"https://api.wolframalpha.com/v1/simple?i={question.replace('+', '%2B')}&appid={api_key}"
    async with get_running(Adapter).session.get(url=url) as resp:
        if resp.status == 200:
            res = await resp.read()
channel = Channel.current()

channel.name("HotWordsExplainer")
channel.author("SAGIRI-kawaii")
channel.description("一个可以查询热门词的插件,在群中发送 `{keyword}是什么梗`")


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([RegexMatch(r"[^\s]+") @ "keyword",
                      FullMatch("是什么梗")])
        ],
        decorators=[
            FrequencyLimit.require("hot_words_explainer", 2),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def hot_words_explainer(app: Ariadne, message: MessageChain,
                              group: Group, keyword: RegexResult):
    await app.sendGroupMessage(group,
                               await get_result(keyword.result.asDisplay()),
                               quote=message.getFirst(Source))


async def get_result(keyword: str) -> MessageChain:
    url = "https://api.jikipedia.com/go/search_definitions"
    headers = {"Content-Type": "application/json;charset=UTF-8"}
    payload = {"phrase": keyword, "page": 1}
Exemple #20
0
from sagiri_bot.control import FrequencyLimit, Function, BlackListControl, UserCalledCountControl

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

channel.name("Tarot")
channel.author("SAGIRI-kawaii")
channel.description("可以抽塔罗牌的插件,在群中发送 `塔罗牌` 即可")


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[Twilight([FullMatch("塔罗牌")])],
                   decorators=[
                       FrequencyLimit.require("tarot", 1),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def tarot(app: Ariadne, message: MessageChain, group: Group):
    await app.sendGroupMessage(group,
                               Tarot.get_tarot(),
                               quote=message.getFirst(Source))


class Tarot(object):
    @staticmethod
    def get_tarot() -> MessageChain:
        card, filename = Tarot.get_random_tarot()
Exemple #21
0

@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight(
                [
                    FullMatch("来点"),
                    RegexMatch(r"[^\s]+") @ "keyword",
                    RegexMatch(r"[色涩瑟]图$"),
                ]
            )
        ],
        decorators=[
            FrequencyLimit.require("lolicon_keyword_searcher", 2),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.SETU),
        ],
    )
)
async def lolicon_keyword_searcher(
    app: Ariadne, message: MessageChain, group: Group, keyword: RegexResult
):
    keyword = keyword.result.asDisplay()
    msg_chain = await get_image(group, keyword)
    if msg_chain.onlyContains(Plain):
        return await app.sendGroupMessage(
            group, msg_chain, quote=message.getFirst(Source)
        )
Exemple #22
0
    "美国": america_jokes,
    "苏联": soviet_jokes
}


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           FullMatch("来点"),
                           RegexMatch(r"[^\s]+") @ "keyword",
                           FullMatch("笑话")
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("joke", 1),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def joke(app: Ariadne, group: Group, keyword: RegexResult):
    keyword = keyword.result.asDisplay()
    if keyword in joke_non_replace.keys():
        await app.sendGroupMessage(
            group, MessageChain(random.choice(joke_non_replace[keyword])))
    else:
        await app.sendGroupMessage(
            group,
            MessageChain(random.choice(jokes).replace("%name%", keyword)))
Exemple #23
0
channel.author("SAGIRI-kawaii")
channel.description("一个简查老师的插件,发送 `/查老师 {作品名/老师名/图片}` 即可")


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                FullMatch("/查老师"), RegexMatch(r"[\s]+", optional=True),
                ElementMatch(Image, optional=True) @ "image",
                WildcardMatch(optional=True) @ "keyword"
            ])
        ],
        decorators=[
            FrequencyLimit.require("xslist", 3),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]
    )
)
async def xslist_handler(app: Ariadne, group: Group, keyword: RegexResult, image: ElementResult):
    if image.matched:
        await app.sendGroupMessage(group, await search(data_bytes=await image.result.get_bytes()))
    elif keyword.matched:
        keyword = keyword.result.asDisplay().strip()
        await app.sendGroupMessage(group, await search(keyword=keyword))
    else:
        await app.sendGroupMessage(group, MessageChain("什么都没有,你让我查什么好呢~"))
Exemple #24
0
                    "在群中发送 `github热搜` 即可查看github热搜")

core = AppCore.get_core_instance()
config = core.get_config()
proxy = config.proxy if config.proxy != "proxy" else ''


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight(
                [UnionMatch("微博热搜", "知乎热搜", "github热搜") @ "trending_type"])
        ],
        decorators=[
            FrequencyLimit.require("trending", 1),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def trending(app: Ariadne, group: Group, trending_type: RegexResult):
    trending_type = trending_type.result.asDisplay()
    if trending_type == "微博热搜":
        await app.sendGroupMessage(group, await Trending.get_weibo_trending())
    elif trending_type == "知乎热搜":
        await app.sendGroupMessage(group, await Trending.get_zhihu_trending())
    elif trending_type == "github热搜":
        await app.sendGroupMessage(group, await Trending.get_github_trending())


class Trending(object):
Exemple #25
0
client_profile.httpProfile = http_profile


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                FullMatch("说").space(SpacePolicy.FORCE),
                ArgumentMatch("-v", "--voice", type=int, optional=True)
                @ "voice_type",
                WildcardMatch().flags(re.DOTALL) @ "content"
            ])
        ],
        decorators=[
            FrequencyLimit.require("speak", 2),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def speak(app: Ariadne, message: MessageChain, group: Group,
                voice_type: ArgResult, content: RegexResult):
    text = content.result.asDisplay()
    voice_type = voice_type.result if voice_type.matched else await group_setting.get_setting(
        group.id, Setting.voice)
    if voice_type == "off":
        return None
    if voice := await Speak.aget_voice(text, voice_type):
        if isinstance(voice, str):
            await app.sendGroupMessage(group,
                                       MessageChain(voice),
Exemple #26
0
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                FullMatch("pica"),
                UnionMatch("download", "search", "random", "rank",
                           "init") @ "operation",
                ArgumentMatch("-forward", action="store_true",
                              optional=True) @ "forward_type",
                ArgumentMatch("-message", action="store_true", optional=True)
                @ "message_type",
                UnionMatch("-H24", "-D7", "-D30", optional=True) @ "rank_time",
                RegexMatch(r".+", optional=True) @ "content"
            ])
        ],
        decorators=[
            FrequencyLimit.require("pica_function", 3),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def pica_function(app: Ariadne, message: MessageChain, group: Group,
                        member: Member, operation: RegexResult,
                        message_type: ArgResult, forward_type: ArgResult,
                        rank_time: RegexResult, content: RegexResult):
    if not pica.init:
        await app.sendGroupMessage(group,
                                   MessageChain("pica实例初始化失败,请重启机器人或重载插件!"))
        return
    if any([
            operation.result.asDisplay() == "download"
            and not DAILY_DOWNLOAD_LIMITER.check(member.id),
channel.author("SAGIRI-kawaii")
channel.description("可以搜索Github项目信息的插件,在群中发送 `/github [-i] {项目名}`")


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                FullMatch("/github"),
                ArgumentMatch("-i", "-image", action="store_true", optional=True) @ "image",
                RegexMatch(r"[^\s]+") @ "keyword"
            ])
        ],
        decorators=[
            FrequencyLimit.require("github_info", 2),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]
    )
)
async def github_info(app: Ariadne, message: MessageChain, group: Group, image: ArgResult, keyword: RegexResult):
    image = image.matched
    keyword = keyword.result.asDisplay()
    url = "https://api.github.com/search/repositories?q="
    img_url = "https://opengraph.githubassets.com/c9f4179f4d560950b2355c82aa2b7750bffd945744f9b8ea3f93cc24779745a0/"
    async with get_running(Adapter).session.get(url=url + keyword) as resp:
        result = (await resp.json())["items"]
    if not result:
        await app.sendGroupMessage(group, MessageChain("没有搜索到结果呢~"), quote=message.getFirst(Source))
Exemple #28
0
from graia.saya.builtins.broadcast.schema import ListenerSchema

from statics.character_dict import character_dict
from sagiri_bot.control import FrequencyLimit, Function, BlackListControl, UserCalledCountControl

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

channel.name("RandomCharacter")
channel.author("SAGIRI-kawaii")
channel.description("随机生成人设插件,在群中发送 `随机人设` 即可")


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[Twilight([FullMatch("随机人设")])],
                   decorators=[
                       FrequencyLimit.require("random_character", 1),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def random_character(app: Ariadne, message: MessageChain, group: Group):
    await app.sendGroupMessage(group,
                               MessageChain("\n".join([
                                   f"{k}:{random.choice(character_dict[k])}"
                                   for k in character_dict.keys()
                               ])),
                               quote=message.getFirst(Source))
Exemple #29
0
BREAK_LINE_MSG = '文字长度过长,请手动换行或适当缩减'


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                UnionMatch("nokia", "鲁迅说", "王境泽", "喜报", "记仇", "狂爱", "狂粉", "低语",
                           "别说了", "一巴掌", "为所欲为", "馋身子", "切格瓦拉", "谁反对", "连连看",
                           "压力大爷", "你好骚啊", "食屎啦你", "五年", "滚屏") @ "prefix",
                RegexMatch(r"[\s\S]+") @ "content"
            ])
        ],
        decorators=[
            FrequencyLimit.require("memes", 2),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def memes(app: Ariadne, message: MessageChain, group: Group,
                prefix: RegexResult, content: RegexResult):
    prefix = prefix.result.asDisplay().strip()
    content = [content.result.asDisplay()]
    result = None
    if prefix == "nokia":
        result = await Memes.make_nokia(content)
    elif prefix == "鲁迅说":
        result = await Memes.make_luxunsay(content)
    elif prefix == "喜报":
        result = await Memes.make_goodnews(content)
Exemple #30
0
from sagiri_bot.control import FrequencyLimit, Function, BlackListControl, UserCalledCountControl

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

channel.name("Dice")
channel.author("SAGIRI-kawaii")
channel.description("一个简单的投骰子插件,发送 `{times}d{range}` 即可")


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[Twilight([RegexMatch(r"[0-9]+d[0-9]+$")])],
        decorators=[
            FrequencyLimit.require("dice", 1),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]))
async def dice(app: Ariadne, message: MessageChain, group: Group):
    if not await group_setting.get_setting(group.id, Setting.dice):
        await app.sendGroupMessage(group,
                                   MessageChain("骰子功能尚未开启哟~"),
                                   quote=message.getFirst(Source))
        return
    times, max_point = message.asDisplay().strip().split('d')
    times, max_point = int(times), int(max_point)
    if times > 100:
        await app.sendGroupMessage(group,
                                   MessageChain("nmd,太多次了!"),