Exemple #1
0
from sagiri_bot.control import FrequencyLimit, Function, BlackListControl, UserCalledCountControl

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

channel.name("PoisonousChickenSoup")
channel.author("SAGIRI-kawaii")
channel.description("一个获取毒鸡汤的插件,在群中发送 `[鸡汤|毒鸡汤|来碗鸡汤]` 即可")

core = AppCore.get_core_instance()
config = core.get_config()


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[Twilight([RegexMatch(r"(鸡汤|毒鸡汤|来碗鸡汤)$")])],
        decorators=[
            FrequencyLimit.require("poisonous_chicken_soup", 1),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS)
        ]
    )
)
async def poisonous_chicken_soup(app: Ariadne, group: Group):
    url = f"https://api.shadiao.app/du"
    async with get_running(Adapter).session.get(url=url) as resp:
        text = (await resp.json())["data"].get("text", "未找到数据")
    await app.sendGroupMessage(group, MessageChain(text))
saya = Saya.current()
channel = Channel.current()

channel.name("GithubInfo")
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/"
Exemple #3
0
frames = tuple([f'{os.getcwd()}/statics/PetPetFrames/frame{i}.png' for i in range(5)])


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

channel.name("AvatarFunPic")
channel.author("SAGIRI-kawaii")
channel.description("一个可以生成头像相关趣味图的插件,在群中发送 `[摸|亲|贴|撕|丢|爬|精神支柱|吞] [@目标|目标qq|目标图片]` 即可")


@channel.use(ListenerSchema(
    listening_events=[GroupMessage],
    inline_dispatchers=[
        Twilight([
            RegexMatch("(摸|亲|贴|撕|丢|爬|精神支柱|吞)") @ "cmd",
            ElementMatch(At, optional=True) @ "at1",
            ElementMatch(At, optional=True) @ "at2",
            RegexMatch(r"[0-9]+", optional=True) @ "qq1",
            RegexMatch(r"[0-9]+", optional=True) @ "qq2",
            ElementMatch(Image, optional=True) @ "img1",
            ElementMatch(Image, optional=True) @ "img2"
        ])
    ]
))
async def avatar_fun_pic(
    app: Ariadne,
    message: MessageChain,
    group: Group,
    member: Member,
    cmd: RegexResult,
channel.description("一个可以以图搜图的插件,在群中发送 `搜图` 后,等待回应在30s内发送图片即可(多张图片只会搜索第一张)")

core = AppCore.get_core_instance()
bcc = core.get_bcc()
config = core.get_config()
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(
Exemple #5
0
    """ 超时Waiter """
    def __init__(self, group: Union[int, Group], member: Union[int, Member]):
        self.group = group if isinstance(group, int) else group.id
        self.member = (member if isinstance(member, int) else
                       member.id) if member else None

    async def detected_event(self, app: Ariadne, group: Group, member: Member,
                             message: MessageChain):
        if group.id == self.group and member.id == self.member:
            return True if re.match(r"[是否]", message.asDisplay()) else False


add_keyword_twilight = Twilight([
    FullMatch(r"添加"),
    FullMatch("群组", optional=True) @ "group_only",
    RegexMatch(r"(模糊|正则)", optional=True) @ "op_type",
    FullMatch("回复关键词#"),
    RegexMatch(r"[^\s]+") @ "keyword",
    FullMatch("#"),
    WildcardMatch().flags(re.DOTALL) @ "response"
])

delete_keyword_twilight = Twilight([
    FullMatch(r"删除"),
    FullMatch("群组", optional=True) @ "group_only",
    RegexMatch(r"(模糊|正则)", optional=True) @ "op_type",
    FullMatch("回复关键词#"),
    RegexMatch(r"[^\s]+") @ "keyword"
])

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

saya = Saya.current()
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))

Exemple #7
0
channel = Channel.current()

channel.name("CPGenerator")
channel.author("SAGIRI-kawaii")
channel.description("生成CP文的插件,在群中发送 `/cp {攻名字} {受名字}`")

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"])
from sagiri_bot.control import FrequencyLimit, Function, BlackListControl, UserCalledCountControl

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

channel.name("NetworkCompiler")
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,
saya = Saya.current()
channel = Channel.current()

channel.name("PhantomTank")
channel.author("SAGIRI-kawaii")
channel.description("一个幻影坦克生成器,在群中发送 `幻影 [显示图] [隐藏图]` 即可")


@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):
Exemple #10
0
from sagiri_bot.control import FrequencyLimit, Function, BlackListControl, UserCalledCountControl

