diff --git a/.drone.yml b/.drone.yml index 5c9eba7..401caf9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -37,6 +37,6 @@ steps: settings: token: from_secret: gitea_token - base: https://git.canopymc.net + base: https://git.etztech.xyz files: - - "canopeas" \ No newline at end of file + - "sedbot" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0d2088b..e1c8229 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # GoLand .idea/ -# canopeas -canopeas* -!config/canopeas.example.toml \ No newline at end of file +# sedbot +sedbot* +!config/sedbot.example.toml \ No newline at end of file diff --git a/README.md b/README.md index ea719ca..5451cdc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# canopeas +# SedBot -Canopy Discord generi-bot. +BirbMC Discord generi-bot. ## Commands @@ -20,6 +20,12 @@ Canopy Discord generi-bot. * `clear [<@user>] ` - Clear messages (optionally only by @user) +## Building + +```text +make build-all +``` + ## License [MIT](LICENSE) \ No newline at end of file diff --git a/config/config.go b/config/config.go index bd0d679..a1bd19e 100644 --- a/config/config.go +++ b/config/config.go @@ -8,7 +8,7 @@ import ( "github.com/pelletier/go-toml" ) -//go:embed canopeas.example.toml +//go:embed sedbot.example.toml var defaultConfig []byte type Config struct { @@ -35,19 +35,16 @@ type Config struct { AccessToken string `toml:"access_token"` AccessSecret string `toml:"access_secret"` } `toml:"twitter"` - StaffRoles []string `toml:"staff_roles"` - Echoes []Echo `toml:"echoes"` - Albums []Album `toml:"albums"` - MessageRoles []MessageRole `toml:"message_roles"` - Register struct { - URL string `toml:"url"` - Role string `toml:"role"` - WelcomeChannel string `toml:"welcome_channel"` - } `toml:"register"` - LeaveChannel string `toml:"leave_channel"` - FiredRole string `toml:"fired_role"` - MemeRate string `toml:"meme_rate"` - Insult struct { + + StaffRoles []string `toml:"staff_roles"` + Echoes []Echo `toml:"echoes"` + MessageRoles []MessageRole `toml:"message_roles"` + RegisterRole string `toml:"register_role"` + RegisteredChannel string `toml:"registered_channel"` + LeaveChannel string `toml:"leave_channel"` + FiredRole string `toml:"fired_role"` + MemeRate string `toml:"meme_rate"` + Insult struct { Targets []string `toml:"targets"` Comparisons []string `toml:"comparisons"` Adjectives []string `toml:"adjectives"` @@ -61,13 +58,10 @@ type Config struct { } type MessageRole struct { - ChannelID string `toml:"channel_id"` - MessageID string `toml:"message_id"` - Reactions []MessageReaction `toml:"reactions"` -} -type MessageReaction struct { - Emoji string `toml:"emoji"` - RoleID string `toml:"role_id"` + ChannelID string `toml:"channel_id"` + MessageID string `toml:"message_id"` + RoleID string `toml:"role_id"` + Emoji string `toml:"emoji"` } type Echo struct { @@ -77,18 +71,11 @@ type Echo struct { Help string `toml:"help"` } -type Album struct { - Name string `toml:"name"` - Aliases []string `toml:"aliases"` - AlbumID string `toml:"album_id"` - Help string `toml:"help"` -} - func Load(configPath string) (*Config, error) { var err error var configContent []byte if len(configPath) == 0 { - configPath = "canopeas.toml" + configPath = "sedbot.toml" } configContent, err = ioutil.ReadFile(configPath) diff --git a/config/canopeas.example.toml b/config/sedbot.example.toml similarity index 77% rename from config/canopeas.example.toml rename to config/sedbot.example.toml index f1ff6a1..4af6fcc 100644 --- a/config/canopeas.example.toml +++ b/config/sedbot.example.toml @@ -5,7 +5,7 @@ token = "" prefix = "!" # db_path is the path to the database (default is next to binary) -db_path = "canopeas.db" +db_path = "sedbot.db" # mc_path is the path to the root directory of the minecraft server mc_path = "/home/minecraft/server/" @@ -13,6 +13,12 @@ mc_path = "/home/minecraft/server/" # fired_role is to check how many time Carolyn has been fired fired_role = "0" +# register_role is the role to assign to a user after registering +register_role = "0" + +# registered_channel is the channel to message to welcome the newly registered user +registered_channel = "0" + # leave_channel is the channel to post leave messages to leave_channel = "0" @@ -25,16 +31,6 @@ meme_rate = "0" # Imgur Client ID imgur_client_id = "" -[register] -# role is the role to assign to a user after registering -role = "0" - -# url is the URL to show to new users -url = "https://google.com" - -# welcome_channel is the channel to message to welcome the newly registered user -welcome_channel = "0" - # ServerAPI options [serverapi] # API endpoint @@ -82,12 +78,6 @@ verbs = [] nouns = [] minor_things = [] -[[albums]] -name = "jupiter" -aliases = ["jup", "jupjup"] -album_id = "" -help = "Images of Jupiter" - # echoes are any basic command -> message [[echoes]] name = "discord" @@ -99,9 +89,5 @@ help = "Get the invite link" [[message_roles]] channel_id = "0" message_id = "0" -[[message_roles.reactions]] role_id = "0" -emoji = "👍" -[[message_roles.reactions]] -role_id = "0" -emoji = "👎" \ No newline at end of file +emoji = "👍" \ No newline at end of file diff --git a/discord/ban.go b/discord/ban.go index 5601499..1180784 100644 --- a/discord/ban.go +++ b/discord/ban.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "git.canopymc.net/Etzelia/go-serverapi" + "go.etztech.xyz/go-serverapi" ) func init() { diff --git a/discord/birb.go b/discord/birb.go index 572fb82..91642c3 100644 --- a/discord/birb.go +++ b/discord/birb.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "git.canopymc.net/Etzelia/falseknees" + "go.etztech.xyz/falseknees" ) func init() { diff --git a/discord/broadcast.go b/discord/broadcast.go index a6c3513..18de5d1 100644 --- a/discord/broadcast.go +++ b/discord/broadcast.go @@ -5,7 +5,7 @@ import ( "net/http" "strings" - "git.canopymc.net/Etzelia/go-serverapi" + "go.etztech.xyz/go-serverapi" ) func init() { diff --git a/discord/clear.go b/discord/clear.go index 3a86822..f75c676 100644 --- a/discord/clear.go +++ b/discord/clear.go @@ -9,8 +9,7 @@ const clearMax = 20 func init() { commands = append(commands, &command{ - name: "clear", - staffOnly: true, + name: "clear", validate: func(cmd commandInit) bool { return isStaff(cmd.message.Member.Roles, cmd.config.StaffRoles) }, diff --git a/discord/dad.go b/discord/dad.go index c91c39f..a9fb940 100644 --- a/discord/dad.go +++ b/discord/dad.go @@ -2,11 +2,8 @@ package discord import ( "encoding/json" - "errors" "io/ioutil" "net/http" - - "go.jolheiser.com/beaver" ) const ( @@ -31,9 +28,33 @@ func init() { return "", nil } - dj, err := newDadJoke() + req, err := http.NewRequest(http.MethodGet, dadJokeAPI, nil) if err != nil { - beaver.Warnf("error getting new dad joke: %v", err) + return "", err + } + req.Header.Add("Accept", "application/json") + + resp, err := http.DefaultClient.Do(req) + if err != nil { + return "", err + } + + if resp.StatusCode != http.StatusOK { + return dadJokeErr, nil + } + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return "", err + } + + var dj dadJoke + if err := json.Unmarshal(body, &dj); err != nil { + return "", nil + } + + // Check status again, in case API returned an error + if dj.Status != http.StatusOK { return dadJokeErr, nil } @@ -42,37 +63,3 @@ func init() { help: "Get a random Dad joke", }) } - -func newDadJoke() (*dadJoke, error) { - req, err := http.NewRequest(http.MethodGet, dadJokeAPI, nil) - if err != nil { - return nil, err - } - req.Header.Add("Accept", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return nil, err - } - - if resp.StatusCode != http.StatusOK { - return nil, errors.New("non-ok status") - } - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - var dj *dadJoke - if err := json.Unmarshal(body, &dj); err != nil { - return nil, errors.New("could not unmarshal") - } - - // Check status again, in case API returned an error - if dj.Status != http.StatusOK { - return nil, errors.New("API error") - } - - return dj, nil -} diff --git a/discord/discord.go b/discord/discord.go index 00a9527..5b0c533 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -5,13 +5,14 @@ import ( "strings" "time" - "git.canopymc.net/Etzelia/canopeas/config" - "git.canopymc.net/Etzelia/canopeas/database" + "go.etztech.xyz/sedbot/config" + "go.etztech.xyz/sedbot/database" + "go.etztech.xyz/sedbot/imgur" - "git.canopymc.net/Etzelia/go-serverapi" "github.com/bwmarrin/discordgo" "github.com/dghubble/go-twitter/twitter" "github.com/dghubble/oauth1" + "go.etztech.xyz/go-serverapi" "go.jolheiser.com/beaver" ) @@ -37,7 +38,7 @@ type commandInit struct { type command struct { staffOnly bool deleteInvocation bool - child bool + echo bool // TODO Does this really need to exist separately? validate func(cmd commandInit) bool run func(cmd commandInit) (string, error) @@ -52,8 +53,11 @@ func Bot(cfg *config.Config, db *database.Database) (*discordgo.Session, error) return nil, err } - // Init rand + // Init Jupiter images rand.Seed(time.Now().UnixNano()) + if err := imgur.Init(cfg.ImgurClientID); err != nil { + return nil, err + } // Init ServerAPI sapi := serverapi.NewClient(cfg.ServerAPI.Endpoint, serverapi.WithToken(cfg.ServerAPI.Token)) @@ -75,16 +79,11 @@ func Bot(cfg *config.Config, db *database.Database) (*discordgo.Session, error) if messageRoleMap[messageRole.MessageID] == nil { messageRoleMap[messageRole.MessageID] = make(map[string]string) } - for _, reaction := range messageRole.Reactions { - _ = bot.MessageReactionAdd(messageRole.ChannelID, messageRole.MessageID, reaction.Emoji) - messageRoleMap[messageRole.MessageID][reaction.Emoji] = reaction.RoleID - } + _ = bot.MessageReactionAdd(messageRole.ChannelID, messageRole.MessageID, messageRole.Emoji) + messageRoleMap[messageRole.MessageID][messageRole.Emoji] = messageRole.RoleID } // Init commandMap - if err := Album(cfg); err != nil { - return nil, err - } Echo(cfg) for _, c := range commands { if c.name == "" { @@ -165,9 +164,6 @@ func isStaff(authorRoleIDs, staffRoleIDs []string) bool { func readyHandler() func(s *discordgo.Session, m *discordgo.Ready) { return func(s *discordgo.Session, r *discordgo.Ready) { beaver.Infof("https://discord.com/api/oauth2/authorize?client_id=%s&permissions=0&redirect_uri=https://birbmc.com&scope=bot", r.User.ID) - - // Init status changer - go updateStatus(s) } } @@ -279,16 +275,3 @@ func leaveHandler(cfg *config.Config) func(s *discordgo.Session, m *discordgo.Gu sendMessage(s, cfg.LeaveChannel, fmt.Sprintf("%s (%s) left the server. :sob:", m.Mention(), m.User.String()), true) } } - -func updateStatus(s *discordgo.Session) { - ticker := time.NewTicker(time.Minute * 30) - for { - dj, err := newDadJoke() - if err != nil { - beaver.Warnf("could not get new dad joke: %v", err) - } else if err := s.UpdateStatus(1, dj.Joke); err != nil { - beaver.Warnf("could not update status: %v", err) - } - <-ticker.C - } -} diff --git a/discord/echo.go b/discord/echo.go index 439bff7..9ba244b 100644 --- a/discord/echo.go +++ b/discord/echo.go @@ -4,18 +4,17 @@ import ( "fmt" "strings" - "git.canopymc.net/Etzelia/canopeas/config" + "go.etztech.xyz/sedbot/config" "github.com/bwmarrin/discordgo" ) func Echo(cfg *config.Config) { - for _, echo := range cfg.Echoes { - e := echo // Closure + for _, e := range cfg.Echoes { commands = append(commands, &command{ name: e.Name, aliases: e.Aliases, - child: true, + echo: true, validate: func(cmd commandInit) bool { return true }, diff --git a/discord/help.go b/discord/help.go index 9b88c32..2587ef6 100644 --- a/discord/help.go +++ b/discord/help.go @@ -65,7 +65,7 @@ func allHelp(cmd commandInit) *discordgo.MessageEmbed { embed.Description = "Commands with an asterisk (*) are staff-only" } for _, c := range commands { - if c.child { + if c.echo { continue } diff --git a/discord/history.go b/discord/history.go index fe697c1..baa609a 100644 --- a/discord/history.go +++ b/discord/history.go @@ -5,10 +5,10 @@ import ( "strings" "time" - "gitea.com/jolheiser/gojang" - "gitea.com/jolheiser/gojang/rate" "github.com/bwmarrin/discordgo" "go.jolheiser.com/beaver" + "go.jolheiser.com/gojang" + "go.jolheiser.com/gojang/rate" ) func init() { diff --git a/discord/imgur.go b/discord/imgur.go deleted file mode 100644 index 7705375..0000000 --- a/discord/imgur.go +++ /dev/null @@ -1,71 +0,0 @@ -package discord - -import ( - "fmt" - "strings" - - "git.canopymc.net/Etzelia/canopeas/config" - "git.canopymc.net/Etzelia/canopeas/imgur" - - "github.com/bwmarrin/discordgo" -) - -func Album(cfg *config.Config) error { - for _, a := range cfg.Albums { - images, err := imgur.Get(cfg.ImgurClientID, a.AlbumID) - if err != nil { - return err - } - commands = append(commands, &command{ - name: a.Name, - aliases: a.Aliases, - child: true, - validate: func(cmd commandInit) bool { - return true - }, - run: func(cmd commandInit) (string, error) { - if !memeRateLimit.Try() { - return "", nil - } - img := images[rand.Intn(len(images))-1] - return img.Link, nil - }, - help: a.Help, - }) - } - - commands = append(commands, &command{ - deleteInvocation: true, - name: "albums", - validate: func(cmd commandInit) bool { - return true - }, - run: func(cmd commandInit) (string, error) { - embed := &discordgo.MessageEmbed{ - Title: "Album Commands", - Fields: make([]*discordgo.MessageEmbedField, len(cfg.Albums)), - } - for i, a := range cfg.Albums { - name := a.Name - if len(a.Aliases) > 0 { - name += fmt.Sprintf(" (%s)", strings.Join(a.Aliases, ", ")) - } - embed.Fields[i] = &discordgo.MessageEmbedField{ - Name: name, - Value: a.Help, - Inline: true, - } - } - - channel, err := cmd.session.UserChannelCreate(cmd.message.Author.ID) - if err != nil { - return "", err - } - - sendEmbed(cmd.session, channel.ID, embed) - return "", nil - }, - help: "Get all imgur albums", - }) - return nil -} diff --git a/discord/inspire.go b/discord/inspire.go index 8a66759..e4238ae 100644 --- a/discord/inspire.go +++ b/discord/inspire.go @@ -1,6 +1,6 @@ package discord -import "git.canopymc.net/Etzelia/inspiro" +import "go.etztech.xyz/inspiro" func init() { commands = append(commands, &command{ diff --git a/discord/jupiter.go b/discord/jupiter.go new file mode 100644 index 0000000..1fecc3e --- /dev/null +++ b/discord/jupiter.go @@ -0,0 +1,21 @@ +package discord + +import "go.etztech.xyz/sedbot/imgur" + +func init() { + commands = append(commands, &command{ + name: "jupiter", + aliases: []string{"jup", "jupjup"}, + validate: func(cmd commandInit) bool { + return true + }, + run: func(cmd commandInit) (string, error) { + if !memeRateLimit.Try() { + return "", nil + } + img := imgur.Images[rand.Intn(len(imgur.Images))-1] + return img.Link, nil + }, + help: "Get a Jupiter image", + }) +} diff --git a/discord/register.go b/discord/register.go index e1fb0e4..9901d3a 100644 --- a/discord/register.go +++ b/discord/register.go @@ -7,10 +7,10 @@ import ( "path/filepath" "strings" - "git.canopymc.net/Etzelia/canopeas/config" + "go.etztech.xyz/sedbot/config" - "git.canopymc.net/Etzelia/go-mcm" - "git.canopymc.net/Etzelia/go-mcm/model/django" + "go.etztech.xyz/go-mcm" + "go.etztech.xyz/go-mcm/model/django" ) const bannedPlayersFile = "banned-players.json" @@ -69,7 +69,7 @@ func init() { } } else if len(apps) > 0 { if apps[0].Accepted != nil && *apps[0].Accepted { - return fmt.Sprintf("Please join the server at `%s` and then re-try this command", cmd.config.Register.URL), nil + return "Please join the server and then re-try this command", nil } } else { return "No player or applications found for that username", nil @@ -82,30 +82,16 @@ func init() { return "Your application was denied, good luck finding a new server", nil } - // Accepted, check for dupe user - guild, err := cmd.session.State.Guild(cmd.message.GuildID) - if err != nil { - return "", err - } - for _, member := range guild.Members { - nick := member.Nick - if nick == "" { - } - nick = member.User.Username - if strings.EqualFold(nickname, nick) && cmd.message.Author.ID != member.User.ID { - return "A member with that name already exists in this Discord. Please contact staff.", nil - } - } - + // Accepted if err := cmd.session.GuildMemberNickname(cmd.message.GuildID, cmd.message.Author.ID, nickname); err != nil { return "", err } - if err := cmd.session.GuildMemberRoleAdd(cmd.message.GuildID, cmd.message.Author.ID, cmd.config.Register.Role); err != nil { + if err := cmd.session.GuildMemberRoleAdd(cmd.message.GuildID, cmd.message.Author.ID, cmd.config.RegisterRole); err != nil { return "", err } // Don't return feedback because this goes in a different channel - sendMessage(cmd.session, cmd.config.Register.WelcomeChannel, fmt.Sprintf("Welcome, **%s**!", cmd.message.Author.Mention()), false) + sendMessage(cmd.session, cmd.config.RegisteredChannel, fmt.Sprintf("Welcome, **%s**!", cmd.message.Author.Mention()), false) return "", nil }, help: "Register yourself with the Discord", diff --git a/discord/status.go b/discord/status.go index 57eb5a5..e2afe3a 100644 --- a/discord/status.go +++ b/discord/status.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "gitea.com/jolheiser/gojang/query" "github.com/bwmarrin/discordgo" + "go.jolheiser.com/gojang/query" ) func init() { @@ -18,7 +18,7 @@ func init() { run: func(cmd commandInit) (string, error) { server := query.NewServer(cmd.config.Server.Address, cmd.config.Server.Port) - q, err := server.Query(query.DefaultTimeout, query.DefaultDeadline) + q, err := server.Query(query.DefaultTimeout) if err != nil { return "", err } diff --git a/discord/unban.go b/discord/unban.go index cee5344..b699acd 100644 --- a/discord/unban.go +++ b/discord/unban.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "git.canopymc.net/Etzelia/canopeas/database" + "go.etztech.xyz/sedbot/database" ) func init() { diff --git a/discord/utils.go b/discord/utils.go index c599243..22b60cc 100644 --- a/discord/utils.go +++ b/discord/utils.go @@ -5,9 +5,9 @@ import ( "net/http" "time" - "git.canopymc.net/Etzelia/canopeas/database" + "go.etztech.xyz/sedbot/database" - "git.canopymc.net/Etzelia/go-serverapi" + "go.etztech.xyz/go-serverapi" "go.jolheiser.com/beaver" ) diff --git a/discord/utils_test.go b/discord/utils_test.go index 9444471..f0d2e04 100644 --- a/discord/utils_test.go +++ b/discord/utils_test.go @@ -11,7 +11,7 @@ func TestRateLimit(t *testing.T) { } now() - limit := NewRateLimit(time.Second) + limit := NewRateLimit(time.Second * 2) if ok := limit.Try(); !ok { now() @@ -25,7 +25,7 @@ func TestRateLimit(t *testing.T) { t.FailNow() } - time.Sleep(time.Millisecond * 500) + time.Sleep(time.Second) if ok := limit.Try(); ok { now() @@ -33,7 +33,7 @@ func TestRateLimit(t *testing.T) { t.FailNow() } - time.Sleep(time.Millisecond * 500) + time.Sleep(time.Second) if ok := limit.Try(); !ok { now() diff --git a/discord/xkcd.go b/discord/xkcd.go index d7e861c..b498a76 100644 --- a/discord/xkcd.go +++ b/discord/xkcd.go @@ -2,12 +2,11 @@ package discord import ( "context" - "errors" "fmt" "strconv" "strings" - "gitea.com/jolheiser/xkcd" + "go.jolheiser.com/xkcd" ) func init() { @@ -31,7 +30,7 @@ func init() { } else { comicNum, err := strconv.Atoi(args[1]) if err != nil { - return "", errors.New("this command only accepts a number or no arguments") + return "", err } comic, err = client.Comic(context.Background(), comicNum) } diff --git a/go.mod b/go.mod index 2e0b0b8..f90ef43 100644 --- a/go.mod +++ b/go.mod @@ -1,21 +1,21 @@ -module git.canopymc.net/Etzelia/canopeas +module go.etztech.xyz/sedbot go 1.16 require ( - git.canopymc.net/Etzelia/falseknees v0.0.0-20210713232726-7325698e2451 - git.canopymc.net/Etzelia/go-mcm v0.0.0-20210713232816-d2b27d7edff0 - git.canopymc.net/Etzelia/go-serverapi v0.0.0-20210713233104-94e800dbb304 - git.canopymc.net/Etzelia/inspiro v0.0.3-0.20210713233035-ffd88077147f - gitea.com/jolheiser/gojang v0.0.7 - gitea.com/jolheiser/xkcd v0.0.2 github.com/bwmarrin/discordgo v0.22.0 github.com/dghubble/go-twitter v0.0.0-20201011215211-4b180d0cc78d github.com/dghubble/oauth1 v0.7.0 github.com/gorilla/websocket v1.4.2 // indirect github.com/pelletier/go-toml v1.8.1 go.etcd.io/bbolt v1.3.4 + go.etztech.xyz/falseknees v0.0.1 + go.etztech.xyz/go-mcm v1.3.1 + go.etztech.xyz/go-serverapi v0.0.3 + go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359 go.jolheiser.com/beaver v1.0.2 + go.jolheiser.com/gojang v0.0.3 + go.jolheiser.com/xkcd v0.0.1 golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect golang.org/x/sys v0.0.0-20201024232916-9f70ab9862d5 // indirect ) diff --git a/go.sum b/go.sum index 8b1ea55..7ba0f54 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,3 @@ -git.canopymc.net/Etzelia/falseknees v0.0.0-20210713232726-7325698e2451 h1:EbxWDS7sOyxv8einE7ps8WsywvlFqyKp3vdvk4PYVw4= -git.canopymc.net/Etzelia/falseknees v0.0.0-20210713232726-7325698e2451/go.mod h1:bgGHtcoYFmNIFgcU4P2LwqANZsJxoygnLI0C6OWE/U4= -git.canopymc.net/Etzelia/go-mcm v0.0.0-20210713232816-d2b27d7edff0 h1:UrwR0Ap4sjoRDfbi/ow76OeBAR9pI+BFKMYU6Jj9EtU= -git.canopymc.net/Etzelia/go-mcm v0.0.0-20210713232816-d2b27d7edff0/go.mod h1:M9yjY5mBSK5vGVPru7RG6K5bUfoRH7dTtyQ+MCuJ33g= -git.canopymc.net/Etzelia/go-serverapi v0.0.0-20210713233104-94e800dbb304 h1:gBzoEToJCO1nKbfhfzhGMgSWY6szwDbA8doVmPr3SIY= -git.canopymc.net/Etzelia/go-serverapi v0.0.0-20210713233104-94e800dbb304/go.mod h1:U0H8WgtAzR+L+65odnpUH1lT6z7ylcG6R9keOOTG+fk= -git.canopymc.net/Etzelia/inspiro v0.0.3-0.20210713233035-ffd88077147f h1:CupD+6/4Vrx0fGDIFf+cu8ponr19or3bCzkPPQXmRJk= -git.canopymc.net/Etzelia/inspiro v0.0.3-0.20210713233035-ffd88077147f/go.mod h1:7zYT6obYO7/a3v+gV+uNfNlWK1dJz6Mz7lY9FeRSGOU= -gitea.com/jolheiser/gojang v0.0.7 h1:Q4cG7QYiKQsJtUWgXXiolAH9DCLRoaQ4olaO9OV628U= -gitea.com/jolheiser/gojang v0.0.7/go.mod h1:r9kj2wv/21Da7VpWz+qmxLexH85o2BAM4NMxeYgQlcY= -gitea.com/jolheiser/xkcd v0.0.2 h1:HJP83YwSKxSYcoNfpb1ZpAfBvkUAnN+YgeukraXtfrc= -gitea.com/jolheiser/xkcd v0.0.2/go.mod h1:aDa2vX54wLaX8Ra5CGN2GWBX13UWAGJKGGddzHl/hks= github.com/bwmarrin/discordgo v0.22.0 h1:uBxY1HmlVCsW1IuaPjpCGT6A2DBwRn0nvOguQIxDdFM= github.com/bwmarrin/discordgo v0.22.0/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M= github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY= @@ -37,10 +25,22 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= +go.etztech.xyz/falseknees v0.0.1 h1:XjlBqMyBUH5b7e/9oedEwZ9pnz3sqMhXQv6vnQocxeM= +go.etztech.xyz/falseknees v0.0.1/go.mod h1:Acn1AwrvAArQEqhMBDlak5BvCZ3jgV8vdL8Pe5ZldRE= +go.etztech.xyz/go-mcm v1.3.1 h1:RLdOQrMgw0eP7bsfRRbXLW8c5/RaJ5Mg7i/ESFaUwvY= +go.etztech.xyz/go-mcm v1.3.1/go.mod h1:Hz2YULB3sN/aQA8cPSm2d6LM3E3qTMspzfRCIAD/1dc= +go.etztech.xyz/go-serverapi v0.0.3 h1:h2Zww0x5E61cH4jXB97x3oUnbryEuLkuq+RTgIi5/U4= +go.etztech.xyz/go-serverapi v0.0.3/go.mod h1:tq4J5zxVnAwzOiv79iLUzpfNAd7IoNirOfb0gt3/IEY= +go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359 h1:j/ZeoAj185wHfCSYD52Kt/69i3Bzk1MXN4Qh1yP6+P4= +go.etztech.xyz/inspiro v0.0.0-20200606185551-edfdf9da2359/go.mod h1:+fC1WzJm/oS4UEgqr1jPouWerxBys52lTTDA94/5bf8= go.jolheiser.com/beaver v1.0.2 h1:KA2D6iO8MQhZi1nZYi/Chak/f1Cxfrs6b1XO623+Khk= go.jolheiser.com/beaver v1.0.2/go.mod h1:7X4F5+XOGSC3LejTShoBdqtRCnPWcnRgmYGmG3EKW8g= +go.jolheiser.com/gojang v0.0.3 h1:EWDLMo6X3f67DK2p/mSB680H43t8SDrDYNZnXvY7PLg= +go.jolheiser.com/gojang v0.0.3/go.mod h1:hUBULFDoampNM97E1IaYUhkLBJ30sb7iGsoFOdDU76I= go.jolheiser.com/gql v0.0.1 h1:y3LGHcJUZI9otTCcMn8TVdF3aEzNX0FW6m0YUamlLto= go.jolheiser.com/gql v0.0.1/go.mod h1:74eYqVRIxsOFxtVl0RYGKNyYQgJYQaxOCgar7LP71Hw= +go.jolheiser.com/xkcd v0.0.1 h1:pRNY2BXxUS+NMtKlm/ENumOr7g3k4VWY/QoDri9YSNU= +go.jolheiser.com/xkcd v0.0.1/go.mod h1:AzWPrZToCLfpazsZBkeu/nPuIvurMqfCOptiydz7Dvk= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E= diff --git a/imgur/imgur.go b/imgur/imgur.go index 0b2e680..b7b6378 100644 --- a/imgur/imgur.go +++ b/imgur/imgur.go @@ -6,6 +6,10 @@ import ( "net/http" ) +// TODO Make a client for this in a separate module + +var Images []*Image + type Response struct { Images []*Image `json:"data"` Success bool `json:"success"` @@ -29,20 +33,23 @@ type Image struct { Link string `json:"link"` } -func Get(clientID, albumID string) ([]*Image, error) { +func Init(clientID string) error { - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://api.imgur.com/3/album/%s/images", albumID), nil) + req, err := http.NewRequest(http.MethodGet, "https://api.imgur.com/3/album/TaJVIdQ/images", nil) if err != nil { - return nil, err + return err } req.Header.Set("Authorization", fmt.Sprintf("Client-ID %s", clientID)) resp, err := http.DefaultClient.Do(req) if err != nil { - return nil, err + return err } - defer resp.Body.Close() var imgurResp Response - return imgurResp.Images, json.NewDecoder(resp.Body).Decode(&imgurResp) + if err := json.NewDecoder(resp.Body).Decode(&imgurResp); err != nil { + return err + } + Images = imgurResp.Images + return resp.Body.Close() } diff --git a/main.go b/main.go index 295fe0c..9be634f 100644 --- a/main.go +++ b/main.go @@ -6,9 +6,9 @@ import ( "os/signal" "syscall" - "git.canopymc.net/Etzelia/canopeas/config" - "git.canopymc.net/Etzelia/canopeas/database" - "git.canopymc.net/Etzelia/canopeas/discord" + "go.etztech.xyz/sedbot/config" + "go.etztech.xyz/sedbot/database" + "go.etztech.xyz/sedbot/discord" "go.jolheiser.com/beaver" ) @@ -16,7 +16,7 @@ import ( var configFlag string func main() { - flag.StringVar(&configFlag, "config", "canopeas.toml", "Set config path") + flag.StringVar(&configFlag, "config", "sedbot.toml", "Set config path") flag.Parse() beaver.Console.Format = beaver.FormatOptions{