Exemplo n.º 1
0
def initNow(app: GraiaMiraiApplication, message: MessageChain, friend, loop):
    global setuList, haotuList
    getPicList()
    if type(friend) is Friend:
        asyncio.run_coroutine_threadsafe(app.sendFriendMessage(friend, message.create(
            [Plain("今日色图:{}份\n今日好图:{}份".format(len(setuList), len(haotuList)))])), loop)
    elif type(friend) is Group:
        asyncio.run_coroutine_threadsafe(app.sendGroupMessage(friend, message.create(
            [Plain("今日色图:{}份\n今日好图:{}份".format(len(setuList), len(haotuList)))])), loop)
Exemplo n.º 2
0
    def __init__(self):
        with open('cfg.json', 'r', encoding='utf-8') as cfg:
            self.cfg = json.load(cfg)
        self.loop = asyncio.get_event_loop()
        self.bcc = Broadcast(loop=self.loop)
        self.qq = self.cfg['botConfig']['qq']
        self.name = self.cfg['botConfig']['botName']
        self.app = GraiaMiraiApplication(
            broadcast=self.bcc,
            connect_info=Session(host=self.cfg['botConfig']['host'],
                                 authKey=self.cfg['botConfig']['authKey'],
                                 account=self.qq,
                                 websocket=True))

        self.setu = self.cfg['setu']
        self.sticker = self.cfg['sticker']
        self.onlyGroup = self.cfg['onlyGroup']
        self.shieldGroup = self.cfg['shieldGroup']
        self.shieldFriend = self.cfg['shieldFriend']
        self.illustrationSearch = self.cfg['illustrationSearch']
        self.animeSearch = self.cfg['animeSearch']
        self.chatBot = self.cfg['chatBot']
        self.weather = self.cfg['weather']

        self.setuPath = self.cfg['setu']['path'] if self.cfg['setu'][
            'enable'] else None
        self.stickerPath = self.cfg['sticker']['path'] if self.cfg['sticker'][
            'enable'] else None
Exemplo n.º 3
0
def fixPics(app: GraiaMiraiApplication, message: MessageChain, friend, loop):
    """
    修复图片感叹号

    :param app:
    :param message:
    :param friend: 这里表示friend或者group
    :param loop:
    :return:
    """
    dirs = pivixDownloader._ROOTDIC + "/" + getDate()
    for ls in pivixDownloader._MODE:
        dir = dirs + "/" + ls
        pivixDownloader.PicTransfer(dir)
    if type(friend) is Friend:
        asyncio.run_coroutine_threadsafe(app.sendFriendMessage(friend, message.create(
            [Plain("修好啦!没修好的就没救了".format(len(setuList), len(haotuList)))])), loop)
    elif type(friend) is Group:
        asyncio.run_coroutine_threadsafe(app.sendGroupMessage(friend, message.create(
            [Plain("修好啦!没修好的就没救了".format(len(setuList), len(haotuList)))])), loop)
Exemplo n.º 4
0
async def RequsetBotMaster(
    app: GraiaMiraiApplication,
    target: Union[Friend, int],
    event: BotInvitedJoinGroupRequestEvent,
):
    botMessage = None
    try:
        await asyncio.sleep(randint(1, 10))
        botMessage = app.sendFriendMessage(
            target,
            MessageChain.create([
                Plain("有人邀请加群。\n"),
                Plain(f"请求事件ID: {event.requestId}\n"),
                Plain(f"邀请人为: {event.supplicant}\n"),
                Plain(f"邀请人称呼为: {event.nickname}\n"),
                Plain(f"群号为: {event.groupId}\n"),
                Plain(f"群名称为: {event.groupName}\n"),
                Plain(f"附加消息: {event.message}"),
            ]),
        )

        @Waiter.create_using_function([FriendMessage])
        async def wait(
                wait_event: FriendMessage,
                regexResult=regexPlain(r"^#(同意|拒绝)(?:\s*(?<=\s)(.*)|)$"),
        ):
            quote = wait_event.messageChain.get(Quote)
            if (not quote or wait_event.sender.id != target
                    or quote[0].id == botMessage.messageId):
                return None
            return regexResult

        raise ReturnValue([
            await Interrupt.interruptcontrol.wait(wait), target,
            botMessage.messageId
        ])
    except asyncio.CancelledError:
        await asyncio.sleep(randint(1, 10))
        await app.sendFriendMessage(target,
                                    MessageChain.create([Plain("已由其他人处理")]),
                                    quote=botMessage.messageId)
