mirror of
https://github.com/idanoo/go-mastodon-matrix-webhooks.git
synced 2024-11-24 09:25:18 +00:00
Handle single struct
This commit is contained in:
parent
1eb5d23762
commit
2a898e3bd1
18
main.go
18
main.go
@ -57,7 +57,7 @@ func main() {
|
|||||||
// Handle requests
|
// Handle requests
|
||||||
func handler(w http.ResponseWriter, r *http.Request) {
|
func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Body != nil {
|
if r.Body != nil {
|
||||||
var i IdentifyingRequest
|
var i MastodonEvent
|
||||||
err := json.NewDecoder(r.Body).Decode(&i)
|
err := json.NewDecoder(r.Body).Decode(&i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
@ -65,26 +65,14 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if i.Event == "report.created" {
|
if i.Event == "report.created" {
|
||||||
var report MastodonReportEvent
|
|
||||||
err := json.NewDecoder(r.Body).Decode(&report)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = sendWebhook("New report!")
|
err = sendWebhook("New report!")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if i.Event == "account.created" {
|
} else if i.Event == "account.created" {
|
||||||
var account MastodonSignUpEvent
|
country := ipLookup(i.Object.IP)
|
||||||
err := json.NewDecoder(r.Body).Decode(&account)
|
err = sendWebhook(fmt.Sprintf("*New Signup* %s has joined from %s", i.Object.Username, country))
|
||||||
if err != nil {
|
|
||||||
log.Println(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
country := ipLookup(account.Object.IP)
|
|
||||||
err = sendWebhook(fmt.Sprintf("*New Signup* %s has joined from %s", account.Object.Username, country))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
return
|
return
|
||||||
|
80
structs.go
80
structs.go
@ -2,71 +2,31 @@ package main
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type IdentifyingRequest struct {
|
|
||||||
Event string `json:"event"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type MatrixWebhook struct {
|
type MatrixWebhook struct {
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MastodonSignUpEvent struct {
|
type MastodonEvent struct {
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
Object struct {
|
||||||
Object struct {
|
ID string `json:"id"`
|
||||||
ID string `json:"id"`
|
Username string `json:"username"`
|
||||||
Username string `json:"username"`
|
Email string `json:"email"`
|
||||||
Domain interface{} `json:"domain"`
|
IP string `json:"ip"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
TargetAccount struct {
|
||||||
Email string `json:"email"`
|
ID string `json:"id"`
|
||||||
IP string `json:"ip"`
|
Username string `json:"username"`
|
||||||
Role struct {
|
Domain string `json:"domain"`
|
||||||
ID int `json:"id"`
|
Account struct {
|
||||||
Name string `json:"name"`
|
ID string `json:"id"`
|
||||||
Color string `json:"color"`
|
Username string `json:"username"`
|
||||||
Position int `json:"position"`
|
Acct string `json:"acct"`
|
||||||
Permissions int `json:"permissions"`
|
DisplayName string `json:"display_name"`
|
||||||
Highlighted bool `json:"highlighted"`
|
Note string `json:"note"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
URL string `json:"url"`
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
} `json:"account"`
|
||||||
} `json:"role"`
|
} `json:"target_account"`
|
||||||
Confirmed bool `json:"confirmed"`
|
|
||||||
Suspended bool `json:"suspended"`
|
|
||||||
Silenced bool `json:"silenced"`
|
|
||||||
Sensitized bool `json:"sensitized"`
|
|
||||||
Disabled bool `json:"disabled"`
|
|
||||||
Approved bool `json:"approved"`
|
|
||||||
Locale string `json:"locale"`
|
|
||||||
InviteRequest string `json:"invite_request"`
|
|
||||||
Ips []struct {
|
|
||||||
IP string `json:"ip"`
|
|
||||||
UsedAt time.Time `json:"used_at"`
|
|
||||||
} `json:"ips"`
|
|
||||||
Account struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
Username string `json:"username"`
|
|
||||||
Acct string `json:"acct"`
|
|
||||||
DisplayName string `json:"display_name"`
|
|
||||||
Locked bool `json:"locked"`
|
|
||||||
Bot bool `json:"bot"`
|
|
||||||
Discoverable interface{} `json:"discoverable"`
|
|
||||||
Group bool `json:"group"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
Note string `json:"note"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
Avatar string `json:"avatar"`
|
|
||||||
AvatarStatic string `json:"avatar_static"`
|
|
||||||
Header string `json:"header"`
|
|
||||||
HeaderStatic string `json:"header_static"`
|
|
||||||
FollowersCount int `json:"followers_count"`
|
|
||||||
FollowingCount int `json:"following_count"`
|
|
||||||
StatusesCount int `json:"statuses_count"`
|
|
||||||
LastStatusAt interface{} `json:"last_status_at"`
|
|
||||||
Noindex bool `json:"noindex"`
|
|
||||||
Emojis []interface{} `json:"emojis"`
|
|
||||||
Fields []interface{} `json:"fields"`
|
|
||||||
} `json:"account"`
|
|
||||||
} `json:"object"`
|
} `json:"object"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user