Commit cb06520b authored by Him188's avatar Him188

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

parent 9660b441
...@@ -162,16 +162,11 @@ internal class QQImpl( ...@@ -162,16 +162,11 @@ internal class QQImpl(
TODO("not implemented") TODO("not implemented")
} }
override fun equals(other: Any?): Boolean { override fun toString(): String = "QQ($id)"
if (this === other) return true
return other is QQ && other.id == this.id
}
override fun hashCode(): Int = super.hashCode()
} }
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate", "DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE")
internal class MemberImpl( internal class MemberImpl(
qq: QQImpl, qq: QQImpl,
group: GroupImpl, group: GroupImpl,
...@@ -279,12 +274,9 @@ internal class MemberImpl( ...@@ -279,12 +274,9 @@ internal class MemberImpl(
} }
} }
override fun equals(other: Any?): Boolean { override fun toString(): String {
if (this === other) return true return "Member($id)"
return other is Member && other.id == this.id
} }
override fun hashCode(): Int = super.hashCode()
} }
internal class MemberInfoImpl( internal class MemberInfoImpl(
...@@ -600,10 +592,7 @@ internal class GroupImpl( ...@@ -600,10 +592,7 @@ internal class GroupImpl(
image.input.close() image.input.close()
} }
override fun equals(other: Any?): Boolean { override fun toString(): String {
if (this === other) return true return "Group($id)"
return other is Group && other.id == this.id
} }
override fun hashCode(): Int = super.hashCode()
} }
\ No newline at end of file
...@@ -74,6 +74,16 @@ interface Contact : CoroutineScope { ...@@ -74,6 +74,16 @@ interface Contact : CoroutineScope {
* 而 [QQ] 含义为一个独立的人, 可以是好友, 也可以是陌生人. * 而 [QQ] 含义为一个独立的人, 可以是好友, 也可以是陌生人.
*/ */
override fun equals(other: Any?): Boolean 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()) suspend inline fun Contact.sendMessage(message: Message) = sendMessage(message.toChain())
......
...@@ -97,11 +97,11 @@ interface Group : Contact, CoroutineScope { ...@@ -97,11 +97,11 @@ interface Group : Contact, CoroutineScope {
/** /**
* 机器人在这个群里的权限 * 机器人在这个群里的权限
* *
* **MiraiExperimentalAPI**: 在未来可能会被修改 * @see Group.checkBotPermission
* @see Group.checkBotPermissionOperator
* *
* @see BotGroupPermissionChangeEvent * @see BotGroupPermissionChangeEvent
*/ */
@MiraiExperimentalAPI
val botPermission: MemberPermission val botPermission: MemberPermission
...@@ -129,6 +129,7 @@ interface Group : Contact, CoroutineScope { ...@@ -129,6 +129,7 @@ interface Group : Contact, CoroutineScope {
/** /**
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败 * 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
*/ */
@MiraiExperimentalAPI("还未支持")
suspend fun quit(): Boolean suspend fun quit(): Boolean
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment