Skip to content

Commit e14c941

Browse files
Add some new bot actions
1 parent 5156e30 commit e14c941

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Task object or list of task objects. Task objects have the following properties:
180180
- `runAtStart`: Boolean value for whether or not the task should be run immediately. Defaults to false.
181181

182182
#### `secure`
183+
183184
If `true`, the bot will use HTTPS. If `false`, it will use HTTP. Default value is `true`.
184185

185186
#### `dbFile`
@@ -222,9 +223,9 @@ The actions are as follows, grouped by access level in ascending order:
222223
- `getComment(form: GetComment)`: Retrieve a comment based on its ID.
223224
- `getParentOfComment(form: Comment)`: Retrieves the parent of a comment. Accepts a comment object, which is returned from handlers that deal with comments (e.g. comment handler, mention handler, reply handler, etc.). Returns an object with the following properties:
224225
- `type` `"post"` or `"comment"`
225-
When `type` is `"post"`:
226+
When `type` is `"post"`:
226227
- `post`: `GetPostResponse`
227-
When `type` is `"comment"`:
228+
When `type` is `"comment"`:
228229
- `comment`: `CommentResponse`
229230
- `isCommunityMod(form: {community: Community, person: Person})`: Returns whether or not a person is a moderator of a given community.
230231

@@ -275,6 +276,12 @@ The actions are as follows, grouped by access level in ascending order:
275276
- `comment_id` number
276277
- `content` _optional_ string
277278
- `language_id` _optional_ number
279+
- `listMedia(form: ListMedia)`: List all media that was posted by the bot. The `form` argument is optional and has the following properties:
280+
- `page`: number
281+
- `limit`: number
282+
- `hidePost(form: HidePost)`: Hide posta so they don't show up in your feed. The `form` argument has the following properties:
283+
- `postIds`: number[]
284+
- `hide`: boolean
278285

279286
#### Community moderator
280287

@@ -317,12 +324,12 @@ The actions are as follows, grouped by access level in ascending order:
317324

318325
- `getCommentVotes(form: ListCommentLikes)`: Show who voted on a comment, and what their vote is. Accepts an object with the following properties:
319326
- `comment_id` number
320-
- `page` __optional__ number
321-
- `limit` __optional__ number
327+
- `page` **optional** number
328+
- `limit` **optional** number
322329
- `getPostVotes(form: ListPostLikes)`: Show who voted on a post, and what their vote is. Accepts an object with the following properties:
323330
- `post_id` number
324-
- `page` __optional__ number
325-
- `limit` __optional__ number
331+
- `page` **optional** number
332+
- `limit` **optional** number
326333
- `banFromSite(form: BanFromSite)`: Ban or unban a user from the instance. Accepts an object with the following properties:
327334
- `person_id` number
328335
- `ban` number
@@ -332,12 +339,17 @@ The actions are as follows, grouped by access level in ascending order:
332339
- `approveRegistrationApplication(form: ApproveRegistrationApplication)`: Approve the creation of an account. Accepts an object with the following properties:
333340
- `id` number
334341
- `approve` boolean
335-
- `deny_reason` __optional__ string
342+
- `deny_reason` **optional** string
343+
- `listAllMedia(form: ListMedia)`: List all media that has been posted on the instance. Optionally accepts an object with the following properties:
344+
- `page`: number
345+
- `limit`: number
336346

337347
## HTTP Client
348+
338349
If you need to use the [lemmy client](https://github.com/LemmyNet/lemmy-js-client) directly, the `__httpClient__` property is available so you don't need add it to your project separately. For your convenience, you can also access this in paramaters for polled event handlers and scheduled tasks.
339350

340351
## Running Your Bot
352+
341353
There are templates for docker and systemd in the templates folder to help you run your bot once you've made it.
342354

343355
## Examples

src/bot.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,21 @@ class LemmyBot {
251251
this.#performLoggedInBotAction({
252252
logMessage: `Getting details for ${form.username ? form.username : `user with ID ${form.person_id}`}`,
253253
action: () => this.__httpClient__.getPersonDetails(form)
254+
}),
255+
listMedia: (form = {}) =>
256+
this.#performLoggedInBotAction({
257+
logMessage: 'Listing media posted by bot',
258+
action: () => this.__httpClient__.listMedia(form)
259+
}),
260+
listAllMedia: (form) =>
261+
this.#performLoggedInBotAction({
262+
logMessage: 'Listing all media posted on instance',
263+
action: () => this.__httpClient__.listAllMedia(form)
264+
}),
265+
hidePost: (form) =>
266+
this.#performLoggedInBotAction({
267+
logMessage: `Hiding posts with IDs = ${form.post_ids.join(', ')}`,
268+
action: () => this.__httpClient__.hidePost(form)
254269
})
255270
};
256271

src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ import {
6969
ListCommentLikesResponse,
7070
ListPostLikes,
7171
ListPostLikesResponse,
72-
DistinguishComment
72+
DistinguishComment,
73+
ListMedia,
74+
ListMediaResponse,
75+
HidePost,
76+
SuccessResponse
7377
} from 'lemmy-js-client';
7478

7579
export type BotOptions = {
@@ -199,6 +203,9 @@ export type BotActions = {
199203
community: Community;
200204
}) => Promise<boolean>;
201205
resolveObject: (form: ResolveObject) => Promise<ResolveObjectResponse>;
206+
listMedia: (form?: ListMedia) => Promise<ListMediaResponse>;
207+
listAllMedia: (form?: ListMedia) => Promise<ListMediaResponse>;
208+
hidePost: (form: HidePost) => Promise<SuccessResponse>;
202209
};
203210

204211
export type InternalHandlers = {

0 commit comments

Comments
 (0)