Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions base/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ func (d *DebugOutput) Config() *ChatDebugOutputConfig {
return d.config
}

func (d *DebugOutput) Debug(format string, args ...interface{}) {
func (d *DebugOutput) Debug(format string, args ...any) {
msg := fmt.Sprintf(format, args...)
fmt.Printf("%s: %s\n", d.name, msg)
}

func (d *DebugOutput) Errorf(msg string, args ...interface{}) {
func (d *DebugOutput) Errorf(msg string, args ...any) {
d.Debug(msg, args...)
msg = fmt.Sprintf("```%s```", msg)
d.Report(msg, args...)
}

func (d *DebugOutput) Report(msg string, args ...interface{}) {
func (d *DebugOutput) Report(msg string, args ...any) {
if d.config == nil {
d.Debug("Errorf: Unable to report error to chat, errReportConv, chat debug not configured")
} else if d.config.ErrReportConv == "" || d.config.KBC == nil {
Expand All @@ -61,27 +61,27 @@ func (d *DebugOutput) Report(msg string, args ...interface{}) {
}
}

func (d *DebugOutput) ChatDebug(convID chat1.ConvIDStr, msg string, args ...interface{}) {
func (d *DebugOutput) ChatDebug(convID chat1.ConvIDStr, msg string, args ...any) {
d.Debug(msg, args...)
if _, err := d.config.KBC.SendMessageByConvID(convID, "Something went wrong!"); err != nil && !IsDeletedConvError(err) {
d.Errorf("ChatDebug: failed to send error message: %s", err)
}
}

func (d *DebugOutput) ChatErrorf(convID chat1.ConvIDStr, msg string, args ...interface{}) {
func (d *DebugOutput) ChatErrorf(convID chat1.ConvIDStr, msg string, args ...any) {
d.Errorf(msg, args...)
if _, err := d.config.KBC.SendMessageByConvID(convID, "Something went wrong!"); err != nil && !IsDeletedConvError(err) {
d.Errorf("ChatErrorf: failed to send error message: %s", err)
}
}

func (d *DebugOutput) ChatEcho(convID chat1.ConvIDStr, msg string, args ...interface{}) {
func (d *DebugOutput) ChatEcho(convID chat1.ConvIDStr, msg string, args ...any) {
if _, err := d.config.KBC.SendMessageByConvID(convID, msg, args...); err != nil && !IsDeletedConvError(err) {
d.Errorf("ChatEcho: failed to send echo message: %s", err)
}
}

func (d *DebugOutput) Trace(err *error, format string, args ...interface{}) func() {
func (d *DebugOutput) Trace(err *error, format string, args ...any) func() {
msg := fmt.Sprintf(format, args...)
start := time.Now()
fmt.Printf("+ %s: %s\n", d.name, msg)
Expand Down
8 changes: 2 additions & 6 deletions base/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"os"
"os/signal"
"slices"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -259,12 +260,7 @@ func (s *Server) listenForConvs(shutdownCh chan struct{}, sub *kbchat.Subscripti
}

func (s *Server) allowHiddenCommand(msg chat1.MsgSummary) bool {
for _, username := range s.botAdmins {
if username == msg.Sender.Username {
return true
}
}
return false
return slices.Contains(s.botAdmins, msg.Sender.Username)
}

func (s *Server) handleLogSend(msg chat1.MsgSummary) error {
Expand Down
2 changes: 1 addition & 1 deletion base/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *StathatBackend) Shutdown() error {
return nil
}

func NewStatsBackend(btype StatsBackendType, config interface{}) (StatsBackend, error) {
func NewStatsBackend(btype StatsBackendType, config any) (StatsBackend, error) {
switch btype {
case StathatStatsBackendType:
cfg, ok := config.(StathatConfig)
Expand Down
6 changes: 3 additions & 3 deletions base/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ var DefaultBotAdmins = []string{
"mikem",
}

func MsgpackDecode(dst interface{}, src []byte) error {
func MsgpackDecode(dst any, src []byte) error {
h := codecHandle()
return codec.NewDecoderBytes(src, h).Decode(dst)
}

func MsgpackEncode(src interface{}) ([]byte, error) {
func MsgpackEncode(src any) ([]byte, error) {
h := codecHandle()
var ret []byte
err := codec.NewEncoderBytes(&ret, h).Encode(src)
Expand Down Expand Up @@ -279,7 +279,7 @@ func MakeSecret(repo string, convID chat1.ConvIDStr, secret string) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(repo+string(ShortConvID(convID))+secret)))
}

func SendByConvNameOrID(kbc *kbchat.API, debugOutput *DebugOutput, name, msg string, args ...interface{}) (err error) {
func SendByConvNameOrID(kbc *kbchat.API, debugOutput *DebugOutput, name, msg string, args ...any) (err error) {
if _, err = kbc.SendMessageByConvID(chat1.ConvIDStr(name), msg, args...); err == nil {
return nil
}
Expand Down
5 changes: 1 addition & 4 deletions elastiwatch/elastiwatch/grouper.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ func (t *treeifyGrouper) buildForest(trees []*tree) (forest []*tree) {
return trees
}
numParts := len(trees[0].words)
minDist := numParts
if minDist > t.maxGroups {
minDist = t.maxGroups
}
minDist := min(numParts, t.maxGroups)
for _, loneTree := range trees {
consumed := false
for _, forestTree := range forest {
Expand Down
6 changes: 3 additions & 3 deletions elastiwatch/elastiwatch/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ func (h *Handler) handleDeferrals(convID chat1.ConvIDStr, _ string) error {
if err != nil {
return err
}
body := ""
var body strings.Builder
if len(deferrals) == 0 {
h.ChatEcho(convID, "No deferrals in use")
return nil
}
for _, d := range deferrals {
body += fmt.Sprintf("id: %d author: %s regex: %s (created: %v)\n", d.ID, d.Author, d.Regex, d.Ctime)
body.WriteString(fmt.Sprintf("id: %d author: %s regex: %s (created: %v)\n", d.ID, d.Author, d.Regex, d.Ctime))
}
h.ChatEcho(convID, "%s", body)
h.ChatEcho(convID, "%s", body.String())
return nil
}

Expand Down
8 changes: 5 additions & 3 deletions elastiwatch/elastiwatch/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"regexp"
"strings"
"time"

"github.com/keybase/go-keybase-chat-bot/kbchat/types/chat1"
Expand Down Expand Up @@ -79,14 +80,15 @@ func (l *LogWatch) alertFromChunk(c chunk) {
}

func (l *LogWatch) alertEmail(subject string, chunks []chunk) {
body := fmt.Sprintf("Email sent: %s", subject)
var body strings.Builder
body.WriteString(fmt.Sprintf("Email sent: %s", subject))
for _, c := range chunks {
if c.Severity == "INFO" {
continue
}
body += fmt.Sprintf("\n%s %d %s", c.Severity, c.Count, c.Message)
body.WriteString(fmt.Sprintf("\n%s %d %s", c.Severity, c.Count, c.Message))
}
l.ChatEcho(l.emailConvID, "```%s```", body)
l.ChatEcho(l.emailConvID, "```%s```", body.String())
}

func (l *LogWatch) filterEntries(entries []*entry) (res []*entry) {
Expand Down
2 changes: 1 addition & 1 deletion gcalbot/gcalbot/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (h *Handler) handleAccountsList(msg chat1.MsgSummary) error {
}

accountListMessage := "Here are your connected accounts:" + strings.Repeat("\n• %s", len(accounts))
accountInterfaces := make([]interface{}, len(accounts))
accountInterfaces := make([]any, len(accounts))
for index := range accounts {
accountInterfaces[index] = accounts[index].AccountNickname
}
Expand Down
2 changes: 1 addition & 1 deletion gcalbot/gcalbot/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (h *Handler) handleCalendarsList(msg chat1.MsgSummary, args []string) error
return nil
}

data := []interface{}{accountNickname}
data := []any{accountNickname}
for _, calendarItem := range calendarList {
if calendarItem.SummaryOverride != "" {
data = append(data, calendarItem.SummaryOverride)
Expand Down
12 changes: 6 additions & 6 deletions gcalbot/gcalbot/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ func FormatEvent(
}
}

var conferenceData string
var conferenceData strings.Builder
if event.ConferenceData != nil {
for _, entryPoint := range event.ConferenceData.EntryPoints {
uri := strings.TrimPrefix(entryPoint.Uri, "https://")
switch entryPoint.EntryPointType {
case "video", "more":
conferenceData += fmt.Sprintf("\n> Join online: %s", uri)
conferenceData.WriteString(fmt.Sprintf("\n> Join online: %s", uri))
case "phone":
conferenceData += fmt.Sprintf("\n> Join by phone: %s", entryPoint.Label)
conferenceData.WriteString(fmt.Sprintf("\n> Join by phone: %s", entryPoint.Label))
if entryPoint.Pin != "" {
conferenceData += fmt.Sprintf(" PIN: %s", entryPoint.Pin)
conferenceData.WriteString(fmt.Sprintf(" PIN: %s", entryPoint.Pin))
}
case "sip":
conferenceData += fmt.Sprintf("\n> Join by SIP: %s", entryPoint.Label)
conferenceData.WriteString(fmt.Sprintf("\n> Join by SIP: %s", entryPoint.Label))
}
}
}
Expand All @@ -101,7 +101,7 @@ func FormatEvent(
url := strings.TrimPrefix(event.HtmlLink, "https://")

return fmt.Sprintf(message,
what, when, where, conferenceData, organizer, calendarSummary, description, url), nil
what, when, where, conferenceData.String(), organizer, calendarSummary, description, url), nil
}

func FormatEventSchedule(
Expand Down
2 changes: 1 addition & 1 deletion gcalbot/gcalbot/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ var templates = template.Must(template.Must(template.Must(template.Must(template
},
}).Parse(tmplConfig))

func (h *HTTPSrv) servePage(w http.ResponseWriter, name string, data interface{}) {
func (h *HTTPSrv) servePage(w http.ResponseWriter, name string, data any) {
var page bytes.Buffer
if err := templates.ExecuteTemplate(&page, name, data); err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion gcalbot/gcalbot/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (h *HTTPSrv) configHandler(w http.ResponseWriter, r *http.Request) {
}
// get list of times in half hour increments
baseTime := time.Date(2006, time.January, 2, 0, 0, 0, 0, dsTimezone)
for i := 0; i < 48; i++ {
for i := range 48 {
var title string
minutes := i * 30
dateTime := baseTime.Add(time.Duration(minutes) * time.Minute)
Expand Down
8 changes: 4 additions & 4 deletions githubbot/githubbot/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,21 @@ func (h *Handler) handleListSubscriptions(msg chat1.MsgSummary) (err error) {
return nil
}

var res string
var res strings.Builder
for repo, f := range features {
res += fmt.Sprintf("- *%s* (%s)\n", repo, &f)
res.WriteString(fmt.Sprintf("- *%s* (%s)\n", repo, &f))
if f.Commits {
branches, err := h.db.GetAllBranchesForRepo(msg.ConvID, repo)
if err != nil {
return fmt.Errorf("error getting branches for repo: %s", err)
}

for _, branch := range branches {
res += fmt.Sprintf(" - %s\n", branch)
res.WriteString(fmt.Sprintf(" - %s\n", branch))
}
}
}
h.ChatEcho(msg.ConvID, "%s", res)
h.ChatEcho(msg.ConvID, "%s", res.String())
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion githubbot/githubbot/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (h *HTTPSrv) handleWebhook(_ http.ResponseWriter, r *http.Request) {
}
}

func (h *HTTPSrv) formatMessage(convID chat1.ConvIDStr, event interface{}, repo string, client *github.Client) (message string, branch string) {
func (h *HTTPSrv) formatMessage(convID chat1.ConvIDStr, event any, repo string, client *github.Client) (message string, branch string) {
parsedRepo := strings.Split(repo, "/")
if len(parsedRepo) != 2 {
h.Debug("invalid repo: %s", repo)
Expand Down
2 changes: 1 addition & 1 deletion githubbot/githubbot/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func getPossibleKBUser(kbc *kbchat.API, d *DB, debug *base.DebugOutput, githubUs
}

// pref checking
func shouldParseEvent(event interface{}, features *Features) bool {
func shouldParseEvent(event any, features *Features) bool {
if features == nil {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions gitlabbot/gitlabbot/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ func (h *Handler) handleListSubscriptions(msg chat1.MsgSummary) (err error) {
return nil
}

var res string
var res strings.Builder
for _, repo := range subscriptions {
res += fmt.Sprintf("- *%s*\n", repo)
res.WriteString(fmt.Sprintf("- *%s*\n", repo))
}
h.ChatEcho(msg.ConvID, "%s", res)
h.ChatEcho(msg.ConvID, "%s", res.String())
return nil
}
2 changes: 1 addition & 1 deletion macrobot/macrobot/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (h *Handler) handleList(msg chat1.MsgSummary) error {
return nil
}

data := []interface{}{getChannelType(msg.Channel, true)}
data := []any{getChannelType(msg.Channel, true)}
hasConvs := false
for i, macro := range macroList {
// If we have a team and conv command defined with the same name we
Expand Down
17 changes: 9 additions & 8 deletions pollbot/pollbot/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ func (h *Handler) generateAnonymousPoll(convID chat1.ConvIDStr, prompt string, o
return fmt.Errorf("failed to get ID of prompt message")
}
promptMsgID := *sendRes.Result.MessageID
var body string
var body strings.Builder
for index, option := range options {
body += fmt.Sprintf("\n%s *%s*\n%s\n", base.NumberToEmoji(index+1), option,
h.generateVoteLink(id, index+1))
body.WriteString(fmt.Sprintf("\n%s *%s*\n%s\n", base.NumberToEmoji(index+1), option,
h.generateVoteLink(id, index+1)))
}
h.ChatEcho(convID, "%s", body)
h.ChatEcho(convID, "%s", body.String())
if sendRes, err = h.kbc.SendMessageByConvID(convID, "*Results*\n_No votes yet_"); err != nil {
return fmt.Errorf("failed to send poll: %s", err)
}
Expand All @@ -78,12 +78,13 @@ func (h *Handler) generateAnonymousPoll(convID chat1.ConvIDStr, prompt string, o
}

func (h *Handler) generatePoll(convID chat1.ConvIDStr, prompt string, options []string) error {
body := fmt.Sprintf("Poll: *%s*\n\n", prompt)
var body strings.Builder
body.WriteString(fmt.Sprintf("Poll: *%s*\n\n", prompt))
for index, option := range options {
body += fmt.Sprintf("%s %s\n", base.NumberToEmoji(index+1), option)
body.WriteString(fmt.Sprintf("%s %s\n", base.NumberToEmoji(index+1), option))
}
body += "Tap a reaction below to register your vote!"
sendRes, err := h.kbc.SendMessageByConvID(convID, "%s", body)
body.WriteString("Tap a reaction below to register your vote!")
sendRes, err := h.kbc.SendMessageByConvID(convID, "%s", body.String())
if err != nil {
return fmt.Errorf("failed to send poll: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pollbot/pollbot/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func formatTally(tally Tally, numChoices int) (res string) {
for _, t := range tally {
tallyMap[t.choice] = t
}
for i := 0; i < numChoices; i++ {
for i := range numChoices {
t, ok := tallyMap[i+1]
if !ok {
t.choice = i + 1
Expand Down
6 changes: 3 additions & 3 deletions webhookbot/webhookbot/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func (h *Handler) handleList(_ string, msg chat1.MsgSummary) (err error) {
h.ChatEcho(convID, "No hooks in this conversation")
return nil
}
var body string
var body strings.Builder
for _, hook := range hooks {
body += fmt.Sprintf("%s, %s\n", hook.Name, h.formURL(hook.ID))
body.WriteString(fmt.Sprintf("%s, %s\n", hook.Name, h.formURL(hook.ID)))
}
if _, err := h.kbc.SendMessageByTlfName(msg.Sender.Username, "%s", body); err != nil {
if _, err := h.kbc.SendMessageByTlfName(msg.Sender.Username, "%s", body.String()); err != nil {
h.Debug("handleList: failed to send hook: %s", err)
}
h.ChatEcho(convID, "List sent to @%s", msg.Sender.Username)
Expand Down
Loading