1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-28 10:12:02 +08:00

opt search

This commit is contained in:
shaoying 2021-01-07 00:25:17 +08:00
parent 9c190ee746
commit 5aec0cc544
18 changed files with 227 additions and 193 deletions

View File

@ -31,33 +31,15 @@ func _user_create(m *ice.Message, name, word string) {
m.Event(USER_CREATE, name) m.Event(USER_CREATE, name)
} }
func _user_search(m *ice.Message, kind, name, text string, arg ...string) { func _user_search(m *ice.Message, kind, name, text string, arg ...string) {
fields := kit.Split(m.Option(mdb.FIELDS)) if kind != USER {
return
}
m.Richs(USER, nil, kit.MDB_FOREACH, func(key string, val map[string]interface{}) { m.Richs(USER, nil, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
if name != "" && name != val[USERNAME] { if name != "" && name != val[USERNAME] {
return return
} }
for _, k := range fields { m.PushSearch("cmd", USER, "type", kit.Format(UserRole(m, val[USERNAME])),
switch k { "name", kit.Format(val[USERNICK]), "text", kit.Format(val[USERNAME]))
case kit.SSH_POD:
m.Push(k, m.Option(ice.MSG_USERPOD))
case kit.SSH_CTX:
m.Push(k, m.Prefix())
case kit.SSH_CMD:
m.Push(k, USER)
case kit.MDB_TIME:
m.Push(k, m.Time())
case kit.MDB_SIZE:
m.Push(k, "")
case kit.MDB_TYPE:
m.Push(k, kit.Format(UserRole(m, val[USERNAME])))
case kit.MDB_NAME:
m.Push(k, kit.Format(val[USERNICK]))
case kit.MDB_TEXT:
m.Push(k, kit.Format(val[USERNAME]))
default:
m.Push(k, "")
}
}
}) })
} }

View File

@ -10,6 +10,10 @@ import (
) )
func _command_search(m *ice.Message, arg ...string) { func _command_search(m *ice.Message, arg ...string) {
if !(arg[0] == "command" || arg[0] == "*" && arg[1] != "") {
return
}
ice.Pulse.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) { ice.Pulse.Travel(func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
if strings.HasPrefix(key, "_") || strings.HasPrefix(key, "/") { if strings.HasPrefix(key, "_") || strings.HasPrefix(key, "/") {
return return

View File

@ -27,7 +27,8 @@ func _hash_insert(m *ice.Message, prefix, chain string, arg ...string) {
m.Conf(prefix, kit.Keys(chain, kit.MDB_META, kit.MDB_SHORT), m.Conf(prefix, kit.Keys(kit.MDB_META, kit.MDB_SHORT))) m.Conf(prefix, kit.Keys(chain, kit.MDB_META, kit.MDB_SHORT), m.Conf(prefix, kit.Keys(kit.MDB_META, kit.MDB_SHORT)))
} }
m.Log_INSERT(kit.MDB_KEY, path.Join(prefix, chain), arg[0], arg[1]) m.Log_INSERT(kit.MDB_KEY, path.Join(prefix, chain), arg[0], arg[1])
m.Echo(m.Rich(prefix, chain, kit.Data(arg))) h := m.Rich(prefix, chain, kit.Data(arg))
m.Echo(h)
} }
func _hash_delete(m *ice.Message, prefix, chain, field, value string) { func _hash_delete(m *ice.Message, prefix, chain, field, value string) {
m.Richs(prefix, chain, value, func(key string, val map[string]interface{}) { m.Richs(prefix, chain, value, func(key string, val map[string]interface{}) {

View File

@ -27,14 +27,14 @@ func init() {
return return
} }
if strings.Contains(arg[1], ";") {
arg = strings.Split(arg[1], ";")
}
m.Option(FIELDS, kit.Select("pod,ctx,cmd,time,size,type,name,text", kit.Select(m.Option(FIELDS), arg, 2))) m.Option(FIELDS, kit.Select("pod,ctx,cmd,time,size,type,name,text", kit.Select(m.Option(FIELDS), arg, 2)))
for _, k := range strings.Split(arg[0], ",") { for _, k := range strings.Split(arg[0], ",") {
m.Richs(SEARCH, nil, k, func(key string, value map[string]interface{}) { for _, kk := range strings.Split(arg[1], ",") {
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, arg[0], arg[1], kit.Select("", arg, 2)) m.Richs(SEARCH, nil, k, func(key string, value map[string]interface{}) {
}) m.Debug("what %v --- %v %v ", k, kk, key)
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, k, kk, kit.Select("", arg, 2))
})
}
} }
}}, }},
}}) }})

