Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9cf42df1ea | ||
![]() |
b81e1e482a | ||
![]() |
3d7011e504 |
@@ -12,9 +12,11 @@ import (
|
||||
|
||||
var (
|
||||
configCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Use: "config [editor]",
|
||||
Short: "Edit config file",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
editors = append(args, editors...)
|
||||
|
||||
if editor := findEditor(); editor != "" {
|
||||
process := exec.Command(editor, storage.Path.Config())
|
||||
process.Stdin = os.Stdin
|
||||
@@ -27,7 +29,7 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
editors = []string{"nano", "notepad", "vi", "emacs"}
|
||||
editors = []string{"nano", "code", "vi", "emacs", "notepad"}
|
||||
)
|
||||
|
||||
func findEditor() string {
|
||||
|
@@ -46,19 +46,19 @@ login = true
|
||||
# Enable username/password registration
|
||||
registration = true
|
||||
|
||||
[auth.github]
|
||||
[auth.providers.github]
|
||||
key = ""
|
||||
secret = ""
|
||||
|
||||
[auth.facebook]
|
||||
[auth.providers.facebook]
|
||||
key = ""
|
||||
secret = ""
|
||||
|
||||
[auth.google]
|
||||
[auth.providers.google]
|
||||
key = ""
|
||||
secret = ""
|
||||
|
||||
[auth.twitter]
|
||||
[auth.providers.twitter]
|
||||
key = ""
|
||||
secret = ""
|
||||
|
||||
|
@@ -3,8 +3,8 @@ package config
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/khlieng/dispatch/storage"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/khlieng/dispatch/storage"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@@ -18,6 +18,7 @@ type Config struct {
|
||||
Defaults Defaults
|
||||
HTTPS HTTPS
|
||||
LetsEncrypt LetsEncrypt
|
||||
Auth Auth
|
||||
}
|
||||
|
||||
type Defaults struct {
|
||||
@@ -51,6 +52,18 @@ type LetsEncrypt struct {
|
||||
Email string
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
Anonymous bool
|
||||
Login bool
|
||||
Registration bool
|
||||
Providers map[string]Provider
|
||||
}
|
||||
|
||||
type Provider struct {
|
||||
Key string
|
||||
Secret string
|
||||
}
|
||||
|
||||
func LoadConfig() (*Config, chan *Config) {
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath(storage.Path.ConfigRoot())
|
||||
|
@@ -119,6 +119,7 @@ func (c *Client) Join(channels ...string) {
|
||||
|
||||
func (c *Client) Part(channels ...string) {
|
||||
c.Write("PART " + strings.Join(channels, ","))
|
||||
c.removeChannels(channels...)
|
||||
}
|
||||
|
||||
func (c *Client) Topic(channel string, topic ...string) {
|
||||
@@ -183,6 +184,18 @@ func (c *Client) addChannel(channel string) {
|
||||
c.lock.Unlock()
|
||||
}
|
||||
|
||||
func (c *Client) removeChannels(channels ...string) {
|
||||
c.lock.Lock()
|
||||
for _, removeCh := range channels {
|
||||
for i, ch := range c.channels {
|
||||
if c.EqualFold(removeCh, ch) {
|
||||
c.channels = append(c.channels[:i], c.channels[i+1:]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
c.lock.Unlock()
|
||||
}
|
||||
|
||||
func (c *Client) flushChannels() {
|
||||
c.lock.Lock()
|
||||
if len(c.channels) > 0 {
|
||||
|
@@ -162,6 +162,8 @@ func TestFlushChannels(t *testing.T) {
|
||||
c.flushChannels()
|
||||
assert.Equal(t, <-out, "JOIN #chan1\r\n")
|
||||
c.addChannel("#chan2")
|
||||
c.addChannel("#chan4")
|
||||
c.removeChannels("#chan4")
|
||||
c.addChannel("#chan3")
|
||||
c.flushChannels()
|
||||
assert.Equal(t, <-out, "JOIN #chan2,#chan3\r\n")
|
||||
|
Reference in New Issue
Block a user