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 returns a user's information given an ID
|
||||||
Profile(string) (user.User, error)
|
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
|
// Plugin interface used for compatibility with the Plugin interface
|
||||||
|
|
|
@ -113,8 +113,7 @@ func NewMockBot() *MockBot {
|
||||||
return &b
|
return &b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mb *MockBot) GetPluginNames() []string { return nil }
|
func (mb *MockBot) GetPluginNames() []string { return nil }
|
||||||
func (mb *MockBot) RefreshPluginBlacklist() error { return nil }
|
func (mb *MockBot) RefreshPluginBlacklist() error { return nil }
|
||||||
func (mb *MockBot) RefreshPluginWhitelist() error { return nil }
|
func (mb *MockBot) RefreshPluginWhitelist() error { return nil }
|
||||||
func (mb *MockBot) GetWhitelist() []string { return []string{} }
|
func (mb *MockBot) GetWhitelist() []string { return []string{} }
|
||||||
func (mb *MockBot) URLFormat(title, url string) string { return title + url }
|
|
||||||
|
|
|
@ -144,7 +144,6 @@ func (c *Config) Unset(key string) error {
|
||||||
// Note, this is always a string. Use the SetArray for an array helper
|
// Note, this is always a string. Use the SetArray for an array helper
|
||||||
func (c *Config) Set(key, value string) error {
|
func (c *Config) Set(key, value string) error {
|
||||||
key = strings.ToLower(key)
|
key = strings.ToLower(key)
|
||||||
value = strings.Trim(value, "`")
|
|
||||||
q := `insert into config (key,value) values (?, ?)
|
q := `insert into config (key,value) values (?, ?)
|
||||||
on conflict(key) do update set value=?;`
|
on conflict(key) do update set value=?;`
|
||||||
tx, err := c.Begin()
|
tx, err := c.Begin()
|
||||||
|
|
|
@ -219,15 +219,3 @@ func (d *Discord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreate
|
||||||
|
|
||||||
d.event(d, bot.Message, msg)
|
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) {
|
func (i Irc) Profile(string) (user.User, error) {
|
||||||
return user.User{}, fmt.Errorf("unimplemented")
|
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) {
|
func (s *Slack) Profile(string) (user.User, error) {
|
||||||
return user.User{}, fmt.Errorf("unimplemented")
|
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)
|
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 <https://adventofcode.com/%d/leaderboard/private/view/%d|Leaderboard>:\n", year, boardId)
|
||||||
msg := fmt.Sprintf("AoC %s:\n", link)
|
|
||||||
for _, m := range members {
|
for _, m := range members {
|
||||||
if m.Stars == 0 {
|
if m.Stars == 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -97,11 +96,11 @@ func (p *AOC) message(c bot.Connector, kind bot.Kind, message msg.Message, args
|
||||||
trophy := ""
|
trophy := ""
|
||||||
switch m.ID {
|
switch m.ID {
|
||||||
case goldID:
|
case goldID:
|
||||||
trophy = c.Emojy(":gold-trophy:")
|
trophy = ":gold-trophy:"
|
||||||
case silverID:
|
case silverID:
|
||||||
trophy = c.Emojy(":silver-trophy:")
|
trophy = ":silver-trophy:"
|
||||||
case bronzeID:
|
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)
|
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) GetEmojiList() map[string]string { return nil }
|
||||||
func (p *CliPlugin) Serve() error { return nil }
|
func (p *CliPlugin) Serve() error { return nil }
|
||||||
func (p *CliPlugin) Who(s string) []string { 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")
|
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"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
token = flag.String("token", "", "Slack API token")
|
token = flag.String("token", "", "Slack API token")
|
||||||
channel = flag.String("channel", "", "Slack channel ID")
|
channel = flag.String("channel", "", "Slack channel ID")
|
||||||
limit = flag.Int("limit", 10000, "Number of items to return")
|
limit = flag.Int("limit", 10000, "Number of items to return")
|
||||||
types = flag.String("types", "images,pdfs,video", "Type of object")
|
types = flag.String("types", "images,pdfs", "Type of object")
|
||||||
path = flag.String("path", "./", "Path to save files")
|
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")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Second * time.Duration(*rateLimit))
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
files, count := getFiles()
|
files, count := getFiles()
|
||||||
log.Debug().Msgf("Got %d files, count is %d", len(files), count)
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
downloadFile(f)
|
downloadFile(f)
|
||||||
deleteFile(f)
|
deleteFile(f)
|
||||||
|
@ -44,47 +37,27 @@ func main() {
|
||||||
if count == 1 {
|
if count == 1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
<-ticker.C
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFiles() ([]slackFile, int) {
|
func getFiles() ([]slackFile, int) {
|
||||||
files := fileResp{}
|
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")
|
log.Debug().Msg("Getting files")
|
||||||
body := mkReq("https://slack.com/api/files.list",
|
body := mkReq("https://slack.com/api/files.list",
|
||||||
"token", *token,
|
"token", *token,
|
||||||
"count", strconv.Itoa(*limit),
|
"count", strconv.Itoa(*limit),
|
||||||
"types", *types,
|
"types", *types,
|
||||||
"ts_to", strconv.FormatInt(toTime.Unix(), 10),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
err = json.Unmarshal(body, &files)
|
err := json.Unmarshal(body, &files)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
||||||
log.Info().
|
log.Info().
|
||||||
Int("count", files.Paging.Count).
|
Int("count", files.Paging.Count).
|
||||||
Int("total", files.Paging.Total).
|
Bool("ok", files.Ok)
|
||||||
Bool("ok", files.Ok).
|
|
||||||
Msg("file result")
|
|
||||||
if !files.Ok {
|
if !files.Ok {
|
||||||
log.Error().
|
log.Error().Interface("files", files)
|
||||||
Interface("files", files).
|
|
||||||
Str("body", string(body)).
|
|
||||||
Msg("Error getting files")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return files.Files, files.Paging.Pages
|
return files.Files, files.Paging.Pages
|
||||||
|
|
Loading…
Reference in New Issue