Skip to content

Commit

Permalink
Merge pull request #24 from nado/various-fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
Depado committed Jan 21, 2016
2 parents 064dc2f + bb7bfe7 commit 5c5a7c8
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 45 deletions.
4 changes: 2 additions & 2 deletions plugins/afk/command.go
Expand Up @@ -49,15 +49,15 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
} }
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/afk/middleware.go
Expand Up @@ -32,15 +32,15 @@ func (m *Middleware) Get(ib *irc.Connection, from string, to string, message str
} }
} }


// Start starts the middleware and returns any occured error, nil otherwise // Start starts the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Start() error { func (m *Middleware) Start() error {
if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) {
m.Started = true m.Started = true
} }
return nil return nil
} }


// Stop returns nil when it didnt encounter any error, the error otherwise // Stop returns nil when it didn’t encounter any error, the error otherwise
func (m *Middleware) Stop() error { func (m *Middleware) Stop() error {
m.Started = false m.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/anon/command.go
Expand Up @@ -41,15 +41,15 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
} }
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/choice/command.go
Expand Up @@ -48,15 +48,15 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
} }
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/dice/command.go
Expand Up @@ -69,15 +69,15 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
} }
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/duckduckgo/command.go
Expand Up @@ -79,15 +79,15 @@ func (c *Command) Get(ircbot *irc.Connection, from string, to string, args []str
} }
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/github/middleware.go
Expand Up @@ -77,15 +77,15 @@ func (m *Middleware) Get(ib *irc.Connection, from string, to string, message str
} }
} }


// Start starts the middleware and returns any occured error, nil otherwise // Start starts the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Start() error { func (m *Middleware) Start() error {
if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) {
m.Started = true m.Started = true
} }
return nil return nil
} }


// Stop stops the middleware and returns any occured error, nil otherwise // Stop stops the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Stop() error { func (m *Middleware) Stop() error {
m.Started = false m.Started = false
return nil return nil
Expand Down
2 changes: 1 addition & 1 deletion plugins/init.go
Expand Up @@ -23,7 +23,7 @@ type Middleware interface {
IsStarted() bool IsStarted() bool
} }


// Plugins is the map structure of all configured plugins // Commands is the map structure of all configured plugins
var Commands = map[string]Command{} var Commands = map[string]Command{}


// Middlewares is the slice of all configured middlewares Get() func // Middlewares is the slice of all configured middlewares Get() func
Expand Down
6 changes: 3 additions & 3 deletions plugins/karma/command.go
Expand Up @@ -21,7 +21,7 @@ const (
mainKey = "main" mainKey = "main"
) )


// Data is the struct that contains the data about the karma intented to be stored somewhere. // Data is the struct that contains the data about the karma intended to be stored somewhere.
type Data struct { type Data struct {
Karma map[string]int Karma map[string]int
} }
Expand Down Expand Up @@ -166,7 +166,7 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
} }
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
if err := database.BotStorage.CreateBucket(bucketName); err != nil { if err := database.BotStorage.CreateBucket(bucketName); err != nil {
Expand All @@ -180,7 +180,7 @@ func (c *Command) Start() error {
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
8 changes: 4 additions & 4 deletions plugins/logger/middleware.go
Expand Up @@ -56,7 +56,7 @@ func (m *Middleware) Get(ib *irc.Connection, from string, to string, message str
} }
} }


// Start starts the middleware and returns any occured error, nil otherwise // Start starts the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Start() error { func (m *Middleware) Start() error {
if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) {
if err := InitLoggers(); err != nil { if err := InitLoggers(); err != nil {
Expand All @@ -67,19 +67,19 @@ func (m *Middleware) Start() error {
return nil return nil
} }


// Stop returns nil when it didnt encounter any error, the error otherwise // Stop returns nil when it didn’t encounter any error, the error otherwise
func (m *Middleware) Stop() error { func (m *Middleware) Stop() error {
if !m.Started { if !m.Started {
return nil return nil
} }
var closeErr error var closeErr error
if err := HistoryFile.Close(); err != nil { if err := HistoryFile.Close(); err != nil {
log.Printf("Error closing history file : %s\n", err) log.Printf("Error closing history file : %s\n", err)
closeErr = fmt.Errorf("error occured while closing loggers’ files") closeErr = fmt.Errorf("error occurred while closing loggers’ files")
} }
if err := LinkFile.Close(); err != nil { if err := LinkFile.Close(); err != nil {
log.Printf("closing links file : %s\n", err) log.Printf("closing links file : %s\n", err)
closeErr = fmt.Errorf("error occured while closing loggers’ files") closeErr = fmt.Errorf("error occurred while closing loggers’ files")
} }


if closeErr != nil { if closeErr != nil {
Expand Down
4 changes: 2 additions & 2 deletions plugins/markov/command.go
Expand Up @@ -44,15 +44,15 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
ib.Privmsg(to, MainChain.Generate()) ib.Privmsg(to, MainChain.Generate())
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/markov/middleware.go
Expand Up @@ -53,7 +53,7 @@ func (m *Middleware) Get(ib *irc.Connection, from string, to string, message str
} }
} }


// Start starts the middleware and returns any occured error, nil otherwise // Start starts the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Start() error { func (m *Middleware) Start() error {
if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) {
MainChain = NewChain("main") MainChain = NewChain("main")
Expand All @@ -67,7 +67,7 @@ func (m *Middleware) Start() error {
return nil return nil
} }


// Stop stops the middleware and returns any occured error, nil otherwise // Stop stops the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Stop() error { func (m *Middleware) Stop() error {
MainChain = nil MainChain = nil
m.Started = false m.Started = false
Expand Down
4 changes: 2 additions & 2 deletions plugins/seen/command.go
Expand Up @@ -57,15 +57,15 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
} }
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/seen/middleware.go
Expand Up @@ -30,15 +30,15 @@ func (m *Middleware) Get(ib *irc.Connection, from string, to string, message str
Map[from] = time.Now() Map[from] = time.Now()
} }


