Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/bot.py

68 lines
1.9 KiB
Python
Raw Normal View History

2020-08-07 06:55:35 +00:00
import asyncio
2021-02-01 15:25:57 +00:00
import os
2021-02-15 09:36:01 +00:00
from os.path import abspath
import config
2020-09-19 10:35:13 +00:00
2021-02-01 15:13:11 +00:00
from graia.application import GraiaMiraiApplication
2021-02-02 09:33:55 +00:00
from graia.application.event.mirai import NewFriendRequestEvent, BotInvitedJoinGroupRequestEvent
2020-08-12 16:01:34 +00:00
from graia.application.friend import Friend
from graia.application.group import Group, Member
from graia.application.message.chain import MessageChain
2021-02-01 15:13:11 +00:00
from core.broadcast import bcc, app
from core.loader import rss_loader
from core.parser import parser
2021-02-01 15:25:57 +00:00
from legacy_subbot import newbie
2021-02-01 15:13:11 +00:00
2021-02-03 14:51:49 +00:00
import shutil
2021-02-03 14:43:24 +00:00
2021-02-01 15:13:11 +00:00
cache_path = os.path.abspath('./cache/')
if os.path.exists(cache_path):
2021-02-03 14:51:49 +00:00
shutil.rmtree(cache_path)
2021-02-03 14:53:18 +00:00
os.mkdir(cache_path)
2021-02-01 15:13:11 +00:00
else:
os.mkdir(cache_path)
2021-02-01 15:25:57 +00:00
2021-02-01 15:13:11 +00:00
@bcc.receiver('GroupMessage')
async def group_message_handler(message: MessageChain, group: Group, member: Member):
kwargs = {MessageChain: message, Group: group, Member: member}
await parser(kwargs)
@bcc.receiver('FriendMessage')
async def group_message_handler(message: MessageChain, friend: Friend):
kwargs = {MessageChain: message, Friend: friend}
await parser(kwargs)
2021-02-02 09:33:55 +00:00
@bcc.receiver("NewFriendRequestEvent")
async def NFriend(event: NewFriendRequestEvent):
await event.accept()
@bcc.receiver("BotInvitedJoinGroupRequestEvent")
async def NGroup(event: BotInvitedJoinGroupRequestEvent):
await event.accept()
2021-02-01 15:13:11 +00:00
@bcc.receiver('ApplicationLaunched')
async def message_handler(app: GraiaMiraiApplication):
rss_list = rss_loader()
gather_list = []
for x in rss_list:
gather_list.append(asyncio.ensure_future(rss_list[x](app)))
await asyncio.gather(*gather_list)
2020-10-04 07:25:33 +00:00
2021-02-01 15:25:57 +00:00
@bcc.receiver('ApplicationLaunched')
async def legacy_message_handler(app: GraiaMiraiApplication):
2021-02-15 09:36:01 +00:00
config_filename = 'config.cfg'
config_path = abspath('./config/' + config_filename)
if config.config(config_path, 'account') != '2052142661':
await newbie(app)
2021-02-01 15:25:57 +00:00
2020-08-12 16:01:34 +00:00
app.launch_blocking()