This commit is contained in:
parent
9c78ea2d48
commit
7c684af8c3
79 changed files with 3594 additions and 3257 deletions
|
@ -1,11 +1,12 @@
|
|||
## Contributing
|
||||
|
||||
To run the project locally you will need [poetry](https://python-poetry.org/).
|
||||
To run the project locally you will need Go 1.19 or higher.
|
||||
|
||||
```
|
||||
```bash
|
||||
git clone git@github.com:fmartingr/butterrobot.git
|
||||
cd butterrobot
|
||||
make setup
|
||||
make build
|
||||
```
|
||||
|
||||
Create a `.env-local` file with the required environment variables, you have [an example file](.env-example).
|
||||
|
@ -13,11 +14,16 @@ Create a `.env-local` file with the required environment variables, you have [an
|
|||
```
|
||||
SLACK_TOKEN=xxx
|
||||
TELEGRAM_TOKEN=xxx
|
||||
HOSTNAME=myhostname.com
|
||||
...
|
||||
```
|
||||
|
||||
And then you can run it directly with poetry:
|
||||
And then you can run it directly:
|
||||
|
||||
```
|
||||
poetry run python -m butterrobot
|
||||
```bash
|
||||
# Run directly with Go
|
||||
go run ./cmd/butterrobot/main.go
|
||||
|
||||
# Or run the built binary
|
||||
./bin/butterrobot
|
||||
```
|
||||
|
|
|
@ -2,36 +2,61 @@
|
|||
|
||||
## Example
|
||||
|
||||
This simple "Marco Polo" plugin will answer _Polo_ to the user that say _Marco_:
|
||||
This simple "Marco Polo" plugin will answer _Polo_ to the user that says _Marco_:
|
||||
|
||||
``` python
|
||||
# mypackage/plugins.py
|
||||
from butterrobot.plugins import Plugin
|
||||
from butterrobot.objects import Message
|
||||
```go
|
||||
package myplugin
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
class PingPlugin(Plugin):
|
||||
name = "Marco/Polo"
|
||||
id = "test.marco"
|
||||
"git.nakama.town/fmartingr/butterrobot/internal/model"
|
||||
"git.nakama.town/fmartingr/butterrobot/internal/plugin"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def on_message(cls, message, **kwargs):
|
||||
if message.text == "Marco":
|
||||
yield Message(
|
||||
chat=message.chat, reply_to=message.id, text=f"polo",
|
||||
)
|
||||
```
|
||||
|
||||
``` python
|
||||
# setup.py
|
||||
# ...
|
||||
entrypoints = {
|
||||
"test.marco" = "mypackage.plugins:MarcoPlugin"
|
||||
// MarcoPlugin is a simple Marco/Polo plugin
|
||||
type MarcoPlugin struct {
|
||||
plugin.BasePlugin
|
||||
}
|
||||
|
||||
setup(
|
||||
# ...
|
||||
entry_points=entrypoints,
|
||||
# ...
|
||||
)
|
||||
// New creates a new MarcoPlugin instance
|
||||
func New() *MarcoPlugin {
|
||||
return &MarcoPlugin{
|
||||
BasePlugin: plugin.BasePlugin{
|
||||
ID: "test.marco",
|
||||
Name: "Marco/Polo",
|
||||
Help: "Responds to 'Marco' with 'Polo'",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// OnMessage handles incoming messages
|
||||
func (p *MarcoPlugin) OnMessage(msg *model.Message, config map[string]interface{}) []*model.Message {
|
||||
if !strings.EqualFold(strings.TrimSpace(msg.Text), "Marco") {
|
||||
return nil
|
||||
}
|
||||
|
||||
response := &model.Message{
|
||||
Text: "Polo",
|
||||
Chat: msg.Chat,
|
||||
ReplyTo: msg.ID,
|
||||
Channel: msg.Channel,
|
||||
}
|
||||
|
||||
return []*model.Message{response}
|
||||
}
|
||||
```
|
||||
|
||||
To use the plugin, register it in your application:
|
||||
|
||||
```go
|
||||
// In app.go or similar initialization file
|
||||
func (a *App) Run() error {
|
||||
// ...
|
||||
|
||||
// Register plugins
|
||||
plugin.Register(myplugin.New())
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
### Development
|
||||
|
||||
- `!ping`: Say `!ping` to get response with time elapsed.
|
||||
- `ping`: Say `ping` to get response with time elapsed.
|
||||
|
||||
### Fun and entertainment
|
||||
|
||||
|
||||
- Lo quito: What happens when you say _"lo quito"_...? (Spanish pun)
|
||||
- Dice: Put `!dice` and wathever roll you want to perform.
|
||||
- Coin: Flip a coin and get heads or tails.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue