forked from pothtonswer/discordmuffin
Modify GuildBanCreate to have a days param. Clean up ChannelMessage.
This commit is contained in:
parent
f242890ade
commit
6400f08039
1 changed files with 23 additions and 27 deletions
50
restapi.go
50
restapi.go
|
@ -16,6 +16,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -119,7 +121,7 @@ func (s *Session) Login(email string, password string) (token string, err error)
|
||||||
// even use.
|
// even use.
|
||||||
func (s *Session) Logout() (err error) {
|
func (s *Session) Logout() (err error) {
|
||||||
|
|
||||||
// _, err = s.Request("POST", LOGOUT, fmt.Sprintf(`{"token": "%s"}`, s.Token))
|
// _, err = s.Request("POST", LOGOUT, fmt.Sprintf(`{"token": "%s"}`, s.Token))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,20 +280,16 @@ func (s *Session) GuildBans(guildID string) (st []User, err error) {
|
||||||
// GuildBanCreate bans the given user from the given guild.
|
// GuildBanCreate bans the given user from the given guild.
|
||||||
// guildID : The ID of a Guild.
|
// guildID : The ID of a Guild.
|
||||||
// userID : The ID of a User
|
// userID : The ID of a User
|
||||||
func (s *Session) GuildBanCreate(guildID, userID string) (err error) {
|
// days : The number of days of previous comments to delete.
|
||||||
|
func (s *Session) GuildBanCreate(guildID, userID string, days int) (err error) {
|
||||||
|
|
||||||
_, err = s.Request("PUT", GUILD_BAN(guildID, userID), nil)
|
uri := GUILD_BAN(guildID, userID)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// GuildBanCreateAndDeleteComments bans the given user from the given guild
|
if days > 0 {
|
||||||
// and deletes all of their comments younger than a number of days.
|
uri = fmt.Sprintf("%s?delete-message-days=%d", uri, days)
|
||||||
// guildID : The ID of a Guild.
|
}
|
||||||
// userID : The ID of a User
|
|
||||||
// days : The number of days of comments to delete
|
|
||||||
func (s *Session) GuildBanCreateAndDeleteComments(guildID, userID string, days int) (err error) {
|
|
||||||
|
|
||||||
_, err = s.Request("PUT", fmt.Sprintf("%s?delete-message-days=%d", GUILD_BAN(guildID, userID), days), nil)
|
_, err = s.Request("PUT", uri, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,29 +467,27 @@ func (s *Session) ChannelTyping(channelID string) (err error) {
|
||||||
// afterID : If provided all messages returned will be after given ID.
|
// afterID : If provided all messages returned will be after given ID.
|
||||||
func (s *Session) ChannelMessages(channelID string, limit int, beforeID int, afterID int) (st []Message, err error) {
|
func (s *Session) ChannelMessages(channelID string, limit int, beforeID int, afterID int) (st []Message, err error) {
|
||||||
|
|
||||||
var urlStr string
|
uri := CHANNEL_MESSAGES(channelID)
|
||||||
|
|
||||||
|
v := url.Values{}
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
urlStr = fmt.Sprintf("?limit=%d", limit)
|
v.Set("limit", strconv.Itoa(limit))
|
||||||
}
|
}
|
||||||
|
|
||||||
if afterID > 0 {
|
if afterID > 0 {
|
||||||
if urlStr != "" {
|
v.Set("after", strconv.Itoa(afterID))
|
||||||
urlStr = urlStr + fmt.Sprintf("&after=%d", afterID)
|
|
||||||
} else {
|
|
||||||
urlStr = fmt.Sprintf("?after=%d", afterID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if beforeID > 0 {
|
if beforeID > 0 {
|
||||||
if urlStr != "" {
|
v.Set("before", strconv.Itoa(beforeID))
|
||||||
urlStr = urlStr + fmt.Sprintf("&before=%d", beforeID)
|
}
|
||||||
} else {
|
if len(v) > 0 {
|
||||||
urlStr = fmt.Sprintf("?before=%d", beforeID)
|
uri = fmt.Sprintf("%s?%s", uri, v.Encode())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body, err := s.Request("GET", uri, nil)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := s.Request("GET", CHANNEL_MESSAGES(channelID)+urlStr, nil)
|
|
||||||
err = json.Unmarshal(body, &st)
|
err = json.Unmarshal(body, &st)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue