-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from traP-jp/add-anonSodan_2
Add anon sodan 2
- Loading branch information
Showing
6 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package handler | ||
|
||
import ( | ||
"database/sql" | ||
"errors" | ||
"log" | ||
"net/http" | ||
"quickwiki-backend/model" | ||
"strconv" | ||
|
||
"github.com/labstack/echo" | ||
) | ||
|
||
func (h *Handler) PostMessageToTraQ(c echo.Context) error { | ||
var message model.MessageToTraQ_POST | ||
err := c.Bind(&message) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusBadRequest, "bad request body") | ||
} | ||
|
||
channelId := "aff37b5f-0911-4255-81c3-b49985c8943f" | ||
err = h.scraper.MessageToTraQ(message.Content, channelId) | ||
|
||
if err != nil { | ||
log.Println("post message err : ", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, "Internal server error.") | ||
} | ||
|
||
return c.JSON(http.StatusOK, h.GetSodanHandler(c)) | ||
} | ||
|
||
func (h *Handler) PatchMessageToTraQ(c echo.Context) error { | ||
wikiId, err := strconv.Atoi(c.QueryParam("wikiId")) | ||
if err != nil { | ||
log.Printf("failed to convert wikiId to int: %v", err) | ||
return c.JSON(http.StatusBadRequest, err) | ||
} | ||
|
||
var message model.MessageToTraQ_POST | ||
err = c.Bind(&message) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusBadRequest, "bad request body") | ||
} | ||
|
||
var messageContents model.SodanContent_fromDB | ||
err = h.db.Select(&messageContents, "select * from messages where wiki_id = ? order by created_at desc limit 1", wikiId) | ||
if err != nil { | ||
if errors.Is(err, sql.ErrNoRows) { | ||
return c.NoContent(http.StatusNotFound) | ||
} | ||
log.Printf("failed to get sodanContent: %s\n", err) | ||
return c.NoContent(http.StatusInternalServerError) | ||
} | ||
messageID := messageContents.MessageID | ||
err = h.scraper.MessageToTraQ(message.Content, messageID) | ||
|
||
if err != nil { | ||
log.Println("post message err : ", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, "Internal server error.") | ||
} | ||
|
||
return c.JSON(http.StatusOK, h.GetSodanHandler(c)) | ||
} | ||
|
||
func (h *Handler) PostRepliesToTraQ(c echo.Context) error { | ||
wikiId, err := strconv.Atoi(c.QueryParam("wikiId")) | ||
if err != nil { | ||
log.Printf("failed to convert wikiId to int: %v", err) | ||
return c.JSON(http.StatusBadRequest, err) | ||
} | ||
|
||
var message model.MessageToTraQ_POST | ||
err = c.Bind(&message) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusBadRequest, "bad request body") | ||
} | ||
|
||
var messageContents model.SodanContent_fromDB | ||
err = h.db.Select(&messageContents, "select * from messages where wiki_id = ? order by created_at desc limit 1", wikiId) | ||
if err != nil { | ||
if errors.Is(err, sql.ErrNoRows) { | ||
return c.NoContent(http.StatusNotFound) | ||
} | ||
log.Printf("failed to get sodanContent: %s\n", err) | ||
return c.NoContent(http.StatusInternalServerError) | ||
} | ||
channelID := messageContents.ChannelID | ||
err = h.scraper.MessageToTraQ(message.Content, channelID) | ||
|
||
if err != nil { | ||
log.Println("post message err : ", err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, "Internal server error.") | ||
} | ||
|
||
return c.JSON(http.StatusOK, h.GetSodanHandler(c)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package scraper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/traPtitech/go-traq" | ||
) | ||
|
||
func (s *Scraper) MessageToTraQ(message string, PostChanellId string) error { | ||
PostChanellId = "01913f8b-8c05-76a2-b51f-bb83e9e93615" //DEV_MODE | ||
_, _, err := s.bot.API(). | ||
MessageApi. | ||
PostMessage(context.Background(), PostChanellId). | ||
PostMessageRequest(traq.PostMessageRequest{ | ||
Content: message, | ||
}). | ||
Execute() | ||
return err | ||
} | ||
|
||
func (s *Scraper) MessageEditOnTraQ(message string, editMessageId string) error { | ||
editMessageId = "0191a3c2-6659-7c4e-a03f-6a37d080cd10" //DEV_MODE | ||
_, err := s.bot.API().MessageApi. | ||
EditMessage(context.Background(), editMessageId). | ||
PostMessageRequest(traq.PostMessageRequest{ | ||
Content: message, | ||
}). | ||
Execute() | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters