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
2 changes: 1 addition & 1 deletion examples/echobot/echobot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/keybase/go-keybase-chat-bot/kbchat"
)

func fail(msg string, args ...interface{}) {
func fail(msg string, args ...any) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(3)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/helloworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/keybase/go-keybase-chat-bot/kbchat"
)

func fail(msg string, args ...interface{}) {
func fail(msg string, args ...any) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(3)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/secret_storage/secret_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (r *RentalBotClient) ListTools() ([]string, error) {
return tools, nil
}

func fail(msg string, args ...interface{}) {
func fail(msg string, args ...any) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(3)
}
Expand Down
44 changes: 22 additions & 22 deletions kbchat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ type sendMessageBody struct {
}

type sendMessageOptions struct {
Channel chat1.ChatChannel `json:"channel,omitempty"`
Channel chat1.ChatChannel `json:"channel"`
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
Message sendMessageBody `json:",omitempty"`
Filename string `json:"filename,omitempty"`
Title string `json:"title,omitempty"`
MsgID chat1.MessageID `json:"message_id,omitempty"`
ConfirmLumenSend bool `json:"confirm_lumen_send"`
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
Message sendMessageBody
Filename string `json:"filename,omitempty"`
Title string `json:"title,omitempty"`
MsgID chat1.MessageID `json:"message_id,omitempty"`
ConfirmLumenSend bool `json:"confirm_lumen_send"`
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
}

type sendMessageParams struct {
Expand Down Expand Up @@ -122,7 +122,7 @@ func (a *API) GetTextMessages(channel chat1.ChatChannel, unreadOnly bool) ([]cha
return res, nil
}

func (a *API) SendMessage(channel chat1.ChatChannel, body string, args ...interface{}) (resp SendResponse, err error) {
func (a *API) SendMessage(channel chat1.ChatChannel, body string, args ...any) (resp SendResponse, err error) {
defer a.Trace(&err, "SendMessage")()
arg := newSendArg(sendMessageOptions{
Channel: channel,
Expand All @@ -133,14 +133,14 @@ func (a *API) SendMessage(channel chat1.ChatChannel, body string, args ...interf
return a.doSend(arg)
}

func (a *API) Broadcast(body string, args ...interface{}) (SendResponse, error) {
func (a *API) Broadcast(body string, args ...any) (SendResponse, error) {
return a.SendMessage(chat1.ChatChannel{
Name: a.GetUsername(),
Public: true,
}, body, args...)
}

func (a *API) SendMessageByConvID(convID chat1.ConvIDStr, body string, args ...interface{}) (resp SendResponse, err error) {
func (a *API) SendMessageByConvID(convID chat1.ConvIDStr, body string, args ...any) (resp SendResponse, err error) {
defer a.Trace(&err, "SendMessageByConvID")()
arg := newSendArg(sendMessageOptions{
ConversationID: convID,
Expand All @@ -152,7 +152,7 @@ func (a *API) SendMessageByConvID(convID chat1.ConvIDStr, body string, args ...i
}

// SendMessageByTlfName sends a message on the given TLF name
func (a *API) SendMessageByTlfName(tlfName string, body string, args ...interface{}) (resp SendResponse, err error) {
func (a *API) SendMessageByTlfName(tlfName string, body string, args ...any) (resp SendResponse, err error) {
defer a.Trace(&err, "SendMessageByTlfName")()
arg := newSendArg(sendMessageOptions{
Channel: chat1.ChatChannel{
Expand All @@ -165,7 +165,7 @@ func (a *API) SendMessageByTlfName(tlfName string, body string, args ...interfac
return a.doSend(arg)
}

func (a *API) SendMessageByTeamName(teamName string, inChannel *string, body string, args ...interface{}) (resp SendResponse, err error) {
func (a *API) SendMessageByTeamName(teamName string, inChannel *string, body string, args ...any) (resp SendResponse, err error) {
defer a.Trace(&err, "SendMessageByTeamName")()
channel := "general"
if inChannel != nil {
Expand All @@ -184,7 +184,7 @@ func (a *API) SendMessageByTeamName(teamName string, inChannel *string, body str
return a.doSend(arg)
}

func (a *API) SendReply(channel chat1.ChatChannel, replyTo *chat1.MessageID, body string, args ...interface{}) (SendResponse, error) {
func (a *API) SendReply(channel chat1.ChatChannel, replyTo *chat1.MessageID, body string, args ...any) (SendResponse, error) {
arg := newSendArg(sendMessageOptions{
Channel: channel,
Message: sendMessageBody{
Expand All @@ -195,7 +195,7 @@ func (a *API) SendReply(channel chat1.ChatChannel, replyTo *chat1.MessageID, bod
return a.doSend(arg)
}

func (a *API) SendReplyByConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID, body string, args ...interface{}) (SendResponse, error) {
func (a *API) SendReplyByConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID, body string, args ...any) (SendResponse, error) {
arg := newSendArg(sendMessageOptions{
ConversationID: convID,
Message: sendMessageBody{
Expand All @@ -206,7 +206,7 @@ func (a *API) SendReplyByConvID(convID chat1.ConvIDStr, replyTo *chat1.MessageID
return a.doSend(arg)
}

func (a *API) SendReplyByTlfName(tlfName string, replyTo *chat1.MessageID, body string, args ...interface{}) (SendResponse, error) {
func (a *API) SendReplyByTlfName(tlfName string, replyTo *chat1.MessageID, body string, args ...any) (SendResponse, error) {
arg := newSendArg(sendMessageOptions{
Channel: chat1.ChatChannel{
Name: tlfName,
Expand Down Expand Up @@ -418,7 +418,7 @@ func (a *API) LeaveChannel(teamName string, channelName string) (chat1.EmptyRes,
// Send lumens in chat /////////////////////////////////
////////////////////////////////////////////////////////

func (a *API) InChatSend(channel chat1.ChatChannel, body string, args ...interface{}) (SendResponse, error) {
func (a *API) InChatSend(channel chat1.ChatChannel, body string, args ...any) (SendResponse, error) {
arg := newSendArg(sendMessageOptions{
Channel: channel,
Message: sendMessageBody{
Expand All @@ -429,7 +429,7 @@ func (a *API) InChatSend(channel chat1.ChatChannel, body string, args ...interfa
return a.doSend(arg)
}

func (a *API) InChatSendByConvID(convID chat1.ConvIDStr, body string, args ...interface{}) (SendResponse, error) {
func (a *API) InChatSendByConvID(convID chat1.ConvIDStr, body string, args ...any) (SendResponse, error) {
arg := newSendArg(sendMessageOptions{
ConversationID: convID,
Message: sendMessageBody{
Expand All @@ -440,7 +440,7 @@ func (a *API) InChatSendByConvID(convID chat1.ConvIDStr, body string, args ...in
return a.doSend(arg)
}

func (a *API) InChatSendByTlfName(tlfName string, body string, args ...interface{}) (SendResponse, error) {
func (a *API) InChatSendByTlfName(tlfName string, body string, args ...any) (SendResponse, error) {
arg := newSendArg(sendMessageOptions{
Channel: chat1.ChatChannel{
Name: tlfName,
Expand Down Expand Up @@ -501,7 +501,7 @@ type clearCmdsParams struct {

type clearCmdsArg struct {
Method string `json:"method"`
Params clearCmdsParams `json:"params,omitempty"`
Params clearCmdsParams `json:"params"`
}

func (a *API) ClearCommands(filter *chat1.ClearCommandAPIParam) error {
Expand All @@ -517,7 +517,7 @@ func (a *API) ClearCommands(filter *chat1.ClearCommandAPIParam) error {
}

type listCmdsOptions struct {
Channel chat1.ChatChannel `json:"channel,omitempty"`
Channel chat1.ChatChannel `json:"channel"`
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
}

Expand Down Expand Up @@ -572,7 +572,7 @@ func (a *API) listCommands(arg listCmdsArg) ([]chat1.UserBotCommandOutput, error
}

type listMembersOptions struct {
Channel chat1.ChatChannel `json:"channel,omitempty"`
Channel chat1.ChatChannel `json:"channel"`
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
}

Expand Down Expand Up @@ -636,7 +636,7 @@ type GetMessagesResult struct {
}

type getMessagesOptions struct {
Channel chat1.ChatChannel `json:"channel,omitempty"`
Channel chat1.ChatChannel `json:"channel"`
ConversationID chat1.ConvIDStr `json:"conversation_id,omitempty"`
MessageIDs []chat1.MessageID `json:"message_ids,omitempty"`
}
Expand Down
9 changes: 2 additions & 7 deletions kbchat/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kbchat
import (
"os"
"path"
"slices"
"testing"

"github.com/keybase/go-keybase-chat-bot/kbchat/types/chat1"
Expand Down Expand Up @@ -167,13 +168,7 @@ func TestListChannels(t *testing.T) {
channels, err := alice.ListChannels(teamChannel.Name)
require.NoError(t, err)
require.True(t, len(channels) > 0)
channelFound := false
for _, channel := range channels {
if channel == teamChannel.TopicName {
channelFound = true
break
}
}
channelFound := slices.Contains(channels, teamChannel.TopicName)
require.True(t, channelFound)
}

Expand Down
4 changes: 2 additions & 2 deletions kbchat/kbchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (a *API) GetUsername() string {
return a.username
}

func (a *API) doSend(arg interface{}) (resp SendResponse, err error) {
func (a *API) doSend(arg any) (resp SendResponse, err error) {
bArg, err := json.Marshal(arg)
if err != nil {
return SendResponse{}, fmt.Errorf("unable to send arg: %+v: %v", arg, err)
Expand Down Expand Up @@ -583,7 +583,7 @@ func (a *API) Listen(opts ListenOptions) (sub *Subscription, err error) {
if err := p.Wait(); err != nil {
stderrBytes, rerr := io.ReadAll(stderr)
if rerr != nil {
stderrBytes = []byte(fmt.Sprintf("failed to get stderr: %v", rerr))
stderrBytes = fmt.Appendf(nil, "failed to get stderr: %v", rerr)
}
a.Debug("Listen: failed to Wait for command, restarting pipes: %s (```%s```)", err, stderrBytes)
if err := a.startPipes(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions kbchat/kbchat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestListenForNewTextMessages(t *testing.T) {

done := make(chan bool)
go func() {
for i := 0; i < 5; i++ {
for i := range 5 {
time.Sleep(time.Second)
message := strconv.Itoa(i)
_, err := bob.SendMessage(channel, "%s", message)
Expand All @@ -117,7 +117,7 @@ func TestListenForNewTextMessages(t *testing.T) {
"4": false,
}

for i := 0; i < 5; i++ {
for range 5 {
msg, err := sub.Read()
require.NoError(t, err)
require.Equal(t, msg.Message.Content.TypeName, "text")
Expand Down
10 changes: 5 additions & 5 deletions kbchat/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ type kvstoreAPIReq struct {

type GetEntryRes struct {
Result keybase1.KVGetResult `json:"result"`
Error Error `json:"error,omitempty"`
Error Error `json:"error"`
}

type PutEntryRes struct {
Result keybase1.KVPutResult `json:"result"`
Error Error `json:"error,omitempty"`
Error Error `json:"error"`
}

type DeleteEntryRes struct {
Result keybase1.KVDeleteEntryResult `json:"result"`
Error Error `json:"error,omitempty"`
Error Error `json:"error"`
}

type ListNamespacesRes struct {
Result keybase1.KVListNamespaceResult `json:"result"`
Error Error `json:"error,omitempty"`
Error Error `json:"error"`
}

type ListEntryKeysRes struct {
Result keybase1.KVListEntryResult `json:"result"`
Error Error `json:"error,omitempty"`
Error Error `json:"error"`
}

type KVStoreAPI interface {
Expand Down
8 changes: 2 additions & 6 deletions kbchat/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kbchat

import (
"fmt"
"slices"
"testing"
"time"

Expand All @@ -10,12 +11,7 @@ import (
)

func contains(a []string, x string) bool {
for _, n := range a {
if x == n {
return true
}
}
return false
return slices.Contains(a, x)
}

func containsKey(a []keybase1.KVListEntryKey, x string) bool {
Expand Down
4 changes: 2 additions & 2 deletions kbchat/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func NewDebugOutput(name string) *DebugOutput {
}
}

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

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()
log.Printf("+ %s: %s\n", d.name, msg)
Expand Down
Loading