-
Notifications
You must be signed in to change notification settings - Fork 34
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
白名单运行 #34
Draft
RikaCelery
wants to merge
2
commits into
RicheyJang:master
Choose a base branch
from
RikaCelery:feat/whitelist
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
白名单运行 #34
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,21 +16,29 @@ func SetUserPluginStatus(status bool, userID int64, plugin *manager.PluginCondit | |||||||||||||
var key string | ||||||||||||||
if plugin != nil { | ||||||||||||||
key = plugin.Key | ||||||||||||||
} else { // plugin 为空,代表所有插件 | ||||||||||||||
key = AllPluginKey | ||||||||||||||
} else { | ||||||||||||||
panic("SetGroupPluginStatus: plugin is nil") | ||||||||||||||
} | ||||||||||||||
// 更新数据库 | ||||||||||||||
var preUser dao.UserSetting | ||||||||||||||
proxy.GetDB().Take(&preUser, userID) | ||||||||||||||
preUser.ID = userID | ||||||||||||||
if status { // 启用 | ||||||||||||||
preUser.BlackPlugins = delPluginKey(preUser.BlackPlugins, key) | ||||||||||||||
} else { // 关闭 | ||||||||||||||
preUser.BlackPlugins = addPluginKey(preUser.BlackPlugins, key) | ||||||||||||||
if preUser.WhiteMode { | ||||||||||||||
if status { // 启用 | ||||||||||||||
preUser.WhitePlugins = addPluginKey(preUser.WhitePlugins, key) | ||||||||||||||
} else { // 关闭 | ||||||||||||||
preUser.WhitePlugins = delPluginKey(preUser.WhitePlugins, key) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
if status { // 启用 | ||||||||||||||
preUser.BlackPlugins = delPluginKey(preUser.BlackPlugins, key) | ||||||||||||||
} else { // 关闭 | ||||||||||||||
preUser.BlackPlugins = addPluginKey(preUser.BlackPlugins, key) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
if err := proxy.GetDB().Clauses(clause.OnConflict{ | ||||||||||||||
Columns: []clause.Column{{Name: "id"}}, | ||||||||||||||
DoUpdates: clause.AssignmentColumns([]string{"black_plugins"}), // Upsert | ||||||||||||||
DoUpdates: clause.AssignmentColumns([]string{"black_plugins", "white_plugins"}), // Upsert | ||||||||||||||
}).Create(&preUser).Error; err != nil { | ||||||||||||||
log.Errorf("set user(%v) black_plugins error(sql): %v", userID, err) | ||||||||||||||
return err | ||||||||||||||
|
@@ -51,21 +59,29 @@ func SetGroupPluginStatus(status bool, groupID int64, plugin *manager.PluginCond | |||||||||||||
var key string | ||||||||||||||
if plugin != nil { | ||||||||||||||
key = plugin.Key | ||||||||||||||
} else { // plugin 为空,代表所有插件 | ||||||||||||||
key = AllPluginKey | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上,传入参数不可能为nil PaimengBot/basic/ban/switch.go Lines 53 to 58 in c8266f4
|
||||||||||||||
} else { | ||||||||||||||
panic("SetGroupPluginStatus: plugin is nil") | ||||||||||||||
} | ||||||||||||||
// 更新数据库 | ||||||||||||||
var preGroup dao.GroupSetting | ||||||||||||||
proxy.GetDB().Take(&preGroup, groupID) | ||||||||||||||
preGroup.ID = groupID | ||||||||||||||
if status { // 启用 | ||||||||||||||
preGroup.BlackPlugins = delPluginKey(preGroup.BlackPlugins, key) | ||||||||||||||
} else { // 关闭 | ||||||||||||||
preGroup.BlackPlugins = addPluginKey(preGroup.BlackPlugins, key) | ||||||||||||||
if preGroup.WhiteMode { | ||||||||||||||
if status { // 启用 | ||||||||||||||
preGroup.WhitePlugins = addPluginKey(preGroup.WhitePlugins, key) | ||||||||||||||
} else { // 关闭 | ||||||||||||||
preGroup.WhitePlugins = delPluginKey(preGroup.WhitePlugins, key) | ||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
if status { // 启用 | ||||||||||||||
preGroup.BlackPlugins = delPluginKey(preGroup.BlackPlugins, key) | ||||||||||||||
} else { // 关闭 | ||||||||||||||
preGroup.BlackPlugins = addPluginKey(preGroup.BlackPlugins, key) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
if err := proxy.GetDB().Clauses(clause.OnConflict{ | ||||||||||||||
Columns: []clause.Column{{Name: "id"}}, | ||||||||||||||
DoUpdates: clause.AssignmentColumns([]string{"black_plugins"}), // Upsert | ||||||||||||||
DoUpdates: clause.AssignmentColumns([]string{"black_plugins", "white_plugins"}), // Upsert | ||||||||||||||
}).Create(&preGroup).Error; err != nil { | ||||||||||||||
log.Errorf("set group(%v) black_plugins error(sql): %v", groupID, err) | ||||||||||||||
return err | ||||||||||||||
|
@@ -92,7 +108,11 @@ func GetUserPluginStatus(userID int64, plugin *manager.PluginCondition) bool { | |||||||||||||
// 查询 | ||||||||||||||
var preUser dao.UserSetting | ||||||||||||||
proxy.GetDB().Take(&preUser, userID) | ||||||||||||||
return !(hasPluginKey(preUser.BlackPlugins, key) || hasPluginKey(preUser.BlackPlugins, AllPluginKey)) | ||||||||||||||
if preUser.WhiteMode { // 白名单模式 | ||||||||||||||
return hasPluginKey(preUser.WhitePlugins, key) | ||||||||||||||
} else { | ||||||||||||||
return !(hasPluginKey(preUser.BlackPlugins, key) || hasPluginKey(preUser.BlackPlugins, AllPluginKey)) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// GetGroupPluginStatus 获取群插件状态(能否使用) | ||||||||||||||
|
@@ -101,11 +121,29 @@ func GetGroupPluginStatus(groupID int64, plugin *manager.PluginCondition) bool { | |||||||||||||
var key string | ||||||||||||||
if plugin != nil { | ||||||||||||||
key = plugin.Key | ||||||||||||||
} else { // plugin 为空,代表所有插件 | ||||||||||||||
} else { | ||||||||||||||
key = AllPluginKey | ||||||||||||||
} | ||||||||||||||
// 查询 | ||||||||||||||
var preGroup dao.GroupSetting | ||||||||||||||
proxy.GetDB().Take(&preGroup, groupID) | ||||||||||||||
return !(hasPluginKey(preGroup.BlackPlugins, key) || hasPluginKey(preGroup.BlackPlugins, AllPluginKey)) | ||||||||||||||
if preGroup.WhiteMode { // 白名单模式 | ||||||||||||||
return hasPluginKey(preGroup.WhitePlugins, key) | ||||||||||||||
} else { | ||||||||||||||
return !(hasPluginKey(preGroup.BlackPlugins, key) || hasPluginKey(preGroup.BlackPlugins, AllPluginKey)) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// GetGroupRunningMode 获取群运行模式(白名单模式为true,黑名单为false) | ||||||||||||||
func GetGroupRunningMode(groupID int64) bool { | ||||||||||||||
var preGroup dao.GroupSetting | ||||||||||||||
proxy.GetDB().Take(&preGroup, groupID) | ||||||||||||||
return preGroup.WhiteMode | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// GetUserRunningMode 获取用户运行模式(白名单模式为true,黑名单为false) | ||||||||||||||
func GetUserRunningMode(userID int64) bool { | ||||||||||||||
var preUser dao.UserSetting | ||||||||||||||
proxy.GetDB().Take(&preUser, userID) | ||||||||||||||
return preUser.WhiteMode | ||||||||||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看了一下这里没有这种情况出现
PaimengBot/basic/ban/switch.go
Lines 53 to 58 in c8266f4