Example #1
0
func (bugger *Bugger) ChatHandler(conv *slick.Conversation, msg *slick.Message) {

	if !msg.MentionsMe {
		return
	}

	if msg.ContainsAny([]string{"bug report", "bug count"}) && msg.ContainsAny([]string{"how", "help"}) {

		var report string

		if msg.Contains("bug report") {
			report = "bug report"
		} else {
			report = "bug count"
		}
		mention := bugger.bot.Config.Nickname

		conv.Reply(msg, fmt.Sprintf(
			`Usage: %s, [give me a | insert demand]  <%s>  [from the | syntax filler] [last | past] [n] [days | weeks]
examples: %s, please give me a %s over the last 5 days
%s, produce a %s   (7 day default)
%s, I want a %s from the past 2 weeks
%s, %s from the past week`, mention, report, mention, report, mention, report, mention, report, mention, report))

	} else if msg.Contains("bug report") {

		days := util.GetDaysFromQuery(msg.Text)
		bugger.messageReport(days, msg, conv, func() string {
			reporter := bugger.makeBugReporter(days)
			return reporter.printReport(days)
		})

	} else if msg.Contains("bug count") {

		days := util.GetDaysFromQuery(msg.Text)
		bugger.messageReport(days, msg, conv, func() string {
			reporter := bugger.makeBugReporter(days)
			return reporter.printCount(days)
		})

	}

	return

}
Example #2
0
func (standup *Standup) ChatHandler(conv *slick.Conversation, msg *slick.Message) {
	res := sectionRegexp.FindAllStringSubmatchIndex(msg.Text, -1)
	if res != nil {
		for _, section := range extractSectionAndText(msg.Text, res) {
			standup.TriggerReminders(msg, section.name)
			err := standup.StoreLine(msg, section.name, section.text)
			if err != nil {
				log.Println(err)
			}
		}
	} else if msg.MentionsMe && msg.Contains("standup report") {
		daysAgo := util.GetDaysFromQuery(msg.Text)
		smap, err := standup.getRange(getStandupDate(-daysAgo), getStandupDate(TODAY))
		if err != nil {
			log.Println(err)
			conv.Reply(msg, standup.bot.WithMood("Sorry, could not retrieve your report...",
				"I am the eggman and the walrus ate your report - Fzaow!"))
		} else {
			if msg.Contains(" my ") {
				conv.Reply(msg, "/quote "+smap.filterByEmail(msg.FromUser.Profile.Email).String())
			} else {
				conv.Reply(msg, "/quote "+smap.String())
			}
		}
	}
}
Example #3
0
func (bugger *Bugger) messageReport(days int, msg *slick.Message, conv *slick.Conversation, genReport func() string) {

	if days > 31 {
		conv.Reply(msg, fmt.Sprintf("Whaoz, %d is too much data to compile - well maybe not, I am just scared", days))
		return
	}

	conv.Reply(msg, bugger.bot.WithMood("Building report - one moment please",
		"Whaooo! Pinging those githubbers - Let's do this!"))

	conv.Reply(msg, genReport())

}
Example #4
0
func (wicked *Wicked) ChatHandler(conv *slick.Conversation, msg *slick.Message) {
	bot := conv.Bot
	uuidNow := time.Now()

	if strings.HasPrefix(msg.Text, "!wicked ") {
		fromRoom := ""
		if msg.FromChannel != nil {
			fromRoom = msg.FromChannel.Id
		}

		availableRoom := wicked.FindAvailableRoom(fromRoom)

		if availableRoom == nil {
			conv.Reply(msg, "No available Wicked Confroom for a meeting! Seems you'll need to create new Wicked Confrooms !")
			goto continueLogging
		}

		id := wicked.NextMeetingID()
		meeting := NewMeeting(id, msg.FromUser, msg.Text[7:], bot, availableRoom, uuidNow)

		wicked.pastMeetings = append(wicked.pastMeetings, meeting)
		wicked.meetings[availableRoom.Id] = meeting

		if availableRoom.Id == fromRoom {
			meeting.sendToRoom(fmt.Sprintf(`*** Starting wicked meeting W%s in here.`, meeting.ID))
		} else {
			conv.Reply(msg, fmt.Sprintf(`*** Starting wicked meeting W%s in room "%s". Join with !join W%s`, meeting.ID, availableRoom.Name, meeting.ID))
			initiatedFrom := ""
			if fromRoom != "" {
				initiatedFrom = fmt.Sprintf(` in "%s"`, msg.FromChannel.Name)
			}
			meeting.sendToRoom(fmt.Sprintf(`*** Wicked meeting initiated by @%s%s. Goal: %s`, msg.FromUser.Name, initiatedFrom, meeting.Goal))
		}

		meeting.sendToRoom(fmt.Sprintf(`*** Access report at %s/wicked/%s.html`, wicked.bot.Config.WebBaseURL, meeting.ID))
		meeting.setTopic(fmt.Sprintf(`[Running] W%s goal: %s`, meeting.ID, meeting.Goal))
	} else if strings.HasPrefix(msg.Text, "!join") {
		match := joinMatcher.FindStringSubmatch(msg.Text)
		if match == nil {
			conv.ReplyMention(msg, `invalid !join syntax. Use something like "!join W123"`)
		} else {
			for _, meeting := range wicked.meetings {
				if match[1] == meeting.ID {
					meeting.sendToRoom(fmt.Sprintf(`*** @%s asked to join`, msg.FromUser.Name))
				}
			}
		}
	}

continueLogging:

	//
	// Public commands and messages
	//
	if msg.FromChannel == nil {
		return
	}
	room := msg.FromChannel.Id
	meeting, meetingExists := wicked.meetings[room]
	if !meetingExists {
		return
	}

	user := meeting.ImportUser(msg.FromUser)

	if strings.HasPrefix(msg.Text, "!proposition ") {
		decision := meeting.AddDecision(user, msg.Text[12:], uuidNow)
		if decision == nil {
			conv.Reply(msg, "Whoops, wrong syntax for !proposition")
		} else {
			conv.Reply(msg, fmt.Sprintf("Proposition added, ref: D%s", decision.ID))
		}

	} else if strings.HasPrefix(msg.Text, "!ref ") {

		meeting.AddReference(user, msg.Text[4:], uuidNow)
		conv.Reply(msg, "Ref. added")

	} else if strings.HasPrefix(msg.Text, "!conclude") {
		meeting.Conclude()
		// TODO: kill all waiting goroutines dealing with messaging
		delete(wicked.meetings, room)
		meeting.sendToRoom("Concluding Wicked meeting, that's all folks!")
		meeting.setTopic(fmt.Sprintf(`[Concluded] W%s goal: %s`, meeting.ID, meeting.Goal))

	} else if match := decisionMatcher.FindStringSubmatch(msg.Text); match != nil {

		decision := meeting.GetDecisionByID(match[1])
		if decision != nil {
			decision.RecordPlusplus(user)
			conv.ReplyMention(msg, "noted")
		}

	}

	// Log message
	newMessage := &Message{
		From:      user,
		Timestamp: uuidNow,
		Text:      msg.Text,
	}
	meeting.Logs = append(meeting.Logs, newMessage)
}
Example #5
0
// Handler
func (healthy *Healthy) ChatHandler(conv *slick.Conversation, msg *slick.Message) {
	log.Println("Health check. Requested by", msg.FromUser.Name)
	conv.Reply(msg, healthy.CheckAll())
}
Example #6
0
func (dep *Deployer) ChatHandler(conv *slick.Conversation, msg *slick.Message) {
	bot := conv.Bot

	// Discard non "mention_name, " prefixed messages
	if !strings.HasPrefix(msg.Text, fmt.Sprintf("%s, ", bot.Config.Nickname)) {
		return
	}

	if match := deployFormat.FindStringSubmatch(msg.Text); match != nil {
		if dep.lockedBy != "" {
			conv.Reply(msg, fmt.Sprintf("Deployment was locked by %s.  Unlock with '%s, unlock deployment' if they're OK with it.", dep.lockedBy, dep.bot.Config.Nickname))
			return
		}
		if dep.runningJob != nil {
			params := dep.runningJob.params
			conv.Reply(msg, fmt.Sprintf("@%s Deploy currently running: %s", msg.FromUser.Name, params))
			return
		} else {
			params := &DeployParams{
				Environment:      match[3],
				Branch:           match[2],
				Tags:             match[8],
				DeploymentBranch: match[5],
				InitiatedBy:      msg.FromUser.RealName,
				From:             "chat",
				initiatedByChat:  msg,
			}
			go dep.handleDeploy(params)
		}
		return

	} else if msg.Contains("cancel deploy") {

		if dep.runningJob == nil {
			conv.Reply(msg, "No deploy running, sorry man..")
		} else {
			if dep.runningJob.killing == true {
				conv.Reply(msg, "deploy: Interrupt signal already sent, waiting to die")
				return
			} else {
				conv.Reply(msg, "deploy: Sending Interrupt signal...")
				dep.runningJob.killing = true
				dep.runningJob.kill <- true
			}
		}
		return
	} else if msg.Contains("in the pipe") {
		url := dep.getCompareUrl("prod", dep.config.DefaultStreambedBranch)
		mention := msg.FromUser.Name
		if url != "" {
			conv.Reply(msg, fmt.Sprintf("@%s in %s branch, waiting to reach prod: %s", mention, dep.config.DefaultStreambedBranch, url))
		} else {
			conv.Reply(msg, fmt.Sprintf("@%s couldn't get current revision on prod", mention))
		}
	} else if msg.Contains("unlock deploy") {
		dep.lockedBy = ""
		conv.Reply(msg, fmt.Sprintf("Deployment is now unlocked."))
		bot.Notify(dep.config.AnnounceRoom, "purple", "text", fmt.Sprintf("%s has unlocked deployment", msg.FromUser.Name), true)
	} else if msg.Contains("lock deploy") {
		dep.lockedBy = msg.FromUser.Name
		conv.Reply(msg, fmt.Sprintf("Deployment is now locked.  Unlock with '%s, unlock deployment' ASAP!", dep.bot.Config.Nickname))
		bot.Notify(dep.config.AnnounceRoom, "purple", "text", fmt.Sprintf("%s has locked deployment", dep.lockedBy), true)
	} else if msg.Contains("deploy") || msg.Contains("push to") {
		mention := dep.bot.Config.Nickname
		conv.Reply(msg, fmt.Sprintf(`Usage: %s, [please|insert reverence] deploy [<branch-name>] to <environment> [using <deployment-branch>][, tags: <ansible-playbook tags>, ..., ...]
examples: %s, please deploy to prod
%s, deploy thing-to-test to stage
%s, deploy complicated-thing to stage, tags: updt_streambed, blow_up_the_sun
other commands: %s, what's in the pipe? - show what's waiting to be deployed to prod
%s, lock deployment - prevent deployment until it's unlocked`, mention, mention, mention, mention, mention, mention))
	}
}
Example #7
0
func (plotberry *PlotBerry) ChatHandler(conv *slick.Conversation, msg *slick.Message) {
	if msg.MentionsMe && msg.Contains("how many user") {
		conv.Reply(msg, fmt.Sprintf("We got %d users!", plotberry.totalUsers))
	}
	return
}
Example #8
0
File: totw.go Project: plotly/slick
func (totw *Totw) ChatHandler(conv *slick.Conversation, msg *slick.Message) {
	if strings.HasPrefix(msg.Text, "!totw") || strings.HasPrefix(msg.Text, "!techoftheweek") {
		conv.ReplyMention(msg, slick.RandomString("tech adept"))
	}
}