mirror of
https://gitea.phreedom.club/localhost_frssoft/mastodon-group-bot
synced 2024-11-22 04:11:29 +00:00
add primitive admin panel
This commit is contained in:
parent
cd868e44b1
commit
3c96ba5095
46
main.go
46
main.go
|
@ -7,6 +7,8 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/mattn/go-mastodon"
|
||||
)
|
||||
|
@ -23,6 +25,7 @@ func main() {
|
|||
ClientSecret string `json:"ClientSecret"`
|
||||
AccessToken string `json:"AccessToken"`
|
||||
WelcomeMessage string `json:"WelcomeMessage"`
|
||||
Admins []string `json:"Admins"`
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(*ConfPath)
|
||||
|
@ -48,7 +51,6 @@ func main() {
|
|||
|
||||
my_account, _ := c.GetAccountCurrentUser(ctx)
|
||||
followers, _ := c.GetAccountFollowers(ctx, my_account.ID, &mastodon.Pagination{Limit: 60})
|
||||
signed := false
|
||||
|
||||
// Run bot
|
||||
for {
|
||||
|
@ -75,19 +77,38 @@ func main() {
|
|||
postToot(message, "public")
|
||||
}
|
||||
|
||||
// Reblog toot
|
||||
// Read message
|
||||
if notif.Type == "mention" {
|
||||
sender := notif.Status.Account.Acct
|
||||
|
||||
// Subscription check
|
||||
for i := 0; i < len(followers); i++ {
|
||||
if sender == string(followers[i].Acct) {
|
||||
signed = true
|
||||
}
|
||||
}
|
||||
|
||||
if signed {
|
||||
for i := 0; i < len(followers); i++ { // Follow check
|
||||
if notif.Status.Account.Acct == string(followers[i].Acct) {
|
||||
if notif.Status.Visibility == "public" { // Reblog toot
|
||||
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 {
|
||||
var message = fmt.Sprintf("@%s%s", notif.Account.Acct, ", you are not subscribed!")
|
||||
postToot(message, "direct")
|
||||
|
@ -95,3 +116,4 @@ func main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue