-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
209 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
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,62 @@ | ||
package fortress | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
func (f *Fortress) SyncMemoLogs() (memos *model.MemoLogsResponse, err error) { | ||
req, err := f.makeReq("/api/v1/memos/sync", http.MethodPost, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
var errMsg ErrorMessage | ||
if err := json.NewDecoder(resp.Body).Decode(&errMsg); err != nil { | ||
return nil, errors.New("[SyncMemo] invalid decoded, error " + err.Error()) | ||
} | ||
return nil, errors.New("[SyncMemo] invalid call, code " + strconv.Itoa(resp.StatusCode) + " " + errMsg.Message) | ||
} | ||
|
||
if err := json.NewDecoder(resp.Body).Decode(&memos); err != nil { | ||
return nil, fmt.Errorf("[GetMemoLogs] invalid decoded, error %v", err.Error()) | ||
} | ||
|
||
return memos, nil | ||
} | ||
|
||
func (f *Fortress) GetMemoLogs() (memos *model.MemoLogsResponse, err error) { | ||
req, err := f.makeReq("/api/v1/memos", http.MethodGet, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer resp.Body.Close() | ||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("[GetMemoLogs] invalid call, code %v", resp.StatusCode) | ||
} | ||
|
||
if err := json.NewDecoder(resp.Body).Decode(&memos); err != nil { | ||
return nil, fmt.Errorf("[GetMemoLogs] invalid decoded, error %v", err.Error()) | ||
} | ||
|
||
return memos, nil | ||
} |
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
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
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,25 @@ | ||
package memo | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bwmarrin/discordgo" | ||
"github.com/dwarvesf/fortress-discord/pkg/discord/view/base" | ||
"github.com/dwarvesf/fortress-discord/pkg/model" | ||
) | ||
|
||
func (e *Memo) Sync(original *model.DiscordMessage, memos []model.MemoLog) error { | ||
var content string | ||
for i := range memos { | ||
if i <= 10 { | ||
content += fmt.Sprintf("%d ・ [%s](%s)\n", i+1, memos[i].Title, memos[i].URL) | ||
} | ||
} | ||
|
||
msg := &discordgo.MessageEmbed{ | ||
Title: "<:pepeyes:885513213431648266> New Memo <:pepeyes:885513213431648266> \n", | ||
Description: content, | ||
} | ||
|
||
return base.SendEmbededMessage(e.ses, original, msg) | ||
} |
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