logging: pt1
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package connector
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
@@ -39,7 +39,7 @@ func (d *Discord) Start(a *agent.Agent) {
|
||||
// Create a new Discord session using the provided bot token.
|
||||
dg, err := discordgo.New(Token)
|
||||
if err != nil {
|
||||
fmt.Println("error creating Discord session,", err)
|
||||
slog.Info("error creating Discord session,", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func (d *Discord) Start(a *agent.Agent) {
|
||||
// Open a websocket connection to Discord and begin listening.
|
||||
err = dg.Open()
|
||||
if err != nil {
|
||||
fmt.Println("error opening connection,", err)
|
||||
slog.Info("error opening connection,", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func (d *Discord) messageCreate(a *agent.Agent) func(s *discordgo.Session, m *di
|
||||
)
|
||||
_, err := s.ChannelMessageSend(m.ChannelID, job.Response)
|
||||
if err != nil {
|
||||
fmt.Println("error sending message,", err)
|
||||
slog.Info("error sending message,", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package connector
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -57,7 +58,7 @@ func (g *GithubIssues) Start(a *agent.Agent) {
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
fmt.Println("Looking into github issues...")
|
||||
slog.Info("Looking into github issues...")
|
||||
g.issuesService()
|
||||
case <-a.Context().Done():
|
||||
return
|
||||
@@ -79,7 +80,7 @@ func (g *GithubIssues) issuesService() {
|
||||
g.repository,
|
||||
&github.IssueListByRepoOptions{})
|
||||
if err != nil {
|
||||
fmt.Println("Error listing issues", err)
|
||||
slog.Info("Error listing issues", err)
|
||||
}
|
||||
for _, issue := range issues {
|
||||
// Do something with the issue
|
||||
@@ -99,7 +100,7 @@ func (g *GithubIssues) issuesService() {
|
||||
}
|
||||
|
||||
if userName == user.GetLogin() {
|
||||
fmt.Println("Ignoring issue opened by the bot")
|
||||
slog.Info("Ignoring issue opened by the bot")
|
||||
continue
|
||||
}
|
||||
messages := []openai.ChatCompletionMessage{
|
||||
@@ -133,7 +134,7 @@ func (g *GithubIssues) issuesService() {
|
||||
// if last comment is from the user and mentions the bot username, we must answer
|
||||
if comment.User.GetName() != user.GetLogin() && len(comments)-1 == i {
|
||||
if strings.Contains(comment.GetBody(), fmt.Sprintf("@%s", user.GetLogin())) {
|
||||
fmt.Println("Bot was mentioned in the last comment")
|
||||
slog.Info("Bot was mentioned in the last comment")
|
||||
mustAnswer = true
|
||||
}
|
||||
}
|
||||
@@ -141,9 +142,9 @@ func (g *GithubIssues) issuesService() {
|
||||
|
||||
if len(comments) == 0 || !botAnsweredAlready {
|
||||
// if no comments, or bot didn't answer yet, we must answer
|
||||
fmt.Println("No comments, or bot didn't answer yet")
|
||||
fmt.Println("Comments:", len(comments))
|
||||
fmt.Println("Bot answered already", botAnsweredAlready)
|
||||
slog.Info("No comments, or bot didn't answer yet")
|
||||
slog.Info("Comments:", len(comments))
|
||||
slog.Info("Bot answered already", botAnsweredAlready)
|
||||
mustAnswer = true
|
||||
}
|
||||
|
||||
@@ -163,7 +164,7 @@ func (g *GithubIssues) issuesService() {
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println("Error creating comment", err)
|
||||
slog.Info("Error creating comment", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package connector
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -60,11 +61,11 @@ func (t *Slack) Start(a *agent.Agent) {
|
||||
for evt := range client.Events {
|
||||
switch evt.Type {
|
||||
case socketmode.EventTypeConnecting:
|
||||
fmt.Println("Connecting to Slack with Socket Mode...")
|
||||
slog.Info("Connecting to Slack with Socket Mode...")
|
||||
case socketmode.EventTypeConnectionError:
|
||||
fmt.Println("Connection failed. Retrying later...")
|
||||
slog.Info("Connection failed. Retrying later...")
|
||||
case socketmode.EventTypeConnected:
|
||||
fmt.Println("Connected to Slack with Socket Mode.")
|
||||
slog.Info("Connected to Slack with Socket Mode.")
|
||||
case socketmode.EventTypeEventsAPI:
|
||||
eventsAPIEvent, ok := evt.Data.(slackevents.EventsAPIEvent)
|
||||
if !ok {
|
||||
@@ -91,7 +92,7 @@ func (t *Slack) Start(a *agent.Agent) {
|
||||
if t.channelID == "" && !t.alwaysReply || // If we have set alwaysReply and no channelID
|
||||
t.channelID != ev.Channel { // If we have a channelID and it's not the same as the event channel
|
||||
// Skip messages from other channels
|
||||
fmt.Println("Skipping reply to channel", ev.Channel, t.channelID)
|
||||
slog.Info("Skipping reply to channel", ev.Channel, t.channelID)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ func (t *Slack) Start(a *agent.Agent) {
|
||||
|
||||
// strip our id from the message
|
||||
message = strings.ReplaceAll(message, "<@"+b.UserID+"> ", "")
|
||||
fmt.Println("Message", message)
|
||||
slog.Info("Message", message)
|
||||
|
||||
go func() {
|
||||
res := a.Ask(
|
||||
|
||||
Reference in New Issue
Block a user