// Start starts the middleware and returns any occured error, nil otherwise // Start starts the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Start() error { func (m *Middleware) Start() error {
if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) {
m.Started = true m.Started = true
} }
return nil return nil
} }


// Stop stops the middleware and returns any occured error, nil otherwise // Stop stops the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Stop() error { func (m *Middleware) Stop() error {
m.Started = false m.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/title/middleware.go
Expand Up @@ -147,15 +147,15 @@ func (m *Middleware) Get(ib *irc.Connection, from string, to string, message str
} }
} }


// Start starts the middleware and returns any occured error, nil otherwise // Start starts the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Start() error { func (m *Middleware) Start() error {
if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) {
m.Started = true m.Started = true
} }
return nil return nil
} }


// Stop stops the middleware and returns any occured error, nil otherwise // Stop stops the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Stop() error { func (m *Middleware) Stop() error {
m.Started = false m.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/translate/command.go
Expand Up @@ -70,15 +70,15 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
} }
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/urban/command.go
Expand Up @@ -127,15 +127,15 @@ func (c *Command) fetch(query string) error {
return nil return nil
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/usercommand/command.go
Expand Up @@ -80,7 +80,7 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
ib.Privmsgf(to, "Registered commands : %s", strings.Join(l, " ")) ib.Privmsgf(to, "Registered commands : %s", strings.Join(l, " "))
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(command, configuration.Config.Commands) { if utils.StringInSlice(command, configuration.Config.Commands) {
CreateBucket() CreateBucket()
Expand All @@ -89,7 +89,7 @@ func (c *Command) Start() error {
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down
12 changes: 9 additions & 3 deletions plugins/usercommand/middleware.go
@@ -1,6 +1,7 @@
package usercommand package usercommand


import ( import (
"log"
"strings" "strings"


"github.com/depado/go-b0tsec/configuration" "github.com/depado/go-b0tsec/configuration"
Expand Down Expand Up @@ -33,9 +34,14 @@ func (m *Middleware) Get(ib *irc.Connection, from string, to string, message str
if !strings.HasPrefix(message, cnf.UserCommandCharacter) || len(message) == 1 { if !strings.HasPrefix(message, cnf.UserCommandCharacter) || len(message) == 1 {
return return
} }

splittedMsg := strings.Fields(message[1:]) splittedMsg := strings.Fields(message[1:])
uc := UserCommand{splittedMsg[0], ""} uc := UserCommand{splittedMsg[0], ""}
database.BotStorage.Get(bucketName, uc.Name, &uc)
if err := database.BotStorage.Get(bucketName, uc.Name, &uc); err != nil {
log.Println(err)
return
}


if strings.HasPrefix(uc.Value, cnf.CommandCharacter) { if strings.HasPrefix(uc.Value, cnf.CommandCharacter) {
if len(uc.Value) > 1 { if len(uc.Value) > 1 {
Expand All @@ -56,7 +62,7 @@ func (m *Middleware) Get(ib *irc.Connection, from string, to string, message str
ib.Privmsg(to, msg) ib.Privmsg(to, msg)
} }


// Start starts the middleware and returns any occured error, nil otherwise // Start starts the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Start() error { func (m *Middleware) Start() error {
if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) {
CreateBucket() CreateBucket()
Expand All @@ -65,7 +71,7 @@ func (m *Middleware) Start() error {
return nil return nil
} }


// Stop stops the middleware and returns any occured error, nil otherwise // Stop stops the middleware and returns any occurred error, nil otherwise
func (m *Middleware) Stop() error { func (m *Middleware) Stop() error {
m.Started = false m.Started = false
return nil return nil
Expand Down
4 changes: 2 additions & 2 deletions plugins/youtube/command.go
Expand Up @@ -75,15 +75,15 @@ func (c *Command) Get(ib *irc.Connection, from string, to string, args []string)
} }
} }


// Start starts the plugin and returns any occured error, nil otherwise // Start starts the plugin and returns any occurred error, nil otherwise
func (c *Command) Start() error { func (c *Command) Start() error {
if utils.StringInSlice(pluginCommand, configuration.Config.Commands) { if utils.StringInSlice(pluginCommand, configuration.Config.Commands) {
c.Started = true c.Started = true
} }
return nil return nil
} }


// Stop stops the plugin and returns any occured error, nil otherwise // Stop stops the plugin and returns any occurred error, nil otherwise
func (c *Command) Stop() error { func (c *Command) Stop() error {
c.Started = false c.Started = false
return nil return nil
Expand Down

0 comments on commit 5c5a7c8

Please sign in to comment.