This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
plug-sdk/README.md

50 lines
1.4 KiB
Markdown
Raw Permalink Normal View History

2024-02-20 20:20:33 +00:00
# Anthrove Plug SDK
2024-07-08 13:25:26 +00:00
Anthrove Plug SDK is a Golang-based Software Development Kit (SDK) that provides a gRPC server implementation for the Anthrove system. This SDK enables users to easily set up a server, establish a database connection, and set a task execution function.
2024-02-20 20:20:33 +00:00
## Installation
To install the Anthrove Plug SDK, you will need to have Go installed on your system. You can then use the go get command to fetch the SDK:
```bash
2024-07-08 13:43:02 +00:00
go get git.dragse.it/anthrove/plug-sdk/v2
2024-02-20 20:20:33 +00:00
```
## Usage
Below is a basic example of how to use the SDK:
````go
2024-07-08 13:25:26 +00:00
import "git.dragse.it/anthrove/plug-sdk/v2/pkg/plug"
2024-02-20 20:20:33 +00:00
2024-07-08 13:25:26 +00:00
// Define what Source this Plug is used for
source := models.Source{
DisplayName: "e621",
Domain: "e621.net",
Icon: "e621.net/icon.png",
}
2024-02-20 20:20:33 +00:00
2024-07-08 13:25:26 +00:00
// Create a new Plug instance
p := plug.NewPlug(ctx, "localhost", "50051", source)
2024-02-20 20:20:33 +00:00
2024-07-08 13:25:26 +00:00
// Set the OtterSpace database
p.WithOtterSpace(database)
2024-02-20 20:20:33 +00:00
2024-07-08 13:25:26 +00:00
// Set the task execution function
p.TaskExecutionFunction(func(ctx context.Context, database database.OtterSpace, sourceUsername string, anthroveUser models.User, deepScrape bool, apiKey string, cancelFunction func()) error {
// Your task execution logic here
})
2024-02-20 20:20:33 +00:00
2024-07-08 13:25:26 +00:00
// Set the send message execution function
p.SendMessageExecution(func(ctx context.Context, userSourceID string, message string) error {
// Your message sending logic here
})
2024-02-20 20:20:33 +00:00
2024-07-08 13:25:26 +00:00
// Start the server
err := p.Listen()
if err != nil {
log.Fatalf("Failed to start server: %v", err)
2024-02-20 20:20:33 +00:00
}
````