Working with Go's Style Guide

This commit is contained in:
Elliott Pardee 2015-01-16 15:23:31 -05:00
parent 216cb5d62d
commit 3266cc0f7e
2 changed files with 140 additions and 128 deletions

26
bot.go
View File

@ -1,10 +1,10 @@
package main
import (
"github.com/thoj/go-ircevent"
"strings"
"fmt"
"github.com/thoj/go-ircevent"
"os"
"strings"
)
type Bot struct {
@ -51,16 +51,22 @@ var argmap = map[string]int{
}
func fillCharmap(nick string, cat string, item string, val string) {
charmap = map[string]map[string]map[string]string { nick: map[string]map[string]string{ cat: map[string]string{ item: val, }, }, }
charmap = map[string]map[string]map[string]string{
nick: map[string]map[string]string{
cat: map[string]string{
item: val,
},
},
}
}
func (b *Bot) Command(nick string, msg string) {
var args = make([]string, len(strings.Split(msg, " ")) - 1)
var args = make([]string, len(strings.Split(msg, " "))-1)
var command = ""
for i, j := range strings.Split(msg, " ") {
if j != " " && i !=0 {
args[i - 1] = strings.Split(msg, " ")[i]
if j != " " && i != 0 {
args[i-1] = strings.Split(msg, " ")[i]
}
}
@ -71,7 +77,9 @@ func (b *Bot) Command(nick string, msg string) {
}
}
if argmap[strings.Split(msg, " ")[0]] != len(args) { return }
if argmap[strings.Split(msg, " ")[0]] != len(args) {
return
}
// TODO: Check if mode is enabled and if command can be applied.
@ -145,7 +153,9 @@ func (b *Bot) Say(msg string) {
func (b *Bot) Listen() {
err := b.Conn.Connect(b.Server)
if err != nil { panic(err) }
if err != nil {
panic(err)
}
b.Conn.AddCallback("001", func(e *irc.Event) {
b.Conn.Join(b.Channel)

View File

@ -2,7 +2,9 @@ package main
func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a { return true}
if b == a {
return true
}
}
return false