4 Commits

8 changed files with 78 additions and 51 deletions

File diff suppressed because one or more lines are too long

View File

@@ -187,9 +187,6 @@ export default createCommandMiddleware(COMMAND, {
},
[notFoundHandler](ctx, command, ...params) {
if (command === command.toUpperCase()) {
return this.raw(ctx, command, ...params);
}
return error(`=> /${command}: No such command`);
return this.raw(ctx, command, ...params);
}
});

View File

@@ -27,7 +27,7 @@ export default function createCommandMiddleware(type, handlers) {
return store => next => action => {
if (action.type === type) {
const words = action.command.slice(1).split(' ');
const command = words[0];
const command = words[0].toLowerCase();
const params = words.slice(1);
if (command in handlers) {

View File

@@ -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 {

View File

@@ -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 = ""

View File

@@ -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())

View File

@@ -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 {

View File

@@ -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")