Documentation ¶
Overview ¶
Package slacklog はSlackからエクスポートされた各チャンネルのログの取得、HTMLへ の変換を行なうためのパッケージである。
LogStoreはログデータの取得方法を規定し、必要に応じて各種ログテーブルからデータ を取得する。
ChannelTable/MessageTable/UserTable/EmojiTableはSlackからエクスポートされたJSON 形式のログファイルを読み込み、LogStoreが処理しやすい形でデータを保持する。
TextConverterはログが保持しているテキストのエスケープやHTMLへの変換を行なう。
HTMLGeneratorはLogStoreから取得し、TextConverterで変換したデータを、 text/templateパッケージを用いてHTMLとして出力する。
Index ¶
- Variables
- func HostBySlack(f slack.File) bool
- func LevelOfDetailTime(target, base time.Time) string
- func LocalName(f slack.File, url, suffix string) string
- func LocalPath(f slack.File) string
- func ReadFileAsJSON(filename string, strict bool, dst interface{}) error
- func RegulateFilename(s string) string
- func SortChannel(channels []Channel)
- func ThumbImageHeight(f slack.File) int
- func ThumbImagePath(f slack.File) string
- func ThumbImageWidth(f slack.File) int
- func ThumbVideoPath(f slack.File) string
- func TopLevelMimetype(f slack.File) string
- func TsToDateTime(ts string) time.Time
- type Channel
- type ChannelPin
- type ChannelTable
- type Config
- type Downloader
- type EmojiTable
- type HTMLGenerator
- type Indexer
- type LogStore
- func (s *LogStore) GetAllMessages(channelID string) (Messages, error)
- func (s *LogStore) GetChannels() []Channel
- func (s *LogStore) GetDisplayNameByUserID(userID string) string
- func (s *LogStore) GetDisplayNameMap() map[string]string
- func (s *LogStore) GetEmojiMap() map[string]string
- func (s *LogStore) GetMessagesPerMonth(channelID string) (MessagesMap, error)
- func (s *LogStore) GetThread(channelID, ts string) (*Thread, bool)
- func (s *LogStore) GetUserByID(userID string) (*User, bool)
- func (s *LogStore) HasNextMonth(channelID string, key MessageMonthKey) bool
- func (s *LogStore) HasPrevMonth(channelID string, key MessageMonthKey) bool
- type Message
- type MessageIcons
- type MessageMonthKey
- func (k MessageMonthKey) Month() string
- func (k MessageMonthKey) Next() MessageMonthKey
- func (k MessageMonthKey) NextMonth() string
- func (k MessageMonthKey) NextYear() string
- func (k MessageMonthKey) Prev() MessageMonthKey
- func (k MessageMonthKey) PrevMonth() string
- func (k MessageMonthKey) PrevYear() string
- func (k MessageMonthKey) Year() string
- type MessageTable
- type Messages
- type MessagesMap
- type ReactionInfo
- type TextConverter
- type Thread
- type Ts
- type User
- type UserTable
Constants ¶
This section is empty.
Variables ¶
var FiletypeToExtension = map[string]string{}/* 121 elements not displayed */
FiletypeToExtension is a map which maps filetype to filename extension.
Based on <https://api.slack.com/types/file>
Functions ¶
func HostBySlack ¶
HostBySlack checks a file is hosted by slack or not.
func LevelOfDetailTime ¶
LevelOfDetailTime returns a label string which represents time. The resolution of the string is determined by differece from base time in 4 levels.
func ReadFileAsJSON ¶
ReadFileAsJSON reads a file and unmarshal its contents as JSON to `dst` destination object.
func RegulateFilename ¶
RegulateFilename replaces unusable characters as filepath by '_'.
func SortChannel ¶
func SortChannel(channels []Channel)
SortChannel sorts []Channel by name. It modify original slice.
func ThumbImageHeight ¶
ThumbImageHeight returns height of thumbnail image.
func ThumbImagePath ¶
ThumbImagePath returns path of thumbnail image file.
func ThumbImageWidth ¶
ThumbImageWidth returns width of thumbnail image.
func ThumbVideoPath ¶
ThumbVideoPath returns local path of thumbnail for the video.
func TopLevelMimetype ¶
TopLevelMimetype extracts top level type from MIME Type.
func TsToDateTime ¶
TsToDateTime converts Ts string to time.Time.
Types ¶
type Channel ¶
type Channel struct { slack.Channel Pins []ChannelPin `json:"pins"` }
Channel represents channel object in Slack.
func FilterChannel ¶
FilterChannel : whitelistに指定したチャンネル名に該当するチャンネルのみを返 す。 whitelistに'*'が含まれる場合はchannelをそのまま返す。
type ChannelPin ¶
type ChannelPin struct { ID string `json:"id"` Typ string `json:"type"` Created int64 `json:"created"` User string `json:"user"` Owner string `json:"owner"` }
ChannelPin represents a pinned message for a channel.
type ChannelTable ¶
ChannelTable : チャンネルデータを保持する。 channelsもchannelMapも保持するチャンネルデータは同じで、channelMapはチャンネ ルIDをキーとするmapとなっている。 ユースケースに応じてchannelsとchannelMapは使い分ける。
func NewChannelTable ¶
func NewChannelTable(path string, whitelist []string) (*ChannelTable, error)
NewChannelTable : pathに指定したJSON形式のチャンネルデータを読み込み、 ChannelTable を生成する。 whitelistに指定したチャンネル名のみを読み込む。
type Config ¶
type Config struct { EditedSuffix string `json:"edited_suffix"` Channels []string `json:"channels"` EmojiJSONPath string `json:"emoji_json_path"` }
Config : ログ出力時の設定を保持する。
func ReadConfig ¶
ReadConfig : pathに指定したファイルからコンフィグを読み込む。
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader : ダウンロード処理をするワーカを管理するための構造体。 TODO: 今のところ、ダウンロード処理中にエラーが発生してもキューに積まれたタス クが全て完了するまでは分からない(Wait()の返り値として見るまでは)。
func NewDownloader ¶
func NewDownloader(token string) *Downloader
NewDownloader creates a downloader for Slack with the token.
func (*Downloader) CloseQueue ¶
func (d *Downloader) CloseQueue()
CloseQueue : ダウンロードキューへの追加が完了したことをDownloaderに通知する ために実行する。 TODO: 2回実行するとpanicしてしまうのを修正する。Downloaderに状態でも持たせる とよいだろうか。
func (*Downloader) QueueDownloadRequest ¶
func (d *Downloader) QueueDownloadRequest(url, outputPath string, withToken bool)
QueueDownloadRequest : ダウンロード処理をqueueに積む
func (*Downloader) Wait ¶
func (d *Downloader) Wait() error
Wait : ワーカが全て実行終了するまで待つ。 ダウンロード処理中にエラーが発生していた場合は最初に発生した1つを返す。 他のエラーはログに出力している。
type EmojiTable ¶
type EmojiTable struct { // NameToExtは絵文字名をキーとし、画像の拡張子が値である。 // 絵文字は事前に全てダウンロードしている、という前提であり、そのため拡張子のみ // を保持している。 NameToExt map[string]string }
EmojiTable : 絵文字データを保持する。
func NewEmojiTable ¶
func NewEmojiTable(path string) (*EmojiTable, error)
NewEmojiTable : pathに指定したJSON形式の絵文字データを読み込み、EmojiTableを 生成する。
type HTMLGenerator ¶
type HTMLGenerator struct {
// contains filtered or unexported fields
}
HTMLGenerator : ログデータからHTMLを生成するための構造体。
func NewHTMLGenerator ¶
func NewHTMLGenerator(templateDir string, filesDir string, s *LogStore) *HTMLGenerator
NewHTMLGenerator : HTMLGeneratorを生成する。
func (*HTMLGenerator) Generate ¶
func (g *HTMLGenerator) Generate(outDir string) error
Generate はoutDirにログデータの変換結果を生成する。 目標とする構造は以下となる:
- outDir/
- index.html // generateIndex()
- ${channel_id}/ // generateChannelDir()
- index.html // generateChannelIndex()
- ${YYYY}/
- ${MM}/
- index.html // generateMessageDir()
type LogStore ¶
type LogStore struct {
// contains filtered or unexported fields
}
LogStore : ログデータを各種テーブルを介して取得するための構造体。 MessageTableはチャンネル毎に用意しているためmtsはチャンネルIDをキーとするmap となっている。
func NewLogStore ¶
NewLogStore : 各テーブルを生成して、LogStoreを生成する。
func (*LogStore) GetAllMessages ¶
GetAllMessages returns all messages as array.
func (*LogStore) GetChannels ¶
GetChannels gets all stored channgels.
func (*LogStore) GetDisplayNameByUserID ¶
GetDisplayNameByUserID gets display name for the user.
func (*LogStore) GetDisplayNameMap ¶
GetDisplayNameMap gets a map from user ID to user's display name.
func (*LogStore) GetEmojiMap ¶
GetEmojiMap gets a map from emoji name to its file extension (image type).
func (*LogStore) GetMessagesPerMonth ¶
func (s *LogStore) GetMessagesPerMonth(channelID string) (MessagesMap, error)
GetMessagesPerMonth gets a messages map for the channel. Messages map have all message split in per month.
func (*LogStore) GetThread ¶
GetThread gets a thread (chain of messages) by channel ID and Ts (thread root's Ts).
func (*LogStore) GetUserByID ¶
GetUserByID gets a user by (user) ID. Sometimes by bot ID.
func (*LogStore) HasNextMonth ¶
func (s *LogStore) HasNextMonth(channelID string, key MessageMonthKey) bool
HasNextMonth returns a channel has next key or not.
func (*LogStore) HasPrevMonth ¶
func (s *LogStore) HasPrevMonth(channelID string, key MessageMonthKey) bool
HasPrevMonth returns a channel has previous logs or not.
type Message ¶
type Message struct { slack.Message // Trail shows the user of message is same as the previous one. // FIXME: 本来はココに書いてはいけない Trail bool `json:"-"` }
Message : メッセージ エクスポートしたYYYY-MM-DD.jsonの中身を保持する。 https://slack.com/intl/ja-jp/help/articles/220556107-Slack-%E3%81%8B%E3%82%89%E3%82%A8%E3%82%AF%E3%82%B9%E3%83%9D%E3%83%BC%E3%83%88%E3%81%97%E3%81%9F%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AE%E8%AA%AD%E3%81%BF%E6%96%B9
func (Message) IsRootOfThread ¶
IsRootOfThread : メッセージがスレッドの最初のメッセージであるかを判定する。
func (*Message) RemoveTokenFromURLs ¶
func (m *Message) RemoveTokenFromURLs()
RemoveTokenFromURLs removes the token from URLs in a message.
type MessageIcons ¶
type MessageIcons struct {
Image48 string `json:"image_48"`
}
MessageIcons represents icon for each message.
type MessageMonthKey ¶
type MessageMonthKey struct {
// contains filtered or unexported fields
}
MessageMonthKey is a key for messages.
func NewMessageMonthKey ¶
func NewMessageMonthKey(year, month string) (MessageMonthKey, error)
NewMessageMonthKey creates MessageMonthKey key from two strings: which represents year and month.
func (MessageMonthKey) Month ¶
func (k MessageMonthKey) Month() string
Month returns string represents month.
func (MessageMonthKey) Next ¶
func (k MessageMonthKey) Next() MessageMonthKey
Next gets a key for next month.
func (MessageMonthKey) NextMonth ¶
func (k MessageMonthKey) NextMonth() string
NextMonth returns a string for next month.
func (MessageMonthKey) NextYear ¶
func (k MessageMonthKey) NextYear() string
NextYear returns a string for next year.
func (MessageMonthKey) Prev ¶
func (k MessageMonthKey) Prev() MessageMonthKey
Prev gets a key for previous month.
func (MessageMonthKey) PrevMonth ¶
func (k MessageMonthKey) PrevMonth() string
PrevMonth returns a string for previous month.
func (MessageMonthKey) PrevYear ¶
func (k MessageMonthKey) PrevYear() string
PrevYear returns a string for previous year.
func (MessageMonthKey) Year ¶
func (k MessageMonthKey) Year() string
Year returns string represents year.
type MessageTable ¶
type MessageTable struct { // key: timestamp AllMessageMap map[string]*Message // key: thread timestamp ThreadMap map[string]*Thread MsgsMap MessagesMap // contains filtered or unexported fields }
MessageTable : メッセージデータを保持する スレッドは投稿時刻からどのスレッドへの返信かが判断できるためThreadMapのキー はtsである。 MsgsMapは月毎にメッセージを保持する。そのためキーは投稿月である。 loadedFilesはすでに読み込んだファイルパスを保持する。 loadedFilesは同じファイルを二度読むことを防ぐために用いている。
func NewMessageTable ¶
func NewMessageTable() *MessageTable
NewMessageTable : MessageTableを生成する。 他のテーブルと違い、メッセージファイルは量が多いため、NewMessageTable()実行 時には読み込まず、(*MessageTable).ReadLogDir()/(*MessageTable).ReadLogFile() 実行時に読み込ませる。
func (*MessageTable) ReadLogDir ¶
func (m *MessageTable) ReadLogDir(path string, readAllMessages bool) error
ReadLogDir : pathに指定したディレクトリに存在するJSON形式のメッセージデータ を読み込む。 すでにそのディレクトリが読み込み済みの場合は処理をスキップする。 デフォルトでは特定のサブタイプを持つメッセージのみをmsgMapに登録するが、 readAllMessages が true である場合はすべてのメッセージを登録する。
func (*MessageTable) ReadLogFile ¶
func (m *MessageTable) ReadLogFile(path string, readAllMessages bool) error
ReadLogFile : pathに指定したJSON形式のメッセージデータを読み込む。 すでにそのファイルが読み込み済みの場合は処理をスキップする。 readAllMessagesがfalseである場合は特定のサブタイプを持つメッセージのみをmsgMapに登録する。
type MessagesMap ¶
type MessagesMap map[MessageMonthKey]Messages
MessagesMap is a map, maps MessageMonthKey to Messages.
func (MessagesMap) Keys ¶
func (mm MessagesMap) Keys() []MessageMonthKey
Keys returns all keys in the map.
type ReactionInfo ¶
ReactionInfo is information for a reaction.
type TextConverter ¶
type TextConverter struct {
// contains filtered or unexported fields
}
TextConverter : markdown形式のテキストをHTMLに変換するための構造体。
func NewTextConverter ¶
func NewTextConverter(users, emojis map[string]string) *TextConverter
NewTextConverter : TextConverter を生成する
func (*TextConverter) ToHTML ¶
func (c *TextConverter) ToHTML(text string) string
ToHTML : markdown形式のtextをHTMLに変換する
type Thread ¶
type Thread struct {
// contains filtered or unexported fields
}
Thread : スレッド rootMsgはスレッドの先頭メッセージを表わす。 repliesにはそのスレッドへの返信メッセージが入る。先頭メッセージは含まない。
func (Thread) LastReplyTime ¶
LastReplyTime returns last replied time for the thread.
func (Thread) ReplyCount ¶
ReplyCount return counts of replied messages.
type Ts ¶
Ts is a type represents "Ts" fields in message.go or so.
func (Ts) MarshalJSON ¶
MarshalJSON implements "encoding/json".Marshaller interface.
func (*Ts) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaller interface.
type User ¶
User : ユーザ エクスポートしたuser.jsonの中身を保持する。 公式の情報は以下だがuser.jsonの解説までは書かれていない。 https://slack.com/intl/ja-jp/help/articles/220556107-Slack-%E3%81%8B%E3%82%89%E3%82%A8%E3%82%AF%E3%82%B9%E3%83%9D%E3%83%BC%E3%83%88%E3%81%97%E3%81%9F%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AE%E8%AA%AD%E3%81%BF%E6%96%B9
type UserTable ¶
UserTable : ユーザデータを保持する UsersもUserMapも保持するユーザデータは同じで、UserMapはユーザIDをキーとする mapとなっている。 ユースケースに応じてUsersとUserMapは使い分ける。
func NewUserTable ¶
NewUserTable : pathに指定したJSON形式のユーザデータを読み込み、UserTableを生 成する。