* Update golang version to 1.24 * Update multiarch Dockerfile to be more ISA agnostic * Refactor existing code and properly structure project into modules * Get rid of global variables except where necessary (go:embed) * Add default values to Config * Add webserver with templates to finally correctly serve videos and gifs * Add tiny caching library to decrease api load and improve latency * Improve Webhook data preparation by filtering out redundant links from the tweet text and properly attaching videos and gifs in separate webhook request by utilising new webserver * Improve tests for filter function * Improve bake definition for easier CI integration
44 lines
896 B
Go
44 lines
896 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
type Config struct {
|
|
Username string
|
|
Password string
|
|
ProxyAddr string
|
|
Channels []string
|
|
Filter []uint8
|
|
Webhook string
|
|
DbPath string
|
|
CookiePath string
|
|
UseWebServer bool
|
|
HostURL string
|
|
WebPort uint16
|
|
UserAgents []string
|
|
NitterBase string
|
|
}
|
|
|
|
func ConfigFromFile(filePath string) (*Config, error) {
|
|
conf := &Config{
|
|
// Default values
|
|
DbPath: "./data/tweets.db",
|
|
CookiePath: "./data/cookies.json",
|
|
UseWebServer: true,
|
|
WebPort: 8080,
|
|
UserAgents: []string{"discordbot", "curl", "httpie", "lwp-request", "wget", "python-requests", "openbsd ftp", "powershell"},
|
|
NitterBase: "https://xcancel.com",
|
|
}
|
|
|
|
tomlData, err := os.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
_, err = toml.Decode(string(tomlData), conf)
|
|
|
|
return conf, err
|
|
}
|