Explicitly override hashCode and toString in interface Contact, close #80

This commit is contained in:
Him188 2020-02-20 22:01:34 +08:00
parent 9660b44142
commit cb06520b8e
3 changed files with 19 additions and 19 deletions

View File

@ -162,16 +162,11 @@ internal class QQImpl(
TODO("not implemented")
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
return other is QQ && other.id == this.id
}
override fun hashCode(): Int = super.hashCode()
override fun toString(): String = "QQ($id)"
}
@Suppress("MemberVisibilityCanBePrivate")
@Suppress("MemberVisibilityCanBePrivate", "DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
internal class MemberImpl(
qq: QQImpl,
group: GroupImpl,
@ -279,12 +274,9 @@ internal class MemberImpl(
}
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
return other is Member && other.id == this.id
override fun toString(): String {
return "Member($id)"
}
override fun hashCode(): Int = super.hashCode()
}
internal class MemberInfoImpl(
@ -600,10 +592,7 @@ internal class GroupImpl(
image.input.close()
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
return other is Group && other.id == this.id
override fun toString(): String {
return "Group($id)"
}
override fun hashCode(): Int = super.hashCode()
}

View File

@ -74,6 +74,16 @@ interface Contact : CoroutineScope {
* [QQ] 含义为一个独立的人, 可以是好友, 也可以是陌生人.
*/
override fun equals(other: Any?): Boolean
/**
* @return `bot.hashCode() * 31 + id.hashCode()`
*/
override fun hashCode(): Int
/**
* @return "QQ($id)" or "Group($id)" or "Member($id)"
*/
override fun toString(): String
}
suspend inline fun Contact.sendMessage(message: Message) = sendMessage(message.toChain())

View File

@ -97,11 +97,11 @@ interface Group : Contact, CoroutineScope {
/**
* 机器人在这个群里的权限
*
* **MiraiExperimentalAPI**: 在未来可能会被修改
* @see Group.checkBotPermission
* @see Group.checkBotPermissionOperator
*
* @see BotGroupPermissionChangeEvent
*/
@MiraiExperimentalAPI
val botPermission: MemberPermission
@ -129,6 +129,7 @@ interface Group : Contact, CoroutineScope {
/**
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
*/
@MiraiExperimentalAPI("还未支持")
suspend fun quit(): Boolean
/**