opencode-discord 1.1.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +23 -46
- package/package.json +2 -2
package/index.ts
CHANGED
|
@@ -1,37 +1,21 @@
|
|
|
1
1
|
import type { Plugin } from "@opencode-ai/plugin"
|
|
2
|
-
import
|
|
2
|
+
import RPC from "@theuntraceable/discord-rpc"
|
|
3
3
|
|
|
4
|
-
const CLIENT_ID = process.env.DISCORD_CLIENT_ID ?? "
|
|
4
|
+
const CLIENT_ID = process.env.DISCORD_CLIENT_ID ?? "1369345745815339008"
|
|
5
5
|
|
|
6
|
-
export const DiscordStatus: Plugin = async ({
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
await sdk.app.log({
|
|
10
|
-
service: "opencode-discord",
|
|
11
|
-
level,
|
|
12
|
-
message,
|
|
13
|
-
extra,
|
|
14
|
-
})
|
|
15
|
-
} catch (e) {
|
|
16
|
-
console.error(`[opencode-discord] ${message}`, extra ?? "", e)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
await log("info", "Plugin initializing", { clientId: CLIENT_ID, project: project?.name })
|
|
21
|
-
|
|
22
|
-
const rpc = new Client({ clientId: CLIENT_ID })
|
|
6
|
+
export const DiscordStatus: Plugin = async ({ project }) => {
|
|
7
|
+
const client = new RPC.Client({ transport: "ipc" })
|
|
23
8
|
let connected = false
|
|
24
9
|
let sessionActive = false
|
|
25
10
|
let currentProject = project?.name ?? ""
|
|
26
11
|
let startTimestamp = Date.now()
|
|
27
12
|
let lastEditedFile: string | undefined
|
|
28
13
|
|
|
14
|
+
console.log(`[opencode-discord] init clientId=${CLIENT_ID} project=${currentProject}`)
|
|
15
|
+
|
|
29
16
|
async function updatePresence() {
|
|
30
|
-
|
|
31
|
-
if (!connected)
|
|
32
|
-
await log("warn", "Skipping presence update - not connected to Discord")
|
|
33
|
-
return
|
|
34
|
-
}
|
|
17
|
+
console.log(`[opencode-discord] updatePresence connected=${connected} session=${sessionActive}`)
|
|
18
|
+
if (!connected) return
|
|
35
19
|
|
|
36
20
|
const details = sessionActive
|
|
37
21
|
? currentProject
|
|
@@ -46,7 +30,7 @@ export const DiscordStatus: Plugin = async ({ client: sdk, project }) => {
|
|
|
46
30
|
: "Idle"
|
|
47
31
|
|
|
48
32
|
try {
|
|
49
|
-
await
|
|
33
|
+
await client.user?.setActivity({
|
|
50
34
|
details,
|
|
51
35
|
state,
|
|
52
36
|
startTimestamp,
|
|
@@ -55,67 +39,63 @@ export const DiscordStatus: Plugin = async ({ client: sdk, project }) => {
|
|
|
55
39
|
smallImageKey: sessionActive ? "ai" : "idle",
|
|
56
40
|
smallImageText: sessionActive ? "AI Active" : "Idle",
|
|
57
41
|
})
|
|
58
|
-
|
|
42
|
+
console.log(`[opencode-discord] presence set: ${details} / ${state}`)
|
|
59
43
|
} catch (e) {
|
|
60
|
-
|
|
44
|
+
console.error(`[opencode-discord] presence failed:`, e)
|
|
61
45
|
}
|
|
62
46
|
}
|
|
63
47
|
|
|
64
|
-
|
|
48
|
+
client.on("ready", () => {
|
|
65
49
|
connected = true
|
|
66
50
|
startTimestamp = Date.now()
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
console.log(`[opencode-discord] discord connected as ${client.user?.username}`)
|
|
52
|
+
updatePresence()
|
|
69
53
|
})
|
|
70
54
|
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
client.on("error", (err: any) => {
|
|
56
|
+
console.error(`[opencode-discord] discord error:`, err)
|
|
73
57
|
})
|
|
74
58
|
|
|
75
|
-
|
|
59
|
+
client.on("disconnected", () => {
|
|
76
60
|
connected = false
|
|
77
|
-
|
|
61
|
+
console.log(`[opencode-discord] discord disconnected`)
|
|
78
62
|
})
|
|
79
63
|
|
|
80
64
|
try {
|
|
81
|
-
|
|
82
|
-
await
|
|
83
|
-
|
|
65
|
+
console.log(`[opencode-discord] logging in...`)
|
|
66
|
+
await client.login({ clientId: CLIENT_ID })
|
|
67
|
+
console.log(`[opencode-discord] login ok`)
|
|
84
68
|
} catch (e) {
|
|
85
69
|
connected = false
|
|
86
|
-
|
|
70
|
+
console.error(`[opencode-discord] login failed:`, e)
|
|
87
71
|
}
|
|
88
72
|
|
|
89
73
|
return {
|
|
90
74
|
event: async ({ event }) => {
|
|
91
|
-
|
|
75
|
+
console.log(`[opencode-discord] event: ${event.type}`)
|
|
92
76
|
|
|
93
77
|
switch (event.type) {
|
|
94
78
|
case "session.created":
|
|
95
79
|
sessionActive = true
|
|
96
80
|
startTimestamp = Date.now()
|
|
97
81
|
lastEditedFile = undefined
|
|
98
|
-
await log("info", "Session created")
|
|
99
82
|
break
|
|
100
83
|
|
|
101
84
|
case "session.idle":
|
|
102
85
|
case "session.error":
|
|
103
86
|
sessionActive = false
|
|
104
87
|
lastEditedFile = undefined
|
|
105
|
-
await log("info", `Session ${event.type}`)
|
|
106
88
|
break
|
|
107
89
|
|
|
108
90
|
case "session.deleted":
|
|
109
91
|
sessionActive = false
|
|
110
92
|
lastEditedFile = undefined
|
|
111
|
-
await log("info", "Session deleted")
|
|
112
93
|
break
|
|
113
94
|
|
|
114
95
|
case "file.edited":
|
|
115
96
|
lastEditedFile =
|
|
116
97
|
(event as any).file?.split("/").pop() ??
|
|
117
98
|
(event as any).file
|
|
118
|
-
await log("info", "File edited", { file: lastEditedFile })
|
|
119
99
|
break
|
|
120
100
|
}
|
|
121
101
|
|
|
@@ -123,13 +103,10 @@ export const DiscordStatus: Plugin = async ({ client: sdk, project }) => {
|
|
|
123
103
|
},
|
|
124
104
|
|
|
125
105
|
"tool.execute.after": async (input) => {
|
|
126
|
-
await log("debug", `Tool executed: ${input.tool}`, { args: input.args })
|
|
127
|
-
|
|
128
106
|
if (input.tool === "edit" || input.tool === "write") {
|
|
129
107
|
const path = input.args?.filePath as string | undefined
|
|
130
108
|
if (path) {
|
|
131
109
|
lastEditedFile = path.split("/").pop() ?? path
|
|
132
|
-
await log("info", "File tool detected", { file: lastEditedFile })
|
|
133
110
|
}
|
|
134
111
|
await updatePresence()
|
|
135
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-discord",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Discord Rich Presence plugin for OpenCode — shows your AI coding activity in Discord",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/TheUntraceable/opencode-discord-status#readme",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@theuntraceable/discord-rpc": "^
|
|
28
|
+
"@theuntraceable/discord-rpc": "^4.0.8"
|
|
29
29
|
}
|
|
30
30
|
}
|