mirror of https://github.com/velour/catbase.git
Compare commits
No commits in common. "844e350b16c21360ecc59c385ef5b1798d423791" and "c8e195609910cfd249b3b9a51e16fdc49b8fe4ee" have entirely different histories.
844e350b16
...
c8e1956099
|
@ -142,12 +142,6 @@ type Connector interface {
|
|||
|
||||
// Profile returns a user's information given an ID
|
||||
Profile(string) (user.User, error)
|
||||
|
||||
// URL Format utility
|
||||
URLFormat(title, url string) string
|
||||
|
||||
// Translate emojy to/from services
|
||||
Emojy(string) string
|
||||
}
|
||||
|
||||
// Plugin interface used for compatibility with the Plugin interface
|
||||
|
|
|
@ -113,8 +113,7 @@ func NewMockBot() *MockBot {
|
|||
return &b
|
||||
}
|
||||
|
||||
func (mb *MockBot) GetPluginNames() []string { return nil }
|
||||
func (mb *MockBot) RefreshPluginBlacklist() error { return nil }
|
||||
func (mb *MockBot) RefreshPluginWhitelist() error { return nil }
|
||||
func (mb *MockBot) GetWhitelist() []string { return []string{} }
|
||||
func (mb *MockBot) URLFormat(title, url string) string { return title + url }
|
||||
func (mb *MockBot) GetPluginNames() []string { return nil }
|
||||
func (mb *MockBot) RefreshPluginBlacklist() error { return nil }
|
||||
func (mb *MockBot) RefreshPluginWhitelist() error { return nil }
|
||||
func (mb *MockBot) GetWhitelist() []string { return []string{} }
|
||||
|
|
|
@ -144,7 +144,6 @@ func (c *Config) Unset(key string) error {
|
|||
// Note, this is always a string. Use the SetArray for an array helper
|
||||
func (c *Config) Set(key, value string) error {
|
||||
key = strings.ToLower(key)
|
||||
value = strings.Trim(value, "`")
|
||||
q := `insert into config (key,value) values (?, ?)
|
||||
on conflict(key) do update set value=?;`
|
||||
tx, err := c.Begin()
|
||||
|
|
|
@ -219,15 +219,3 @@ func (d *Discord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreate
|
|||
|
||||
d.event(d, bot.Message, msg)
|
||||
}
|
||||
|
||||
func (d *Discord) Emojy(name string) string {
|
||||
e := d.config.GetMap("discord.emojy", map[string]string{})
|
||||
if emojy, ok := e[name]; ok {
|
||||
return emojy
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func (d *Discord) URLFormat(title, url string) string {
|
||||
return fmt.Sprintf("%s (%s)", title, url)
|
||||
}
|
||||
|
|
|
@ -314,15 +314,3 @@ func (i Irc) Who(channel string) []string {
|
|||
func (i Irc) Profile(string) (user.User, error) {
|
||||
return user.User{}, fmt.Errorf("unimplemented")
|
||||
}
|
||||
|
||||
func (i Irc) URLFormat(title, url string) string {
|
||||
return fmt.Sprintf("%s (%s)", title, url)
|
||||
}
|
||||
|
||||
func (i Irc) Emojy(name string) string {
|
||||
e := i.config.GetMap("irc.emojy", map[string]string{})
|
||||
if emojy, ok := e[name]; ok {
|
||||
return emojy
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
|
|
@ -734,15 +734,3 @@ func (s *Slack) Who(id string) []string {
|
|||
func (s *Slack) Profile(string) (user.User, error) {
|
||||
return user.User{}, fmt.Errorf("unimplemented")
|
||||
}
|
||||
|
||||
func (s *Slack) Emojy(name string) string {
|
||||
e := s.config.GetMap("slack.emojy", map[string]string{})
|
||||
if emojy, ok := e[name]; ok {
|
||||
return emojy
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func (s *Slack) URLFormat(title, url string) string {
|
||||
return fmt.Sprintf("<%s|%s>", url, title)
|
||||
}
|
||||
|
|
|
@ -682,17 +682,3 @@ func (s *SlackApp) Profile(identifier string) (user.User, error) {
|
|||
|
||||
return user.User{}, fmt.Errorf("user %s not found", err)
|
||||
}
|
||||
|
||||
func (s *SlackApp) Emojy(name string) string {
|
||||
e := s.config.GetMap("slack.emojy", map[string]string{})
|
||||
if emojy, ok := e[name]; ok {
|
||||
log.Debug().Msgf("Found emoji %s for %s", emojy, name)
|
||||
return emojy
|
||||
}
|
||||
log.Debug().Msgf("Found no emojy for %s", name)
|
||||
return name
|
||||
}
|
||||
|
||||
func (s *SlackApp) URLFormat(title, url string) string {
|
||||
return fmt.Sprintf("<%s|%s>", url, title)
|
||||
}
|
||||
|
|
|
@ -88,8 +88,7 @@ func (p *AOC) message(c bot.Connector, kind bot.Kind, message msg.Message, args
|
|||
}
|
||||
}
|
||||
|
||||
link := c.URLFormat("leaderboard", fmt.Sprintf("https://adventofcode.com/%d/leaderboard/private/view/%d", year, boardId))
|
||||
msg := fmt.Sprintf("AoC %s:\n", link)
|
||||
msg := fmt.Sprintf("AoC <https://adventofcode.com/%d/leaderboard/private/view/%d|Leaderboard>:\n", year, boardId)
|
||||
for _, m := range members {
|
||||
if m.Stars == 0 {
|
||||
continue
|
||||
|
@ -97,11 +96,11 @@ func (p *AOC) message(c bot.Connector, kind bot.Kind, message msg.Message, args
|
|||
trophy := ""
|
||||
switch m.ID {
|
||||
case goldID:
|
||||
trophy = c.Emojy(":gold-trophy:")
|
||||
trophy = ":gold-trophy:"
|
||||
case silverID:
|
||||
trophy = c.Emojy(":silver-trophy:")
|
||||
trophy = ":silver-trophy:"
|
||||
case bronzeID:
|
||||
trophy = c.Emojy(":bronze-trophy:")
|
||||
trophy = ":bronze-trophy:"
|
||||
}
|
||||
msg += fmt.Sprintf("%s has %d :star: for a score of %d%s\n", m.Name, m.Stars, m.LocalScore, trophy)
|
||||
}
|
||||
|
|
|
@ -117,10 +117,6 @@ func (p *CliPlugin) Send(kind bot.Kind, args ...interface{}) (string, error) {
|
|||
func (p *CliPlugin) GetEmojiList() map[string]string { return nil }
|
||||
func (p *CliPlugin) Serve() error { return nil }
|
||||
func (p *CliPlugin) Who(s string) []string { return nil }
|
||||
func (p *CliPlugin) Profile(name string) (user.User, error) {
|
||||
func (s *CliPlugin) Profile(name string) (user.User, error) {
|
||||
return user.User{}, fmt.Errorf("unimplemented")
|
||||
}
|
||||
func (p *CliPlugin) Emojy(name string) string { return name }
|
||||
func (p *CliPlugin) URLFormat(title, url string) string {
|
||||
return fmt.Sprintf("%s (%s)", title, url)
|
||||
}
|
||||
|
|
|
@ -11,32 +11,25 @@ import (
|
|||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var (
|
||||
token = flag.String("token", "", "Slack API token")
|
||||
channel = flag.String("channel", "", "Slack channel ID")
|
||||
limit = flag.Int("limit", 10000, "Number of items to return")
|
||||
types = flag.String("types", "images,pdfs,video", "Type of object")
|
||||
path = flag.String("path", "./", "Path to save files")
|
||||
to = flag.String("to", "", "Time limit in '2006-01-02T15:04:05Z07:00' format. Default -30d")
|
||||
rateLimit = flag.Int("rate", 1, "rate limit in seconds")
|
||||
token = flag.String("token", "", "Slack API token")
|
||||
channel = flag.String("channel", "", "Slack channel ID")
|
||||
limit = flag.Int("limit", 10000, "Number of items to return")
|
||||
types = flag.String("types", "images,pdfs", "Type of object")
|
||||
path = flag.String("path", "./", "Path to save files")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
|
||||
ticker := time.NewTicker(time.Second * time.Duration(*rateLimit))
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
files, count := getFiles()
|
||||
log.Debug().Msgf("Got %d files, count is %d", len(files), count)
|
||||
for _, f := range files {
|
||||
downloadFile(f)
|
||||
deleteFile(f)
|
||||
|
@ -44,47 +37,27 @@ func main() {
|
|||
if count == 1 {
|
||||
break
|
||||
}
|
||||
<-ticker.C
|
||||
}
|
||||
}
|
||||
|
||||
func getFiles() ([]slackFile, int) {
|
||||
files := fileResp{}
|
||||
|
||||
var toTime time.Time
|
||||
var err error
|
||||
|
||||
if *to == "" {
|
||||
toTime = time.Now().Add(time.Hour * 24 * 30 * -1)
|
||||
} else {
|
||||
toTime, err = time.Parse(time.RFC3339, *to)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Error reading time format")
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug().Msg("Getting files")
|
||||
body := mkReq("https://slack.com/api/files.list",
|
||||
"token", *token,
|
||||
"count", strconv.Itoa(*limit),
|
||||
"types", *types,
|
||||
"ts_to", strconv.FormatInt(toTime.Unix(), 10),
|
||||
)
|
||||
|
||||
err = json.Unmarshal(body, &files)
|
||||
err := json.Unmarshal(body, &files)
|
||||
checkErr(err)
|
||||
|
||||
log.Info().
|
||||
Int("count", files.Paging.Count).
|
||||
Int("total", files.Paging.Total).
|
||||
Bool("ok", files.Ok).
|
||||
Msg("file result")
|
||||
Bool("ok", files.Ok)
|
||||
if !files.Ok {
|
||||
log.Error().
|
||||
Interface("files", files).
|
||||
Str("body", string(body)).
|
||||
Msg("Error getting files")
|
||||
os.Exit(1)
|
||||
log.Error().Interface("files", files)
|
||||
}
|
||||
|
||||
return files.Files, files.Paging.Pages
|
||||
|
|
Loading…
Reference in New Issue