@evanp/activitypub-bot 0.13.7 → 0.13.10

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.
@@ -58,16 +58,16 @@ export class ActivityHandler {
58
58
  const actor = this.#getActor(activity)
59
59
  if (!actor) {
60
60
  this.#logger.warn(
61
- 'Create activity has no actor',
62
- { activity: activity.id }
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
- 'Create activity has no object',
70
- { activity: activity.id }
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
@@ -50,7 +50,8 @@ export class KeyStorage {
50
50
  'found key for bot in database')
51
51
  publicKey = result[0].public_key
52
52
  privateKey = result[0].private_key
53
- } else {
53
+ }
54
+ if (!publicKey || !privateKey) {
54
55
  this.#logger.debug(
55
56
  { username, method: 'KeyStorage.#getKeys' },
56
57
  'no key for bot, generating new key'
@@ -62,11 +63,13 @@ export class KeyStorage {
62
63
  )
63
64
  await this.#saveKeyPair(username, publicKey, privateKey)
64
65
  }
66
+ const publicKeyHash = publicKey ? this.#hasher.humanize(publicKey) : null
67
+ const privateKeyHash = privateKey ? this.#hasher.humanize(privateKey) : null
65
68
  this.#logger.debug({
66
69
  username,
67
70
  method: 'KeyStorage.#getKeys',
68
- publicKeyHash: this.#hasher.humanize(publicKey),
69
- privateKeyHash: this.#hasher.humanize(privateKey)
71
+ publicKeyHash,
72
+ privateKeyHash
70
73
  })
71
74
  return [publicKey, privateKey]
72
75
  }
@@ -91,7 +94,11 @@ export class KeyStorage {
91
94
 
92
95
  async #saveKeyPair (username, publicKey, privateKey) {
93
96
  await this.#connection.query(`
94
- INSERT INTO new_keys (username, public_key, private_key) VALUES (?, ?, ?)
97
+ INSERT INTO new_keys (username, public_key, private_key)
98
+ VALUES (?, ?, ?)
99
+ ON CONFLICT(username) DO UPDATE SET
100
+ public_key = excluded.public_key,
101
+ private_key = excluded.private_key
95
102
  `, { replacements: [username, publicKey, privateKey] })
96
103
  }
97
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.13.7",
3
+ "version": "0.13.10",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",