add primitive admin panel

This commit is contained in:
fade 2022-08-22 04:53:02 -04:00
parent cd868e44b1
commit 3c96ba5095

46
main.go
View File

@ -7,6 +7,8 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"regexp"
"strings"
"github.com/mattn/go-mastodon" "github.com/mattn/go-mastodon"
) )
@ -23,6 +25,7 @@ func main() {
ClientSecret string `json:"ClientSecret"` ClientSecret string `json:"ClientSecret"`
AccessToken string `json:"AccessToken"` AccessToken string `json:"AccessToken"`
WelcomeMessage string `json:"WelcomeMessage"` WelcomeMessage string `json:"WelcomeMessage"`
Admins []string `json:"Admins"`
} }
data, err := os.ReadFile(*ConfPath) data, err := os.ReadFile(*ConfPath)
@ -48,7 +51,6 @@ func main() {
my_account, _ := c.GetAccountCurrentUser(ctx) my_account, _ := c.GetAccountCurrentUser(ctx)
followers, _ := c.GetAccountFollowers(ctx, my_account.ID, &mastodon.Pagination{Limit: 60}) followers, _ := c.GetAccountFollowers(ctx, my_account.ID, &mastodon.Pagination{Limit: 60})
signed := false
// Run bot // Run bot
for { for {
@ -75,23 +77,43 @@ func main() {
postToot(message, "public") postToot(message, "public")
} }
// Reblog toot // Read message
if notif.Type == "mention" { if notif.Type == "mention" {
sender := notif.Status.Account.Acct for i := 0; i < len(followers); i++ { // Follow check
if notif.Status.Account.Acct == string(followers[i].Acct) {
// Subscription check if notif.Status.Visibility == "public" { // Reblog toot
for i := 0; i < len(followers); i++ {
if sender == string(followers[i].Acct) {
signed = true
}
}
if signed {
c.Reblog(ctx, notif.Status.ID) c.Reblog(ctx, notif.Status.ID)
} else if notif.Status.Visibility == "direct" { // Admin commands
for y := 0; y < len(Conf.Admins); y++ {
if notif.Status.Account.Acct == Conf.Admins[y] {
text := notif.Status.Content
recmd := regexp.MustCompile(`<.*?> `)
command := recmd.ReplaceAllString(text, "")
args := strings.Split(command, " ")
if len(args) == 2 {
switch args[0] {
case "unboost":
c.Unreblog(ctx, mastodon.ID((args[1])))
case "delete":
c.DeleteStatus(ctx, mastodon.ID(args[1]))
case "block":
c.AccountBlock(ctx, mastodon.ID(args[1]))
case "unblock":
c.AccountUnblock(ctx, mastodon.ID(args[1]))
}
}
} else {
var message = fmt.Sprintf("@%s%s", notif.Account.Acct, ", you are not admin!")
postToot(message, "direct")
}
}
}
} else { } else {
var message = fmt.Sprintf("@%s%s", notif.Account.Acct, ", you are not subscribed!") var message = fmt.Sprintf("@%s%s", notif.Account.Acct, ", you are not subscribed!")
postToot(message, "direct") postToot(message, "direct")
} }
} }
} }
}
} }