View File

@ -58,11 +58,12 @@ func init() {
CLIENT: {Name: "client hash auto prunes", Help: "客户端", Action: map[string]*ice.Action{ CLIENT: {Name: "client hash auto prunes", Help: "客户端", Action: map[string]*ice.Action{
DIAL: {Name: "dial type name port=9010 host=", Help: "连接", Hand: func(m *ice.Message, arg ...string) { DIAL: {Name: "dial type name port=9010 host=", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
c, e := net.Dial(TCP, m.Option(HOST)+":"+m.Option(PORT)) c, e := net.Dial(TCP, m.Option(HOST)+":"+m.Option(PORT))
h := m.Cmdx(mdb.INSERT, CLIENT, "", mdb.HASH, PORT, m.Option(PORT), HOST, m.Option(HOST), // h := m.Cmdx(mdb.INSERT, CLIENT, "", mdb.HASH, PORT, m.Option(PORT), HOST, m.Option(HOST),
kit.MDB_TYPE, m.Option(kit.MDB_TYPE), kit.MDB_NAME, m.Option(kit.MDB_NAME), // kit.MDB_TYPE, m.Option(kit.MDB_TYPE), kit.MDB_NAME, m.Option(kit.MDB_NAME),
kit.MDB_STATUS, kit.Select(ERROR, OPEN, e == nil), kit.MDB_ERROR, kit.Format(e)) // kit.MDB_STATUS, kit.Select(ERROR, OPEN, e == nil), kit.MDB_ERROR, kit.Format(e))
//
c = &Conn{m: m, h: h, s: &Stat{}, Conn: c} // c = &Conn{m: m, h: h, s: &Stat{}, Conn: c}
c = &Conn{m: m, s: &Stat{}, Conn: c}
if e == nil { if e == nil {
defer c.Close() defer c.Close()
} }

View File

@ -54,10 +54,11 @@ func init() {
SERVER: {Name: "server hash auto prunes", Help: "服务器", Action: map[string]*ice.Action{ SERVER: {Name: "server hash auto prunes", Help: "服务器", Action: map[string]*ice.Action{
LISTEN: {Name: "LISTEN type name port=9010 host=", Help: "监听", Hand: func(m *ice.Message, arg ...string) { LISTEN: {Name: "LISTEN type name port=9010 host=", Help: "监听", Hand: func(m *ice.Message, arg ...string) {
l, e := net.Listen(TCP, m.Option(HOST)+":"+m.Option(PORT)) l, e := net.Listen(TCP, m.Option(HOST)+":"+m.Option(PORT))
h := m.Cmdx(mdb.INSERT, SERVER, "", mdb.HASH, arg, // h := m.Cmdx(mdb.INSERT, SERVER, "", mdb.HASH, arg,
kit.MDB_STATUS, kit.Select(ERROR, OPEN, e == nil), kit.MDB_ERROR, kit.Format(e)) // kit.MDB_STATUS, kit.Select(ERROR, OPEN, e == nil), kit.MDB_ERROR, kit.Format(e))
//
l = &Listener{m: m, h: h, s: &Stat{}, Listener: l} // l = &Listener{m: m, h: h, s: &Stat{}, Listener: l}
l = &Listener{m: m, s: &Stat{}, Listener: l}
if e == nil { if e == nil {
defer l.Close() defer l.Close()
} }

View File

@ -9,19 +9,28 @@ import (
func _email_show(m *ice.Message, name, text string, arg ...string) { func _email_show(m *ice.Message, name, text string, arg ...string) {
} }
func _email_search(m *ice.Message, kind, name, text string) { func _email_search(m *ice.Message, kind, name, text string) {
m.PushSearch("cmd", EMAIL, "type", "163", "name", name, "text", kit.MergeURL("https://mail.163.com")) if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, EMAIL) {
m.PushSearchWeb(EMAIL, name)
}
} }
const EMAIL = "email" const EMAIL = "email"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{
EMAIL: {Name: "email [name] word", Help: "百度", Action: map[string]*ice.Action{ Configs: map[string]*ice.Config{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { EMAIL: {Name: "email", Help: "邮件", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
_email_search(m, arg[0], arg[1], arg[2]) },
Commands: map[string]*ice.Command{
EMAIL: {Name: "email [name] word", Help: "邮件", Action: map[string]*ice.Action{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_email_search(m, arg[0], arg[1], arg[2])
}},
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.INSERT, m.Prefix(EMAIL), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_email_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }})
_email_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
}})
} }

View File

@ -3,16 +3,31 @@ package chat
import ( import (
ice "github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/mdb"
kit "github.com/shylinux/toolkits"
) )
const SEARCHS = "searchs"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{
"/search": {Name: "/search", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { Configs: map[string]*ice.Config{
if arg[0] == mdb.RENDER { SEARCHS: {Name: "searchs", Help: "搜索", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
m.Cmdy(m.Space(m.Option(POD)), mdb.RENDER, arg[1:]) },
return Commands: map[string]*ice.Command{
} "/search": {Name: "/search", Help: "搜索引擎", Action: map[string]*ice.Action{
m.Cmdy(m.Space(m.Option(POD)), mdb.SEARCH, arg) mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
}}, m.Cmdy(m.Space(m.Option(POD)), mdb.RENDER, arg[1:])
}}) }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if kit.Contains(arg[1], ";") {
arg = kit.Split(arg[1], ";", ";", ";")
}
if m.Cmdy(m.Space(m.Option(POD)), mdb.SEARCH, arg); arg[1] == "" {
return
}
m.Cmd(mdb.INSERT, m.Prefix(SEARCHS), "", mdb.HASH,
"name", arg[1], "type", arg[0], "text", kit.Select("", arg, 2))
}},
}})
} }

View File

@ -4,51 +4,32 @@ import (
ice "github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/mdb"
kit "github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"strings"
) )
func _csdn_show(m *ice.Message, name, text string, arg ...string) { func _csdn_show(m *ice.Message, name, text string, arg ...string) {
} }
func _csdn_search(m *ice.Message, kind, name, text string) { func _csdn_search(m *ice.Message, kind, name, text string) {
if !strings.Contains(kind, "*") && !strings.Contains(kind, "csdn") { if kit.Contains(kind, "*") || kit.Contains(kind, "csdn") {
return m.PushSearchWeb(CSDN, name)
} }
m.PushSearch("cmd", CSDN, "type", "csdn", "name", name, "text",
kit.MergeURL("https://so.csdn.net/so/search/all", "q", name))
m.PushSearch("cmd", CSDN, "type", "juejin", "name", name, "text",
kit.MergeURL("https://juejin.cn/search?type=all", "query", name))
m.PushSearch("cmd", CSDN, "type", "51cto", "name", name, "text",
kit.MergeURL("http://so.51cto.com/?sort=time", "keywords", name))
m.PushSearch("cmd", CSDN, "type", "oschina", "name", name, "text",
kit.MergeURL("https://www.oschina.net/search?scope=project", "q", name))
m.PushSearch("cmd", CSDN, "type", "imooc", "name", name, "text",
kit.MergeURL("https://www.imooc.com/search/", "words", name))
m.PushSearch("cmd", CSDN, "type", "segmentfault", "name", name, "text",
kit.MergeURL("https://segmentfault.com/search", "q", name))
m.PushSearch("cmd", CSDN, "type", "nowcoder", "name", name, "text",
kit.MergeURL("https://www.nowcoder.com/search?type=all", "query", name))
m.PushSearch("cmd", CSDN, "type", "leetcode-cn", "name", name, "text",
kit.MergeURL("https://leetcode-cn.com/problemset/all/", "search", name))
} }
const CSDN = "csdn" const CSDN = "csdn"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{
CSDN: {Name: "csdn [name] word", Help: "百度", Action: map[string]*ice.Action{ Configs: map[string]*ice.Config{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { CSDN: {Name: "csdn", Help: "博客", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
_csdn_search(m, arg[0], arg[1], arg[2]) }, Commands: map[string]*ice.Command{
CSDN: {Name: "csdn [name] word", Help: "博客", Action: map[string]*ice.Action{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_csdn_search(m, arg[0], arg[1], arg[2])
}},
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.INSERT, m.Prefix(CSDN), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_csdn_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }})
_csdn_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
}})
} }

View File

@ -9,20 +9,28 @@ import (
func _github_show(m *ice.Message, name, text string, arg ...string) { func _github_show(m *ice.Message, name, text string, arg ...string) {
} }
func _github_search(m *ice.Message, kind, name, text string) { func _github_search(m *ice.Message, kind, name, text string) {
m.PushSearch("cmd", GITHUB, "type", "github", "name", name, "text", if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, GITHUB) {
kit.MergeURL("https://github.com/search", "q", name)) m.PushSearchWeb(GITHUB, name)
}
} }
const GITHUB = "github" const GITHUB = "github"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{
GITHUB: {Name: "github [name] word", Help: "百度", Action: map[string]*ice.Action{ Configs: map[string]*ice.Config{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { GITHUB: {Name: "github", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
_github_search(m, arg[0], arg[1], arg[2]) },
Commands: map[string]*ice.Command{
GITHUB: {Name: "github [name] word", Help: "百度", Action: map[string]*ice.Action{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_github_search(m, arg[0], arg[1], arg[2])
}},
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.INSERT, m.Prefix(GITHUB), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_github_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }})
_github_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
}})
} }

View File

@ -4,27 +4,33 @@ import (
ice "github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/mdb"
kit "github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"net/url"
) )
func _beike_show(m *ice.Message, name, text string, arg ...string) { func _beike_show(m *ice.Message, name, text string, arg ...string) {
} }
func _beike_search(m *ice.Message, kind, name, text string) { func _beike_search(m *ice.Message, kind, name, text string) {
m.PushSearch("cmd", BEIKE, "type", kind, "name", name, "text", if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, BEIKE) {
kit.MergeURL("https://ke.com/ershoufang/rs"+url.QueryEscape(name))) m.PushSearchWeb(BEIKE, name)
}
} }
const BEIKE = "beike" const BEIKE = "beike"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{
BEIKE: {Name: "beike [name] word", Help: "百度", Action: map[string]*ice.Action{ Configs: map[string]*ice.Config{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { BEIKE: {Name: "beike", Help: "贝壳", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
_beike_search(m, arg[0], arg[1], arg[2]) },
Commands: map[string]*ice.Command{
BEIKE: {Name: "beike [name] word", Help: "百度", Action: map[string]*ice.Action{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_beike_search(m, arg[0], arg[1], arg[2])
}},
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.INSERT, m.Prefix(BEIKE), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_beike_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }})
_beike_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
}})
} }

