@evanp/activitypub-bot 0.44.2 → 0.45.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/CHANGELOG.md +33 -0
- package/README.md +37 -1
- package/lib/app.js +4 -2
- package/lib/botcontext.js +36 -1
- package/lib/bots/litepubrelayclient.js +21 -0
- package/lib/bots/logging.js +103 -0
- package/lib/bots/mastodonrelayclient.js +90 -30
- package/lib/index.js +1 -0
- package/package.json +1 -1
- package/.eslintrc +0 -7
- package/.markdownlint.json +0 -4
- package/CODE_OF_CONDUCT.md +0 -129
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,39 @@ and this project adheres to
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [0.45.1] - 2026-04-23
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- LitePubRelayClientBot test was not clearing
|
|
17
|
+
queued jobs
|
|
18
|
+
|
|
19
|
+
## [0.45.0] - 2026-04-23
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- LoggingBot class for debugging installations
|
|
24
|
+
- addFollowingUnsafe(), removeFollowingUnsafe(), fanoutPublic()
|
|
25
|
+
methods of BotContext
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- MastodonRelayClientBot can take an array of relay ids as
|
|
30
|
+
`relay` option or one as a string
|
|
31
|
+
- MastodonRelayClientBot ignores `unsubscribe`, syncs relay
|
|
32
|
+
array instead
|
|
33
|
+
- MastodonRelayClientBot adds relay server to `following`
|
|
34
|
+
- MastodonRelayClientBot and LitePubRelayClientBot fan out
|
|
35
|
+
relay server `Announce` activities to all other bots
|
|
36
|
+
- BotContext constructor takes `bots` argument
|
|
37
|
+
|
|
38
|
+
## [0.44.3] - 2026-04-23
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
|
|
42
|
+
- MastodonRelayClientBot has type 'Application' to work
|
|
43
|
+
with relay servers like Pleroma-Relay that require it
|
|
44
|
+
|
|
12
45
|
## [0.44.2] - 2026-04-23
|
|
13
46
|
|
|
14
47
|
### Fixed
|
package/README.md
CHANGED
|
@@ -204,6 +204,13 @@ An *OKBot* instance will reply to any message that it's mentioned in with the co
|
|
|
204
204
|
|
|
205
205
|
A *DoNothingBot* instance will only do default stuff, like accepting follows.
|
|
206
206
|
|
|
207
|
+
#### LoggingBot
|
|
208
|
+
|
|
209
|
+
A *LoggingBot* behaves like `DoNothingBot` but logs each `Bot` interface
|
|
210
|
+
callback it receives (`onPublic`, `onFollow`, `onMention`, etc.) at `debug`
|
|
211
|
+
level. Useful as a smoke-test bot to confirm that activities are being
|
|
212
|
+
delivered to local bots; silent in production unless log level is lowered.
|
|
213
|
+
|
|
207
214
|
#### FollowBackBot
|
|
208
215
|
|
|
209
216
|
A *FollowBackBot* will follow back anyone who follows it. Useful for collecting
|
|
@@ -211,7 +218,15 @@ public information.
|
|
|
211
218
|
|
|
212
219
|
#### MastodonRelayClientBot
|
|
213
220
|
|
|
214
|
-
A *MastodonRelayClientBot* can be the client of
|
|
221
|
+
A *MastodonRelayClientBot* can be the client of one or more Mastodon-style
|
|
222
|
+
relays. Its `relay` option accepts either a single actor URL as a string or
|
|
223
|
+
an array of actor URLs; the bot sends a Mastodon-style `Follow`
|
|
224
|
+
(`object: https://www.w3.org/ns/activitystreams#Public`) to each on
|
|
225
|
+
initialize. To unsubscribe from a relay, remove it from the array and
|
|
226
|
+
re-initialize — the bot diffs the new config against the current `following`
|
|
227
|
+
collection and sends an `Undo`/`Follow` for each removed relay. It also
|
|
228
|
+
advertises `Application` actor type, which Mastodon-style relay software
|
|
229
|
+
(e.g. Pleroma-Relay) requires from subscribers.
|
|
215
230
|
|
|
216
231
|
#### MastodonRelayServerBot
|
|
217
232
|
|
|
@@ -475,6 +490,27 @@ Async generator that yields each actor in this bot's `following` collection, one
|
|
|
475
490
|
|
|
476
491
|
Returns `true` if `url` is served by this activitypub-bot instance (i.e. its origin matches the configured `--origin`). Synchronous.
|
|
477
492
|
|
|
493
|
+
#### async addFollowingUnsafe (actor)
|
|
494
|
+
|
|
495
|
+
Forcibly adds `actor` to this bot's `following` collection without sending
|
|
496
|
+
a `Follow` or waiting for an `Accept`. Intended for bots (like relay
|
|
497
|
+
clients) whose followship is established through a protocol exchange that
|
|
498
|
+
sits outside the usual Follow/Accept flow. Trust that the caller knows
|
|
499
|
+
what they're doing.
|
|
500
|
+
|
|
501
|
+
#### async removeFollowingUnsafe (actor)
|
|
502
|
+
|
|
503
|
+
Forcibly removes `actor` from this bot's `following` collection without
|
|
504
|
+
sending an `Undo`/`Follow`. The protocol-level cleanup is the caller's
|
|
505
|
+
responsibility. Pair with `addFollowingUnsafe()` for symmetry.
|
|
506
|
+
|
|
507
|
+
#### async fanoutPublic (activity)
|
|
508
|
+
|
|
509
|
+
Invokes `onPublic(activity)` on every bot registered on the server, so one
|
|
510
|
+
bot can forward a public activity it received through a side-channel
|
|
511
|
+
(e.g. a relay-forwarded `Announce`) to all local bots. Errors in any
|
|
512
|
+
individual bot's `onPublic` are logged and do not interrupt the fanout.
|
|
513
|
+
|
|
478
514
|
#### async onIdle ()
|
|
479
515
|
|
|
480
516
|
Resolves when the background distribution queue has drained. Intended for test code that needs to wait for outbound activities to finish being delivered before asserting on their effects.
|
package/lib/app.js
CHANGED
|
@@ -143,7 +143,8 @@ export async function makeApp ({ databaseUrl, origin, bots, logLevel = 'silent',
|
|
|
143
143
|
distributor,
|
|
144
144
|
formatter,
|
|
145
145
|
transformer,
|
|
146
|
-
logger
|
|
146
|
+
logger,
|
|
147
|
+
bots
|
|
147
148
|
)
|
|
148
149
|
))
|
|
149
150
|
)
|
|
@@ -164,7 +165,8 @@ export async function makeApp ({ databaseUrl, origin, bots, logLevel = 'silent',
|
|
|
164
165
|
distributor,
|
|
165
166
|
formatter,
|
|
166
167
|
transformer,
|
|
167
|
-
logger
|
|
168
|
+
logger,
|
|
169
|
+
bots
|
|
168
170
|
))
|
|
169
171
|
|
|
170
172
|
const { workers: deliveryWorkers, runs: deliveryWorkerRuns } = createWorkers(logger, deliveryWorkerCount, DeliveryWorker, jobQueue, logger, { actorStorage, activityHandler, bots })
|
package/lib/botcontext.js
CHANGED
|
@@ -25,6 +25,8 @@ export class BotContext {
|
|
|
25
25
|
#formatter = null
|
|
26
26
|
#transformer = null
|
|
27
27
|
#logger = null
|
|
28
|
+
#bots
|
|
29
|
+
|
|
28
30
|
get botId () {
|
|
29
31
|
return this.#botId
|
|
30
32
|
}
|
|
@@ -42,7 +44,8 @@ export class BotContext {
|
|
|
42
44
|
distributor,
|
|
43
45
|
formatter,
|
|
44
46
|
transformer,
|
|
45
|
-
logger
|
|
47
|
+
logger,
|
|
48
|
+
bots
|
|
46
49
|
) {
|
|
47
50
|
this.#botId = botId
|
|
48
51
|
this.#botDataStorage = botDataStorage
|
|
@@ -52,6 +55,7 @@ export class BotContext {
|
|
|
52
55
|
this.#distributor = distributor
|
|
53
56
|
this.#formatter = formatter
|
|
54
57
|
this.#transformer = transformer
|
|
58
|
+
this.#bots = bots
|
|
55
59
|
this.#logger = logger.child({ class: 'BotContext', botId })
|
|
56
60
|
}
|
|
57
61
|
|
|
@@ -481,6 +485,37 @@ export class BotContext {
|
|
|
481
485
|
yield * this.#actorStorage.items(this.#botId, 'following')
|
|
482
486
|
}
|
|
483
487
|
|
|
488
|
+
async addFollowingUnsafe (actor) {
|
|
489
|
+
assert.ok(actor)
|
|
490
|
+
assert.equal(typeof actor, 'object')
|
|
491
|
+
await this.#actorStorage.addToCollection(this.#botId, 'following', actor)
|
|
492
|
+
this.#logger.debug({ actor: actor.id }, 'unsafe add to following')
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
async removeFollowingUnsafe (actor) {
|
|
496
|
+
assert.ok(actor)
|
|
497
|
+
assert.equal(typeof actor, 'object')
|
|
498
|
+
await this.#actorStorage.removeFromCollection(this.#botId, 'following', actor)
|
|
499
|
+
this.#logger.debug({ actor: actor.id }, 'unsafe remove from following')
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
async fanoutPublic (activity) {
|
|
503
|
+
assert.ok(activity)
|
|
504
|
+
assert.equal(typeof activity, 'object')
|
|
505
|
+
await Promise.all(Object.values(this.#bots).map(async (bot) => {
|
|
506
|
+
let result
|
|
507
|
+
try {
|
|
508
|
+
result = await bot.onPublic(activity)
|
|
509
|
+
} catch (err) {
|
|
510
|
+
this.#logger.warn(
|
|
511
|
+
{ err, activity: activity.id, bot: bot.id },
|
|
512
|
+
'Error handling public activity for bot'
|
|
513
|
+
)
|
|
514
|
+
}
|
|
515
|
+
return result
|
|
516
|
+
}))
|
|
517
|
+
}
|
|
518
|
+
|
|
484
519
|
async #isInCollection (name, obj) {
|
|
485
520
|
assert.ok(name)
|
|
486
521
|
assert.equal(typeof name, 'string')
|
|
@@ -4,6 +4,7 @@ import Bot from '../bot.js'
|
|
|
4
4
|
|
|
5
5
|
const NS = 'https://www.w3.org/ns/activitystreams#'
|
|
6
6
|
const CREATE = `${NS}Create`
|
|
7
|
+
const ANNOUNCE = `${NS}Announce`
|
|
7
8
|
|
|
8
9
|
const DEFAULT_NAME = 'LitePubRelayClientBot'
|
|
9
10
|
const DEFAULT_DESCRIPTION = 'A LitePub relay client'
|
|
@@ -75,6 +76,26 @@ export default class LitePubRelayClientBot extends Bot {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
async handleActivity (activity) {
|
|
80
|
+
if (activity.type === ANNOUNCE) {
|
|
81
|
+
return await this.#handleAnnounce(activity)
|
|
82
|
+
} else {
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async #handleAnnounce (activity) {
|
|
88
|
+
if (this.#relay.includes(activity.actor?.first?.id)) {
|
|
89
|
+
this._context.logger.debug(
|
|
90
|
+
{ activity: activity.id },
|
|
91
|
+
'fanning out relay announce activity'
|
|
92
|
+
)
|
|
93
|
+
await this._context.fanoutPublic(activity)
|
|
94
|
+
return true
|
|
95
|
+
}
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
|
|
78
99
|
async #hasAnyFollower () {
|
|
79
100
|
for await (const actor of this._context.followers()) {
|
|
80
101
|
if (this.#relay.includes(actor.id)) {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Bot from '../bot.js'
|
|
2
|
+
|
|
3
|
+
const DEFAULT_FULLNAME = 'Logging Bot'
|
|
4
|
+
const DEFAULT_DESCRIPTION = 'A bot that logs callback events.'
|
|
5
|
+
|
|
6
|
+
export default class LoggingBot extends Bot {
|
|
7
|
+
constructor (username, options = {}) {
|
|
8
|
+
super(username, {
|
|
9
|
+
fullname: DEFAULT_FULLNAME,
|
|
10
|
+
description: DEFAULT_DESCRIPTION,
|
|
11
|
+
...options
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async onMention (object, activity) {
|
|
16
|
+
this._context.logger.debug(
|
|
17
|
+
{
|
|
18
|
+
class: this.constructor.name,
|
|
19
|
+
object: await object.export(),
|
|
20
|
+
activity: await activity.export()
|
|
21
|
+
},
|
|
22
|
+
'onMention'
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async onFollow (actor, activity) {
|
|
27
|
+
this._context.logger.debug(
|
|
28
|
+
{
|
|
29
|
+
class: this.constructor.name,
|
|
30
|
+
actor: await actor.export(),
|
|
31
|
+
activity: await activity.export()
|
|
32
|
+
},
|
|
33
|
+
'onFollow'
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async onLike (object, activity) {
|
|
38
|
+
this._context.logger.debug(
|
|
39
|
+
{
|
|
40
|
+
class: this.constructor.name,
|
|
41
|
+
object: await object.export(),
|
|
42
|
+
activity: await activity.export()
|
|
43
|
+
},
|
|
44
|
+
'onLike'
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async onAnnounce (object, activity) {
|
|
49
|
+
this._context.logger.debug(
|
|
50
|
+
{
|
|
51
|
+
class: this.constructor.name,
|
|
52
|
+
object: await object.export(),
|
|
53
|
+
activity: await activity.export()
|
|
54
|
+
},
|
|
55
|
+
'onAnnounce'
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async onPublic (activity) {
|
|
60
|
+
this._context.logger.debug(
|
|
61
|
+
{
|
|
62
|
+
class: this.constructor.name,
|
|
63
|
+
activity: await activity.export()
|
|
64
|
+
},
|
|
65
|
+
'onPublic'
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async actorOK (actorId, activity) {
|
|
70
|
+
this._context.logger.debug(
|
|
71
|
+
{
|
|
72
|
+
class: this.constructor.name,
|
|
73
|
+
actorId,
|
|
74
|
+
activity: await activity.export()
|
|
75
|
+
},
|
|
76
|
+
'actorOK'
|
|
77
|
+
)
|
|
78
|
+
return false
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async handleActivity (activity) {
|
|
82
|
+
this._context.logger.debug(
|
|
83
|
+
{
|
|
84
|
+
class: this.constructor.name,
|
|
85
|
+
activity: await activity.export()
|
|
86
|
+
},
|
|
87
|
+
'handleActivity'
|
|
88
|
+
)
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async onUndoFollow (actor, undoActivity, followActivity) {
|
|
93
|
+
this._context.logger.debug(
|
|
94
|
+
{
|
|
95
|
+
class: this.constructor.name,
|
|
96
|
+
actor: await actor.export(),
|
|
97
|
+
undoActivity: await undoActivity.export(),
|
|
98
|
+
followActivity: await followActivity.export()
|
|
99
|
+
},
|
|
100
|
+
'onUndoFollow'
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -1,17 +1,38 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
|
|
1
3
|
import Bot from '../bot.js'
|
|
2
4
|
|
|
3
5
|
const NS = 'https://www.w3.org/ns/activitystreams#'
|
|
4
6
|
const ACCEPT = `${NS}Accept`
|
|
5
7
|
const REJECT = `${NS}Reject`
|
|
8
|
+
const ANNOUNCE = `${NS}Announce`
|
|
6
9
|
|
|
7
10
|
export default class MastodonRelayClientBot extends Bot {
|
|
8
11
|
#relay
|
|
9
|
-
#
|
|
12
|
+
#relayForwarding
|
|
10
13
|
|
|
11
14
|
constructor (username, options = {}) {
|
|
15
|
+
if (typeof username !== 'string') {
|
|
16
|
+
throw new Error('username must be a string')
|
|
17
|
+
}
|
|
18
|
+
if (typeof options !== 'object') {
|
|
19
|
+
throw new Error('options must be an object')
|
|
20
|
+
}
|
|
21
|
+
if (typeof options.relay !== 'string' &&
|
|
22
|
+
!Array.isArray(options.relay)) {
|
|
23
|
+
throw new Error('relay option must be a string or array')
|
|
24
|
+
}
|
|
12
25
|
super(username, options)
|
|
13
|
-
this.#relay = options.relay
|
|
14
|
-
|
|
26
|
+
this.#relay = Array.isArray(options.relay)
|
|
27
|
+
? options.relay
|
|
28
|
+
: [options.relay]
|
|
29
|
+
this.#relayForwarding = ('relayForwarding' in options)
|
|
30
|
+
? options.relayForwarding
|
|
31
|
+
: true
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get type () {
|
|
35
|
+
return 'Application'
|
|
15
36
|
}
|
|
16
37
|
|
|
17
38
|
get fullname () {
|
|
@@ -22,24 +43,29 @@ export default class MastodonRelayClientBot extends Bot {
|
|
|
22
43
|
return 'A bot for subscribing to relays'
|
|
23
44
|
}
|
|
24
45
|
|
|
25
|
-
get key () {
|
|
26
|
-
return `follow:${this.#relay}`
|
|
27
|
-
}
|
|
28
|
-
|
|
29
46
|
async initialize (context) {
|
|
30
|
-
super.initialize(context)
|
|
47
|
+
await super.initialize(context)
|
|
31
48
|
this._context.logger.info(
|
|
32
|
-
{ relay: this.#relay
|
|
49
|
+
{ relay: this.#relay },
|
|
33
50
|
'Initialising relay client'
|
|
34
51
|
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
52
|
+
|
|
53
|
+
assert.ok(Array.isArray(this.#relay))
|
|
54
|
+
|
|
55
|
+
const toFollow = new Set(this.#relay)
|
|
56
|
+
|
|
57
|
+
for await (const actor of this._context.following()) {
|
|
58
|
+
if (toFollow.has(actor.id)) {
|
|
59
|
+
toFollow.delete(actor.id)
|
|
60
|
+
} else {
|
|
61
|
+
await this.#unfollowRelay(actor)
|
|
38
62
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const id of toFollow) {
|
|
66
|
+
const actor = await this._context.getObject(id)
|
|
67
|
+
if (!await this.#hasFollowActivity(actor)) {
|
|
68
|
+
await this.#followRelay(actor)
|
|
43
69
|
}
|
|
44
70
|
}
|
|
45
71
|
}
|
|
@@ -52,40 +78,42 @@ export default class MastodonRelayClientBot extends Bot {
|
|
|
52
78
|
return await this.#handleAccept(activity)
|
|
53
79
|
} else if (activity.type === REJECT) {
|
|
54
80
|
return await this.#handleReject(activity)
|
|
81
|
+
} else if (activity.type === ANNOUNCE) {
|
|
82
|
+
return await this.#handleAnnounce(activity)
|
|
55
83
|
} else {
|
|
56
84
|
return false
|
|
57
85
|
}
|
|
58
86
|
}
|
|
59
87
|
|
|
60
88
|
async actorOK (actorId, activity) {
|
|
61
|
-
return
|
|
89
|
+
return this.#relay.includes(actorId)
|
|
62
90
|
}
|
|
63
91
|
|
|
64
|
-
async #followRelay () {
|
|
92
|
+
async #followRelay (actor) {
|
|
65
93
|
this._context.logger.info(
|
|
66
|
-
{ relay:
|
|
94
|
+
{ relay: actor.id },
|
|
67
95
|
'Following relay'
|
|
68
96
|
)
|
|
69
97
|
const activity = await this._context.doActivity({
|
|
70
|
-
to:
|
|
98
|
+
to: actor.id,
|
|
71
99
|
type: 'Follow',
|
|
72
100
|
object: 'https://www.w3.org/ns/activitystreams#Public'
|
|
73
101
|
})
|
|
74
102
|
this._context.logger.info(
|
|
75
|
-
{ relay:
|
|
103
|
+
{ relay: actor.id, activity: activity.id },
|
|
76
104
|
'Saving follow for later'
|
|
77
105
|
)
|
|
78
|
-
this
|
|
106
|
+
await this.#setFollowActivity(actor, activity)
|
|
79
107
|
}
|
|
80
108
|
|
|
81
|
-
async #unfollowRelay () {
|
|
82
|
-
const activityId = await this
|
|
109
|
+
async #unfollowRelay (actor) {
|
|
110
|
+
const activityId = await this.#getFollowActivity(actor)
|
|
83
111
|
this._context.logger.info(
|
|
84
|
-
{ relay:
|
|
112
|
+
{ relay: actor.id, activity: activityId },
|
|
85
113
|
'Unfollowing relay'
|
|
86
114
|
)
|
|
87
115
|
await this._context.doActivity({
|
|
88
|
-
to:
|
|
116
|
+
to: actor.id,
|
|
89
117
|
type: 'Undo',
|
|
90
118
|
object: {
|
|
91
119
|
id: activityId,
|
|
@@ -94,19 +122,22 @@ export default class MastodonRelayClientBot extends Bot {
|
|
|
94
122
|
}
|
|
95
123
|
})
|
|
96
124
|
this._context.logger.info(
|
|
97
|
-
{ relay:
|
|
125
|
+
{ relay: actor.id },
|
|
98
126
|
'Clearing follow data'
|
|
99
127
|
)
|
|
100
|
-
this._context.
|
|
128
|
+
await this._context.removeFollowingUnsafe(actor)
|
|
129
|
+
await this.#deleteFollowActivity(actor)
|
|
101
130
|
}
|
|
102
131
|
|
|
103
132
|
async #handleAccept (activity) {
|
|
104
|
-
const
|
|
133
|
+
const actor = activity.actor?.first
|
|
134
|
+
const activityId = await this.#getFollowActivity(actor)
|
|
105
135
|
if (activity.object?.first?.id === activityId) {
|
|
106
136
|
this._context.logger.info(
|
|
107
137
|
{ accept: activity.id, follow: activityId },
|
|
108
138
|
'Follow accepted'
|
|
109
139
|
)
|
|
140
|
+
await this._context.addFollowingUnsafe(activity.actor.first)
|
|
110
141
|
return true
|
|
111
142
|
} else {
|
|
112
143
|
return false
|
|
@@ -114,7 +145,8 @@ export default class MastodonRelayClientBot extends Bot {
|
|
|
114
145
|
}
|
|
115
146
|
|
|
116
147
|
async #handleReject (activity) {
|
|
117
|
-
const
|
|
148
|
+
const actor = activity.actor?.first
|
|
149
|
+
const activityId = await this.#getFollowActivity(actor)
|
|
118
150
|
if (activity.object?.first?.id === activityId) {
|
|
119
151
|
this._context.logger.info(
|
|
120
152
|
{ accept: activity.id, follow: activityId },
|
|
@@ -125,4 +157,32 @@ export default class MastodonRelayClientBot extends Bot {
|
|
|
125
157
|
return false
|
|
126
158
|
}
|
|
127
159
|
}
|
|
160
|
+
|
|
161
|
+
async #handleAnnounce (activity) {
|
|
162
|
+
if (this.#relay.includes(activity.actor?.first?.id)) {
|
|
163
|
+
await this._context.fanoutPublic(activity)
|
|
164
|
+
return true
|
|
165
|
+
}
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async #setFollowActivity (actor, activity) {
|
|
170
|
+
const key = `follow:${actor.id}`
|
|
171
|
+
return await this._context.setData(key, activity.id)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async #getFollowActivity (actor) {
|
|
175
|
+
const key = `follow:${actor.id}`
|
|
176
|
+
return await this._context.getData(key)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async #deleteFollowActivity (actor) {
|
|
180
|
+
const key = `follow:${actor.id}`
|
|
181
|
+
return await this._context.deleteData(key)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async #hasFollowActivity (actor) {
|
|
185
|
+
const key = `follow:${actor.id}`
|
|
186
|
+
return await this._context.hasData(key)
|
|
187
|
+
}
|
|
128
188
|
}
|
package/lib/index.js
CHANGED
|
@@ -8,3 +8,4 @@ export { default as MastodonRelayServerBot, default as RelayServerBot } from './
|
|
|
8
8
|
export { default as FollowBackBot } from './bots/followback.js'
|
|
9
9
|
export { default as LitePubRelayClientBot } from './bots/litepubrelayclient.js'
|
|
10
10
|
export { default as LitePubRelayServerBot } from './bots/litepubrelayserver.js'
|
|
11
|
+
export { default as LoggingBot } from './bots/logging.js'
|
package/package.json
CHANGED
package/.eslintrc
DELETED
package/.markdownlint.json
DELETED
package/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
-
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
-
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
-
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
-
and orientation.
|
|
11
|
-
|
|
12
|
-
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
-
diverse, inclusive, and healthy community.
|
|
14
|
-
|
|
15
|
-
## Our Standards
|
|
16
|
-
|
|
17
|
-
Examples of behavior that contributes to a positive environment for our
|
|
18
|
-
community include:
|
|
19
|
-
|
|
20
|
-
* Demonstrating empathy and kindness toward other people
|
|
21
|
-
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
-
* Giving and gracefully accepting constructive feedback
|
|
23
|
-
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
-
and learning from the experience
|
|
25
|
-
* Focusing on what is best not just for us as individuals, but for the
|
|
26
|
-
overall community
|
|
27
|
-
|
|
28
|
-
Examples of unacceptable behavior include:
|
|
29
|
-
|
|
30
|
-
* The use of sexualized language or imagery, and sexual attention or
|
|
31
|
-
advances of any kind
|
|
32
|
-
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
-
* Public or private harassment
|
|
34
|
-
* Publishing others' private information, such as a physical or email
|
|
35
|
-
address, without their explicit permission
|
|
36
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
-
professional setting
|
|
38
|
-
|
|
39
|
-
## Enforcement Responsibilities
|
|
40
|
-
|
|
41
|
-
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
-
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
-
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
-
or harmful.
|
|
45
|
-
|
|
46
|
-
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
-
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
-
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
-
decisions when appropriate.
|
|
50
|
-
|
|
51
|
-
## Scope
|
|
52
|
-
|
|
53
|
-
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
-
an individual is officially representing the community in public spaces.
|
|
55
|
-
Examples of representing our community include using an official e-mail address,
|
|
56
|
-
posting via an official social media account, or acting as an appointed
|
|
57
|
-
representative at an online or offline event.
|
|
58
|
-
|
|
59
|
-
## Enforcement
|
|
60
|
-
|
|
61
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
-
reported to the community leaders responsible for enforcement at
|
|
63
|
-
mailto:contact@socialwebfoundation.org.
|
|
64
|
-
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
-
|
|
66
|
-
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
-
reporter of any incident.
|
|
68
|
-
|
|
69
|
-
## Enforcement Guidelines
|
|
70
|
-
|
|
71
|
-
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
-
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
-
|
|
74
|
-
### 1. Correction
|
|
75
|
-
|
|
76
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
-
unprofessional or unwelcome in the community.
|
|
78
|
-
|
|
79
|
-
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
-
clarity around the nature of the violation and an explanation of why the
|
|
81
|
-
behavior was inappropriate. A public apology may be requested.
|
|
82
|
-
|
|
83
|
-
### 2. Warning
|
|
84
|
-
|
|
85
|
-
**Community Impact**: A violation through a single incident or series
|
|
86
|
-
of actions.
|
|
87
|
-
|
|
88
|
-
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
-
interaction with the people involved, including unsolicited interaction with
|
|
90
|
-
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
-
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
-
like social media. Violating these terms may lead to a temporary or
|
|
93
|
-
permanent ban.
|
|
94
|
-
|
|
95
|
-
### 3. Temporary Ban
|
|
96
|
-
|
|
97
|
-
**Community Impact**: A serious violation of community standards, including
|
|
98
|
-
sustained inappropriate behavior.
|
|
99
|
-
|
|
100
|
-
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
-
communication with the community for a specified period of time. No public or
|
|
102
|
-
private interaction with the people involved, including unsolicited interaction
|
|
103
|
-
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
-
Violating these terms may lead to a permanent ban.
|
|
105
|
-
|
|
106
|
-
### 4. Permanent Ban
|
|
107
|
-
|
|
108
|
-
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
-
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
-
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
-
|
|
112
|
-
**Consequence**: A permanent ban from any sort of public interaction within
|
|
113
|
-
the community.
|
|
114
|
-
|
|
115
|
-
## Attribution
|
|
116
|
-
|
|
117
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
-
version 2.0, available at
|
|
119
|
-
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
|
|
120
|
-
|
|
121
|
-
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
122
|
-
enforcement ladder](https://github.com/mozilla/diversity).
|
|
123
|
-
|
|
124
|
-
[homepage]: https://www.contributor-covenant.org
|
|
125
|
-
|
|
126
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
|
127
|
-
[https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq).
|
|
128
|
-
Translations are available at
|
|
129
|
-
[https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations).
|