func (r *cronRuleset) attach(self bot.Self, ruleName, room string) string { r.mu.Lock() defer r.mu.Unlock() if _, ok := r.cronRules[ruleName]; !ok { return ruleName + " not found" } for _, rn := range r.attachedCrons[room] { if rn == ruleName { return ruleName + " already attached to this room" } } r.attachedCrons[room] = append(r.attachedCrons[room], ruleName) b, err := json.Marshal(r.attachedCrons) if err != nil { return fmt.Sprintf("error attaching %s: %v", ruleName, err) } self.MemorySave("cron", "attached", b) return ruleName + " attached to this room" }
func (r *cronRuleset) detach(self bot.Self, ruleName, room string) string { r.mu.Lock() defer r.mu.Unlock() if _, ok := r.attachedCrons[room]; !ok { return "room not found in cron memory" } var newRoom []string for _, rn := range r.attachedCrons[room] { if rn == ruleName { continue } newRoom = append(newRoom, rn) } r.attachedCrons[room] = newRoom b, err := json.Marshal(r.attachedCrons) if err != nil { return fmt.Sprintf("error detaching %s: %v", ruleName, err) } self.MemorySave("cron", "attached", b) return ruleName + " detached to this room" }