View File

@ -9,19 +9,28 @@ import (
func _taobao_show(m *ice.Message, name, text string, arg ...string) { func _taobao_show(m *ice.Message, name, text string, arg ...string) {
} }
func _taobao_search(m *ice.Message, kind, name, text string) { func _taobao_search(m *ice.Message, kind, name, text string) {
m.PushSearch("cmd", TAOBAO, "type", kind, "name", name, "text", kit.MergeURL("https://s.taobao.com/search", "q", name)) if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, TAOBAO) {
m.PushSearchWeb(TAOBAO, name)
}
} }
const TAOBAO = "taobao" const TAOBAO = "taobao"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{
TAOBAO: {Name: "taobao [name] word", Help: "百度", Action: map[string]*ice.Action{ Configs: map[string]*ice.Config{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { TAOBAO: {Name: "taobao", Help: "淘宝", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
_taobao_search(m, arg[0], arg[1], arg[2]) },
Commands: map[string]*ice.Command{
TAOBAO: {Name: "taobao [name] word", Help: "百度", Action: map[string]*ice.Action{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_taobao_search(m, arg[0], arg[1], arg[2])
}},
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.INSERT, m.Prefix(TAOBAO), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_taobao_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }})
_taobao_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
}})
} }

View File

@ -4,9 +4,6 @@ import (
ice "github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/mdb"
kit "github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"net/url"
"strings"
) )
func _baidu_show(m *ice.Message, name, text string, arg ...string) { func _baidu_show(m *ice.Message, name, text string, arg ...string) {
@ -14,37 +11,29 @@ func _baidu_show(m *ice.Message, name, text string, arg ...string) {
// m.Cmdy(mdb.RENDER, web.RENDER.Frame, kit.Format("https://baidu.com/s?wd=%s", text)) // m.Cmdy(mdb.RENDER, web.RENDER.Frame, kit.Format("https://baidu.com/s?wd=%s", text))
} }
func _baidu_search(m *ice.Message, kind, name, text string) { func _baidu_search(m *ice.Message, kind, name, text string) {
if !strings.Contains(kind, "*") && !strings.Contains(kind, "baidu") { if kit.Contains(kind, "*") || kit.Contains(kind, "baidu") {
return m.PushSearchWeb(BAIDU, name)
} }
m.PushSearch("cmd", BAIDU, "type", "web", "name", name, "text",
kit.MergeURL("https://www.baidu.com/s", "wd", name))
m.PushSearch("cmd", BAIDU, "type", "map", "name", name, "text",
kit.MergeURL("https://map.baidu.com/search?querytype=s", "wd", name))
m.PushSearch("cmd", BAIDU, "type", "zhihu", "name", name, "text",
kit.MergeURL("https://www.zhihu.com/search?type=content", "q", name))
m.PushSearch("cmd", BAIDU, "type", "weibo", "name", name, "text",
kit.MergeURL("https://s.weibo.com/weibo/"+url.QueryEscape(name)))
m.PushSearch("cmd", BAIDU, "type", "taotiao", "name", name, "text",
kit.MergeURL("https://www.toutiao.com/search/", "keyword", name))
} }
const BAIDU = "baidu" const BAIDU = "baidu"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{
BAIDU: {Name: "baidu [name] word", Help: "百度", Action: map[string]*ice.Action{ Configs: map[string]*ice.Config{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { BAIDU: {Name: "baidu", Help: "百度", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
_baidu_search(m, arg[0], arg[1], arg[2]) },
Commands: map[string]*ice.Command{
BAIDU: {Name: "baidu [name] word", Help: "百度", Action: map[string]*ice.Action{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_baidu_search(m, arg[0], arg[1], arg[2])
}},
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.INSERT, m.Prefix(BAIDU), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_baidu_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }})
arg = _name(m, arg)
_baidu_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
}})
} }