saya = Saya.current()
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(
Exemple #11
0
channel.name("PDFSearcher")
channel.author("SAGIRI-kawaii")
channel.description("可以搜索pdf的插件,在群中发送 `pdf 书名` 即可")

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(
Exemple #12
0
from sagiri_bot.utils import group_setting
from sagiri_bot.orm.async_orm import Setting
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:
channel.author("SAGIRI-kawaii")
channel.description("群词云生成器," "在群中发送 `[我的|本群][日|月|年]内总结` 即可查看个人/群 月/年词云(群词云需要权限等级2)")

loop = AppCore.get_core_instance().get_loop()


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight(
                [
                    UnionMatch("我的", "本群") @ "scope",
                    UnionMatch("年内", "月内", "日内", "今日", "本月", "本年", "年度", "月度") @ "period",
                    UnionMatch("总结", "词云"),
                    RegexMatch(r"[0-9]+", optional=True) @ "topK",
                    RegexMatch(r"[\s]", optional=True),
                    ElementMatch(Image, optional=True) @ "mask",
                    RegexMatch(r"[\s]", optional=True)
                ]
            )
        ],
        decorators=[
            FrequencyLimit.require(channel.meta["name"], 2),
            Function.require(channel.module),
            BlackListControl.enable(),
            UserCalledCountControl.add(UserCalledCountControl.FUNCTIONS),
        ],
    )
)
async def group_wordcloud_generator(
channel.name("ColorCard")
channel.author("SAGIRI-kawaii")
channel.description("一个获取图片色卡的插件,在群中发送 `/色卡 -s={size} -m={mode} -t {图片/@成员/qq号/回复有图片的消息}` 即可,发送 `/色卡 -h` 查看帮助")

loop = AppCore.get_core_instance().get_loop()
bcc = saya.broadcast
inc = InterruptControl(bcc)


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                ElementMatch(At, optional=True),
                RegexMatch(r"/?色卡"),
                ArgumentMatch("-h", "-help", optional=True, action="store_true") @ "help",
                RegexMatch(r"-(s|size)=[0-9]+", optional=True) @ "size",
                RegexMatch(r"-(m|mode)=\w+", optional=True) @ "mode",
                RegexMatch(r"-(t|text)", optional=True) @ "text",
                RegexMatch(r"[\n\r]?", optional=True),
                ElementMatch(Image, optional=True) @ "image",
                ElementMatch(At, optional=True) @ "at",
                RegexMatch(r"[1-9][0-9]+", optional=True) @ "qq",
                RegexMatch(r"[\n\r]?", optional=True)
            ])
        ],
        decorators=[
            FrequencyLimit.require("color_card", 3),
            Function.require(channel.module),
            BlackListControl.enable(),
Exemple #15
0
                            [Image(data_bytes=self.wordle.get_board_bytes())]),
                        quote=message_source)
                return False


@channel.use(
    ListenerSchema(
        listening_events=[GroupMessage],
        inline_dispatchers=[
            Twilight([
                FullMatch("/wordle"),
                ArgumentMatch("-single", action="store_true",
                              optional=True) @ "single_game",
                ArgumentMatch("-group", action="store_true",
                              optional=True) @ "group_game",
                RegexMatch(r"-(l|length)=[0-9]+", optional=True) @ "length",
                RegexMatch(r"-(d|dic)=\w+", optional=True) @ "dic",
                ArgumentMatch(
                    "-help", "-h", action="store_true",
                    optional=True) @ "get_help",
                ArgumentMatch(
                    "-giveup", "-g", action="store_true", optional=True)
                @ "give_up",
                ArgumentMatch(
                    "-s", "-statistic", action="store_true", optional=True)
                @ "statistic"
            ])
        ]))
async def wordle(app: Ariadne, message: MessageChain, group: Group,
                 member: Member, single_game: ArgResult, dic: RegexResult,
                 length: ArgResult, get_help: ArgResult, give_up: ArgResult,
saya = Saya.current()
channel = Channel.current()

channel.name("MarketingContentGenerator")
channel.author("SAGIRI-kawaii")
channel.description("一个营销号内容生成器插件,在群中发送 `营销号#事件主体#事件内容#事件另一种说法` 即可")


@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,
Exemple #17
0
# 检查gid_pool.json是否存在,没有创建空的
if not os.path.exists(os.path.join(FILE_PATH, 'gid_pool.json')):
    save_group_pool()

# 读取gid_pool.json的信息
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,
Exemple #18
0
    player_name = params.result.asDisplay()
    player_uuid = await apis.MojangPlayerUuidApi.get(player_name)
    if not player_uuid.existed:
        await app.sendGroupMessage(group, MessageChain.create([Plain(f'「{player_name}」不存在')]))
        return
    async with aiohttp.ClientSession() as session:
        async with session.get(f'https://crafatar.com/renders/body/{player_uuid.id}?overlay') as resp:
            if resp.status == 200:
                image = await resp.content.read()
                await app.sendGroupMessage(group, MessageChain.create([Image(data_bytes=image)]))
            else:
                err_msg = await resp.text()
                await app.sendGroupMessage(group, MessageChain.create([Plain(f'Crafatar Error: {err_msg.strip()[:64]}')]))


@bcc.receiver("GroupMessage", dispatchers=[Twilight(Sparkle([RegexMatch(r'^草*$')]))])
async def grass_spammer(app: Ariadne, 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=[Twilight(Sparkle([CommandMatch('recall', False)]))])
async def command_handler(app: Ariadne, messagechain: MessageChain):
    if Quote in messagechain:
        origin_message = messagechain[Quote][0].id
        current_message = messagechain[Source][0].id
        await app.recallMessage(origin_message)
        await app.recallMessage(current_message)
channel.name("BWGrass")
channel.author("SAGIRI-kawaii")
channel.description("一个生成黑白草图的插件,在群中发送 `黑白[草]图 内容 图片` 即可")

core = AppCore.get_core_instance()
config = core.get_config()


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           FullMatch("黑白"),
                           FullMatch("草", optional=True),
                           FullMatch("图"),
                           RegexMatch(r".+") @ "content",
                           ElementMatch(Image) @ "image"
                       ])
                   ]))
