func (s *SlackLink) handleSlackMessage(msg *slack.MessageEvent) { info := s.slack.GetInfo() if msg.User == "" || msg.User == info.User.ID { return } msg.Text = html.UnescapeString(msg.Text) if strings.HasPrefix(msg.Text, ".") { // Always handle commands, regardless of channel s.forwardSlackMessageToChatLink(msg, false) return } channel := info.GetChannelByID(msg.Channel) if channel == nil { // We don't know about this channel. return } switch channel.Name { case "minecraft": case "minecraft-ops": msg.Text = "#" + msg.Text default: return } s.forwardSlackMessageToChatLink(msg, true) }
func newMessageEvent(text, user string) *slack.MessageEvent { ret := new(slack.MessageEvent) ret.Text = text ret.User = user return ret }
func (s *SlackLink) forwardSlackMessageToChatLink(msg *slack.MessageEvent, specialAcknowledgement bool) { if strings.HasPrefix(msg.Text, ".") { msg.Text = "/" + msg.Text[1:] } minecraftAccount := s.getMinecraftFromSlack(msg.User) if minecraftAccount == nil { // They aren't associated with an account. Ignore. return } muuid, _ := uuid.NewRandom() cmi := &ChatMessageIn{ Server: "Slack", Context: muuid, Type: messages.MessageType_TEXT, From: minecraftAccount, Timestamp: parseSlackTimestamp(msg.Timestamp), Contents: msg.Text, } s.addContextAssociation(cmi.Context, msg.Channel) if specialAcknowledgement { cleanedMessage := cmi.Contents if strings.HasPrefix(cleanedMessage, "#") { cleanedMessage = cleanedMessage[1:] } ref := slack.NewRefToMessage(msg.Channel, msg.Timestamp) s.addSpecialAcknowledgementContext(cmi.Context, &ref, cleanedMessage) } s.chatLinkOut <- CMIToProtoCMI(cmi) }
func anzuMessageProcess(bot *Anzu, e *slack.MessageEvent) interface{} { force_accept := false switch { case e.Text == "사람은 일을 하고 살아야한다. 메우": return "이거 놔라 이 퇴근도 못하는 놈이" case e.Text == "안즈쨩 뭐해?": return "숨셔" default: if AcceptRE(e.Text, give_candy_re) { last := bot.rc.Get(fmt.Sprintf("%s_lastfail", e.User)).Val() if last == "" { return "" } force_accept = true e.Text = last } if matched, ok := MatchRE(e.Text, remember_re); ok { key, val := strings.TrimSpace(matched[1]), strings.TrimSpace(matched[2]) var ret string switch { case key == "" || val == "": ret = "에...?" case AcceptRE(val, tell_re): ret = "에... 귀찮아..." case force_accept: ret = "응응 기억했어" fallthrough case rand.Float32() < 0.4: bot.rc.Set(key, val, 0) if len(ret) == 0 { ret = "에... 귀찮지만 기억했어" } default: ret = "귀찮아..." bot.rc.Set(fmt.Sprintf("%s_lastfail", e.User), e.Text, time.Duration(300*time.Second)) } return ret } else if matched, ok := MatchRE(e.Text, tell_re); ok { key := strings.TrimSpace(matched[1]) val := bot.rc.Get(key).Val() var ret string switch { case val == "": ret = "그런거 몰라" case force_accept: ret = fmt.Sprintf("%s 물어봤지? %s 야", key, val) case rand.Float32() < 0.4: ret = val default: bot.rc.Set(fmt.Sprintf("%s_lastfail", e.User), e.Text, time.Duration(300*time.Second)) ret = "Zzz..." } return ret } else if _, ok := MatchRE(e.Text, kawaii_re); ok { return "뭐... 뭐라는거야" } else if matched, ok := MatchRE(e.Text, dice); ok { num, e := strconv.Atoi(matched[1]) if e != nil { return "주사위는 정수만 가능해" } return fmt.Sprintf("%d", int(float32(num-1)*rand.Float32())+1) } } return nil }