-
Notifications
You must be signed in to change notification settings - Fork 13
/
mod.go
110 lines (102 loc) · 2.77 KB
/
mod.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
105
106
107
108
109
110
package mira
import (
"net/http"
"strconv"
)
// Approve is a mod tool to approve a comment or a submission
// Will fail if not a mod.
func (c *Reddit) Approve() error {
name, _, err := c.checkType(commentType)
if err != nil {
return err
}
target := RedditOauth + "/api/approve"
_, err = c.MiraRequest(http.MethodPost, target, map[string]string{
"id": name,
"api_type": JsonAPI,
})
return err
}
// Distinguish is a mod tool to distinguish a comment or a submission
// Will fail if not a mod.
func (c *Reddit) Distinguish(how string, sticky bool) error {
name, _, err := c.checkType(commentType)
if err != nil {
return err
}
target := RedditOauth + "/api/distinguish"
_, err = c.MiraRequest(http.MethodPost, target, map[string]string{
"id": name,
"how": how,
"sticky": strconv.FormatBool(sticky),
"api_type": JsonAPI,
})
return err
}
// UpdateSidebar updates subreddit's sidebar, Needs mod privileges.
func (c *Reddit) UpdateSidebar(text string) error {
name, _, err := c.checkType(subredditType)
if err != nil {
return err
}
target := RedditOauth + "/api/site_admin"
_, err = c.MiraRequest(http.MethodPost, target, map[string]string{
"sr": name,
"name": "None",
"description": text,
"title": name,
"wikimode": "anyone",
"link_type": "any",
"type": "public",
"api_type": JsonAPI,
})
return err
}
// SelectFlair sets a submission flair.
func (c *Reddit) SelectFlair(text string) error {
name, _, err := c.checkType(submissionType)
if err != nil {
return err
}
target := RedditOauth + "/api/selectflair"
_, err = c.MiraRequest(http.MethodPost, target, map[string]string{
"link": name,
"text": text,
"api_type": JsonAPI,
})
return err
}
// SelectFlairWithID sets submission flair with explicit ID.
func (c *Reddit) SelectFlairWithID(name, text string) error {
target := RedditOauth + "/api/selectflair"
_, err := c.MiraRequest(http.MethodPost, target, map[string]string{
"link": name,
"text": text,
"api_type": JsonAPI,
})
return err
}
// UserFlair updates user's flair in a sub. Needs mod permissions.
func (c *Reddit) UserFlair(user, text string) error {
name, _, err := c.checkType(subredditType)
if err != nil {
return err
}
target := RedditOauth + "/r/" + name + "/api/flair"
_, err = c.MiraRequest(http.MethodPost, target, map[string]string{
"name": user,
"text": text,
"api_type": JsonAPI,
})
return err
}
// UserFlairWithID is the same as UserFlair but explicit redditor name.
func (c *Reddit) UserFlairWithID(name, user, text string) error {
target := RedditOauth + "/r/" + name + "/api/flair"
_, err := c.MiraRequest(http.MethodPost, target, map[string]string{
"name": user,
"text": text,
"api_type": JsonAPI,
})
return err
}