Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
8eb59747
Commit
8eb59747
authored
Mar 24, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract group settings to `interface GroupSettings`
parent
22ade1af
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
141 additions
and
243 deletions
+141
-243
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
...ommonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
+83
-80
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Group.kt
...e/src/androidMain/kotlin/net/mamoe/mirai/contact/Group.kt
+2
-47
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
...re/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
+54
-68
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Group.kt
...-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Group.kt
+2
-48
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
View file @
8eb59747
...
...
@@ -412,7 +412,7 @@ internal class GroupImpl(
@OptIn
(
MiraiExperimentalAPI
::
class
)
override
val
botAsMember
:
Member
by
lazy
{
Member
(
object
:
MemberInfo
{
new
Member
(
object
:
MemberInfo
{
override
val
nameCard
:
String
get
()
=
bot
.
nick
// TODO: 2020/2/21 机器人在群内的昵称获取
override
val
permission
:
MemberPermission
...
...
@@ -447,7 +447,7 @@ internal class GroupImpl(
owner
=
botAsMember
}
null
}
else
Member
(
it
).
also
{
member
->
}
else
new
Member
(
it
).
also
{
member
->
if
(
member
.
permission
==
MemberPermission
.
OWNER
)
{
owner
=
member
}
...
...
@@ -465,7 +465,7 @@ internal class GroupImpl(
override
var
name
:
String
get
()
=
_name
set
(
newValue
)
{
this
.
checkBotPermissionOperator
()
checkBotPermissionOperator
()
if
(
_name
!=
newValue
)
{
val
oldValue
=
_name
_name
=
newValue
...
...
@@ -482,101 +482,104 @@ internal class GroupImpl(
}
}
override
var
entranceAnnouncement
:
String
get
()
=
_announcement
set
(
newValue
)
{
this
.
checkBotPermissionOperator
()
if
(
_announcement
!=
newValue
)
{
val
oldValue
=
_announcement
_announcement
=
newValue
launch
{
bot
.
network
.
run
{
TroopManagement
.
GroupOperation
.
memo
(
client
=
bot
.
client
,
groupCode
=
id
,
newMemo
=
newValue
).
sendWithoutExpect
()
override
val
settings
:
GroupSettings
=
object
:
GroupSettings
{
override
var
entranceAnnouncement
:
String
get
()
=
_announcement
set
(
newValue
)
{
checkBotPermissionOperator
()
if
(
_announcement
!=
newValue
)
{
val
oldValue
=
_announcement
_announcement
=
newValue
launch
{
bot
.
network
.
run
{
TroopManagement
.
GroupOperation
.
memo
(
client
=
bot
.
client
,
groupCode
=
id
,
newMemo
=
newValue
).
sendWithoutExpect
()
}
GroupEntranceAnnouncementChangeEvent
(
oldValue
,
newValue
,
this
@GroupImpl
,
null
).
broadcast
()
}
GroupEntranceAnnouncementChangeEvent
(
oldValue
,
newValue
,
this
@GroupImpl
,
null
).
broadcast
()
}
}
}
override
var
isAllowMemberInvite
:
Boolean
get
()
=
_allowMemberInvite
set
(
newValue
)
{
this
.
checkBotPermissionOperator
()
if
(
_allowMemberInvite
!=
newValue
)
{
val
oldValue
=
_allowMemberInvite
_allowMemberInvite
=
newValue
launch
{
bot
.
network
.
run
{
TroopManagement
.
GroupOperation
.
allowMemberInvite
(
client
=
bot
.
client
,
groupCode
=
id
,
switch
=
newValue
).
sendWithoutExpect
()
override
var
isAllowMemberInvite
:
Boolean
get
()
=
_allowMemberInvite
set
(
newValue
)
{
checkBotPermissionOperator
()
if
(
_allowMemberInvite
!=
newValue
)
{
val
oldValue
=
_allowMemberInvite
_allowMemberInvite
=
newValue
launch
{
bot
.
network
.
run
{
TroopManagement
.
GroupOperation
.
allowMemberInvite
(
client
=
bot
.
client
,
groupCode
=
id
,
switch
=
newValue
).
sendWithoutExpect
()
}
GroupAllowMemberInviteEvent
(
oldValue
,
newValue
,
this
@GroupImpl
,
null
).
broadcast
()
}
GroupAllowMemberInviteEvent
(
oldValue
,
newValue
,
this
@GroupImpl
,
null
).
broadcast
()
}
}
}
override
var
isAutoApproveEnabled
:
Boolean
get
()
=
_autoApprove
@Suppress
(
"UNUSED_PARAMETER"
)
set
(
newValue
)
{
TODO
()
}
override
var
isAutoApproveEnabled
:
Boolean
get
()
=
_autoApprove
@Suppress
(
"UNUSED_PARAMETER"
)
set
(
newValue
)
{
TODO
()
}
override
var
isAnonymousChatEnabled
:
Boolean
get
()
=
_anonymousChat
@Suppress
(
"UNUSED_PARAMETER"
)
set
(
newValue
)
{
TODO
()
}
override
var
isAnonymousChatEnabled
:
Boolean
get
()
=
_anonymousChat
@Suppress
(
"UNUSED_PARAMETER"
)
set
(
newValue
)
{
TODO
()
}
override
var
isConfessTalkEnabled
:
Boolean
get
()
=
_confessTalk
set
(
newValue
)
{
this
.
checkBotPermissionOperator
()
if
(
_confessTalk
!=
newValue
)
{
val
oldValue
=
_confessTalk
_confessTalk
=
newValue
launch
{
bot
.
network
.
run
{
TroopManagement
.
GroupOperation
.
confessTalk
(
client
=
bot
.
client
,
groupCode
=
id
,
switch
=
newValue
).
sendWithoutExpect
()
override
var
isConfessTalkEnabled
:
Boolean
get
()
=
_confessTalk
set
(
newValue
)
{
checkBotPermissionOperator
()
if
(
_confessTalk
!=
newValue
)
{
val
oldValue
=
_confessTalk
_confessTalk
=
newValue
launch
{
bot
.
network
.
run
{
TroopManagement
.
GroupOperation
.
confessTalk
(
client
=
bot
.
client
,
groupCode
=
id
,
switch
=
newValue
).
sendWithoutExpect
()
}
GroupAllowConfessTalkEvent
(
oldValue
,
newValue
,
this
@GroupImpl
,
true
).
broadcast
()
}
GroupAllowConfessTalkEvent
(
oldValue
,
newValue
,
this
@GroupImpl
,
true
).
broadcast
()
}
}
}
override
var
isMuteAll
:
Boolean
get
()
=
_muteAll
set
(
newValue
)
{
this
.
checkBotPermissionOperator
()
if
(
_muteAll
!=
newValue
)
{
val
oldValue
=
_muteAll
_muteAll
=
newValue
launch
{
bot
.
network
.
run
{
TroopManagement
.
GroupOperation
.
muteAll
(
client
=
bot
.
client
,
groupCode
=
id
,
switch
=
newValue
).
sendWithoutExpect
()
override
var
isMuteAll
:
Boolean
get
()
=
_muteAll
set
(
newValue
)
{
checkBotPermissionOperator
()
if
(
_muteAll
!=
newValue
)
{
val
oldValue
=
_muteAll
_muteAll
=
newValue
launch
{
bot
.
network
.
run
{
TroopManagement
.
GroupOperation
.
muteAll
(
client
=
bot
.
client
,
groupCode
=
id
,
switch
=
newValue
).
sendWithoutExpect
()
}
GroupMuteAllEvent
(
oldValue
,
newValue
,
this
@GroupImpl
,
null
).
broadcast
()
}
GroupMuteAllEvent
(
oldValue
,
newValue
,
this
@GroupImpl
,
null
).
broadcast
()
}
}
}
}
@MiraiExperimentalAPI
override
suspend
fun
quit
():
Boolean
{
...
...
@@ -585,7 +588,7 @@ internal class GroupImpl(
}
@OptIn
(
MiraiExperimentalAPI
::
class
)
override
fun
Member
(
memberInfo
:
MemberInfo
):
Member
{
override
fun
new
Member
(
memberInfo
:
MemberInfo
):
Member
{
return
MemberImpl
(
@OptIn
(
LowLevelAPI
::
class
)
bot
.
_lowLevelNewQQ
(
memberInfo
)
as
QQImpl
,
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/contact/Group.kt
View file @
8eb59747
...
...
@@ -38,54 +38,9 @@ actual abstract class Group : Contact(), CoroutineScope {
actual
abstract
var
name
:
String
/**
* 入群公告, 没有时为空字符串.
*
* 在修改时将会异步上传至服务器.
*
* @see GroupEntranceAnnouncementChangeEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
actual
abstract
var
entranceAnnouncement
:
String
/**
* 全体禁言状态. `true` 为开启.
*
* 当前仅能修改状态.
*
* @see GroupMuteAllEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
actual
abstract
var
isMuteAll
:
Boolean
/**
* 坦白说状态. `true` 为允许.
*
* 在修改时将会异步上传至服务器.
*
* @see GroupAllowConfessTalkEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
actual
abstract
var
isConfessTalkEnabled
:
Boolean
/**
* 允许群员邀请好友入群的状态. `true` 为允许
*
* 在修改时将会异步上传至服务器.
*
* @see GroupAllowMemberInviteEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
actual
abstract
var
isAllowMemberInvite
:
Boolean
/**
* 自动加群审批
*/
actual
abstract
val
isAutoApproveEnabled
:
Boolean
/**
* 匿名聊天
* 群设置
*/
actual
abstract
val
isAnonymousChatEnabled
:
Boolean
actual
abstract
val
settings
:
GroupSettings
/**
* 同为 groupCode, 用户看到的群号码.
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
View file @
8eb59747
...
...
@@ -40,50 +40,11 @@ expect abstract class Group() : Contact, CoroutineScope {
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
abstract
var
name
:
String
/**
* 入群公告, 没有时为空字符串.
*
* 在修改时将会异步上传至服务器.
*
* @see GroupEntranceAnnouncementChangeEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
abstract
var
entranceAnnouncement
:
String
/**
* 全体禁言状态. `true` 为开启.
*
* 当前仅能修改状态.
*
* @see GroupMuteAllEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
abstract
var
isMuteAll
:
Boolean
/**
* 坦白说状态. `true` 为允许.
*
* 在修改时将会异步上传至服务器.
*
* @see GroupAllowConfessTalkEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
abstract
var
isConfessTalkEnabled
:
Boolean
/**
* 允许群员邀请好友入群的状态. `true` 为允许
*
* 在修改时将会异步上传至服务器.
*
* @see GroupAllowMemberInviteEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
abstract
var
isAllowMemberInvite
:
Boolean
/**
* 自动加群审批
*/
abstract
val
isAutoApproveEnabled
:
Boolean
/**
* 匿名聊天
* 群设置
*/
abstract
val
isAnonymousChatEnabled
:
Boolean
abstract
val
settings
:
GroupSettings
/**
* 同为 groupCode, 用户看到的群号码.
...
...
@@ -200,38 +161,63 @@ expect abstract class Group() : Contact, CoroutineScope {
fun
toFullString
():
String
}
internal
object
CommonGroupCalculations
{
/**
* 群设置
*
* @see Group.settings 获取群设置
*/
@SinceMirai
(
"0.30.0"
)
interface
GroupSettings
{
/**
* by @kar98k
* 入群公告, 没有时为空字符串.
*
* 在修改时将会异步上传至服务器.
*
* @see GroupEntranceAnnouncementChangeEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
fun
calculateGroupUinByGroupCode
(
groupCode
:
Long
):
Long
{
var
left
:
Long
=
groupCode
/
1000000L
var
entranceAnnouncement
:
String
when
(
left
)
{
in
0
..
10
->
left
+=
202
in
11
..
19
->
left
+=
480
-
11
in
20
..
66
->
left
+=
2100
-
20
in
67
..
156
->
left
+=
2010
-
67
in
157
..
209
->
left
+=
2147
-
157
in
210
..
309
->
left
+=
4100
-
210
in
310
..
499
->
left
+=
3800
-
310
}
/**
* 全体禁言状态. `true` 为开启.
*
* 当前仅能修改状态.
*
* @see GroupMuteAllEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
var
isMuteAll
:
Boolean
return
left
*
1000000L
+
groupCode
%
1000000L
}
/**
* 坦白说状态. `true` 为允许.
*
* 在修改时将会异步上传至服务器.
*
* @see GroupAllowConfessTalkEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
var
isConfessTalkEnabled
:
Boolean
fun
calculateGroupCodeByGroupUin
(
groupUin
:
Long
):
Long
{
var
left
:
Long
=
groupUin
/
1000000L
/**
* 允许群员邀请好友入群的状态. `true` 为允许
*
* 在修改时将会异步上传至服务器.
*
* @see GroupAllowMemberInviteEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
var
isAllowMemberInvite
:
Boolean
when
(
left
)
{
in
0
+
202
..
10
+
202
->
left
-=
202
in
11
+
480
-
11
..
19
+
480
-
11
->
left
-=
480
-
11
in
20
+
2100
-
20
..
66
+
2100
-
20
->
left
-=
2100
-
20
in
67
+
2010
-
67
..
156
+
2010
-
67
->
left
-=
2010
-
67
in
157
+
2147
-
157
..
209
+
2147
-
157
->
left
-=
2147
-
157
in
210
+
4100
-
210
..
309
+
4100
-
210
->
left
-=
4100
-
210
in
310
+
3800
-
310
..
499
+
3800
-
310
->
left
-=
3800
-
310
}
/**
* 自动加群审批
*/
val
isAutoApproveEnabled
:
Boolean
/**
* 匿名聊天
*/
val
isAnonymousChatEnabled
:
Boolean
}
/**
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/contact/Group.kt
View file @
8eb59747
...
...
@@ -39,54 +39,9 @@ actual abstract class Group : Contact(), CoroutineScope {
actual
abstract
var
name
:
String
/**
* 入群公告, 没有时为空字符串.
*
* 在修改时将会异步上传至服务器.
*
* @see GroupEntranceAnnouncementChangeEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
actual
abstract
var
entranceAnnouncement
:
String
/**
* 全体禁言状态. `true` 为开启.
*
* 当前仅能修改状态.
*
* @see GroupMuteAllEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
* 群设置
*/
actual
abstract
var
isMuteAll
:
Boolean
/**
* 坦白说状态. `true` 为允许.
*
* 在修改时将会异步上传至服务器.
*
* @see GroupAllowConfessTalkEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
actual
abstract
var
isConfessTalkEnabled
:
Boolean
/**
* 允许群员邀请好友入群的状态. `true` 为允许
*
* 在修改时将会异步上传至服务器.
*
* @see GroupAllowMemberInviteEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
actual
abstract
var
isAllowMemberInvite
:
Boolean
/**
* 自动加群审批
*/
actual
abstract
val
isAutoApproveEnabled
:
Boolean
/**
* 匿名聊天
*/
actual
abstract
val
isAnonymousChatEnabled
:
Boolean
actual
abstract
val
settings
:
GroupSettings
/**
* 同为 groupCode, 用户看到的群号码.
...
...
@@ -205,5 +160,4 @@ actual abstract class Group : Contact(), CoroutineScope {
actual
fun
toFullString
():
String
{
return
"Group(id=${this.id}, name=$name, owner=${owner.id}, members=${members.idContentString})"
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment