Exemple #1
0
from botoy.collection import MsgTypes
from botoy.contrib import get_cache_dir
from botoy.decorators import ignore_botself, startswith, these_msgtypes
from botoy.session import SessionHandler, ctx, session

from .internal import convert, font_names, get_font, get_font_styles

weirdfonts_cache = get_cache_dir("weirdfonts") / "cache.json"
if not weirdfonts_cache.is_file():
    with open(weirdfonts_cache, "w") as f:
        json.dump({}, f)

weirdfonts = SessionHandler(
    ignore_botself,
    these_msgtypes(MsgTypes.TextMsg),
    startswith("花体"),
).receive_group_msg()


# 因为这个插件发了蛮多废话,所以都自动撤回一下。需要配合autoRevoke插件
def revoke(msg) -> str:
    return f"{msg}\n\nrevoke[30]"


@weirdfonts.handle
def _():
    # 确定待转化字符
    string = ctx.Content[2:]
    if not string:
        string = session.want("string",
                              revoke("请输入你想要转换的字符串(2分钟内)"),
            bullshit += nickname[random.randint(0, NICKNAME_LEN - 1)]
            bullshit += apology[random.randint(0, APOLOGY - 1)]
        else:
            bullshit += apology_text[random.randint(0, APOLOGY_TEXT - 1)]
    bullshit = bullshit.replace("name", name)
    bullshit = bullshit.replace("event", event)

    bullshit = "\n".join(
        [bullshit[i:i + 50] for i in range(0, len(bullshit), 50)])
    return f"关于{event}致最亲爱的{name}的道歉信\n\n{bullshit}"


honey = (SessionHandler(
    ignore_botself,
    these_msgtypes(MsgTypes.TextMsg),
    startswith("给女朋友道歉"),
).receive_group_msg().receive_friend_msg())


@honey.handle
def _():
    options = ctx.Content[6:].split("|")
    if len(options) == 2:
        honey.finish(generate(*options))

    name = session.want("name", "你想给你女朋友的称呼是啥?", timeout=60)
    if name is None:
        honey.finish()

    event = session.want("event", "为了啥事道歉呢?", timeout=60)
    if event is None:
Exemple #3
0
                del info_items[1]
                del info_items[-1]
                infos.append(" ".join(info_items))
            return "\n".join(infos)
        except Exception:
            pass

    return ""


ratelimit = RateLimit(5, 60)

weather_handler = SessionHandler(
    ignore_botself,
    # 指令必须为天气加地点
    startswith("天气"),
    lambda ctx: None if ctx.Content == "天气" else FILTER_SUCCESS,
    # magic
    ratelimit(lambda _: FILTER_SUCCESS),
).receive_group_msg()


@weather_handler.handle
def _():
    city = ctx.Content[2:]
    cities = search_city(city)
    if not cities:
        weather_handler.finish("没找到改地点相关信息,试试缩短关键字")

    if len(cities) == 1:
        code, name = cities[0]
"""管理员发送 清理僵尸+{可选加清理人数} 即可清理僵尸用户(要求机器人时管理员)"""
import time
from datetime import datetime

from botoy.collection import MsgTypes
from botoy.decorators import (from_admin, ignore_botself, startswith,
                              these_msgtypes)
from botoy.session import SessionHandler, ctx, session

zombie_handler = SessionHandler(
    ignore_botself,
    these_msgtypes(MsgTypes.TextMsg),
    startswith("清理僵尸"),
    from_admin,
).receive_group_msg()


def timestamp2date(timestamp: int):
    return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%m")


@zombie_handler.handle
def _():
    num = ctx.Content[4:]
    if num.isdigit():
        num = min(20, int(num))
    else:
        num = 5
    members = session.action.getGroupMembers(ctx.FromGroupId)
    members = [member for member in members if member["GroupAdmin"] == 0]
    members.sort(key=lambda member: member["LastSpeakTime"])
Exemple #5
0
        resp.raise_for_status()
        data = resp.json()
    except Exception:
        return "啊哦~API出错!"
    else:
        if not data:
            return ""
        name, trans = data[0]["name"], data[0]["trans"]
        trans_str = "、".join(trans)
        return f"【{name}】{trans_str}"


whatis_handler = SessionHandler(
    ignore_botself,
    these_msgtypes(MsgTypes.TextMsg),
    startswith("查询"),
).receive_group_msg()


@whatis_handler.handle
def _():
    # 如果查询指令后跟了内容就直接用这个了
    word: str = ctx.Content[2:]
    if not word:
        word = session.want("word", "你想要查什么呢?发送一个缩写试试~")

    if word is None:  # 超时了,默默退出吧
        whatis_handler.finish()

    result = whatis(word)
    if result: