diff --git a/main.go b/main.go index 1bf498d..82f2ceb 100644 --- a/main.go +++ b/main.go @@ -57,7 +57,7 @@ func main() { // Handle requests func handler(w http.ResponseWriter, r *http.Request) { if r.Body != nil { - var i IdentifyingRequest + var i MastodonEvent err := json.NewDecoder(r.Body).Decode(&i) if err != nil { log.Println(err.Error()) @@ -65,26 +65,14 @@ func handler(w http.ResponseWriter, r *http.Request) { } 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!") if err != nil { log.Println(err.Error()) return } } else if i.Event == "account.created" { - var account MastodonSignUpEvent - err := json.NewDecoder(r.Body).Decode(&account) - 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)) + country := ipLookup(i.Object.IP) + err = sendWebhook(fmt.Sprintf("*New Signup* %s has joined from %s", i.Object.Username, country)) if err != nil { log.Println(err.Error()) return diff --git a/structs.go b/structs.go index e5d160a..98dae18 100644 --- a/structs.go +++ b/structs.go @@ -2,71 +2,31 @@ package main import "time" -type IdentifyingRequest struct { - Event string `json:"event"` -} - type MatrixWebhook struct { Body string `json:"body"` Key string `json:"key"` } -type MastodonSignUpEvent struct { - Event string `json:"event"` - CreatedAt time.Time `json:"created_at"` - Object struct { - ID string `json:"id"` - Username string `json:"username"` - Domain interface{} `json:"domain"` - CreatedAt time.Time `json:"created_at"` - Email string `json:"email"` - IP string `json:"ip"` - Role struct { - ID int `json:"id"` - Name string `json:"name"` - Color string `json:"color"` - Position int `json:"position"` - Permissions int `json:"permissions"` - Highlighted bool `json:"highlighted"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - } `json:"role"` - 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"` +type MastodonEvent struct { + Event string `json:"event"` + Object struct { + ID string `json:"id"` + Username string `json:"username"` + Email string `json:"email"` + IP string `json:"ip"` + TargetAccount struct { + ID string `json:"id"` + Username string `json:"username"` + Domain string `json:"domain"` + Account struct { + ID string `json:"id"` + Username string `json:"username"` + Acct string `json:"acct"` + DisplayName string `json:"display_name"` + Note string `json:"note"` + URL string `json:"url"` + } `json:"account"` + } `json:"target_account"` } `json:"object"` }