Archived
1
0
Fork 0

remove unused files

This commit is contained in:
yzhh 2022-05-22 23:23:12 +08:00
parent 3ee0ee1922
commit 625076cac1
6 changed files with 0 additions and 283 deletions

View file

@ -1,67 +0,0 @@
import asyncio
import logging
import os
from graia.application.event.mirai import NewFriendRequestEvent, BotInvitedJoinGroupRequestEvent
from graia.application.friend import Friend
from graia.application.group import Group, Member
from graia.application.message.chain import MessageChain
from config import Config
from core.elements import MsgInfo, Session, Command, Schedule, PrivateAssets
from core.loader import ModulesManager
from core.parser.message import parser
from core.scheduler import Scheduler
from core.unused_bots.graia.broadcast import bcc, app
from core.unused_bots.graia.message import MessageSession, FetchTarget
from core.utils import init, load_prompt
PrivateAssets.set(os.path.abspath(os.path.dirname(__file__) + '/assets'))
init()
@bcc.receiver('GroupMessage')
async def group_message_handler(message: MessageChain, group: Group, member: Member):
msg = MessageSession(
target=MsgInfo(targetId=f"QQ|Group|{group.id}", senderId=f'QQ|{member.id}', senderName=member.name,
targetFrom='QQ|Group', senderFrom="QQ"),
session=Session(message=message, target=group, sender=member))
await parser(msg)
@bcc.receiver('FriendMessage')
async def friend_message_handler(message: MessageChain, friend: Friend):
msg = MessageSession(
target=MsgInfo(targetId=f"QQ|{friend.id}", senderId=f'QQ|{friend.id}', senderName=friend.nickname,
targetFrom='QQ', senderFrom='QQ'),
session=Session(message=message, target=friend, sender=friend))
await parser(msg)
@bcc.receiver("NewFriendRequestEvent")
async def new_friend(event: NewFriendRequestEvent):
await event.accept()
@bcc.receiver("BotInvitedJoinGroupRequestEvent")
async def new_group(event: BotInvitedJoinGroupRequestEvent):
await event.accept()
@bcc.receiver('ApplicationLaunched')
async def autorun_handler():
gather_list = []
Modules = ModulesManager.return_modules_list_as_dict()
for x in Modules:
if isinstance(Modules[x], Command) and Modules[x].autorun:
gather_list.append(asyncio.ensure_future(Modules[x].function(FetchTarget)))
if isinstance(Modules[x], Schedule):
Scheduler.add_job(func=Modules[x].function, trigger=Modules[x].trigger, args=[FetchTarget])
await asyncio.gather(*gather_list)
Scheduler.start()
logging.getLogger('apscheduler.executors.default').setLevel(logging.WARNING)
await load_prompt(FetchTarget)
if Config('qq_host') and Config('qq_account'):
app.launch_blocking()

View file

@ -1,24 +0,0 @@
import asyncio
from graia.application import GraiaMiraiApplication, Session
from graia.broadcast import Broadcast
from config import Config
from core.logger import Logginglogger
loop = asyncio.get_event_loop()
c = Config
debug = c('debug_flag')
bcc = Broadcast(loop=loop, debug_flag=debug)
app = GraiaMiraiApplication(
broadcast=bcc,
enable_chat_log=c('qq_enable_chat_log'),
connect_info=Session(
host=c('qq_host'), # 填入 httpapi 服务运行的地址
authKey=c('qq_authkey'), # 填入 authKey
account=c('qq_account'), # 你的机器人的 qq 号
websocket=c('qq_websocket') # Graia 已经可以根据所配置的消息接收的方式来保证消息接收部分的正常运作.
),
logger=Logginglogger(**({"debug": True} if debug else {}))
)

View file

