mirror of
https://github.com/Luzifer/discord-community.git
synced 2024-11-08 15:10:02 +00:00
Lint: Fix all linter errors
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
ad4099e9ce
commit
a35d0739cc
7 changed files with 57 additions and 32 deletions
|
@ -80,15 +80,15 @@ func (m moduleAttributeStore) Int64(name string) (int64, error) {
|
|||
return 0, errValueNotSet
|
||||
}
|
||||
|
||||
switch v.(type) {
|
||||
switch v := v.(type) {
|
||||
case int:
|
||||
return int64(v.(int)), nil
|
||||
return int64(v), nil
|
||||
case int16:
|
||||
return int64(v.(int16)), nil
|
||||
return int64(v), nil
|
||||
case int32:
|
||||
return int64(v.(int32)), nil
|
||||
return int64(v), nil
|
||||
case int64:
|
||||
return v.(int64), nil
|
||||
return v, nil
|
||||
}
|
||||
|
||||
return 0, errValueMismatch
|
||||
|
@ -117,14 +117,14 @@ func (m moduleAttributeStore) StringSlice(name string) ([]string, error) {
|
|||
return nil, errValueNotSet
|
||||
}
|
||||
|
||||
switch v.(type) {
|
||||
switch v := v.(type) {
|
||||
case []string:
|
||||
return v.([]string), nil
|
||||
return v, nil
|
||||
|
||||
case []interface{}:
|
||||
var out []string
|
||||
|
||||
for _, iv := range v.([]interface{}) {
|
||||
for _, iv := range v {
|
||||
sv, ok := iv.(string)
|
||||
if !ok {
|
||||
return nil, errors.New("value in slice was not string")
|
||||
|
|
|
@ -17,6 +17,10 @@ import (
|
|||
* @module_desc Cleans up old messages from a channel (for example announcement channel) which are older than the retention time
|
||||
*/
|
||||
|
||||
const (
|
||||
clearChannelNumberOfMessagesToLoad = 100
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterModule("clearchannel", func() module { return &modClearChannel{} })
|
||||
}
|
||||
|
@ -79,15 +83,15 @@ func (m modClearChannel) cronClearChannel() {
|
|||
}
|
||||
|
||||
for {
|
||||
msgs, err := m.discord.ChannelMessages(channelID, 100, "", after, "")
|
||||
msgs, err := m.discord.ChannelMessages(channelID, clearChannelNumberOfMessagesToLoad, "", after, "")
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Unable to fetch announcement channel messages")
|
||||
return
|
||||
}
|
||||
|
||||
sort.Slice(msgs, func(i, j int) bool {
|
||||
iu, _ := strconv.ParseUint(msgs[i].ID, 10, 64)
|
||||
ju, _ := strconv.ParseUint(msgs[j].ID, 10, 64)
|
||||
iu, _ := strconv.ParseUint(msgs[i].ID, 10, 64) //nolint: gomnd // These make no sense to define as constants
|
||||
ju, _ := strconv.ParseUint(msgs[j].ID, 10, 64) //nolint: gomnd // These make no sense to define as constants
|
||||
return iu < ju
|
||||
})
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -18,6 +19,16 @@ import (
|
|||
* @module_desc Announces stream live status based on Discord streaming status
|
||||
*/
|
||||
|
||||
const (
|
||||
livePostingDefaultStreamFreshness = 5 * time.Minute
|
||||
livePostingDiscordProfileHeight = 300
|
||||
livePostingDiscordProfileWidth = 300
|
||||
livePostingNumberOfMessagesToLoad = 100
|
||||
livePostingPreviewHeight = 180
|
||||
livePostingPreviewWidth = 320
|
||||
livePostingTwitchColor = 0x6441a5
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterModule("liveposting", func() module { return &modLivePosting{} })
|
||||
}
|
||||
|
@ -46,6 +57,7 @@ func (m *modLivePosting) Initialize(crontab *cron.Cron, discord *discordgo.Sessi
|
|||
return nil
|
||||
}
|
||||
|
||||
//nolint: gocyclo // One directive too many, makes no sense to split
|
||||
func (m modLivePosting) handlePresenceUpdate(d *discordgo.Session, p *discordgo.PresenceUpdate) {
|
||||
if p.User == nil {
|
||||
// The frick? Non-user presence?
|
||||
|
@ -127,7 +139,7 @@ func (m modLivePosting) handlePresenceUpdate(d *discordgo.Session, p *discordgo.
|
|||
}
|
||||
|
||||
// @attr stream_freshness optional duration "5m" How long after stream start to post shoutout
|
||||
ignoreTime := m.attrs.MustDuration("stream_freshness", ptrDuration(5*time.Minute))
|
||||
ignoreTime := m.attrs.MustDuration("stream_freshness", ptrDuration(livePostingDefaultStreamFreshness))
|
||||
if streams.Data[0].StartedAt.Add(ignoreTime).Before(time.Now()) {
|
||||
// Stream is too old, don't annoounce
|
||||
return
|
||||
|
@ -156,12 +168,12 @@ func (m modLivePosting) sendLivePost(username, displayName, title, game, preview
|
|||
)
|
||||
|
||||
// @attr discord_channel_id required string "" ID of the Discord channel to post the message to
|
||||
msgs, err := m.discord.ChannelMessages(m.attrs.MustString("discord_channel_id", nil), 100, "", "", "")
|
||||
msgs, err := m.discord.ChannelMessages(m.attrs.MustString("discord_channel_id", nil), livePostingNumberOfMessagesToLoad, "", "", "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fetching previous messages")
|
||||
}
|
||||
|
||||
ignoreTime := m.attrs.MustDuration("stream_freshness", ptrDuration(5*time.Minute))
|
||||
ignoreTime := m.attrs.MustDuration("stream_freshness", ptrDuration(livePostingDefaultStreamFreshness))
|
||||
for _, msg := range msgs {
|
||||
mt, err := msg.Timestamp.Parse()
|
||||
if err != nil {
|
||||
|
@ -177,19 +189,19 @@ func (m modLivePosting) sendLivePost(username, displayName, title, game, preview
|
|||
Name: displayName,
|
||||
IconURL: profileImage,
|
||||
},
|
||||
Color: 0x6441a5,
|
||||
Color: livePostingTwitchColor,
|
||||
Fields: []*discordgo.MessageEmbedField{
|
||||
{Name: "Game", Value: game},
|
||||
},
|
||||
Image: &discordgo.MessageEmbedImage{
|
||||
URL: strings.NewReplacer("{width}", "320", "{height}", "180").Replace(previewImage),
|
||||
Width: 320,
|
||||
Height: 180,
|
||||
URL: strings.NewReplacer("{width}", strconv.Itoa(livePostingPreviewWidth), "{height}", strconv.Itoa(livePostingPreviewHeight)).Replace(previewImage),
|
||||
Width: livePostingPreviewWidth,
|
||||
Height: livePostingPreviewHeight,
|
||||
},
|
||||
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
||||
URL: profileImage,
|
||||
Width: 300,
|
||||
Height: 300,
|
||||
Width: livePostingDiscordProfileWidth,
|
||||
Height: livePostingDiscordProfileHeight,
|
||||
},
|
||||
Title: title,
|
||||
Type: discordgo.EmbedTypeRich,
|
||||
|
|
|
@ -83,7 +83,7 @@ func (m modLiveRole) handlePresenceUpdate(d *discordgo.Session, p *discordgo.Pre
|
|||
return
|
||||
}
|
||||
|
||||
var exitFunc func(string, string, []string) error = m.removeLiveStreamerRole
|
||||
var exitFunc func(string, string, []string) error
|
||||
defer func() {
|
||||
if exitFunc != nil {
|
||||
if err := exitFunc(p.GuildID, p.User.ID, member.Roles); err != nil {
|
||||
|
|
|
@ -18,6 +18,10 @@ import (
|
|||
* @module_desc Updates the presence status of the bot to display the next stream
|
||||
*/
|
||||
|
||||
const (
|
||||
presenceTimeDay = 24 * time.Hour
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterModule("presence", func() module { return &modPresence{} })
|
||||
}
|
||||
|
@ -49,7 +53,7 @@ func (m *modPresence) Initialize(crontab *cron.Cron, discord *discordgo.Session,
|
|||
}
|
||||
|
||||
func (m modPresence) cronUpdatePresence() {
|
||||
var nextStream *time.Time = nil
|
||||
var nextStream *time.Time
|
||||
|
||||
twitch := newTwitchAdapter(
|
||||
// @attr twitch_client_id required string "" Twitch client ID the token was issued for
|
||||
|
@ -95,8 +99,8 @@ func (m modPresence) cronUpdatePresence() {
|
|||
|
||||
func (m modPresence) durationToHumanReadable(d time.Duration) string {
|
||||
d = time.Duration(math.Abs(float64(d)))
|
||||
if d > time.Hour*24 {
|
||||
return fmt.Sprintf("%.0f Tagen", math.Round(float64(d)/float64(time.Hour*24)))
|
||||
if d > presenceTimeDay {
|
||||
return fmt.Sprintf("%.0f Tagen", math.Round(float64(d)/float64(presenceTimeDay)))
|
||||
}
|
||||
|
||||
var elements []string
|
||||
|
|
|
@ -17,9 +17,14 @@ import (
|
|||
* @module_desc Posts stream schedule derived from Twitch schedule as embed in Discord channel
|
||||
*/
|
||||
|
||||
const (
|
||||
streamScheduleDefaultColor = 0x2ECC71
|
||||
streamScheduleNumberOfMessagesToLoad = 100
|
||||
)
|
||||
|
||||
var (
|
||||
defaultStreamScheduleEntries = ptrInt64(5)
|
||||
defaultStreamSchedulePastTime = ptrDuration(15 * time.Minute)
|
||||
defaultStreamScheduleEntries = ptrInt64(5) //nolint: gomnd // This is already the "constant"
|
||||
defaultStreamSchedulePastTime = ptrDuration(15 * time.Minute) //nolint: gomnd // This is already the "constant"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -75,13 +80,13 @@ func (m modStreamSchedule) cronUpdateSchedule() {
|
|||
}
|
||||
|
||||
msgEmbed := &discordgo.MessageEmbed{
|
||||
// @attr embed_color optional int64 "3066993" Integer representation of the hex color for the embed (default is #2ECC71)
|
||||
Color: int(m.attrs.MustInt64("embed_color", ptrInt64(3066993))),
|
||||
// @attr embed_color optional int64 "0x2ECC71" Integer representation of the hex color for the embed
|
||||
Color: int(m.attrs.MustInt64("embed_color", ptrInt64(streamScheduleDefaultColor))),
|
||||
// @attr embed_description optional string "" Description for the embed block
|
||||
Description: m.attrs.MustString("embed_description", ptrStringEmpty),
|
||||
Fields: []*discordgo.MessageEmbedField{},
|
||||
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
||||
// @attr embed_thumbnail_url optional string "" Publically hosted image URL to use as thumbnail
|
||||
// @attr embed_thumbnail_url optional string "" Publically hosted image URL to u100se as thumbnail
|
||||
URL: m.attrs.MustString("embed_thumbnail_url", ptrStringEmpty),
|
||||
// @attr embed_thumbnail_width optional int64 "" Width of the thumbnail
|
||||
Width: int(m.attrs.MustInt64("embed_thumbnail_width", ptrInt64Zero)),
|
||||
|
@ -117,7 +122,7 @@ func (m modStreamSchedule) cronUpdateSchedule() {
|
|||
}
|
||||
|
||||
// @attr discord_channel_id required string "" ID of the Discord channel to post the message to
|
||||
msgs, err := m.discord.ChannelMessages(m.attrs.MustString("discord_channel_id", nil), 100, "", "", "")
|
||||
msgs, err := m.discord.ChannelMessages(m.attrs.MustString("discord_channel_id", nil), streamScheduleNumberOfMessagesToLoad, "", "", "")
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Unable to fetch announcement channel messages")
|
||||
return
|
||||
|
|
|
@ -77,10 +77,10 @@ Posts stream schedule derived from Twitch schedule as embed in Discord channel
|
|||
| `twitch_client_id` | ✅ | string | | Twitch client ID the token was issued for |
|
||||
| `twitch_token` | ✅ | string | | Token for the user the `twitch_channel_id` belongs to |
|
||||
| `cron` | | string | `*/10 * * * *` | When to execute the schedule transfer |
|
||||
| `embed_color` | | int64 | `3066993` | Integer representation of the hex color for the embed (default is #2ECC71) |
|
||||
| `embed_color` | | int64 | `0x2ECC71` | Integer representation of the hex color for the embed |
|
||||
| `embed_description` | | string | | Description for the embed block |
|
||||
| `embed_thumbnail_height` | | int64 | | Height of the thumbnail |
|
||||
| `embed_thumbnail_url` | | string | | Publically hosted image URL to use as thumbnail |
|
||||
| `embed_thumbnail_url` | | string | | Publically hosted image URL to u100se as thumbnail |
|
||||
| `embed_thumbnail_width` | | int64 | | Width of the thumbnail |
|
||||
| `schedule_entries` | | int64 | `5` | How many schedule entries to add to the embed as fields |
|
||||
| `schedule_past_time` | | duration | `15m` | How long in the past should the schedule contain an entry |
|
||||
|
|
Loading…
Reference in a new issue