View File

@ -10,21 +10,29 @@ func _music_show(m *ice.Message, name, text string, arg ...string) {
_option(m, MUSIC, name, text, arg...) _option(m, MUSIC, name, text, arg...)
} }
func _music_search(m *ice.Message, kind, name, text string) { func _music_search(m *ice.Message, kind, name, text string) {
m.PushSearch("cmd", MUSIC, "type", "163", "name", name, "text", if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, MUSIC) {
kit.MergeURL("https://music.163.com/#/search/m/", "s", name)) m.PushSearchWeb(MUSIC, name)
}
} }
const MUSIC = "music" const MUSIC = "music"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{
MUSIC: {Name: "music [name] url", Help: "视频", Action: map[string]*ice.Action{ Configs: map[string]*ice.Config{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { MUSIC: {Name: "music", Help: "音乐", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
_music_search(m, arg[0], arg[1], arg[2]) },
Commands: map[string]*ice.Command{
MUSIC: {Name: "music [name] url", Help: "视频", Action: map[string]*ice.Action{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_music_search(m, arg[0], arg[1], arg[2])
}},
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.INSERT, m.Prefix(MUSIC), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_music_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }})
arg = _name(m, arg)
_music_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
}})
} }

View File

@ -4,8 +4,6 @@ import (
ice "github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/mdb"
kit "github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"net/url"
) )
func _video_show(m *ice.Message, name, text string, arg ...string) { func _video_show(m *ice.Message, name, text string, arg ...string) {
@ -13,31 +11,31 @@ func _video_show(m *ice.Message, name, text string, arg ...string) {
m.Render(ice.RENDER_TEMPLATE, m.Conf(VIDEO, "meta.template")) m.Render(ice.RENDER_TEMPLATE, m.Conf(VIDEO, "meta.template"))
} }
func _video_search(m *ice.Message, kind, name, text string) { func _video_search(m *ice.Message, kind, name, text string) {
m.PushSearch("cmd", VIDEO, "type", "v", "name", name, "text", if kit.Contains(kind, "*") || kit.Contains(kind, VIDEO) {
kit.MergeURL("https://v.qq.com/x/search/", "q", name)) m.PushSearchWeb(VIDEO, name)
}
m.PushSearch("cmd", VIDEO, "type", "iqiyi", "name", name, "text",
kit.MergeURL("https://so.iqiyi.com/so/q_"+url.QueryEscape(name)))
m.PushSearch("cmd", VIDEO, "type", "kuaishou", "name", name, "text",
kit.MergeURL("https://video.kuaishou.com/search", "searchKey", name))
m.PushSearch("cmd", VIDEO, "type", "bilibili", "name", name, "text",
kit.MergeURL("https://search.bilibili.com/all", "keyword", name))
} }
const VIDEO = "video" const VIDEO = "video"
func init() { func init() {
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ Index.Merge(&ice.Context{
VIDEO: {Name: "video [name] url", Help: "视频", Action: map[string]*ice.Action{ Configs: map[string]*ice.Config{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { VIDEO: {Name: "video", Help: "视频", Value: kit.Data(
_video_search(m, arg[0], arg[1], arg[2]) kit.MDB_SHORT, kit.MDB_TEXT, "template", video,
)},
},
Commands: map[string]*ice.Command{
VIDEO: {Name: "video [name] url", Help: "视频", Action: map[string]*ice.Action{
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
_video_search(m, arg[0], arg[1], arg[2])
}},
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(mdb.INSERT, m.Prefix(VIDEO), "", mdb.HASH, arg)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_video_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }})
arg = _name(m, arg)
_video_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
}})
} }

View File

@ -333,7 +333,6 @@ func init() {
ORDER: {Name: ORDER, Help: "列表", Value: kit.Data("template", order)}, ORDER: {Name: ORDER, Help: "列表", Value: kit.Data("template", order)},
TABLE: {Name: TABLE, Help: "表格", Value: kit.Data("template", table)}, TABLE: {Name: TABLE, Help: "表格", Value: kit.Data("template", table)},
IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data("template", image)}, IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data("template", image)},
VIDEO: {Name: VIDEO, Help: "视频", Value: kit.Data("template", video)},
WORD: {Name: WORD, Help: "语言文字", Value: kit.Data( WORD: {Name: WORD, Help: "语言文字", Value: kit.Data(
kit.MDB_PATH, "", "regs", ".*\\.shy", "alias", map[string]interface{}{ kit.MDB_PATH, "", "regs", ".*\\.shy", "alias", map[string]interface{}{

27
misc.go
View File

@ -1,11 +1,11 @@
package ice package ice
import ( import (
"path"
kit "github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"fmt" "fmt"
"net/url"
"path"
"strings" "strings"
"sync/atomic" "sync/atomic"
) )
@ -115,12 +115,31 @@ func (m *Message) PushSearch(args ...interface{}) {
case kit.SSH_CMD: case kit.SSH_CMD:
m.Push(k, data[kit.SSH_CMD]) m.Push(k, data[kit.SSH_CMD])
case kit.MDB_TIME: case kit.MDB_TIME:
m.Push(k, kit.Select(m.Time(), data[kit.MDB_TIME])) m.Push(k, m.Time())
case kit.MDB_SIZE:
m.Push(k, "")
case kit.MDB_TYPE:
m.Push(k, data[kit.MDB_TYPE])
case kit.MDB_NAME:
m.Push(k, data[kit.MDB_NAME])
case kit.MDB_TEXT:
m.Push(k, data[kit.MDB_TEXT])
default: default:
m.Push(k, kit.Select("", data[k])) m.Push(k, data[k])
} }
} }
} }
func (m *Message) PushSearchWeb(cmd string, name string) {
msg := m.Spawn()
msg.Option("fields", "type,name,text")
msg.Cmd("mdb.select", m.Prefix(cmd), "", "hash").Table(func(index int, value map[string]string, head []string) {
text := kit.MergeURL(value["text"], value["name"], name)
if value["name"] == "" {
text = kit.MergeURL(value["text"] + url.QueryEscape(name))
}
m.PushSearch("cmd", cmd, "type", kit.Select("", value["type"]), "name", name, "text", text)
})
}
func (m *Message) PushAction(list ...interface{}) { func (m *Message) PushAction(list ...interface{}) {
m.Table(func(index int, value map[string]string, head []string) { m.Table(func(index int, value map[string]string, head []string) {
m.PushRender(kit.MDB_ACTION, kit.MDB_BUTTON, strings.Join(kit.Simple(list...), ",")) m.PushRender(kit.MDB_ACTION, kit.MDB_BUTTON, strings.Join(kit.Simple(list...), ","))

View File

@ -12,7 +12,11 @@ import (
"strings" "strings"
) )
func _alpha_find(m *ice.Message, method, word string) *ice.Message { func _alpha_find(m *ice.Message, method, word string) {
if word == "" {
return
}
// 搜索方法 // 搜索方法
switch word = strings.TrimSpace(word); method { switch word = strings.TrimSpace(word); method {
case "line": case "line":
@ -28,7 +32,7 @@ func _alpha_find(m *ice.Message, method, word string) *ice.Message {
} }
m.PushSearch("cmd", ALPHA, "type", method, "name", value["word"], "text", value["translation"], value) m.PushSearch("cmd", ALPHA, "type", method, "name", value["word"], "text", value["translation"], value)
}) })
return m return
} }
func _alpha_load(m *ice.Message, file, name string) { func _alpha_load(m *ice.Message, file, name string) {
// 清空数据 // 清空数据