async def black_white_grass(app: Ariadne, message: MessageChain, group: Group,
                            member: Member, content: RegexResult,
                            image: ElementResult):
    if result := await BWGrass.handle(app, message, group, member, content,
                                      image):
        await MessageSender(result.strategy).send(app, result.message, message,
                                                  group, member)


class BWGrass(AbstractHandler):
    __name__ = "BWGrass"
    __description__ = "一个生成黑白草图的插件"
Exemple #20
0
saya = Saya.current()
channel = Channel.current()

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
Exemple #21
0
core = AppCore.get_core_instance()
config = core.get_config()
proxy = config.proxy if config.proxy != "proxy" else ""
image_cache = config.data_related.get("lolicon_image_cache")
data_cache = config.data_related.get("lolicon_data_cache")


@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
):
channel = Channel.current()

channel.name("WolframAlpha")
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}"
Exemple #23
0
from sagiri_bot.control import FrequencyLimit, Function, BlackListControl, UserCalledCountControl

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

channel.name("XsList")
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()))
Exemple #24
0

@channel.use(
    ListenerSchema(
        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实例初始化失败,请重启机器人或重载插件!"))
Exemple #25
0
from graia.saya.builtins.broadcast.schema import ListenerSchema

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"
            )
        ]),
channel.name("LeetcodeInfo")
channel.author("SAGIRI-kawaii")
channel.description(
    "一个可以获取Leetcode信息的插件\n"
    "在群中发送 `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())
Exemple #27
0
channel.name("RandomFood")
channel.author("nullqwertyuiop")
channel.description("随机餐点")

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 = []
Exemple #28
0
    "一个生成假聊天记录插件,\n"
    "在群中发送 "
    "`我(有一?个)?朋友(想问问|说|让我问问|想问|让我问|想知道|让我帮他问问|让我帮他问|让我帮忙问|让我帮忙问问|问) [-dark] [@target] 内容` "
    "即可 [@目标]")

core = AppCore.get_core_instance()
config = core.get_config()


@channel.use(
    ListenerSchema(
        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)
        ]))
Exemple #29
0
IMAGE_BASE_PATH = f"{os.getcwd()}/statics/memes/"
THUMB_BASE_PATH = f"{os.getcwd()}/statics/memes/"
DEFAULT_FONT = 'SourceHanSansSC-Regular.otf'
OVER_LENGTH_MSG = '文字长度过长,请适当缩减'
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)
Exemple #30
0
loop = bcc.loop

channel.name("GenshinResourcePoints")
channel.author("SAGIRI-kawaii")
channel.description(
    "一个获取原神资源的插件\n"
    "在群中发送 `{resource_name} 在哪里? | 哪里?有 {resource_name}` 即可查看资源地图\n"
    "在群中发送 `原神资源列表` 即可查看资源列表")


@channel.use(
    ListenerSchema(listening_events=[GroupMessage],
                   inline_dispatchers=[
                       Twilight([
                           FullMatch("原神"),
                           RegexMatch(r"哪里?有", optional=True),
                           RegexMatch(r"[^\s]+") @ "resource_name",
                           RegexMatch(r"在哪里?")
                       ])
                   ],
                   decorators=[
                       FrequencyLimit.require("genshin_resource_points", 4),
                       Function.require(channel.module),
                       BlackListControl.enable(),
                       UserCalledCountControl.add(
                           UserCalledCountControl.FUNCTIONS)
                   ]))
async def genshin_resource_points(app: Ariadne, message: MessageChain,
                                  group: Group, resource_name: RegexResult):
    resource_name = resource_name.result.asDisplay().strip()
    if check_resource_exists(resource_name):