Skip to content

Commit

Permalink
update: monitor logic
Browse files Browse the repository at this point in the history
- Following no longer required if timeline is accessible for everyone
- Will still attempt to follow if timeline isn't accessible in the event
following is needed
  • Loading branch information
fvckgrimm committed Nov 29, 2024
1 parent 2fbbe38 commit 7062b38
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions internal/bot/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,41 @@ func (b *Bot) handleAddCommand(s *discordgo.Session, i *discordgo.InteractionCre

avatarLocation := accountInfo.Avatar.Variants[0].Locations[0].Location

// Check if the account is already being followed
myAccount, err := b.APIClient.GetMyAccountInfo()
//fmt.Printf("%v", myAccount)
if err != nil {
b.respondToInteraction(s, i, fmt.Sprintf("Error: %v", err))
return
}
if myAccount.ID == "" {
b.respondToInteraction(s, i, "Error: Unable to retrieve account information")
return
}

following, err := b.APIClient.GetFollowing(myAccount.ID)
if err != nil {
b.respondToInteraction(s, i, fmt.Sprintf("Error: %v", err))
return
}

isFollowing := false
for _, f := range following {
if f.AccountID == accountInfo.ID {
isFollowing = true
break
// Check if timeline is accessible
timelinePosts, timelineErr := b.APIClient.GetTimelinePost(accountInfo.ID)
timelineAccessible := timelineErr == nil && len(timelinePosts) >= 0

// Try to follow if timeline isn't accessible or required
if !timelineAccessible {
myAccount, err := b.APIClient.GetMyAccountInfo()
if err == nil && myAccount.ID != "" {
following, err := b.APIClient.GetFollowing(myAccount.ID)
if err == nil {
isFollowing := false
for _, f := range following {
if f.AccountID == accountInfo.ID {
isFollowing = true
break
}
}

if isFollowing {
followErr := b.APIClient.FollowAccount(accountInfo.ID)
if followErr != nil {
log.Printf("Note: Could not follow %s: %v", username, followErr)
//continue since we'll try to monitor
}
}
}
}

timelinePosts, timelineErr = b.APIClient.GetTimelinePost(accountInfo.ID)
timelineAccessible = timelineErr == nil
}

if !isFollowing {
err = b.APIClient.FollowAccount(accountInfo.ID)
if err != nil {
b.respondToInteraction(s, i, fmt.Sprintf("Error following account: %v", err))
return
}
if !timelineAccessible {
b.respondToInteraction(s, i, fmt.Sprintf("Cannot monitor %s: Timeline not accessible", username))
return
}

// Store the monitored user in the database
Expand Down

0 comments on commit 7062b38

Please sign in to comment.