@@ -100,163 +100,140 @@ func (c *MisskeyHookPlugin) RegisterWebhook(basePath string, g *gin.RouterGroup)
100
100
return
101
101
}
102
102
103
- var payload WebhookPayload [NoteRelatedWebhookPayloadBody ]
103
+ var payload WebhookPayload [UserPayload ]
104
104
105
105
if err := ctx .BindJSON (& payload ); err != nil {
106
106
ctx .JSON (400 , gin.H {"error" : "Invalid JSON" })
107
107
return
108
108
}
109
109
110
- post := payload .Body
110
+ if payload .Body .Note != nil {
111
+ post := payload .Body .Note
111
112
112
- title := fmt .Sprintf ("[%s] [%s] %s" , payload .Type , src .Name , post .ID )
113
+ title := fmt .Sprintf ("[%s] [%s] %s" , payload .Type , src .Name , post .ID )
113
114
114
- var url string
115
- if payload .Server != "" {
116
- url = strings .TrimRight (payload .Server , "/" ) + "/notes/" + post .ID
117
- }
118
-
119
- var message bytes.Buffer
120
-
121
- message .WriteString (fmt .Sprintf ("User: %s (%s)\n \n " , escapeMarkdown (post .User .Name ), escapeMarkdown (post .User .Username )))
122
-
123
- if post .Cw != nil {
124
- message .WriteString (fmt .Sprintf ("CW: %s\n \n " , escapeMarkdown (* post .Cw )))
125
- } else if post .Text != nil {
126
- message .WriteString (escapeMarkdown (* post .Text ))
127
- } else {
128
- message .WriteString ("<missing content>" )
129
- }
130
-
131
- if post .Reply != nil {
132
- message .WriteString ("\n \n ---\n \n " )
133
-
134
- message .WriteString (fmt .Sprintf ("Parent: %s\n \n " , escapeMarkdown (post .Reply .User .Name )))
135
-
136
- if post .Reply .Cw != nil {
137
- message .WriteString (fmt .Sprintf ("CW: %s\n \n " , escapeMarkdown (* post .Reply .Cw )))
138
- } else if post .Reply .Text != nil {
139
- message .WriteString (escapeMarkdown (* post .Reply .Text ))
140
- } else {
141
- message .WriteString ("<missing content>" )
115
+ var url string
116
+ if payload .Server != "" {
117
+ url = strings .TrimRight (payload .Server , "/" ) + "/notes/" + post .ID
142
118
}
143
119
144
- message .WriteString ("\n \n ---\n \n " )
145
- }
146
-
147
- if post .Renote != nil {
148
- message .WriteString ("\n \n ---\n \n " )
120
+ var message bytes.Buffer
149
121
150
- message .WriteString (fmt .Sprintf ("Renote of : %s\n \n " , escapeMarkdown (post .Renote . User .Name )))
122
+ message .WriteString (fmt .Sprintf ("User : %s (%s) \n \n " , escapeMarkdown (post .User .Name ), escapeMarkdown ( post . User . Username )))
151
123
152
- if post .Renote . Cw != nil {
153
- message .WriteString (fmt .Sprintf ("CW: %s\n \n " , escapeMarkdown (* post .Renote . Cw )))
154
- } else if post .Renote . Text != nil {
155
- message .WriteString (escapeMarkdown (* post .Renote . Text ))
124
+ if post .Cw != nil {
125
+ message .WriteString (fmt .Sprintf ("CW: %s\n \n " , escapeMarkdown (* post .Cw )))
126
+ } else if post .Text != nil {
127
+ message .WriteString (escapeMarkdown (* post .Text ))
156
128
} else {
157
129
message .WriteString ("<missing content>" )
158
130
}
159
131
160
- message . WriteString ( " \n \n --- \n \n " )
161
- }
132
+ if post . Reply != nil {
133
+ message . WriteString ( " \n \n --- \n \n " )
162
134
163
- msg := plugin.Message {
164
- Title : title ,
165
- Message : message .String (),
166
- Priority : 0 ,
167
- Extras : map [string ]interface {}{
168
- "misskey::payload" : map [string ]interface {}{
169
- "note" : post ,
170
- },
171
- "client::display" : map [string ]interface {}{
172
- "contentType" : "text/markdown" ,
173
- },
174
- },
175
- }
176
-
177
- if url != "" {
178
- msg .Extras ["client::notification" ] = map [string ]interface {}{
179
- "click" : map [string ]interface {}{
180
- "url" : url ,
181
- },
182
- }
183
- }
135
+ message .WriteString (fmt .Sprintf ("Parent: %s\n \n " , escapeMarkdown (post .Reply .User .Name )))
184
136
185
- if err := c .msgHandler .SendMessage (msg ); err != nil {
186
- ctx .JSON (500 , gin.H {"error" : "Failed to send message" })
187
- return
188
- }
189
- })
190
-
191
- g .HEAD ("/push/misskey/:slug/follow" , func (ctx * gin.Context ) {
192
- ctx .SetAccepted ("application/json" )
193
- ctx .Status (200 )
194
- })
195
-
196
- g .GET ("/push/misskey/:slug/follow" , func (ctx * gin.Context ) {
197
- ctx .JSON (405 , gin.H {"error" : "Method Not Allowed" })
198
- })
137
+ if post .Reply .Cw != nil {
138
+ message .WriteString (fmt .Sprintf ("CW: %s\n \n " , escapeMarkdown (* post .Reply .Cw )))
139
+ } else if post .Reply .Text != nil {
140
+ message .WriteString (escapeMarkdown (* post .Reply .Text ))
141
+ } else {
142
+ message .WriteString ("<missing content>" )
143
+ }
199
144
200
- g .POST ("/push/misskey/:slug/follow" , func (ctx * gin.Context ) {
201
-
202
- secret := ctx .GetHeader ("X-Misskey-Hook-Secret" )
145
+ message .WriteString ("\n \n ---\n \n " )
146
+ }
203
147
204
- if secret == "" {
205
- ctx .JSON (400 , gin.H {"error" : "Missing secret" })
206
- return
207
- }
148
+ if post .Renote != nil {
149
+ message .WriteString ("\n \n ---\n \n " )
208
150
209
- src := c . config . GetSource ( ctx . Param ( "slug" ))
151
+ message . WriteString ( fmt . Sprintf ( "Renote of: %s \n \n " , escapeMarkdown ( post . Renote . User . Name ) ))
210
152
211
- if src == nil || src .Secret == DummySecret || src .Secret != secret {
212
- ctx .JSON (404 , gin.H {"error" : "Source not found or secret mismatch" })
213
- return
214
- }
153
+ if post .Renote .Cw != nil {
154
+ message .WriteString (fmt .Sprintf ("CW: %s\n \n " , escapeMarkdown (* post .Renote .Cw )))
155
+ } else if post .Renote .Text != nil {
156
+ message .WriteString (escapeMarkdown (* post .Renote .Text ))
157
+ } else {
158
+ message .WriteString ("<missing content>" )
159
+ }
215
160
216
- var payload WebhookPayload [WebhookUser ]
161
+ message .WriteString ("\n \n ---\n \n " )
162
+ }
217
163
218
- if err := ctx .BindJSON (& payload ); err != nil {
219
- ctx .JSON (400 , gin.H {"error" : "Invalid JSON" })
220
- return
221
- }
164
+ msg := plugin.Message {
165
+ Title : title ,
166
+ Message : message .String (),
167
+ Priority : 0 ,
168
+ Extras : map [string ]interface {}{
169
+ "misskey::payload" : map [string ]interface {}{
170
+ "note" : post ,
171
+ },
172
+ "client::display" : map [string ]interface {}{
173
+ "contentType" : "text/markdown" ,
174
+ },
175
+ },
176
+ }
222
177
223
- user := payload .Body
178
+ if url != "" {
179
+ msg .Extras ["client::notification" ] = map [string ]interface {}{
180
+ "click" : map [string ]interface {}{
181
+ "url" : url ,
182
+ },
183
+ }
184
+ }
224
185
225
- title := fmt .Sprintf ("[%s] [%s] %s" , payload .Type , src .Name , user .Name )
186
+ if err := c .msgHandler .SendMessage (msg ); err != nil {
187
+ ctx .JSON (500 , gin.H {"error" : "Failed to send message" })
188
+ return
189
+ }
190
+ } else if payload .Body .User != nil {
191
+ user := payload .Body .User
226
192
227
- var url string
228
- if payload .Server != "" {
229
- url = strings .TrimRight (payload .Server , "/" ) + "/users/" + user .ID
230
- }
193
+ title := fmt .Sprintf ("[%s] [%s] %s" , payload .Type , src .Name , user .UserNameFull ())
231
194
232
- var message bytes. Buffer
195
+ var url string
233
196
234
- message .WriteString (fmt .Sprintf ("User: %s (%s)\n \n " , escapeMarkdown (user .Name ), escapeMarkdown (user .Username )))
197
+ if payload .Server != "" {
198
+ url = strings .TrimRight (payload .Server , "/" ) + "/" + user .UserNameFull ()
199
+ }
235
200
236
- msg := plugin.Message {
237
- Title : title ,
238
- Message : message .String (),
239
- Priority : 0 ,
240
- Extras : map [string ]interface {}{
241
- "misskey::payload" : map [string ]interface {}{
242
- "user" : user ,
243
- },
244
- "client::display" : map [string ]interface {}{
245
- "contentType" : "text/markdown" ,
201
+ var message bytes.Buffer
202
+
203
+ message .WriteString (fmt .Sprintf ("User: %s (%s)\n \n " , escapeMarkdown (user .Name ), escapeMarkdown (user .Username )))
204
+
205
+ message .WriteString (fmt .Sprintf ("Followers: %d\n " , user .FollowersCount ))
206
+ message .WriteString (fmt .Sprintf ("Following: %d\n " , user .FollowingCount ))
207
+ message .WriteString (fmt .Sprintf ("Notes: %d\n " , user .NotesCount ))
208
+
209
+ msg := plugin.Message {
210
+ Title : title ,
211
+ Message : message .String (),
212
+ Priority : 0 ,
213
+ Extras : map [string ]interface {}{
214
+ "misskey::payload" : map [string ]interface {}{
215
+ "user" : user ,
216
+ },
217
+ "client::display" : map [string ]interface {}{
218
+ "contentType" : "text/markdown" ,
219
+ },
246
220
},
247
- },
248
- }
221
+ }
249
222
250
- if url != "" {
251
- msg .Extras ["client::notification" ] = map [string ]interface {}{
252
- "click" : map [string ]interface {}{
253
- "url" : url ,
254
- },
223
+ if url != "" {
224
+ msg .Extras ["client::notification" ] = map [string ]interface {}{
225
+ "click" : map [string ]interface {}{
226
+ "url" : url ,
227
+ },
228
+ }
255
229
}
256
- }
257
230
258
- if err := c .msgHandler .SendMessage (msg ); err != nil {
259
- ctx .JSON (500 , gin.H {"error" : "Failed to send message" })
231
+ if err := c .msgHandler .SendMessage (msg ); err != nil {
232
+ ctx .JSON (500 , gin.H {"error" : "Failed to send message" })
233
+ return
234
+ }
235
+ } else {
236
+ ctx .JSON (400 , gin.H {"error" : "Invalid payload, unknown body" })
260
237
return
261
238
}
262
239
})
@@ -356,7 +333,7 @@ Enabled: {{ .State.Enabled }}
356
333
### **{{ .Name }}** ({{ .Slug }})
357
334
358
335
- Secret: {{ .Secret }}
359
- - URL: [{{ .URL }}]({{ .URL }}) (Append /abuse to receive abuse reports, /follow to receive user follow events )
336
+ - URL: [{{ .URL }}]({{ .URL }}) (Append /abuse to receive abuse reports)
360
337
361
338
{{ end }}
362
339
` )))
0 commit comments