-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiban.go
104 lines (88 loc) · 2.39 KB
/
apiban.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"strconv"
"time"
)
var CASBAN_API = "https://api.cas.chat/check?user_id="
var LOLSBOT_API = "https://api.lols.bot/account?id="
type casban_response struct {
Status bool `json:"ok"`
Description string `json:"description"`
}
var casban casban_response
type lolsbot_response struct {
Status bool `json:"banned"`
Offenses int `json:"offenses"`
Score float32 `json:"spam_factor"`
}
var lolsbot lolsbot_response
func isUserApiBanned(userid int) bool {
casbanned := isUserCasBanned(userid)
lolsbanned := isUserLolsBanned(userid)
slog.Info(fmt.Sprintf("User %d ban status: CAS:%t LOLS:%t", userid, casbanned, lolsbanned))
return casbanned || lolsbanned
}
func isUserCasBanned(userid int) bool {
http.DefaultClient.Timeout = 10 * time.Second
// Send GET request
resp, err := http.Get(CASBAN_API + fmt.Sprint(userid))
if err != nil {
slog.Warn("Error sending request:", "error", err)
return false
}
defer resp.Body.Close()
// Check for successful response status code
if resp.StatusCode != http.StatusOK {
slog.Warn("Error status code:", "statusCode", resp.StatusCode)
return false
}
// Read response body
body, err := io.ReadAll(resp.Body)
if err != nil {
slog.Warn("Error reading response body:", "error", err)
return false
}
err = json.Unmarshal(body, &casban)
if err != nil {
slog.Warn("Error unmarshalling JSON:", "error", err)
return false
}
if casban.Status {
slog.Debug("User "+strconv.Itoa(userid)+" is CasBanned", "response", casban)
}
return casban.Status
}
func isUserLolsBanned(userid int) bool {
http.DefaultClient.Timeout = 10 * time.Second
// Send GET request
resp, err := http.Get(LOLSBOT_API + fmt.Sprint(userid))
if err != nil {
slog.Warn("Error sending request:", "error", err)
return false
}
defer resp.Body.Close()
// Check for successful response status code
if resp.StatusCode != http.StatusOK {
slog.Warn("Error status code:", "statusCode", resp.StatusCode)
return false
}
body, err := io.ReadAll(resp.Body)
if err != nil {
slog.Warn("Error reading response body:", "error", err)
return false
}
err = json.Unmarshal(body, &lolsbot)
if err != nil {
slog.Warn("Error unmarshalling JSON:", "error", err)
return false
}
if lolsbot.Status {
slog.Debug("User "+strconv.Itoa(userid)+" is CasBanned", "response", lolsbot)
}
return lolsbot.Status
}