forked from automuteus/utils
/
modify.go
67 lines (56 loc) · 1.58 KB
/
modify.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
package task
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"time"
"github.com/bwmarrin/discordgo"
"github.com/neomis/utils/pkg/premium"
)
type UserModify struct {
UserID uint64 `json:"userID"`
Mute bool `json:"mute"`
Deaf bool `json:"deaf"`
}
type UserModifyRequest struct {
Premium premium.Tier `json:"premium"`
Users []UserModify `json:"users"`
}
type ModifyTask struct {
GuildID uint64 `json:"guildID"`
UserID uint64 `json:"userID"`
Parameters PatchParams `json:"parameters"`
TaskID string `json:"taskID"`
}
const IDLength = 10
func NewModifyTask(guildID, userID uint64, params PatchParams) ModifyTask {
h := sha256.New()
h.Write([]byte(fmt.Sprintf("%d", guildID)))
h.Write([]byte(fmt.Sprintf("%d", userID)))
h.Write([]byte(fmt.Sprintf("%d", time.Now().Unix())))
return ModifyTask{
GuildID: guildID,
UserID: userID,
Parameters: params,
TaskID: hex.EncodeToString(h.Sum(nil))[0:IDLength],
}
}
type PatchParams struct {
Deaf bool `json:"deaf"`
Mute bool `json:"mute"`
}
func ApplyMuteDeaf(sess *discordgo.Session, guildID, userID string, mute, deaf bool) error {
p := PatchParams{
Deaf: deaf,
Mute: mute,
}
_, err := sess.RequestWithBucketID("PATCH", discordgo.EndpointGuildMember(guildID, userID), p, discordgo.EndpointGuildMember(guildID, ""))
return err
}
// a response indicating how the mutes/deafens were issued, and if ratelimits occurred
type MuteDeafenSuccessCounts struct {
Worker int64 `json:"worker"`
Capture int64 `json:"capture"`
Official int64 `json:"official"`
RateLimit int64 `json:"ratelimit"`
}