This commit is contained in:
cdle
2023-06-06 20:14:51 +08:00
parent 10f300626a
commit e9a82789d8
4 changed files with 78 additions and 15 deletions
+7 -7
View File
@@ -67,13 +67,13 @@ var BotsLocker sync.RWMutex
var ErrNotFind = errors.New("adapter not find") var ErrNotFind = errors.New("adapter not find")
func DestroyAdapterByUUID(uuid string) { func DestroyAdapterByUUID(uuid string) {
BotsLocker.RLock() // BotsLocker.RLock()
defer BotsLocker.RUnlock() // defer BotsLocker.RUnlock()
for i := range Bots { // for i := range Bots {
if Bots[i].uuid == uuid { // if Bots[i].uuid == uuid {
go Bots[i].Destroy() // go Bots[i].Destroy()
} // }
} // }
} }
func GetAdapter(botplt string, bots_id ...string) (*Factory, error) { func GetAdapter(botplt string, bots_id ...string) (*Factory, error) {
+5
View File
@@ -9,6 +9,7 @@ import (
"strings" "strings"
"github.com/cdle/sillyplus/emoji" "github.com/cdle/sillyplus/emoji"
"github.com/cdle/sillyplus/utils"
) )
type Strings struct { type Strings struct {
@@ -201,3 +202,7 @@ func (sender *Strings) ReplaceToEmojis(str string, pattern string) string {
func (sender *Strings) ExtractAddress(input string) string { func (sender *Strings) ExtractAddress(input string) string {
return regexp.MustCompile(`http[s]?://[\w.]+:?\d*`).FindString(input) return regexp.MustCompile(`http[s]?://[\w.]+:?\d*`).FindString(input)
} }
func (sender *Strings) Unique(str ...interface{}) []string {
return utils.Unique(str...)
}
+1 -1
View File
@@ -81,7 +81,7 @@ func publicScript(str string) string {
if su.GetValue("title") == "" { if su.GetValue("title") == "" {
su.SetValue("title", "无名脚本") su.SetValue("title", "无名脚本")
} }
if su.GetValue("message") == "" { if su.GetValue("message") != "" {
su.DeleteValue("message") su.DeleteValue("message")
} }
create_at := su.GetValue("create_at") create_at := su.GetValue("create_at")
+65 -7
View File
@@ -308,24 +308,82 @@ func IsZeroOrEmpty(str string) bool {
return str == "0" || str == "" || str == "nil" return str == "0" || str == "" || str == "nil"
} }
// func Unique(strs ...interface{}) []string {
// m := make(map[string]bool)
// var result []string
// for _, arg := range strs {
// switch arg := arg.(type) {
// case []string:
// for _, v := range arg {
// if _, ok := m[v]; !ok {
// m[v] = true
// result = append(result, v)
// }
// }
// case string:
// if _, ok := m[arg]; !ok {
// m[arg] = true
// result = append(result, arg)
// }
// }
// }
// return result
// }
func Unique(strs ...interface{}) []string { func Unique(strs ...interface{}) []string {
m := make(map[string]bool)
var result []string var result []string
for _, arg := range strs { for _, arg := range strs {
var toAppend []string
switch arg := arg.(type) { switch arg := arg.(type) {
case []string: case []string:
for _, v := range arg { for _, v := range arg {
if _, ok := m[v]; !ok { if !contains(result, v) && !contains(toAppend, v) {
m[v] = true toAppend = append(toAppend, v)
result = append(result, v) }
}
case []interface{}:
for _, v := range arg {
if !contains(result, v.(string)) && !contains(toAppend, v.(string)) {
toAppend = append(toAppend, v.(string))
} }
} }
case string: case string:
if _, ok := m[arg]; !ok { if !contains(result, arg) {
m[arg] = true toAppend = append(toAppend, arg)
result = append(result, arg) }
case [][]string:
subResult := Unique(flatten(arg)...)
for _, v := range subResult {
if !contains(result, v) && !contains(toAppend, v) {
toAppend = append(toAppend, v)
} }
} }
default:
// Unsupported type
continue
}
result = append(result, toAppend...)
}
return result
}
func contains(strs []string, s string) bool {
for _, v := range strs {
if v == s {
return true
}
}
return false
}
func flatten(arr [][]string) []interface{} {
var result []interface{}
for _, subarr := range arr {
var subresult []interface{}
for _, v := range subarr {
subresult = append(subresult, v)
}
result = append(result, subresult)
} }
return result return result
} }