Skip to content

Commit

Permalink
Huge refactoring ._.
Browse files Browse the repository at this point in the history
  • Loading branch information
Depado committed Dec 22, 2015
1 parent 0296990 commit 064dc2f
Show file tree
Hide file tree
Showing 20 changed files with 339 additions and 373 deletions.
4 changes: 2 additions & 2 deletions configuration/configuration.go
Expand Up @@ -17,7 +17,7 @@ type Configuration struct {
InsecureTLS bool `yaml:"insecure_tls"`
CommandCharacter string `yaml:"command_character"`
Middlewares []string `yaml:"middlewares"`
Plugins []string `yaml:"plugins"`
Commands []string `yaml:"commands"`
Admins []string `yaml:"admins"`
GoogleAPIKey string `yaml:"google_api_key"`
YandexTrnslKey string `yaml:"yandex_trnsl_key"`
Expand All @@ -42,7 +42,7 @@ func Load() {
if err != nil {
log.Fatalf("Error parsing YAML : %v", err)
}
sort.Strings(Config.Plugins)
sort.Strings(Config.Commands)
sort.Strings(Config.Middlewares)
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -69,7 +69,7 @@ func main() {
splitted := strings.Fields(m[1:])
command := splitted[0]
args := splitted[1:]
if p, ok := plugins.Plugins[command]; ok {
if p, ok := plugins.Commands[command]; ok {
p.Get(ib, from, to, args)
}
}
Expand Down
30 changes: 15 additions & 15 deletions plugins/afk/plugin.go → plugins/afk/command.go
Expand Up @@ -11,30 +11,30 @@ import (
)

const (
pluginCommand = "afk"
command = "afk"
)

// Plugin is the plugin struct. It will be exposed as packagename.Plugin to keep the API stable and friendly.
type Plugin struct {
// Command is the plugin struct. It will be exposed as packagename.Plugin to keep the API stable and friendly.
type Command struct {
Started bool
}

func init() {
plugins.Plugins[pluginCommand] = new(Plugin)
plugins.Commands[command] = new(Command)
}

// Help must send some help about what the command actually does and how to call it if there are any optional arguments.
func (p *Plugin) Help(ib *irc.Connection, from string) {
if !p.Started {
func (c *Command) Help(ib *irc.Connection, from string) {
if !c.Started {
return
}
ib.Privmsg(from, "Tell the world you're afk, for a reason. Or not.")
ib.Privmsg(from, "Example : !afk reason.")
}

// Get is the actual call to your plugin.
func (p *Plugin) Get(ib *irc.Connection, from string, to string, args []string) {
if !p.Started {
func (c *Command) Get(ib *irc.Connection, from string, to string, args []string) {
if !c.Started {
return
}
reason := ""
Expand All @@ -50,20 +50,20 @@ func (p *Plugin) Get(ib *irc.Connection, from string, to string, args []string)
}

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

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

// IsStarted returns the state of the plugin
func (p *Plugin) IsStarted() bool {
return p.Started
func (c *Command) IsStarted() bool {
return c.Started
}
30 changes: 15 additions & 15 deletions plugins/anon/plugin.go → plugins/anon/command.go
Expand Up @@ -10,30 +10,30 @@ import (
)

const (
pluginCommand = "anon"
command = "anon"
)

// Plugin is the anon plugin. Exposed as anon.Plugin.
type Plugin struct {
// Command is the anon plugin. Exposed as anon.Command.
type Command struct {
Started bool
}

func init() {
plugins.Plugins[pluginCommand] = new(Plugin)
plugins.Commands[command] = new(Command)
}

// Help provides some help on the usage of the plugin.
func (p *Plugin) Help(ib *irc.Connection, from string) {
if !p.Started {
func (c *Command) Help(ib *irc.Connection, from string) {
if !c.Started {
return
}
ib.Privmsg(from, "Allows to send anonymous messages on the channel where the bot is connected.")
ib.Privmsgf(from, "Example : /msg %s !anon Hello everyone.", configuration.Config.BotName)
}

// Get actually sends the data to the channel.
func (p *Plugin) Get(ib *irc.Connection, from string, to string, args []string) {
if !p.Started {
func (c *Command) Get(ib *irc.Connection, from string, to string, args []string) {
if !c.Started {
return
}
if len(args) > 0 {
Expand All @@ -42,20 +42,20 @@ func (p *Plugin) Get(ib *irc.Connection, from string, to string, args []string)
}

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

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

// IsStarted returns the state of the plugin
func (p *Plugin) IsStarted() bool {
return p.Started
func (c *Command) IsStarted() bool {
return c.Started
}
30 changes: 15 additions & 15 deletions plugins/choice/plugin.go → plugins/choice/command.go
Expand Up @@ -10,29 +10,29 @@ import (
)

const (
pluginCommand = "choice"
command = "choice"
)

func init() {
plugins.Plugins[pluginCommand] = new(Plugin)
plugins.Commands[command] = new(Command)
}

// Plugin is the plugin struct. It will be exposed as packagename.Plugin to keep the API stable and friendly.
type Plugin struct {
// Command is the plugin struct. It will be exposed as packagename.Command to keep the API stable and friendly.
type Command struct {
Started bool
}

// Help must send some help about what the command actually does and how to call it if there are any optional arguments.
func (p *Plugin) Help(ib *irc.Connection, from string) {
if !p.Started {
func (c *Command) Help(ib *irc.Connection, from string) {
if !c.Started {
return
}
ib.Privmsg(from, "Makes a choice for you. Example : !choice rhum whisky vodka beer")
}

// Get is the actual call to your plugin.
func (p *Plugin) Get(ib *irc.Connection, from string, to string, args []string) {
if !p.Started {
func (c *Command) Get(ib *irc.Connection, from string, to string, args []string) {
if !c.Started {
return
}
if to == configuration.Config.BotName {
Expand All @@ -49,20 +49,20 @@ func (p *Plugin) Get(ib *irc.Connection, from string, to string, args []string)
}

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

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

// IsStarted returns the state of the plugin
func (p *Plugin) IsStarted() bool {
return p.Started
func (c *Command) IsStarted() bool {
return c.Started
}

0 comments on commit 064dc2f

Please sign in to comment.