Beispiel #1
0
// RemoveReminder cancel a task
// command '/rmalarm'
func (rb *Robot) RemoveReminder(update tgbotapi.Update, step int) (ret string) {
	user := update.Message.Chat.UserName
	tmpAction := userAction[user]
	switch step {
	case 0:
		//init the struct
		tmpAction.ActionStep++
		userAction[user] = tmpAction
		tasks := conn.ReadUserTasks(user)
		if len(tasks) == 0 {
			delete(userAction, user)
			return "You have no alarm now, type '/alarm' to set one?"
		}
		ret = "Ok, which alarm do you want to remove?(type id)\n"
		userTaskIds[user] = make([]int, len(tasks))
		for i := range tasks {
			userTaskIds[user][i] = tasks[i].Id
			ret += fmt.Sprintf("%d. %s:  %s\n", i+1, tasks[i].When, tasks[i].Desc)
		}
	case 1:
		defer func() {
			delete(userAction, user)
			delete(userTaskIds, user)
		}()
		index, err := strconv.Atoi(update.Message.Text)
		if err != nil {
			return "please select the alarm id"
		}
		taskId := userTaskIds[user][index-1]
		//cancel the task
		abortTask[taskId] <- 1
		ret = "Ok, type '/alarms' to see your new alarms"
	}
	return
}
Beispiel #2
0
// GetTasks get the given  user's all tasks
// command 'alarms'
func (rb *Robot) GetTasks(update tgbotapi.Update) (ret string) {
	user := update.Message.Chat.UserName
	tasks := conn.ReadUserTasks(user)
	if len(tasks) == 0 {
		return "You have no alarm now, type '/alarm' to set one?"
	}
	for i := range tasks {
		ret += fmt.Sprintf("%d. %s:  %s\n", i+1, tasks[i].When, tasks[i].Desc)
	}
	return
}