Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
go-cqhttp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
go-cqhttp
Commits
54952523
Commit
54952523
authored
Jul 25, 2020
by
Mrs4s
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
websocket echo field supported.
parent
f19c76d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
54 deletions
+58
-54
server/websocket.go
server/websocket.go
+58
-54
No files found.
server/websocket.go
View file @
54952523
...
...
@@ -116,7 +116,11 @@ func (s *websocketServer) listenApi(c *websocket.Conn) {
t
:=
strings
.
ReplaceAll
(
j
.
Get
(
"action"
)
.
Str
,
"_async"
,
""
)
//TODO: async support
log
.
Infof
(
"API调用: %v"
,
j
.
Get
(
"action"
)
.
Str
)
if
f
,
ok
:=
wsApi
[
t
];
ok
{
_
=
c
.
WriteMessage
(
websocket
.
TextMessage
,
[]
byte
(
f
(
s
.
bot
,
j
.
Get
(
"params"
))))
ret
:=
f
(
s
.
bot
,
j
.
Get
(
"params"
))
if
j
.
Get
(
"echo"
)
.
Exists
()
{
ret
[
"echo"
]
=
j
.
Get
(
"echo"
)
.
Value
()
}
_
=
c
.
WriteJSON
(
ret
)
}
}
}
...
...
@@ -139,54 +143,54 @@ func (s *websocketServer) onBotPushEvent(m coolq.MSG) {
}
}
var
wsApi
=
map
[
string
]
func
(
*
coolq
.
CQBot
,
gjson
.
Result
)
string
{
"get_login_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQGetLoginInfo
()
.
ToJson
()
var
wsApi
=
map
[
string
]
func
(
*
coolq
.
CQBot
,
gjson
.
Result
)
coolq
.
MSG
{
"get_login_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetLoginInfo
()
},
"get_friend_list"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQGetFriendList
()
.
ToJson
()
"get_friend_list"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetFriendList
()
},
"get_group_list"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQGetGroupList
()
.
ToJson
()
"get_group_list"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetGroupList
()
},
"get_group_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQGetGroupInfo
(
p
.
Get
(
"group_id"
)
.
Int
())
.
ToJson
()
"get_group_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetGroupInfo
(
p
.
Get
(
"group_id"
)
.
Int
())
},
"get_group_member_list"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQGetGroupMemberList
(
p
.
Get
(
"group_id"
)
.
Int
())
.
ToJson
()
"get_group_member_list"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetGroupMemberList
(
p
.
Get
(
"group_id"
)
.
Int
())
},
"get_group_member_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
"get_group_member_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetGroupMemberInfo
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"no_cache"
)
.
Bool
(),
)
.
ToJson
()
)
},
"send_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
"send_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
if
p
.
Get
(
"group_id"
)
.
Int
()
!=
0
{
return
bot
.
CQSendGroupMessage
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
.
ToJson
()
return
bot
.
CQSendGroupMessage
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
}
if
p
.
Get
(
"user_id"
)
.
Int
()
!=
0
{
return
bot
.
CQSendPrivateMessage
(
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
.
ToJson
()
return
bot
.
CQSendPrivateMessage
(
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
}
return
""
return
coolq
.
MSG
{}
},
"send_group_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQSendGroupMessage
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
.
ToJson
()
"send_group_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSendGroupMessage
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
},
"send_private_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQSendPrivateMessage
(
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
.
ToJson
()
"send_private_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSendPrivateMessage
(
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
},
"delete_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQDeleteMessage
(
int32
(
p
.
Get
(
"message_id"
)
.
Int
()))
.
ToJson
()
"delete_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQDeleteMessage
(
int32
(
p
.
Get
(
"message_id"
)
.
Int
()))
},
"set_friend_add_request"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
"set_friend_add_request"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
apr
:=
true
if
p
.
Get
(
"approve"
)
.
Exists
()
{
apr
=
p
.
Get
(
"approve"
)
.
Bool
()
}
return
bot
.
CQProcessFriendRequest
(
p
.
Get
(
"flag"
)
.
Str
,
apr
)
.
ToJson
()
return
bot
.
CQProcessFriendRequest
(
p
.
Get
(
"flag"
)
.
Str
,
apr
)
},
"set_group_add_request"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
"set_group_add_request"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
subType
:=
p
.
Get
(
"sub_type"
)
.
Str
apr
:=
true
if
subType
==
""
{
...
...
@@ -195,50 +199,50 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) string{
if
p
.
Get
(
"approve"
)
.
Exists
()
{
apr
=
p
.
Get
(
"approve"
)
.
Bool
()
}
return
bot
.
CQProcessGroupRequest
(
p
.
Get
(
"flag"
)
.
Str
,
subType
,
apr
)
.
ToJson
()
return
bot
.
CQProcessGroupRequest
(
p
.
Get
(
"flag"
)
.
Str
,
subType
,
apr
)
},
"set_group_card"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQSetGroupCard
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"card"
)
.
Str
)
.
ToJson
()
"set_group_card"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSetGroupCard
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"card"
)
.
Str
)
},
"set_group_special_title"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQSetGroupSpecialTitle
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"special_title"
)
.
Str
)
.
ToJson
()
"set_group_special_title"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSetGroupSpecialTitle
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"special_title"
)
.
Str
)
},
"set_group_kick"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQSetGroupKick
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
.
ToJson
()
"set_group_kick"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSetGroupKick
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"user_id"
)
.
Int
(),
p
.
Get
(
"message"
)
.
Str
)
},
"set_group_ban"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQSetGroupBan
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"user_id"
)
.
Int
(),
uint32
(
p
.
Get
(
"duration"
)
.
Int
()))
.
ToJson
()
"set_group_ban"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSetGroupBan
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"user_id"
)
.
Int
(),
uint32
(
p
.
Get
(
"duration"
)
.
Int
()))
},
"set_group_whole_ban"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
"set_group_whole_ban"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSetGroupWholeBan
(
p
.
Get
(
"group_id"
)
.
Int
(),
func
()
bool
{
if
p
.
Get
(
"enable"
)
.
Exists
()
{
return
p
.
Get
(
"enable"
)
.
Bool
()
}
return
true
}())
.
ToJson
()
}())
},
"set_group_name"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQSetGroupName
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"name"
)
.
Str
)
.
ToJson
()
"set_group_name"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQSetGroupName
(
p
.
Get
(
"group_id"
)
.
Int
(),
p
.
Get
(
"name"
)
.
Str
)
},
"get_image"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQGetImage
(
p
.
Get
(
"file"
)
.
Str
)
.
ToJson
()
"get_image"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetImage
(
p
.
Get
(
"file"
)
.
Str
)
},
"get_group_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQGetGroupMessage
(
int32
(
p
.
Get
(
"message_id"
)
.
Int
()))
.
ToJson
()
"get_group_msg"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetGroupMessage
(
int32
(
p
.
Get
(
"message_id"
)
.
Int
()))
},
"can_send_image"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQCanSendImage
()
.
ToJson
()
"can_send_image"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQCanSendImage
()
},
"can_send_record"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQCanSendRecord
()
.
ToJson
()
"can_send_record"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQCanSendRecord
()
},
"get_status"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQGetStatus
()
.
ToJson
()
"get_status"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetStatus
()
},
"get_version_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQGetVersionInfo
()
.
ToJson
()
"get_version_info"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQGetVersionInfo
()
},
".handle_quick_operation"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
string
{
return
bot
.
CQHandleQuickOperation
(
p
.
Get
(
"context"
),
p
.
Get
(
"operation"
))
.
ToJson
()
".handle_quick_operation"
:
func
(
bot
*
coolq
.
CQBot
,
p
gjson
.
Result
)
coolq
.
MSG
{
return
bot
.
CQHandleQuickOperation
(
p
.
Get
(
"context"
),
p
.
Get
(
"operation"
))
},
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment