refactor: python -> go
All checks were successful
ci/woodpecker/tag/release Pipeline was successful

This commit is contained in:
Felipe M 2025-04-20 13:54:22 +02:00
parent 9c78ea2d48
commit 7c684af8c3
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8
79 changed files with 3594 additions and 3257 deletions

View file

@ -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())
// ...
}
```