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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue