mirror of
https://shylinux.com/x/icebergs
synced 2025-04-28 02:02:02 +08:00
opt search
This commit is contained in:
parent
9c190ee746
commit
5aec0cc544
@ -31,33 +31,15 @@ func _user_create(m *ice.Message, name, word string) {
|
||||
m.Event(USER_CREATE, name)
|
||||
}
|
||||
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{}) {
|
||||
if name != "" && name != val[USERNAME] {
|
||||
return
|
||||
}
|
||||
for _, k := range fields {
|
||||
switch k {
|
||||
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, "")
|
||||
}
|
||||
}
|
||||
m.PushSearch("cmd", USER, "type", kit.Format(UserRole(m, val[USERNAME])),
|
||||
"name", kit.Format(val[USERNICK]), "text", kit.Format(val[USERNAME]))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,10 @@ import (
|
||||
)
|
||||
|
||||
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) {
|
||||
if strings.HasPrefix(key, "_") || strings.HasPrefix(key, "/") {
|
||||
return
|
||||
|
@ -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.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) {
|
||||
m.Richs(prefix, chain, value, func(key string, val map[string]interface{}) {
|
||||
|
@ -27,14 +27,14 @@ func init() {
|
||||
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)))
|
||||
for _, k := range strings.Split(arg[0], ",") {
|
||||
m.Richs(SEARCH, nil, k, func(key string, value map[string]interface{}) {
|
||||
m.Cmdy(kit.Keys(value[kit.MDB_TEXT], value[kit.MDB_NAME]), SEARCH, arg[0], arg[1], kit.Select("", arg, 2))
|
||||
})
|
||||
for _, kk := range strings.Split(arg[1], ",") {
|
||||
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))
|
||||
})
|
||||
}
|
||||
}
|
||||
}},
|
||||
}})
|
||||
|
@ -58,11 +58,12 @@ func init() {
|
||||
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) {
|
||||
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),
|
||||
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))
|
||||
|
||||
c = &Conn{m: m, h: h, s: &Stat{}, Conn: c}
|
||||
// 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_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, s: &Stat{}, Conn: c}
|
||||
if e == nil {
|
||||
defer c.Close()
|
||||
}
|
||||
|
@ -54,10 +54,11 @@ func init() {
|
||||
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) {
|
||||
l, e := net.Listen(TCP, m.Option(HOST)+":"+m.Option(PORT))
|
||||
h := m.Cmdx(mdb.INSERT, SERVER, "", mdb.HASH, arg,
|
||||
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}
|
||||
// h := m.Cmdx(mdb.INSERT, SERVER, "", mdb.HASH, arg,
|
||||
// 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, s: &Stat{}, Listener: l}
|
||||
if e == nil {
|
||||
defer l.Close()
|
||||
}
|
||||
|
@ -9,19 +9,28 @@ import (
|
||||
func _email_show(m *ice.Message, name, text string, arg ...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"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{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])
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
EMAIL: {Name: "email", Help: "邮件", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
||||
},
|
||||
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:]...)
|
||||
}},
|
||||
}})
|
||||
}})
|
||||
}
|
||||
|
@ -3,16 +3,31 @@ package chat
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const SEARCHS = "searchs"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
"/search": {Name: "/search", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if arg[0] == mdb.RENDER {
|
||||
m.Cmdy(m.Space(m.Option(POD)), mdb.RENDER, arg[1:])
|
||||
return
|
||||
}
|
||||
m.Cmdy(m.Space(m.Option(POD)), mdb.SEARCH, arg)
|
||||
}},
|
||||
}})
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
SEARCHS: {Name: "searchs", Help: "搜索", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
"/search": {Name: "/search", Help: "搜索引擎", Action: map[string]*ice.Action{
|
||||
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))
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -4,51 +4,32 @@ import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _csdn_show(m *ice.Message, name, text string, arg ...string) {
|
||||
}
|
||||
func _csdn_search(m *ice.Message, kind, name, text string) {
|
||||
if !strings.Contains(kind, "*") && !strings.Contains(kind, "csdn") {
|
||||
return
|
||||
if kit.Contains(kind, "*") || kit.Contains(kind, "csdn") {
|
||||
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"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{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])
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
CSDN: {Name: "csdn", Help: "博客", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
||||
}, 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:]...)
|
||||
}},
|
||||
}})
|
||||
}})
|
||||
}
|
||||
|
@ -9,20 +9,28 @@ import (
|
||||
func _github_show(m *ice.Message, name, text string, arg ...string) {
|
||||
}
|
||||
func _github_search(m *ice.Message, kind, name, text string) {
|
||||
m.PushSearch("cmd", GITHUB, "type", "github", "name", name, "text",
|
||||
kit.MergeURL("https://github.com/search", "q", name))
|
||||
if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, GITHUB) {
|
||||
m.PushSearchWeb(GITHUB, name)
|
||||
}
|
||||
}
|
||||
|
||||
const GITHUB = "github"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{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])
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
GITHUB: {Name: "github", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
||||
},
|
||||
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:]...)
|
||||
}},
|
||||
}})
|
||||
}})
|
||||
}
|
||||
|
@ -4,27 +4,33 @@ import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func _beike_show(m *ice.Message, name, text string, arg ...string) {
|
||||
}
|
||||
func _beike_search(m *ice.Message, kind, name, text string) {
|
||||
m.PushSearch("cmd", BEIKE, "type", kind, "name", name, "text",
|
||||
kit.MergeURL("https://ke.com/ershoufang/rs"+url.QueryEscape(name)))
|
||||
if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, BEIKE) {
|
||||
m.PushSearchWeb(BEIKE, name)
|
||||
}
|
||||
}
|
||||
|
||||
const BEIKE = "beike"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{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])
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
BEIKE: {Name: "beike", Help: "贝壳", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
||||
},
|
||||
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:]...)
|
||||
}},
|
||||
}})
|
||||
}})
|
||||
}
|
||||
|
@ -9,19 +9,28 @@ import (
|
||||
func _taobao_show(m *ice.Message, name, text string, arg ...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"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{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])
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
TAOBAO: {Name: "taobao", Help: "淘宝", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
||||
},
|
||||
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:]...)
|
||||
}},
|
||||
}})
|
||||
}})
|
||||
}
|
||||
|
@ -4,9 +4,6 @@ import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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))
|
||||
}
|
||||
func _baidu_search(m *ice.Message, kind, name, text string) {
|
||||
if !strings.Contains(kind, "*") && !strings.Contains(kind, "baidu") {
|
||||
return
|
||||
if kit.Contains(kind, "*") || kit.Contains(kind, "baidu") {
|
||||
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"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{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])
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
BAIDU: {Name: "baidu", Help: "百度", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
||||
},
|
||||
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:]...)
|
||||
}},
|
||||
}})
|
||||
}})
|
||||
}
|
||||
|
@ -10,21 +10,29 @@ func _music_show(m *ice.Message, name, text string, arg ...string) {
|
||||
_option(m, MUSIC, name, text, arg...)
|
||||
}
|
||||
func _music_search(m *ice.Message, kind, name, text string) {
|
||||
m.PushSearch("cmd", MUSIC, "type", "163", "name", name, "text",
|
||||
kit.MergeURL("https://music.163.com/#/search/m/", "s", name))
|
||||
if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, MUSIC) {
|
||||
m.PushSearchWeb(MUSIC, name)
|
||||
}
|
||||
}
|
||||
|
||||
const MUSIC = "music"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{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])
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
MUSIC: {Name: "music", Help: "音乐", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
||||
},
|
||||
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:]...)
|
||||
}},
|
||||
}})
|
||||
}})
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"net/url"
|
||||
)
|
||||
|
||||
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"))
|
||||
}
|
||||
func _video_search(m *ice.Message, kind, name, text string) {
|
||||
m.PushSearch("cmd", VIDEO, "type", "v", "name", name, "text",
|
||||
kit.MergeURL("https://v.qq.com/x/search/", "q", 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))
|
||||
|
||||
if kit.Contains(kind, "*") || kit.Contains(kind, VIDEO) {
|
||||
m.PushSearchWeb(VIDEO, name)
|
||||
}
|
||||
}
|
||||
|
||||
const VIDEO = "video"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{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])
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
VIDEO: {Name: "video", Help: "视频", Value: kit.Data(
|
||||
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:]...)
|
||||
}},
|
||||
}})
|
||||
}})
|
||||
}
|
||||
|
@ -333,7 +333,6 @@ func init() {
|
||||
ORDER: {Name: ORDER, Help: "列表", Value: kit.Data("template", order)},
|
||||
TABLE: {Name: TABLE, Help: "表格", Value: kit.Data("template", table)},
|
||||
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(
|
||||
kit.MDB_PATH, "", "regs", ".*\\.shy", "alias", map[string]interface{}{
|
||||
|
27
misc.go
27
misc.go
@ -1,11 +1,11 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
)
|
||||
@ -115,12 +115,31 @@ func (m *Message) PushSearch(args ...interface{}) {
|
||||
case kit.SSH_CMD:
|
||||
m.Push(k, data[kit.SSH_CMD])
|
||||
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:
|
||||
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{}) {
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushRender(kit.MDB_ACTION, kit.MDB_BUTTON, strings.Join(kit.Simple(list...), ","))
|
||||
|
@ -12,7 +12,11 @@ import (
|
||||
"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 {
|
||||
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)
|
||||
})
|
||||
return m
|
||||
return
|
||||
}
|
||||
func _alpha_load(m *ice.Message, file, name string) {
|
||||
// 清空数据
|
||||
|
Loading…
x
Reference in New Issue
Block a user