mirror of
https://gitea.phreedom.club/localhost_frssoft/mastodon-group-bot.git
synced 2024-11-22 20:39:19 +02:00
Some fixes for checking replies
This commit is contained in:
parent
9daa1acca2
commit
1654a40396
65
bot.go
65
bot.go
|
@ -29,6 +29,41 @@ type APobject struct {
|
||||||
InReplyTo *string `json:"inReplyTo"`
|
InReplyTo *string `json:"inReplyTo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckAPReply(tooturl string) (bool) {
|
||||||
|
var apobj APobject
|
||||||
|
client := &http.Client{}
|
||||||
|
req, err := http.NewRequest(http.MethodGet, tooturl, nil)
|
||||||
|
if err != nil {
|
||||||
|
ErrorLogger.Println("Failed http request status AP")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
req.Header.Set("Accept", "application/activity+json")
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
ErrorLogger.Println("get AP object")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
ErrorLogger.Println(resp.Body)
|
||||||
|
ErrorLogger.Println("Failed AP object")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&apobj)
|
||||||
|
if err != nil {
|
||||||
|
ErrorLogger.Println("Failed decoding AP object")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
InfoLogger.Println(resp.Body)
|
||||||
|
if apobj.InReplyTo != nil {
|
||||||
|
InfoLogger.Println("AP object of status detected reply")
|
||||||
|
InfoLogger.Println(apobj.InReplyTo)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func RunBot() {
|
func RunBot() {
|
||||||
events, err := c.StreamingUser(ctx)
|
events, err := c.StreamingUser(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -43,7 +78,6 @@ func RunBot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
notif := notifEvent.Notification
|
notif := notifEvent.Notification
|
||||||
client := &http.Client{}
|
|
||||||
|
|
||||||
// New follower
|
// New follower
|
||||||
if notif.Type == "follow" {
|
if notif.Type == "follow" {
|
||||||
|
@ -80,35 +114,14 @@ func RunBot() {
|
||||||
// Follow check
|
// Follow check
|
||||||
if relationship[0].FollowedBy {
|
if relationship[0].FollowedBy {
|
||||||
if notif.Status.Visibility == "public" { // Reblog toot
|
if notif.Status.Visibility == "public" { // Reblog toot
|
||||||
|
var APreply bool
|
||||||
|
APreply = false
|
||||||
if notif.Status.InReplyToID == nil {
|
if notif.Status.InReplyToID == nil {
|
||||||
// Replies protection by get ActivityPub object
|
// Replies protection by get ActivityPub object
|
||||||
// (if breaking threads)
|
// (if breaking threads)
|
||||||
var apobj APobject
|
APreply = CheckAPReply(tooturl)
|
||||||
req, err := http.NewRequest(http.MethodGet, tooturl, nil)
|
|
||||||
if err != nil {
|
|
||||||
ErrorLogger.Println("Failed http request status AP")
|
|
||||||
}
|
|
||||||
req.Header.Set("Accept", "application/activity+json")
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
ErrorLogger.Println("get AP object")
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
ErrorLogger.Println("Failed AP object")
|
|
||||||
}
|
|
||||||
InfoLogger.Println(resp.Body)
|
|
||||||
err = json.NewDecoder(resp.Body).Decode(&apobj)
|
|
||||||
if err != nil {
|
|
||||||
ErrorLogger.Println("Failed decoding AP object")
|
|
||||||
}
|
|
||||||
if &apobj.InReplyTo != nil {
|
|
||||||
InfoLogger.Println("AP object of status detected reply")
|
|
||||||
notif.Status.InReplyToID = &apobj.InReplyTo
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if notif.Status.InReplyToID == nil { // Not boost replies
|
if notif.Status.InReplyToID == nil && APreply == false { // Not boost replies
|
||||||
// Duplicate protection
|
// Duplicate protection
|
||||||
content_hash := sha512.New()
|
content_hash := sha512.New()
|
||||||
content_hash.Write([]byte(content))
|
content_hash.Write([]byte(content))
|
||||||
|
|
Loading…
Reference in New Issue