Exemplo n.º 5
0
def AtBot(param: int) -> callable:
    """
    used in headless_decotator
    """
    @Depend
    def func(messageChain: MessageChain) -> NoReturn:
        p = messageChain.get(At)
        if not p or not reduce(lambda a, b: bool(a or b),
                               map(lambda at: at.target == param, p), False):
            raise ExecutionStop()

    return func


loop = asyncio.get_event_loop()
bcc = Broadcast(loop=loop)
app = GraiaMiraiApplication(broadcast=bcc,
                            connect_info=connection_config(),
                            enable_chat_log=True,
                            debug=False)


@bcc.receiver("GroupMessage", headless_decorators=[AtBot(BotQQ)])
async def temp(app: GraiaMiraiApplication, event: GroupMessage):
    await app.sendGroupMessage(event.sender.group,
                               MessageChain.create([Plain("找我啥事?")]),
                               quote=event.messageChain.get(Source)[0])


app.launch_blocking()
Exemplo n.º 6
0
from utils import ModuleLoader, BotAttributes
from utils import logger

loop = asyncio.get_event_loop()
broadcast = Broadcast(loop=loop)
scheduler = GraiaScheduler(loop, broadcast)
saya = Saya(broadcast)

bot = BotAttributes("./config.json")

saya.install_behaviours(BroadcastBehaviour(broadcast))
saya.install_behaviours(GraiaSchedulerBehaviour(scheduler))

ModuleLoader.load(saya)

app = GraiaMiraiApplication(
    broadcast=broadcast,
    connect_info=Session(
        host=bot.host,
        authKey=bot.authKey,
        account=bot.account,
        websocket=True
    ),
    logger=logger
)

try:
    app.launch_blocking()
except KeyboardInterrupt:
    exit()
Exemplo n.º 7
0
Universe.set_value("SavePicLock", threading.Lock())
# 每日更新进度
isFresh = extraEvent.freshChecker()
# 色图总览
schedulepermission = extraEvent.getschedulepermission()

# 管理员
_MANAGER = accounts._ACCOUNT["BOTmanager"]
loop = asyncio.get_event_loop()

bcc = Broadcast(loop=loop)
app = GraiaMiraiApplication(
    broadcast=bcc,
    connect_info=Session(
        host="http://*****:*****@bcc.receiver("BotGroupPermissionChangeEvent")
async def getOwnerAccess(app: GraiaMiraiApplication):
    print(await app.groupList())


# 由于mirai问题,pcqq好友 无法接受
@bcc.receiver("FriendMessage")
async def friend_message_listener(app: GraiaMiraiApplication,
Exemplo n.º 8
0
from util.StaticText import Text, Strat_Txet, BotChat
from util.translate import language, language_keys

# 缓存区
Trans_member = {}
Img_search = []
Acg_search = []

loop = asyncio.get_event_loop()

bcc = Broadcast(loop=loop)
# bot的头部构造,自行修改
app = GraiaMiraiApplication(
    broadcast=bcc,
    connect_info=Session(
        host="http://*****:*****@bcc.receiver("GroupMessage")
async def group_message_handler(bot: GraiaMiraiApplication,
                                message: MessageChain, group: Group,
                                member: Member):
    # 赶时间,待重构
    if message.asDisplay().endswith(
            r"天气") and message.asDisplay()[0:3] != "亚托莉":
        start = time.perf_counter()
        c = message.asDisplay()
        await app.sendGroupMessage(
Exemplo n.º 9
0
from graia.broadcast import Broadcast
from graia.application.entry import GraiaMiraiApplication, Session
import asyncio
import yaml

with open('setting.yml') as f:
    setting = yaml.load(f, yaml.BaseLoader)
loop = asyncio.get_event_loop()
bcc = Broadcast(loop=loop)
app = GraiaMiraiApplication(
    broadcast=bcc,
    connect_info=Session(host=f"http://{setting['host']}:{setting['port']}",
                         authKey=f"{setting['authKey']}",
                         account=setting['qq'],
                         websocket=setting['enableWebsocket']))