Skip to content

Commit

Permalink
Add resolve object to bot actions
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessOne1917 committed Jul 9, 2023
1 parent 8f32459 commit 6ed4abb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ The actions are as follows, grouped by access level in ascending order:
- `reportPrivateMessage(form: ReportPrivateMessage)`: Report a private message. Accepts an object with the following properties:
- `privateMessage_id` number
- `reason` string
- `uploadImage(image: Buffer)`: Upload an image to pictrs. Returns a promise with an `UploadImageReponse`.
- `uploadImage(image: Buffer)`: Upload an image to pictrs. Returns a promise with an `UploadImageResponse`.
- `resolveObject(form: string | { community: string, instance: string })`: Resolves an object on a remote interest. Use this to federate with communities that aren't showing up on your instance yet. **Note**: If passing in a string, make sure it is in the format "!'community name'@'instance domain'".

#### Community moderator

Expand Down
12 changes: 12 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ class LemmyBot {
});

return moderators.some((mod) => mod.moderator.id === person_id);
},
resolveObject: (form) => {
if (typeof form === 'string') {
return this.#httpClient.resolveObject({ auth: this.#auth!, q: form });
} else {
const { communityName, instance } = form;

return this.#httpClient.resolveObject({
auth: this.#auth!,
q: `!${communityName}@${instance}`
});
}
}
};

Expand Down
6 changes: 5 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
RemovePost as ClientRemovePost,
FeaturePost as ClientFeaturePost,
LockPost as ClientLockPost,
Comment
Comment,
ResolveObjectResponse
} from 'lemmy-js-client';

export type BotOptions = {
Expand Down Expand Up @@ -142,6 +143,9 @@ export type BotActions = {
person_id: number;
community_id: number;
}) => Promise<boolean>;
resolveObject: (
form: string | { instance: string; communityName: string }
) => Promise<ResolveObjectResponse>;
};

export type InternalHandlers = {
Expand Down

0 comments on commit 6ed4abb

Please sign in to comment.