1
1
package top.alazeprt.aqqbot.handler
2
2
3
+ import org.bukkit.Bukkit
3
4
import taboolib.common.platform.function.info
4
5
import top.alazeprt.aonebot.action.GetGroupMemberInfo
5
6
import top.alazeprt.aonebot.action.SendGroupMessage
6
7
import top.alazeprt.aonebot.event.message.GroupMessageEvent
7
8
import top.alazeprt.aonebot.util.GroupRole
8
9
import top.alazeprt.aqqbot.AQQBot
10
+ import top.alazeprt.aqqbot.AQQBot.isFileStorage
9
11
import top.alazeprt.aqqbot.util.AI18n.get
12
+ import top.alazeprt.aqqbot.util.DBQuery.addPlayer
13
+ import top.alazeprt.aqqbot.util.DBQuery.playerInDatabase
14
+ import top.alazeprt.aqqbot.util.DBQuery.qqInDatabase
15
+ import top.alazeprt.aqqbot.util.DBQuery.removePlayer
10
16
11
17
class WhitelistHandler {
12
18
companion object {
13
19
private fun bind (userId : String , groupId : Long , playerName : String ) {
14
- if (AQQBot .dataMap.containsKey(userId)) {
20
+ if (isFileStorage && AQQBot .dataMap.containsKey(userId)) {
21
+ AQQBot .oneBotClient.action(
22
+ SendGroupMessage (groupId, get(" qq.whitelist.already_bind" ), true ))
23
+ return
24
+ } else if (! isFileStorage && qqInDatabase(userId.toLong()) != null ) {
15
25
AQQBot .oneBotClient.action(
16
26
SendGroupMessage (groupId, get(" qq.whitelist.already_bind" ), true ))
17
27
return
@@ -20,32 +30,57 @@ class WhitelistHandler {
20
30
AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.invalid_name" ), true ))
21
31
return
22
32
}
23
- AQQBot .dataMap.values.forEach {
24
- if (it == playerName) {
33
+ if (isFileStorage) {
34
+ AQQBot .dataMap.values.forEach {
35
+ if (it == playerName) {
36
+ AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.already_exist" ), true ))
37
+ return
38
+ }
39
+ }
40
+ } else {
41
+ if (playerInDatabase(playerName)) {
25
42
AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.already_exist" ), true ))
26
43
return
27
44
}
28
45
}
29
- AQQBot .dataMap[userId] = playerName
46
+ if (isFileStorage) AQQBot .dataMap[userId] = playerName
47
+ else addPlayer(userId.toLong(), playerName)
30
48
AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.bind_successful" ), true ))
31
49
}
32
50
33
51
private fun unbind (userId : String , groupId : Long , playerName : String ) {
34
- if (! AQQBot .dataMap.containsKey(userId)) {
52
+ if (isFileStorage && ! AQQBot .dataMap.containsKey(userId)) {
53
+ AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.not_bind" ), true ))
54
+ return
55
+ } else if (! isFileStorage && qqInDatabase(userId.toLong()) == null ) {
35
56
AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.not_bind" ), true ))
36
57
return
37
58
}
38
- AQQBot .dataMap.forEach { (k, v) ->
39
- if (v == playerName && k == userId) {
40
- AQQBot .dataMap.remove(k)
41
- AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" unbind_successful" ), true ))
42
- return
43
- } else if (k == userId) {
44
- AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.bind_by_other" , mutableMapOf (Pair (" name" , v))), true ))
59
+ if (isFileStorage) {
60
+ AQQBot .dataMap.forEach { (k, v) ->
61
+ if (v == playerName && k == userId) {
62
+ AQQBot .dataMap.remove(k)
63
+ AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.unbind_successful" ), true ))
64
+ return
65
+ } else if (k == userId) {
66
+ AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.bind_by_other" , mutableMapOf (Pair (" name" , v))), true ))
67
+ return
68
+ }
69
+ }
70
+ AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.invalid_bind" ), true ))
71
+ } else {
72
+ if (qqInDatabase(userId.toLong()) != playerName) {
73
+ AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.bind_by_other" , mutableMapOf (Pair (" name" , qqInDatabase(userId.toLong())!! ))), true ))
45
74
return
46
75
}
76
+ removePlayer(userId.toLong(), playerName)
77
+ AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.unbind_successful" ), true ))
78
+ for (player in Bukkit .getOnlinePlayers()) {
79
+ if (player.name == playerName) {
80
+ player.kickPlayer(get(" qq.whitelist.unbind_kick" ))
81
+ }
82
+ }
47
83
}
48
- AQQBot .oneBotClient.action(SendGroupMessage (groupId, get(" qq.whitelist.invalid_bind" ), true ))
49
84
}
50
85
51
86
private fun validateName (name : String ): Boolean {
0 commit comments