Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit

Permalink
general features added
Browse files Browse the repository at this point in the history
using the commands settings for channel locking, disabled etc
added eddb plugin and stubs for the simplest commands.
general fixes

refs #21
  • Loading branch information
dmportella committed Sep 26, 2016
1 parent 89ee9dd commit e0bc415
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 4 deletions.
10 changes: 9 additions & 1 deletion bot/qilbot_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ func (qilbot *Qilbot) discordCreateMessage(s *discordgo.Session, m *discordgo.Me
commandCalled := matches[1]

if command, ok := qilbot.commands[commandCalled]; ok {
if command.settings.Disabled {
return
}

if command.settings.OnlyUsableOnChannelID != "" && m.ChannelID != command.settings.OnlyUsableOnChannelID {
return
}

ctx := QilbotCommandContext{
Message: m,
CommandText: matches[2],
Expand Down Expand Up @@ -152,7 +160,7 @@ func (qilbot *Qilbot) AddCommand(command *QilbotCommand) (err error) {
if settings, ok := qilbot.commandSettings[command.Command]; ok {
command.settings = settings
} else {
emptySettings := commandSettings{"", true, false}
emptySettings := commandSettings{"", false, false}

qilbot.commandSettings[command.Command] = &emptySettings

Expand Down
4 changes: 4 additions & 0 deletions bot/qilbotcommon_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (qilbot *Qilbot) helpCommand(ctx *QilbotCommandContext) {
specificCommand := ctx.CommandText != ""

for _, command := range qilbot.commands {
if command.settings != nil && command.settings.Disabled {
continue
}

if strings.Compare(strings.ToLower(ctx.CommandText), strings.ToLower(command.Command)) == 0 {
buffer.WriteString(fmt.Sprintf("**%s** (%s): %s\n", command.Command, command.Template, command.Description))
} else if !specificCommand {
Expand Down
1 change: 0 additions & 1 deletion bot/qilbotsettings_func.go

This file was deleted.

5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/dmportella/qilbot/bot"
"github.com/dmportella/qilbot/logging"
"github.com/dmportella/qilbot/plugins/eddb"
"github.com/dmportella/qilbot/plugins/edsm"
"github.com/dmportella/qilbot/plugins/wow"
"io/ioutil"
Expand Down Expand Up @@ -122,6 +123,10 @@ func main() {
}

func loadPlugins() {
eddbPlugin := eddb.NewPlugin(&botInstance)

logging.Info.Println(eddbPlugin.Name(), "loaded")

edsmPlugin := edsm.NewPlugin(&botInstance)

logging.Info.Println(edsmPlugin.Name(), "loaded")
Expand Down
1 change: 0 additions & 1 deletion plugins/eddb/downloader.go

This file was deleted.

5 changes: 5 additions & 0 deletions plugins/eddb/eddb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package eddb

// Plugin EDDB plugin instance
type Plugin struct {
}
77 changes: 77 additions & 0 deletions plugins/eddb/eddb_func.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package eddb

import (
"bytes"
"github.com/dmportella/qilbot/bot"
)

const (
name = "Qilbot EDDB plugin"
description = "A collection of tools and commands for EDDB."
)

// NewPlugin creates a new instance of WOW Plugin.
func NewPlugin(qilbot *bot.Qilbot) (plugin *Plugin) {
plugin = &Plugin{}

commodities := bot.QilbotCommand{
Command: "commodities",
Template: "commodities **item name**",
Description: "Search the database for commodity information.",
Execute: func(ctx *bot.QilbotCommandContext) {
plugin.underConstructionCommand(ctx)
},
}

stations := bot.QilbotCommand{
Command: "stations",
Template: "stations **system name**",
Description: "Returns the stations available in specified system.",
Execute: func(ctx *bot.QilbotCommandContext) {
plugin.underConstructionCommand(ctx)
},
}

modules := bot.QilbotCommand{
Command: "modules",
Template: "modules **module name**",
Description: "Returns the information about specified module.",
Execute: func(ctx *bot.QilbotCommandContext) {
plugin.underConstructionCommand(ctx)
},
}

bodies := bot.QilbotCommand{
Command: "bodies",
Template: "bodies **body name**",
Description: "Returns the information about specified stellar body.",
Execute: func(ctx *bot.QilbotCommandContext) {
plugin.underConstructionCommand(ctx)
},
}

qilbot.AddCommand(&commodities)
qilbot.AddCommand(&stations)
qilbot.AddCommand(&modules)
qilbot.AddCommand(&bodies)

return
}

// Name returns the name of the plugin
func (plugin *Plugin) Name() string {
return name
}

// Description returns the description of the plugin
func (plugin *Plugin) Description() string {
return description
}

func (plugin *Plugin) underConstructionCommand(ctx *bot.QilbotCommandContext) {
var buffer bytes.Buffer

buffer.WriteString("this command is currently under construction")

ctx.RespondToUser(buffer.String())
}
2 changes: 2 additions & 0 deletions plugins/edsm/edsmplugin_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ func NewPlugin(qilbot *bot.Qilbot) (plugin *Plugin) {
return
}

// Name returns the name of the plugin
func (plugin *Plugin) Name() string {
return name
}

// Description returns the description of the plugin
func (plugin *Plugin) Description() string {
return description
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/wow/wow_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ func NewPlugin(qilbot *bot.Qilbot) (plugin *Plugin) {
return
}

// Name returns the name of the plugin
func (plugin *Plugin) Name() string {
return name
}

// Description returns the description of the plugin
func (plugin *Plugin) Description() string {
return description
}
Expand All @@ -42,7 +44,7 @@ func (plugin *Plugin) armoryCommand(ctx *bot.QilbotCommandContext) {

logging.Info.Println("comand text", ctx.CommandText)

buffer.WriteString("This will give you armory link and all stuff you like")
buffer.WriteString("underconstruction")

ctx.RespondToUser(buffer.String())
}

0 comments on commit e0bc415

Please sign in to comment.