2021-01-31 17:01:04 +08:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from typing_extensions import Literal
|
|
|
|
|
2021-01-29 21:19:13 +08:00
|
|
|
from pydantic import Field
|
|
|
|
|
2021-01-29 17:38:39 +08:00
|
|
|
from .base import Event
|
2021-01-29 21:19:13 +08:00
|
|
|
|
2021-01-31 17:01:04 +08:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..bot import MiraiBot as Bot
|
|
|
|
|
2021-01-29 21:19:13 +08:00
|
|
|
|
|
|
|
class RequestEvent(Event):
|
|
|
|
event_id: int = Field(alias='eventId')
|
|
|
|
message: str
|
|
|
|
nick: str
|
|
|
|
|
|
|
|
|
|
|
|
class NewFriendRequestEvent(RequestEvent):
|
|
|
|
from_id: int = Field(alias='fromId')
|
|
|
|
group_id: int = Field(0, alias='groupId')
|
|
|
|
|
2021-01-31 17:01:04 +08:00
|
|
|
async def approve(self, bot: "Bot"):
|
|
|
|
return await bot.api.post('/resp/newFriendRequestEvent',
|
|
|
|
params={
|
|
|
|
'eventId': self.event_id,
|
|
|
|
'groupId': self.group_id,
|
|
|
|
'fromId': self.from_id,
|
|
|
|
'operate': 0
|
|
|
|
})
|
|
|
|
|
|
|
|
async def reject(self,
|
|
|
|
bot: "Bot",
|
|
|
|
operate: Literal[1, 2] = 1,
|
|
|
|
message: str = ''):
|
|
|
|
assert operate > 0
|
|
|
|
return await bot.api.post('/resp/newFriendRequestEvent',
|
|
|
|
params={
|
|
|
|
'eventId': self.event_id,
|
|
|
|
'groupId': self.group_id,
|
|
|
|
'fromId': self.from_id,
|
|
|
|
'operate': operate,
|
|
|
|
'message': message
|
|
|
|
})
|
|
|
|
|
2021-01-29 21:19:13 +08:00
|
|
|
|
|
|
|
class MemberJoinRequestEvent(RequestEvent):
|
|
|
|
from_id: int = Field(alias='fromId')
|
|
|
|
group_id: int = Field(alias='groupId')
|
|
|
|
group_name: str = Field(alias='groupName')
|
|
|
|
|
2021-01-31 17:01:04 +08:00
|
|
|
async def approve(self, bot: "Bot"):
|
|
|
|
return await bot.api.post('/resp/memberJoinRequestEvent',
|
|
|
|
params={
|
|
|
|
'eventId': self.event_id,
|
|
|
|
'groupId': self.group_id,
|
|
|
|
'fromId': self.from_id,
|
|
|
|
'operate': 0
|
|
|
|
})
|
|
|
|
|
|
|
|
async def reject(self,
|
|
|
|
bot: "Bot",
|
|
|
|
operate: Literal[1, 2, 3, 4] = 1,
|
|
|
|
message: str = ''):
|
|
|
|
assert operate > 0
|
|
|
|
return await bot.api.post('/resp/memberJoinRequestEvent',
|
|
|
|
params={
|
|
|
|
'eventId': self.event_id,
|
|
|
|
'groupId': self.group_id,
|
|
|
|
'fromId': self.from_id,
|
|
|
|
'operate': operate,
|
|
|
|
'message': message
|
|
|
|
})
|
|
|
|
|
2021-01-29 21:19:13 +08:00
|
|
|
|
|
|
|
class BotInvitedJoinGroupRequestEvent(RequestEvent):
|
|
|
|
from_id: int = Field(alias='fromId')
|
|
|
|
group_id: int = Field(alias='groupId')
|
|
|
|
group_name: str = Field(alias='groupName')
|
2021-01-31 17:01:04 +08:00
|
|
|
|
|
|
|
async def approve(self, bot: "Bot"):
|
|
|
|
return await bot.api.post('/resp/botInvitedJoinGroupRequestEvent',
|
|
|
|
params={
|
|
|
|
'eventId': self.event_id,
|
|
|
|
'groupId': self.group_id,
|
|
|
|
'fromId': self.from_id,
|
|
|
|
'operate': 0
|
|
|
|
})
|
|
|
|
|
|
|
|
async def reject(self, bot: "Bot", message: str = ""):
|
|
|
|
return await bot.api.post('/resp/botInvitedJoinGroupRequestEvent',
|
|
|
|
params={
|
|
|
|
'eventId': self.event_id,
|
|
|
|
'groupId': self.group_id,
|
|
|
|
'fromId': self.from_id,
|
|
|
|
'operate': 1,
|
|
|
|
'message': message
|
|
|
|
})
|