Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support decode the join request by member invite #882

Merged
merged 19 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Versions {
const val io = "0.1.16"
const val coroutinesIo = "0.1.16"

const val blockingBridge = "1.7.3"
const val blockingBridge = "1.7.2"

const val androidGradlePlugin = "3.5.3"

Expand Down
97 changes: 96 additions & 1 deletion mirai-core-api/src/commonMain/kotlin/event/events/group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,108 @@ public data class MemberJoinRequestEvent @MiraiInternalApi constructor(
/**
* 申请人昵称
*/
val fromNick: String
val fromNick: String,
/**
* 邀请人 id(如果是邀请入群)
*/
val invitorId: Long? = null
) : BotEvent, Packet, AbstractEvent() {

@Deprecated("For binary compatibility", level = DeprecationLevel.HIDDEN)
public constructor(
bot: Bot,
eventId: Long,
message: String,
fromId: Long,
groupId: Long,
groupName: String,
fromNick: String
) : this(bot, eventId, message, fromId, groupId, groupName, fromNick, null)

@Deprecated("For binary compatibility", level = DeprecationLevel.HIDDEN)
public fun copy(
bot: Bot,
eventId: Long,
message: String,
fromId: Long,
groupId: Long,
groupName: String,
fromNick: String
): MemberJoinRequestEvent {
return copy(
bot = bot,
eventId = eventId,
message = message,
fromId = fromId,
groupId = groupId,
groupName = groupName,
fromNick = fromNick,
invitorId = null
)
}

@Deprecated("For binary compatibility", level = DeprecationLevel.HIDDEN)
public fun `copy$default`(
var0: MemberJoinRequestEvent,
var1: Bot,
var2: Long,
var4: String,
var5: Long,
var7: Long,
var9: String,
var10: String,
var11: Int,
var12: Any
): MemberJoinRequestEvent {
var bot = var1
var eventId = var2
var message = var4
var fromId = var5
var groupId = var7
var groupName = var9
var fromNick = var10
if (var11 and 1 != 0) {
bot = var0.bot
}
if (var11 and 2 != 0) {
eventId = var0.eventId
}
if (var11 and 4 != 0) {
message = var0.message
}
if (var11 and 8 != 0) {
fromId = var0.fromId
}
if (var11 and 16 != 0) {
groupId = var0.groupId
}
if (var11 and 32 != 0) {
groupName = var0.groupName
}
if (var11 and 64 != 0) {
fromNick = var0.fromNick
}
return var0.copy(
bot = bot,
eventId = eventId,
message = message,
fromId = fromId,
groupId = groupId,
groupName = groupName,
fromNick = fromNick
)
}

/**
* 相关群. 若在事件发生后机器人退出这个群, [group] 为 `null`.
*/
public val group: Group? get() = this.bot.getGroup(groupId)

/**
* 邀请入群的成员. 若在事件发生时机器人或该成员退群, [invitor] 为 `null`.
*/
public val invitor: NormalMember? by lazy { invitorId?.let { group?.get(it) } }

@JvmField
@PublishedApi
internal val responded: AtomicBoolean = AtomicBoolean(false)
Expand Down
6 changes: 5 additions & 1 deletion mirai-core/src/commonMain/kotlin/MiraiImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
)

event.group?.getMember(event.fromId)?.let { member ->
MemberJoinEvent.Active(member).broadcast()
if (event.invitor != null) {
MemberJoinEvent.Invite(member, event.invitor!!).broadcast()
} else {
MemberJoinEvent.Active(member).broadcast()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,19 @@ internal class NewContact {
)
}
2 -> {
// 被邀请入群
// Bot 被邀请入群
BotInvitedJoinGroupRequestEvent(
bot, struct.msgSeq, actionUin,
groupCode, groupName, actionUinNick
)
}
22 -> {
// 成员邀请入群
MemberJoinRequestEvent(
bot, struct.msgSeq, msgAdditional,
struct.reqUin, groupCode, groupName, reqUinNick, actionUin
)
}
else -> throw contextualBugReportException(
"parse SystemMsgNewGroup, subType=1",
this._miraiContentToString(),
Expand Down