Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-adapter-wecom
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
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
3rdeye
koishi-plugin-adapter-wecom
Commits
c3b5aba8
Commit
c3b5aba8
authored
Mar 17, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more types
parent
a3651f5b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
16 deletions
+44
-16
dev/index.ts
dev/index.ts
+15
-6
src/bot.ts
src/bot.ts
+3
-1
src/def/def.ts
src/def/def.ts
+7
-0
src/utils.ts
src/utils.ts
+19
-9
No files found.
dev/index.ts
View file @
c3b5aba8
...
...
@@ -30,22 +30,31 @@ app.on('wecom/event', (session) => {
console
.
log
(
`Got event
${
JSON
.
stringify
(
session
.
wecom
)}
`
);
});
app
.
on
(
'
wecom/message
'
,
(
session
)
=>
{
console
.
log
(
`Got custom message
${
JSON
.
stringify
(
session
.
wecom
)}
`
);
});
app
.
on
(
'
message
'
,
(
session
)
=>
{
console
.
log
(
`Got message
${
session
.
content
}
`
);
});
app
.
command
(
'
test1
'
)
.
command
(
'
image
'
)
.
action
(
async
()
=>
segment
.
image
(
await
fs
.
promises
.
readFile
(
__dirname
+
'
/10000.jpg
'
)),
);
app
.
command
(
'
markdown
'
).
action
(
async
()
=>
{
return
`
${
segment
(
'
markdown
'
)}
# 女装\n> 今天梦梦女装了吗?`
;
});
app
.
command
(
'
test2
'
)
.
action
(
async
()
=>
segment
.
image
(
'
https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/10000.jpg
'
,
),
.
command
(
'
media
'
)
.
option
(
'
type
'
,
'
-t, <type:string>
'
,
{
fallback
:
'
image
'
})
.
action
(
async
(
argv
)
=>
segment
(
argv
.
options
.
type
,
{
url
:
'
https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/10000.jpg
'
,
}),
);
app
.
start
();
src/bot.ts
View file @
c3b5aba8
...
...
@@ -283,7 +283,7 @@ export class WeComBot extends Bot<BotConfig> {
}
async
sendMediaMessage
(
type
:
'
image
'
|
'
video
'
,
type
:
string
,
fileName
:
string
,
message
:
Buffer
,
targetUsers
:
string
[],
...
...
@@ -367,6 +367,8 @@ export class WeComBot extends Bot<BotConfig> {
break
;
case
'
image
'
:
case
'
video
'
:
case
'
file
'
:
case
'
voice
'
:
if
(
!
data
.
url
)
{
break
;
}
...
...
src/def/def.ts
View file @
c3b5aba8
...
...
@@ -52,6 +52,13 @@ export interface WecomPicBody extends WecomMediaBody {
PicUrl
:
string
;
}
export
interface
WecomLinkBody
extends
WecomEventBody
{
Title
:
string
;
Description
:
string
;
Url
:
string
;
PicUrl
:
string
;
}
export
interface
CardEventSelectedItems
{
SelectedItem
:
CardEventSelectedItem
|
CardEventSelectedItem
[];
}
...
...
src/utils.ts
View file @
c3b5aba8
...
...
@@ -3,6 +3,8 @@ import { WeComBot } from './bot';
import
{
WecomChatBody
,
WecomEventResponse
,
WecomLinkBody
,
WecomLocationBody
,
WecomPicBody
,
WecomResponse
,
WeComUser
,
...
...
@@ -52,12 +54,8 @@ export function adaptSession(bot: WeComBot, input: WecomEventResponse) {
if
(
body
.
MsgType
===
'
event
'
)
{
session
.
type
=
'
wecom/event
'
;
session
.
subtype
=
body
.
Event
;
}
else
if
(
body
.
MsgType
===
'
text
'
||
body
.
MsgType
===
'
image
'
)
{
session
.
type
=
'
message
'
;
session
.
subtype
=
'
private
'
;
session
.
author
=
{
userId
:
session
.
userId
,
};
}
else
{
let
isKnownMessage
=
true
;
switch
(
body
.
MsgType
)
{
case
'
text
'
:
const
textBody
=
body
as
WecomChatBody
;
...
...
@@ -69,10 +67,22 @@ export function adaptSession(bot: WeComBot, input: WecomEventResponse) {
url
:
imageBody
.
PicUrl
,
});
break
;
case
'
link
'
:
const
linkBody
=
body
as
WecomLinkBody
;
session
.
content
=
linkBody
.
Url
;
default
:
isKnownMessage
=
false
;
}
if
(
isKnownMessage
)
{
session
.
type
=
'
message
'
;
session
.
subtype
=
'
private
'
;
session
.
author
=
{
userId
:
session
.
userId
,
};
}
else
{
session
.
type
=
'
wecom/message
'
;
session
.
subtype
=
body
.
MsgType
;
}
}
else
{
session
.
type
=
'
wecom/message
'
;
session
.
subtype
=
body
.
MsgType
;
}
return
session
;
}
...
...
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