Using golang's time.NewTicker, I am trying to run each record from a database (consisting of text and a timer, i.e the number of seconds before it repeats) but it is only repeating the first record it grabs
func LoadTimedCommands() map[string]time.Duration {
database := InitializeDB()
rows, _ := database.Query("SELECT TimedResponse, Timer from timedcommands")
com := make(map[string]time.Duration)
for rows.Next() {
var TimedResponse string
var Timer time.Duration
rows.Scan(&TimedResponse, &Timer)
com[TimedResponse] = Timer
}
return com
}
func TimedCommands(conn net.Conn, channel string, name string) {
timedcoms := LoadTimedCommands()
for k, v := range timedcoms {
for range time.NewTicker(v * time.Second).C {
BotSendMsg(conn, channel, k, name)
}
}
}
So if I have two records to use from: Sqlite data
Then the code should run the first record every 15 seconds, and the second every 10. But again, only the first one that is loaded into the map is run.