randomquote with usernames
This commit is contained in:
parent
bb9812378c
commit
ec148ed8f6
3 changed files with 72 additions and 142 deletions
98
README.MD
98
README.MD
|
@ -2,100 +2,4 @@
|
||||||
|
|
||||||
#### What is this?
|
#### What is this?
|
||||||
justlog is a bot I maintain for a couple of channels. Its features differ from other bots in that it doesn't support
|
justlog is a bot I maintain for a couple of channels. Its features differ from other bots in that it doesn't support
|
||||||
commands, etc. yet, it focuses on logging and providing an api for the logs.
|
commands, etc. yet, it focuses on logging and providing an api for the logs.
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
**Root Domain** `https://justlog.gempir.com`
|
|
||||||
|
|
||||||
##### All Requests only with HTTPS!
|
|
||||||
|
|
||||||
|
|
||||||
#### RandomQuote
|
|
||||||
|
|
||||||
Responds with a random message from the given user in that channel.
|
|
||||||
|
|
||||||
|
|
||||||
* **URL** `/channel/%channel%/user/%username%/random`
|
|
||||||
|
|
||||||
* **Methods** `GET`
|
|
||||||
|
|
||||||
* **Parameter**
|
|
||||||
- `%channel%` Channel from which you want the quote
|
|
||||||
- `%username%` Username from whom you want the quote
|
|
||||||
|
|
||||||
* **Success Response**
|
|
||||||
|
|
||||||
* **Code:** 200
|
|
||||||
**Content:** `gempir: My Random Message`
|
|
||||||
|
|
||||||
* **Error Response:** `{"Error":"error finding logs"}`
|
|
||||||
|
|
||||||
- **Notice**
|
|
||||||
|
|
||||||
With the Header Content-Type: "application/json" the response will be in json format. Example:
|
|
||||||
`{
|
|
||||||
"channel": "gempbot",
|
|
||||||
"username": "gempir",
|
|
||||||
"message": "MingLee",
|
|
||||||
"timestamp": "2017-03-12 09:43:22"
|
|
||||||
}`
|
|
||||||
|
|
||||||
#### Userlog
|
|
||||||
|
|
||||||
Responds with the timestamped log of a user in the current month for the given channel.
|
|
||||||
|
|
||||||
|
|
||||||
* **URL** `/channel/%channel%/user/%username%`
|
|
||||||
|
|
||||||
* **Methods** `GET`
|
|
||||||
|
|
||||||
* **Parameter**
|
|
||||||
- `%channel%` Channel that the user wrote in
|
|
||||||
- `%username%` Username that typed in the chat
|
|
||||||
|
|
||||||
* **Success Response**
|
|
||||||
|
|
||||||
* **Code:** 200
|
|
||||||
**Content:**
|
|
||||||
|
|
||||||
[2017-04-1 06:40:24] gempir: HaHaa
|
|
||||||
|
|
||||||
[2017-04-1 06:40:36] gempir: KKona
|
|
||||||
|
|
||||||
[2017-04-1 06:40:43] gempir: NaM
|
|
||||||
|
|
||||||
|
|
||||||
* **Error Response:** `{"message":"Not Found"}`
|
|
||||||
* **Notice**
|
|
||||||
|
|
||||||
* This endpoint will redirect to the current month and year so the url will say `/channel/%channel%/user/%username%/2017/April`
|
|
||||||
|
|
||||||
#### Channellog
|
|
||||||
|
|
||||||
Responds with the timestamped log of a channel of the current day for the given channel.
|
|
||||||
|
|
||||||
|
|
||||||
* **URL** `/channel/%channel%`
|
|
||||||
|
|
||||||
* **Methods** `GET`
|
|
||||||
|
|
||||||
* **Parameter**
|
|
||||||
- `%channel%` Channel you want the logs for
|
|
||||||
|
|
||||||
* **Success Response**
|
|
||||||
|
|
||||||
* **Code:** 200
|
|
||||||
**Content:**
|
|
||||||
|
|
||||||
[2017-04-1 06:40:24] gempir: PHPDETECTED
|
|
||||||
|
|
||||||
[2017-04-1 06:40:36] pajlada: KKaper
|
|
||||||
|
|
||||||
[2017-04-1 06:40:43] fourtf: fuck qt
|
|
||||||
|
|
||||||
|
|
||||||
* **Error Response:** `{"message":"Not Found"}`
|
|
||||||
* **Notice**
|
|
||||||
|
|
||||||
* This endpoint will redirect to the current day, month and year so the url will say `/channel/%channel%/2017/April/20`
|
|
114
api/logs.go
114
api/logs.go
|
@ -78,6 +78,75 @@ func (s *Server) getCurrentChannelLogsByName(c echo.Context) error {
|
||||||
return c.Redirect(http.StatusSeeOther, redirectURL)
|
return c.Redirect(http.StatusSeeOther, redirectURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) getChannelLogsByName(c echo.Context) error {
|
||||||
|
channel := strings.ToLower(c.Param("channel"))
|
||||||
|
|
||||||
|
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel})
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return c.JSON(http.StatusInternalServerError, "Failure fetching userID")
|
||||||
|
}
|
||||||
|
|
||||||
|
names := c.ParamNames()
|
||||||
|
names = append(names, "channelid")
|
||||||
|
|
||||||
|
values := c.ParamValues()
|
||||||
|
values = append(values, userMap[channel].ID)
|
||||||
|
|
||||||
|
c.SetParamNames(names...)
|
||||||
|
c.SetParamValues(values...)
|
||||||
|
|
||||||
|
return s.getChannelLogs(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) getUserLogsByName(c echo.Context) error {
|
||||||
|
channel := strings.ToLower(c.Param("channel"))
|
||||||
|
username := strings.ToLower(c.Param("username"))
|
||||||
|
|
||||||
|
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel, username})
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return c.JSON(http.StatusInternalServerError, "Failure fetching userIDs")
|
||||||
|
}
|
||||||
|
|
||||||
|
names := c.ParamNames()
|
||||||
|
names = append(names, "channelid")
|
||||||
|
names = append(names, "userid")
|
||||||
|
|
||||||
|
values := c.ParamValues()
|
||||||
|
values = append(values, userMap[channel].ID)
|
||||||
|
values = append(values, userMap[username].ID)
|
||||||
|
|
||||||
|
c.SetParamNames(names...)
|
||||||
|
c.SetParamValues(values...)
|
||||||
|
|
||||||
|
return s.getUserLogs(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) getRandomQuoteByName(c echo.Context) error {
|
||||||
|
channel := strings.ToLower(c.Param("channel"))
|
||||||
|
username := strings.ToLower(c.Param("username"))
|
||||||
|
|
||||||
|
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel, username})
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return c.JSON(http.StatusInternalServerError, "Failure fetching userIDs")
|
||||||
|
}
|
||||||
|
|
||||||
|
names := c.ParamNames()
|
||||||
|
names = append(names, "channelid")
|
||||||
|
names = append(names, "userid")
|
||||||
|
|
||||||
|
values := c.ParamValues()
|
||||||
|
values = append(values, userMap[channel].ID)
|
||||||
|
values = append(values, userMap[username].ID)
|
||||||
|
|
||||||
|
c.SetParamNames(names...)
|
||||||
|
c.SetParamValues(values...)
|
||||||
|
|
||||||
|
return s.getRandomQuote(c)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) getRandomQuote(c echo.Context) error {
|
func (s *Server) getRandomQuote(c echo.Context) error {
|
||||||
userID := c.Param("userid")
|
userID := c.Param("userid")
|
||||||
channelID := c.Param("channelid")
|
channelID := c.Param("channelid")
|
||||||
|
@ -139,51 +208,6 @@ func (s *Server) getRandomQuote(c echo.Context) error {
|
||||||
return c.String(http.StatusOK, fmt.Sprintf("%s: %s", user.DisplayName, message.Text))
|
return c.String(http.StatusOK, fmt.Sprintf("%s: %s", user.DisplayName, message.Text))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getChannelLogsByName(c echo.Context) error {
|
|
||||||
channel := strings.ToLower(c.Param("channel"))
|
|
||||||
|
|
||||||
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel})
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
return c.JSON(http.StatusInternalServerError, "Failure fetching userID")
|
|
||||||
}
|
|
||||||
|
|
||||||
names := c.ParamNames()
|
|
||||||
names = append(names, "channelid")
|
|
||||||
|
|
||||||
values := c.ParamValues()
|
|
||||||
values = append(values, userMap[channel].ID)
|
|
||||||
|
|
||||||
c.SetParamNames(names...)
|
|
||||||
c.SetParamValues(values...)
|
|
||||||
|
|
||||||
return s.getChannelLogs(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) getUserLogsByName(c echo.Context) error {
|
|
||||||
channel := strings.ToLower(c.Param("channel"))
|
|
||||||
username := strings.ToLower(c.Param("username"))
|
|
||||||
|
|
||||||
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel, username})
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
return c.JSON(http.StatusInternalServerError, "Failure fetching userIDs")
|
|
||||||
}
|
|
||||||
|
|
||||||
names := c.ParamNames()
|
|
||||||
names = append(names, "channelid")
|
|
||||||
names = append(names, "userid")
|
|
||||||
|
|
||||||
values := c.ParamValues()
|
|
||||||
values = append(values, userMap[channel].ID)
|
|
||||||
values = append(values, userMap[username].ID)
|
|
||||||
|
|
||||||
c.SetParamNames(names...)
|
|
||||||
c.SetParamValues(values...)
|
|
||||||
|
|
||||||
return s.getUserLogs(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) getUserLogs(c echo.Context) error {
|
func (s *Server) getUserLogs(c echo.Context) error {
|
||||||
channelID := c.Param("channelid")
|
channelID := c.Param("channelid")
|
||||||
userID := c.Param("userid")
|
userID := c.Param("userid")
|
||||||
|
|
|
@ -59,6 +59,8 @@ func (s *Server) Init() {
|
||||||
|
|
||||||
e.GET("/channel/:channel/user/:username", s.getCurrentUserLogsByName)
|
e.GET("/channel/:channel/user/:username", s.getCurrentUserLogsByName)
|
||||||
e.GET("/channel/:channel/user/:username/:year/:month", s.getUserLogsByName)
|
e.GET("/channel/:channel/user/:username/:year/:month", s.getUserLogsByName)
|
||||||
|
e.GET("/channel/:channel/user/:username/random", s.getRandomQuoteByName)
|
||||||
|
|
||||||
e.GET("/channelid/:channelid/user/:userid", s.getCurrentUserLogs)
|
e.GET("/channelid/:channelid/user/:userid", s.getCurrentUserLogs)
|
||||||
e.GET("/channelid/:channelid/userid/:userid/:year/:month", s.getUserLogs)
|
e.GET("/channelid/:channelid/userid/:userid/:year/:month", s.getUserLogs)
|
||||||
e.GET("/channelid/:channelid/userid/:userid/random", s.getRandomQuote)
|
e.GET("/channelid/:channelid/userid/:userid/random", s.getRandomQuote)
|
||||||
|
|
Loading…
Add table
Reference in a new issue