chore: I have no fucking idea
Build and Publish Package (amd64) / docker (push) Successful in 4m54s

This is vibecoded shit but i can't be bothered to do it myself.
Nobody else besides me is gonna be using this, and this wont ever be
extended or anything, so I just don't care.
This commit is contained in:
2026-07-25 23:07:16 +02:00
parent dee1d94ae4
commit 6756b9f179
7 changed files with 534 additions and 313 deletions
+34 -22
View File
@@ -1,6 +1,7 @@
package main
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
@@ -13,11 +14,10 @@ type HomeserverConfig struct {
type AppserviceConfig struct {
ID string `yaml:"id"`
Address string `yaml:"address"`
BotLocalpart string `yaml:"bot_localpart"`
ASToken string `yaml:"as_token"`
HSToken string `yaml:"hs_token"`
BotLocalpart string `yaml:"bot_localpart"`
Address string `yaml:"address"`
Port uint16 `yaml:"port"`
}
type BridgeConfig struct {
@@ -40,32 +40,37 @@ func LoadConfig(path string) (*Config, error) {
if err = yaml.Unmarshal(data, cfg); err != nil {
return nil, err
}
if cfg.Bridge.Permissions == nil {
cfg.Bridge.Permissions = make(map[string]string)
}
if cfg.Bridge.NtfyURL == "" {
cfg.Bridge.NtfyURL = "https://ntfy.sh"
}
if cfg.Appservice.Address == "" {
cfg.Appservice.Address = "0.0.0.0"
}
if cfg.Appservice.Port == 0 {
cfg.Appservice.Port = 8080
}
cfg.applyDefaults()
return cfg, nil
}
func (b *BridgeConfig) PermissionLevel(id string) string {
if level, ok := b.Permissions[id]; ok {
return level
func (c *Config) applyDefaults() {
if c.Bridge.Permissions == nil {
c.Bridge.Permissions = make(map[string]string)
}
if c.Bridge.NtfyURL == "" {
c.Bridge.NtfyURL = "https://ntfy.sh"
}
if c.Appservice.ID == "" {
c.Appservice.ID = "ntfy-bridge"
}
if c.Appservice.Address == "" {
c.Appservice.Address = "0.0.0.0"
}
return ""
}
func (b *BridgeConfig) HasPermission(userID, requiredLevel string) bool {
level := b.PermissionLevel(userID)
func (c *Config) Save(path string) error {
data, err := yaml.Marshal(c)
if err != nil {
return fmt.Errorf("marshal config: %w", err)
}
return os.WriteFile(path, data, 0600)
}
func (c *BridgeConfig) HasPermission(userID, requiredLevel string) bool {
level := c.PermissionLevel(userID)
if level == "" {
level = b.PermissionLevel("*")
level = c.PermissionLevel("*")
}
if level == "" {
return false
@@ -75,3 +80,10 @@ func (b *BridgeConfig) HasPermission(userID, requiredLevel string) bool {
}
return true
}
func (c *BridgeConfig) PermissionLevel(id string) string {
if level, ok := c.Permissions[id]; ok {
return level
}
return ""
}