@ -1,184 +0,0 @@
import asyncio
import re
import traceback
from typing import List
from core.logger import Logger
from graia.application import MessageChain, GroupMessage, FriendMessage
from graia.application.friend import Friend
from graia.application.group import Group, Member
from graia.application.message.elements.internal import Plain, Image, Source, Voice
from graia.broadcast.interrupt import InterruptControl
from graia.broadcast.interrupt.waiter import Waiter
from config import Config
from core.elements import Plain as BPlain, Image as BImage, Voice as BVoice, MessageSession as MS, MsgInfo, Session, \
FetchTarget as FT, ErrorMessage
from core.elements.others import confirm_command
from core.unused_bots.graia.broadcast import app, bcc
from core.utils import slk_converter
from database import BotDBUtil
from database.logging_message import LoggerMSG
async def msgchain_gen(message) -> MessageChain:
if isinstance(message, str):
if message == '':
message = ErrorMessage('机器人尝试发送空文本消息,请联系机器人开发者解决问题。')
msgchain = MessageChain.create([Plain(message)])
elif isinstance(message, (list, tuple)):
msgchain_list = []
for x in message:
if isinstance(x, BPlain):
msgchain_list.append(Plain(x.text))
if isinstance(x, BImage):
msgchain_list.append(Image.fromLocalFile(await x.get()))
if isinstance(x, BVoice):
msgchain_list.append(Voice().fromLocalFile(filepath=await slk_converter(x.path)))
if not msgchain_list:
msgchain_list.append(Plain(ErrorMessage('机器人尝试发送空文本消息,请联系机器人开发者解决问题。')))
msgchain = MessageChain.create(msgchain_list)
elif isinstance(message, MessageChain):
msgchain = message
else:
msgchain = MessageChain.create([Plain(ErrorMessage('机器人尝试发送非法消息链,请联系机器人开发者解决问题。'))])
return msgchain
class MessageSession(MS):
class Feature:
image = True
voice = True
async def sendMessage(self, msgchain, quote=True):
msgchain = await msgchain_gen(msgchain)
if Config('qq_msg_logging_to_db') and self.session.message:
LoggerMSG(userid=self.target.senderId, command=self.trigger_msg, msg=msgchain.asDisplay())
if isinstance(self.session.target, Group) or self.target.targetFrom == 'QQ|Group':
send = await app.sendGroupMessage(self.session.target, msgchain, quote=self.session.message[Source][0].id
if quote and self.session.message else None)
return MessageSession(
target=MsgInfo(targetId=0, senderId=0, targetFrom='QQ|Bot', senderFrom="QQ|Bot", senderName=''),
session=Session(message=send, target=0, sender=0))
if isinstance(self.session.target, Friend) or self.target.targetFrom == 'QQ':
send = await app.sendFriendMessage(self.session.target, msgchain)
return MessageSession(
target=MsgInfo(targetId=0, senderId=0, targetFrom='QQ|Bot', senderFrom="QQ|Bot", senderName=''),
session=Session(message=send, target=0, sender=0))
async def waitConfirm(self, msgchain=None, quote=True):
if msgchain is not None:
msgchain = await msgchain_gen(msgchain)
msgchain = msgchain.plusWith(MessageChain.create([Plain('(发送“是”或符合确认条件的词语来确认)')]))
send = await self.sendMessage(msgchain, quote=quote)
inc = InterruptControl(bcc)
if isinstance(self.session.target, Group):
@Waiter.create_using_function([GroupMessage])
def waiter(waiter_group: Group,
waiter_member: Member, waiter_message: MessageChain):
if all([
waiter_group.id == self.session.target.id,
waiter_member.id == self.session.sender.id,
]):
if waiter_message.asDisplay() in confirm_command:
return True
else:
return False
elif isinstance(self.session.target, Friend):
@Waiter.create_using_function([FriendMessage])
def waiter(waiter_friend: Friend, waiter_message: MessageChain):
if all([
waiter_friend.id == self.session.sender.id,
]):
if waiter_message.asDisplay() in confirm_command:
return True
else:
return False
wait = await inc.wait(waiter)
if msgchain is not None:
await send.delete()
return wait
def asDisplay(self):
display = self.session.message.asDisplay()
return display
async def delete(self):
"""
用于撤回消息
:param send_msg: 需要撤回的已发送/接收的消息链
:return: 无返回
"""
try:
await app.revokeMessage(self.session.message)
except Exception:
Logger.error(traceback.format_exc())
async def checkPermission(self):
"""
检查对象是否拥有某项权限
:param display_msg: 从函数传入的dict
:return: 若对象为群主管理员或机器人超管则为True
"""
if isinstance(self.session.target, Group):
if str(self.session.sender.permission) in ['MemberPerm.Administrator', 'MemberPerm.Owner'] \
or self.target.senderInfo.query.isSuperUser \
or self.target.senderInfo.check_TargetAdmin(self.target.targetId):
return True
if isinstance(self.session.target, Friend):
return True
return False
def checkSuperUser(self):
return True if self.target.senderInfo.query.isSuperUser else False
class Typing:
def __init__(self, msg: MS):
self.msg = msg
async def __aenter__(self):
if isinstance(self.msg.session.target, Group):
try:
await app.nudge(self.msg.session.sender)
except Exception:
Logger.error(traceback.format_exc())
async def __aexit__(self, exc_type, exc_val, exc_tb):
pass
class FetchTarget(FT):
@staticmethod
async def fetch_target(targetId) -> MessageSession:
matchTarget = re.match(r'^((?:QQ\|Group|QQ))\|(.*)', targetId)
if matchTarget:
return MessageSession(MsgInfo(targetId=targetId, senderId=targetId, senderName='',
targetFrom=matchTarget.group(1), senderFrom=matchTarget.group(1)),
Session(message=False, target=int(matchTarget.group(2)),
sender=int(matchTarget.group(2))))
else:
return False
@staticmethod
async def post_message(module_name, message, user_list: List[MessageSession] = None):
send_list = []
if user_list is not None:
for x in user_list:
try:
send = await x.sendMessage(message, quote=False)
send_list.append(send)
except Exception:
Logger.error(traceback.format_exc())
else:
get_target_id = BotDBUtil.Module.get_enabled_this(module_name)
for x in get_target_id:
fetch = await FetchTarget.fetch_target(x)
if fetch:
try:
send = await fetch.sendMessage(message, quote=False)
send_list.append(send)
await asyncio.sleep(0.5)
except Exception:
Logger.error(traceback.format_exc())
return send_list

View file

@ -1,8 +0,0 @@
import asyncio
import sys
from graiax import silkcoder
filepath = sys.argv[1]
filepath2 = filepath + '.silk'
asyncio.run(silkcoder.encode(filepath, filepath2, rate=240000))