|
|
|
@ -158,7 +158,7 @@ func dynamicCommandHandler(rtm *slack.RTM, ev *slack.MessageEvent, redisClient *
|
|
|
|
|
} |
|
|
|
|
newhandler(rtm, ev, content, "lore", redisClient) |
|
|
|
|
case "rmlore": |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("command not yet supported", ev.Channel)) |
|
|
|
|
rmhandler(rtm, ev, content, "lore", redisClient) |
|
|
|
|
case "rek": |
|
|
|
|
s := strings.SplitN(string(ev.Text), " ", 2) |
|
|
|
|
rekhandler(rtm, ev, s[1], redisClient) |
|
|
|
@ -313,6 +313,42 @@ func loreNewString(nick, newString, newType string, redisClient *redis.Client) e
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func loreRmString(nick, rmString, rmType string, redisClient *redis.Client) error { |
|
|
|
|
t := time.Now() |
|
|
|
|
|
|
|
|
|
// remove content
|
|
|
|
|
keyString := fmt.Sprintf("%s:%s:%s", rmType, rmString, "content") |
|
|
|
|
redisClient.Del(keyString) |
|
|
|
|
//redisClient.Set(keyString, "--LORE HAS BEEN REMOVED--", 0)
|
|
|
|
|
|
|
|
|
|
// set "removed by"
|
|
|
|
|
attribute := "rmby" |
|
|
|
|
setstring := fmt.Sprintf("%s:%s:%s", rmType, rmString, attribute) |
|
|
|
|
redisClient.Set(setstring, nick, 0) |
|
|
|
|
|
|
|
|
|
// set removed date
|
|
|
|
|
attribute = "rmdate" |
|
|
|
|
date := t.Format("2006-01-02 15:04:05") |
|
|
|
|
setstring = fmt.Sprintf("%s:%s:%s", rmType, rmString, attribute) |
|
|
|
|
redisClient.Set(setstring, date, 0) |
|
|
|
|
|
|
|
|
|
// append to deleted index
|
|
|
|
|
appendIndex := fmt.Sprintf("index:%s:removed", rmType) |
|
|
|
|
appendString := fmt.Sprintf(" %s", rmString) |
|
|
|
|
redisClient.Append(appendIndex, appendString) |
|
|
|
|
|
|
|
|
|
// remove from added index
|
|
|
|
|
queryString := fmt.Sprintf("index:%s:added", rmType) |
|
|
|
|
tmpIndex, _ := loreQuery(queryString, redisClient) |
|
|
|
|
// add a space to the beginning of string to replace
|
|
|
|
|
formattedString := fmt.Sprintf(" %s ", rmString) |
|
|
|
|
// find and replace
|
|
|
|
|
newIndex := strings.Replace(tmpIndex, formattedString, " ", -1) |
|
|
|
|
redisClient.Set(queryString, newIndex, 0) |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func loreAttrQuery(queryString, queryType, queryAttr string, redisClient *redis.Client) (string, error) { |
|
|
|
|
searchString := fmt.Sprintf("%s:%s:%s", queryType, queryAttr, queryString) |
|
|
|
|
|
|
|
|
@ -394,3 +430,20 @@ func newhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, newType string,
|
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("entry could not be created", ev.Channel)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func rmhandler(rtm *slack.RTM, ev *slack.MessageEvent, message, rmType string, redisClient *redis.Client) { |
|
|
|
|
// get nick from slack api
|
|
|
|
|
user, err := rtm.GetUserInfo(ev.User) |
|
|
|
|
if err != nil { |
|
|
|
|
fmt.Printf("%s\n", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
nick := fmt.Sprintf("%s", user.Name) |
|
|
|
|
|
|
|
|
|
err = loreRmString(nick, message, rmType, redisClient) |
|
|
|
|
if err == nil { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("entry removed", ev.Channel)) |
|
|
|
|
} else { |
|
|
|
|
rtm.SendMessage(rtm.NewOutgoingMessage("entry could not be removed", ev.Channel)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|