Skip to content

Commit 357c73a

Browse files
committed
feat(chat): use adapter-satori in the client
1 parent 29b759b commit 357c73a

File tree

4 files changed

+62
-18
lines changed

4 files changed

+62
-18
lines changed

packages/chat/client/index.ts

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
import { Context } from '@cordisjs/client'
2+
import HTTP from '@cordisjs/plugin-http'
3+
import Satori from '@satorijs/core'
4+
import SatoriAdapter from '@satorijs/adapter-satori'
25
import {} from '../src'
36
import Chat from './index.vue'
47
import './icons'
58

69
export default (ctx: Context) => {
7-
ctx.page({
8-
path: '/chat',
9-
name: '聊天',
10-
icon: 'activity:chat',
11-
order: 100,
12-
component: Chat,
13-
})
10+
ctx.plugin(HTTP)
11+
ctx.plugin(Satori)
12+
13+
ctx.inject(['satori'], (ctx) => {
14+
ctx.plugin(SatoriAdapter, {
15+
endpoint: new URL('/satori', location.href).href,
16+
})
1417

15-
ctx.menu('chat.message', [{
16-
id: '.delete',
17-
label: '删除消息',
18-
}, {
19-
id: '.quote',
20-
label: '引用回复',
21-
}])
18+
ctx.page({
19+
path: '/chat',
20+
name: '聊天',
21+
icon: 'activity:chat',
22+
order: 100,
23+
component: Chat,
24+
})
25+
26+
ctx.menu('chat.message', [{
27+
id: '.delete',
28+
label: '删除消息',
29+
}, {
30+
id: '.quote',
31+
label: '引用回复',
32+
}])
33+
})
2234
}

packages/chat/client/index.vue

+20-2
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,39 @@
1919
<div>{{ guild.id }}</div>
2020
</div>
2121
</div>
22-
</div>
22+
</el-scrollbar>
2323
</template>
2424
</k-layout>
2525
</template>
2626

2727
<script lang="ts" setup>
2828
2929
import { onMounted, ref, computed, watch, reactive } from 'vue'
30-
import { useRpc } from '@cordisjs/client'
30+
import { useContext, useRpc } from '@cordisjs/client'
3131
import type { Data } from '../src'
32+
import { Universal } from '@satorijs/core'
3233
3334
const data = useRpc<Data>()
35+
const ctx = useContext()
36+
37+
function short(name: string) {
38+
return name.slice(0, 2)
39+
}
40+
41+
function withProxy(url: string) {
42+
return (data.value.proxy ? data.value.proxy + '/' : '') + url
43+
}
44+
45+
async function onClickGuild(guild: Universal.Guild) {
46+
console.log(await ctx.get('satori')!.bots[0].getChannelList(guild.id))
47+
}
3448
3549
</script>
3650

3751
<style lang="scss" scoped>
3852
53+
.el-scrollbar :deep(.el-scrollbar__view) {
54+
padding: 1rem 0;
55+
}
56+
3957
</style>

packages/chat/package.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,25 @@
3333
"required": [
3434
"satori.database",
3535
"webui"
36+
],
37+
"optional": [
38+
"server.proxy"
3639
]
3740
}
3841
},
3942
"peerDependencies": {
40-
"@cordisjs/plugin-webui": "^0.1.1",
43+
"@cordisjs/plugin-webui": "^0.1.3",
4144
"@satorijs/core": "^4.0.0",
4245
"@satorijs/plugin-database": "^0.1.1"
4346
},
4447
"devDependencies": {
45-
"@cordisjs/client": "^0.1.1"
48+
"@cordisjs/client": "^0.1.3",
49+
"@cordisjs/plugin-http": "^0.4.2",
50+
"@cordisjs/plugin-server-proxy": "^0.2.0",
51+
"@cordisjs/plugin-webui": "^0.1.3",
52+
"@satorijs/adapter-satori": "^1.2.0",
53+
"@satorijs/core": "^4.0.0",
54+
"@satorijs/plugin-database": "^0.1.1"
4655
},
4756
"dependencies": {
4857
"cosmokit": "^1.6.2"

packages/chat/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { Context, Dict, mapValues, Schema, Universal } from '@satorijs/core'
22
import {} from '@cordisjs/plugin-webui'
3+
import {} from '@cordisjs/plugin-server-proxy'
34
import {} from '@satorijs/plugin-database'
45

56
export interface Data {
7+
proxy?: string
8+
logins: Universal.Login[]
69
guilds: Dict<Universal.Guild>
710
}
811

@@ -22,6 +25,8 @@ export function apply(ctx: Context) {
2225
import.meta.resolve('../dist/style.css'),
2326
],
2427
}, () => ({
28+
proxy: ctx.get('server.proxy')?.path,
29+
logins: ctx.bots.map(bot => bot.toJSON()),
2530
guilds: mapValues(ctx.satori.database._guilds, g => g.data),
2631
}))
2732

0 commit comments

Comments
 (0)