@evanp/activitypub-bot 0.13.4 → 0.13.9
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/lib/activitydeliverer.js +9 -0
- package/lib/activityhandler.js +8 -4
- package/lib/bots/ok.js +18 -1
- package/lib/keystorage.js +5 -4
- package/lib/routes/inbox.js +2 -0
- package/lib/routes/sharedinbox.js +2 -0
- package/package.json +1 -1
package/lib/activitydeliverer.js
CHANGED
|
@@ -65,15 +65,21 @@ export class ActivityDeliverer {
|
|
|
65
65
|
const recipients = this.getRecipients(activity)
|
|
66
66
|
|
|
67
67
|
for (const recipient of recipients) {
|
|
68
|
+
this.#logger.debug(`Checking recipient ${recipient.id}`)
|
|
68
69
|
if (this.#isPublic(recipient)) {
|
|
70
|
+
this.#logger.debug(`Public recipient for ${activity.id}`)
|
|
69
71
|
await this.#deliverPublic(activity, bots)
|
|
70
72
|
} else if (this.#isLocal(recipient)) {
|
|
73
|
+
this.#logger.debug(`Local recipient for ${activity.id}`)
|
|
71
74
|
const parts = this.#formatter.unformat(recipient.id)
|
|
72
75
|
if (this.#isLocalActor(parts)) {
|
|
76
|
+
this.#logger.debug(`Local actor ${recipient.id} for ${activity.id}`)
|
|
73
77
|
await this.#deliverLocalActor(activity, recipient, bots, deliveredTo)
|
|
74
78
|
} else if (this.#isLocalFollowersCollection(parts)) {
|
|
79
|
+
this.#logger.debug(`Local followers for ${parts.username} for ${activity.id}`)
|
|
75
80
|
await this.#deliverLocalFollowersCollection(activity, parts.username, bots, deliveredTo)
|
|
76
81
|
} else if (this.#isLocalFollowingCollection(parts)) {
|
|
82
|
+
this.#logger.debug(`Local following for ${parts.username} for ${activity.id}`)
|
|
77
83
|
await this.#deliverLocalFollowingCollection(activity, parts.username, bots, deliveredTo)
|
|
78
84
|
} else {
|
|
79
85
|
this.#logger.warn(
|
|
@@ -86,10 +92,13 @@ export class ActivityDeliverer {
|
|
|
86
92
|
if (await this.#isRemoteActor(fullRecipient)) {
|
|
87
93
|
this.#logger.warn(`Skipping remote actor ${recipient.id}`)
|
|
88
94
|
} else if (await this.#isRemoteFollowersCollection(fullActor, fullRecipient)) {
|
|
95
|
+
this.#logger.debug(`Remote followers for ${fullActor.id} for ${activity.id}`)
|
|
89
96
|
await this.#deliverRemoteFollowersCollection(activity, fullRecipient, fullActor, deliveredTo, bots)
|
|
90
97
|
} else if (await this.#isRemoteFollowingCollection(fullActor, fullRecipient)) {
|
|
98
|
+
this.#logger.debug(`Remote following for ${fullActor.id} for ${activity.id}`)
|
|
91
99
|
await this.#deliverRemoteFollowingCollection(activity, fullRecipient, fullActor, deliveredTo, bots)
|
|
92
100
|
} else if (await this.#isRemoteCollection(fullRecipient)) {
|
|
101
|
+
this.#logger.debug(`Remote collection ${fullRecipient.id} for ${activity.id}`)
|
|
93
102
|
await this.#deliverRemoteCollection(activity, fullRecipient, deliveredTo, bots)
|
|
94
103
|
} else {
|
|
95
104
|
this.#logger.warn(`Unrecognized recipient: ${recipient.id}`)
|
package/lib/activityhandler.js
CHANGED
|
@@ -58,16 +58,16 @@ export class ActivityHandler {
|
|
|
58
58
|
const actor = this.#getActor(activity)
|
|
59
59
|
if (!actor) {
|
|
60
60
|
this.#logger.warn(
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
{ activity: activity.id },
|
|
62
|
+
'Create activity has no actor'
|
|
63
63
|
)
|
|
64
64
|
return
|
|
65
65
|
}
|
|
66
66
|
const object = this.#getObject(activity)
|
|
67
67
|
if (!object) {
|
|
68
68
|
this.#logger.warn(
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
{ activity: activity.id },
|
|
70
|
+
'Create activity has no object'
|
|
71
71
|
)
|
|
72
72
|
return
|
|
73
73
|
}
|
|
@@ -79,6 +79,10 @@ export class ActivityHandler {
|
|
|
79
79
|
await this.#handleCreateReplies(bot, activity, actor, object)
|
|
80
80
|
await this.#handleCreateThread(bot, activity, actor, object)
|
|
81
81
|
if (this.#isMention(bot, object)) {
|
|
82
|
+
this.#logger.debug(
|
|
83
|
+
{ username: bot.username, object: object.id },
|
|
84
|
+
'bot mentioned'
|
|
85
|
+
)
|
|
82
86
|
await bot.onMention(object, activity)
|
|
83
87
|
}
|
|
84
88
|
}
|
package/lib/bots/ok.js
CHANGED
|
@@ -10,13 +10,30 @@ export default class OKBot extends Bot {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async onMention (object, activity) {
|
|
13
|
+
this._context.logger.debug(
|
|
14
|
+
{ object: object.id, activity: activity.id },
|
|
15
|
+
'bot mentioned'
|
|
16
|
+
)
|
|
13
17
|
if (!await this.hasSeen(object)) {
|
|
18
|
+
this._context.logger.debug(
|
|
19
|
+
{ object: object.id },
|
|
20
|
+
'not previously seen'
|
|
21
|
+
)
|
|
14
22
|
const attributedTo =
|
|
15
23
|
object.attributedTo?.first.id ||
|
|
16
24
|
activity.actor?.first.id
|
|
25
|
+
this._context.logger.debug(
|
|
26
|
+
{ object: object.id, attributedTo: attributedTo },
|
|
27
|
+
'attributed to'
|
|
28
|
+
)
|
|
17
29
|
const wf = await this._context.toWebfinger(attributedTo)
|
|
18
|
-
this._context.logger.info({ object: object.id, attributedTo, wf }, 'received mention')
|
|
19
30
|
const content = (wf) ? `@${wf} OK` : 'OK'
|
|
31
|
+
this._context.logger.info({
|
|
32
|
+
object: object.id,
|
|
33
|
+
attributedTo,
|
|
34
|
+
wf,
|
|
35
|
+
content
|
|
36
|
+
}, 'sending reply')
|
|
20
37
|
const reply = await this._context.sendReply(content, object)
|
|
21
38
|
this._context.logger.info({
|
|
22
39
|
reply: reply.id,
|
package/lib/keystorage.js
CHANGED
|
@@ -36,11 +36,12 @@ export class KeyStorage {
|
|
|
36
36
|
async #getKeys (username) {
|
|
37
37
|
let privateKey
|
|
38
38
|
let publicKey
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
// system key uses username null but primary key can't be null
|
|
40
|
+
if (!username) {
|
|
41
|
+
username = ''
|
|
42
|
+
}
|
|
42
43
|
const [result] = await this.#connection.query(
|
|
43
|
-
|
|
44
|
+
'SELECT public_key, private_key FROM new_keys WHERE username = ?',
|
|
44
45
|
{ replacements: [username] }
|
|
45
46
|
)
|
|
46
47
|
if (result.length > 0) {
|
package/lib/routes/inbox.js
CHANGED
|
@@ -60,6 +60,8 @@ router.post('/user/:username/inbox', async (req, res, next) => {
|
|
|
60
60
|
return next(createHttpError(400, 'Activity already delivered'))
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
logger.info(`Activity ${activity.id} received at ${bot.username} inbox`)
|
|
64
|
+
|
|
63
65
|
await deliverer.deliverTo(activity, bot)
|
|
64
66
|
|
|
65
67
|
res.status(200)
|
|
@@ -44,6 +44,8 @@ router.post('/shared/inbox', async (req, res, next) => {
|
|
|
44
44
|
return next(createHttpError(403, `${subject} is not the actor ${actor.id}`))
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
logger.info(`Activity ${activity.id} received at shared inbox`)
|
|
48
|
+
|
|
47
49
|
await deliverer.deliverToAll(activity, bots)
|
|
48
50
|
|
|
49
51
|
res.status(200)
|