This commit is contained in:
parent
9c78ea2d48
commit
7c684af8c3
79 changed files with 3594 additions and 3257 deletions
86
internal/model/message.go
Normal file
86
internal/model/message.go
Normal file
|
@ -0,0 +1,86 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Message represents a chat message
|
||||
type Message struct {
|
||||
Text string
|
||||
Chat string
|
||||
Channel *Channel
|
||||
Author string
|
||||
FromBot bool
|
||||
Date time.Time
|
||||
ID string
|
||||
ReplyTo string
|
||||
Raw map[string]interface{}
|
||||
}
|
||||
|
||||
// Channel represents a chat channel
|
||||
type Channel struct {
|
||||
ID int64
|
||||
Platform string
|
||||
PlatformChannelID string
|
||||
ChannelRaw map[string]interface{}
|
||||
Enabled bool
|
||||
Plugins map[string]*ChannelPlugin
|
||||
}
|
||||
|
||||
// HasEnabledPlugin checks if a plugin is enabled for this channel
|
||||
func (c *Channel) HasEnabledPlugin(pluginID string) bool {
|
||||
plugin, exists := c.Plugins[pluginID]
|
||||
if !exists {
|
||||
return false
|
||||
}
|
||||
return plugin.Enabled
|
||||
}
|
||||
|
||||
// ChannelName returns the channel name
|
||||
func (c *Channel) ChannelName() string {
|
||||
// In a real implementation, this would use the platform-specific
|
||||
// ParseChannelNameFromRaw function
|
||||
|
||||
// For simplicity, we'll just use the PlatformChannelID if we can't extract a name
|
||||
// Check if ChannelRaw has a name field
|
||||
if c.ChannelRaw == nil {
|
||||
return c.PlatformChannelID
|
||||
}
|
||||
|
||||
// Check common name fields in ChannelRaw
|
||||
if name, ok := c.ChannelRaw["name"].(string); ok && name != "" {
|
||||
return name
|
||||
}
|
||||
|
||||
// Check for nested objects like "chat" (used by Telegram)
|
||||
if chat, ok := c.ChannelRaw["chat"].(map[string]interface{}); ok {
|
||||
// Try different fields in order of preference
|
||||
if title, ok := chat["title"].(string); ok && title != "" {
|
||||
return title
|
||||
}
|
||||
if username, ok := chat["username"].(string); ok && username != "" {
|
||||
return username
|
||||
}
|
||||
if firstName, ok := chat["first_name"].(string); ok && firstName != "" {
|
||||
return firstName
|
||||
}
|
||||
}
|
||||
|
||||
return c.PlatformChannelID
|
||||
}
|
||||
|
||||
// ChannelPlugin represents a plugin enabled for a channel
|
||||
type ChannelPlugin struct {
|
||||
ID int64
|
||||
ChannelID int64
|
||||
PluginID string
|
||||
Enabled bool
|
||||
Config map[string]interface{}
|
||||
}
|
||||
|
||||
// User represents an admin user
|
||||
type User struct {
|
||||
ID int64
|
||||
Username string
|
||||
Password string
|
||||
}
|
46
internal/model/platform.go
Normal file
46
internal/model/platform.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"git.nakama.town/fmartingr/butterrobot/internal/config"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrPlatform is a general platform error
|
||||
ErrPlatform = errors.New("platform error")
|
||||
|
||||
// ErrPlatformInit is an error during platform initialization
|
||||
ErrPlatformInit = errors.New("platform initialization error")
|
||||
|
||||
// ErrPlatformAuth is an authentication error
|
||||
ErrPlatformAuth = errors.New("platform authentication error")
|
||||
|
||||
// ErrPlatformNotFound is returned when a requested platform doesn't exist
|
||||
ErrPlatformNotFound = errors.New("platform not found")
|
||||
)
|
||||
|
||||
// AuthResponse represents a platform authentication response
|
||||
type AuthResponse struct {
|
||||
Data map[string]any
|
||||
StatusCode int
|
||||
}
|
||||
|
||||
// Platform defines the interface all chat platforms must implement
|
||||
type Platform interface {
|
||||
// Init initializes the platform
|
||||
Init(cfg *config.Config) error
|
||||
|
||||
// ParseIncomingMessage parses the incoming HTTP request into a Message
|
||||
ParseIncomingMessage(r *http.Request) (*Message, error)
|
||||
|
||||
// ParseChannelNameFromRaw extracts a human-readable channel name from raw data
|
||||
ParseChannelNameFromRaw(channelRaw map[string]any) string
|
||||
|
||||
// ParseChannelFromMessage extracts channel data from a message
|
||||
ParseChannelFromMessage(body []byte) (map[string]any, error)
|
||||
|
||||
// SendMessage sends a message through the platform
|
||||
SendMessage(msg *Message) error
|
||||
}
|
28
internal/model/plugin.go
Normal file
28
internal/model/plugin.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrPluginNotFound is returned when a requested plugin doesn't exist
|
||||
ErrPluginNotFound = errors.New("plugin not found")
|
||||
)
|
||||
|
||||
// Plugin defines the interface all chat plugins must implement
|
||||
type Plugin interface {
|
||||
// GetID returns the plugin ID
|
||||
GetID() string
|
||||
|
||||
// GetName returns the plugin name
|
||||
GetName() string
|
||||
|
||||
// GetHelp returns the plugin help text
|
||||
GetHelp() string
|
||||
|
||||
// RequiresConfig indicates if the plugin requires configuration
|
||||
RequiresConfig() bool
|
||||
|
||||
// OnMessage processes an incoming message and returns response messages
|
||||
OnMessage(msg *Message, config map[string]interface{}) []*Message
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue