mirror of
https://git.phreedom.club/localhost_frssoft/mastodon-group-bot.git
synced 2024-12-26 02:59:48 +00:00
bug fix
This commit is contained in:
parent
660e3758ca
commit
30a93f2466
22
bot.go
22
bot.go
@ -24,6 +24,8 @@ var (
|
||||
)
|
||||
|
||||
func RunBot() {
|
||||
LoggerInit()
|
||||
|
||||
events, err := c.StreamingUser(ctx)
|
||||
if err != nil {
|
||||
ErrorLogger.Println("Streaming")
|
||||
@ -45,7 +47,7 @@ func RunBot() {
|
||||
|
||||
// New follower
|
||||
if notif.Type == "follow" {
|
||||
acct := notif.Status.Account.Acct
|
||||
acct := notif.Account.Acct
|
||||
|
||||
if !exist_in_database(acct) { // Add to db and post welcome message
|
||||
InfoLogger.Printf("%s followed", acct)
|
||||
@ -68,8 +70,8 @@ func RunBot() {
|
||||
content := notif.Status.Content
|
||||
tooturl := notif.Status.URL
|
||||
|
||||
for i := range followers {
|
||||
if acct == string(followers[i].Acct) { // Follow check
|
||||
// Follow check
|
||||
if check_following(followers, acct) {
|
||||
if notif.Status.Visibility == "public" { // Reblog toot
|
||||
if notif.Status.InReplyToID == nil { // Not boost replies
|
||||
// Duplicate protection
|
||||
@ -82,7 +84,6 @@ func RunBot() {
|
||||
InfoLogger.Printf("Hash of %s added to database", tooturl)
|
||||
} else {
|
||||
WarnLogger.Printf("%s is a duplicate and not boosted", tooturl)
|
||||
break
|
||||
}
|
||||
|
||||
// Add to db if needed
|
||||
@ -112,7 +113,7 @@ func RunBot() {
|
||||
WarnLogger.Printf("%s is reply and not boosted", tooturl)
|
||||
}
|
||||
} else if notif.Status.Visibility == "direct" { // Admin commands
|
||||
for y := 0; y < len(Conf.Admins); y++ {
|
||||
for y := range Conf.Admins {
|
||||
if acct == Conf.Admins[y] {
|
||||
recmd := regexp.MustCompile(`<[^>]+>`)
|
||||
command := recmd.ReplaceAllString(content, "")
|
||||
@ -128,18 +129,18 @@ func RunBot() {
|
||||
case "delete":
|
||||
c.DeleteStatus(ctx, mID)
|
||||
WarnLogger.Printf("%s was deleted", mID)
|
||||
}
|
||||
default:
|
||||
WarnLogger.Printf("%s entered wrong command", acct)
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
WarnLogger.Printf("%s entered wrong command", acct)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WarnLogger.Printf("%s is not public toot and not boosted", tooturl)
|
||||
break
|
||||
}
|
||||
}
|
||||
if i == len(followers)-1 { // Notify user
|
||||
} else { // Notify user
|
||||
if got_notice(acct) == 0 {
|
||||
if !exist_in_database(acct) {
|
||||
add_to_db(acct)
|
||||
@ -159,5 +160,4 @@ func RunBot() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ var (
|
||||
func DeleteNotices() {
|
||||
wg.Done()
|
||||
|
||||
LoggerInit()
|
||||
|
||||
for {
|
||||
statuses, err := c.GetAccountStatuses(ctx, my_account.ID, &mastodon.Pagination{Limit: 60})
|
||||
if err != nil {
|
||||
|
2
main.go
2
main.go
@ -1,8 +1,6 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
LoggerInit()
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go DeleteNotices()
|
||||
|
10
utils.go
10
utils.go
@ -11,3 +11,13 @@ func postToot(toot string, vis string) (*mastodon.Status, error) {
|
||||
status, err := c.PostStatus(ctx, &conToot)
|
||||
return status, err
|
||||
}
|
||||
|
||||
// Check following
|
||||
func check_following(followers []*mastodon.Account, acct string) bool {
|
||||
for i := range followers {
|
||||
if acct == string(followers[i].Acct) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user