Commit bc37c25c authored by Mike Jones's avatar Mike Jones 🌶

Set maximum size of slice ranges

parent 50eb740f
......@@ -23,25 +23,25 @@ func main() {
// initialise commands
gauntlet.New(config, db)
out := gauntlet.Run("ne7split", `topa`)
out := gauntlet.Run("ne7split", `artist Begrime Exemious`)
if out != "" {
log.Println(out)
}
/*
st, err := store.NewBoltStore(db)
st, err := store.NewBoltStore(db)
if err != nil {
log.Fatalf("Error initialising database: %s", err.Error())
}
if err != nil {
log.Fatalf("Error initialising database: %s", err.Error())
}
inputChannel := make(chan *input.Message)
inputChannel := make(chan *input.Message)
input.Watch(inputChannel, func(m *input.Message) {
if m != nil {
log.Println(m)
}
})
input.Watch(inputChannel, func(m *input.Message) {
if m != nil {
log.Println(m)
}
})
*/
}
......@@ -39,7 +39,7 @@ func (f *Fn) getArtistInfo(artist string) (lastfm.ArtistGetInfo, error) {
}
func (f *Fn) fmtArtistInfo(artist lastfm.ArtistGetInfo) string {
return fmt.Sprintf("%s have %s plays and %s listeners. Similar artists: %s. Tags: %s",
return fmt.Sprintf("%s have %s plays and %s listeners. Similar artists: %s. Tags: %s.",
artist.Name,
artist.Stats.Plays,
artist.Stats.Listeners,
......@@ -49,9 +49,17 @@ func (f *Fn) fmtArtistInfo(artist lastfm.ArtistGetInfo) string {
}
func fmtArtistTags(artist lastfm.ArtistGetInfo) string {
var t []string
var (
t []string
for i := 0; i <= 4; i++ {
max = 4
)
if len(artist.Tags)-1 < max {
max = len(artist.Tags) - 1
}
for i := 0; i <= max; i++ {
t = append(t, artist.Tags[i].Name)
}
......@@ -59,11 +67,19 @@ func fmtArtistTags(artist lastfm.ArtistGetInfo) string {
}
func fmtArtistSimilar(artist lastfm.ArtistGetInfo) string {
var s []string
var (
s []string
for i := 0; i <= 4; i++ {
max = 4
)
if len(artist.Similars)-1 < max {
max = len(artist.Similars) - 1
}
for i := 0; i <= max; i++ {
s = append(s, artist.Similars[i].Name)
}
return strings.Join(s, ", ")
}
\ No newline at end of file
}
......@@ -187,10 +187,11 @@ func (f *Fn) fmtUserTrackStats(username string, track lastfm.TrackGetInfo) strin
func (f *Fn) fmtUserTop(username string, top lastfm.UserGetTopArtists) string {
var (
output []string
max = 9
)
if len(top.Artists) - 1 < max {
if len(top.Artists)-1 < max {
max = len(top.Artists) - 1
}
......
......@@ -41,8 +41,8 @@ func New(c *util.Config, db *bolt.DB) {
}
openCommands = map[string]command.OpenFnCommand{
"artist": fn.ArtistInfo,
"band": fn.ArtistInfo,
"artist": fn.ArtistInfo,
"band": fn.ArtistInfo,
}
}
......@@ -63,4 +63,4 @@ func Run(username string, message string) string {
}
return ""
}
\ No newline at end of file
}
......@@ -35,4 +35,4 @@ func NewConfig() *Config {
}
return c
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment