Documentation
¶
Index ¶
- func CommandAdminHelp(b *Bot, m *discordgo.Message, rest []string)
- func CommandAdminSay(b *Bot, m *discordgo.Message, rest []string)
- func CommandCheck(b *Bot, m *discordgo.Message, rest []string)
- func CommandHelp(b *Bot, m *discordgo.Message, rest []string)
- func CommandLeave(b *Bot, m *discordgo.Message, rest []string)
- func CommandModify(b *Bot, m *discordgo.Message, rest []string)
- func CommandSetDonor(b *Bot, m *discordgo.Message, rest []string)
- type BansFile
- type Bot
- func (b *Bot) CancelReap(c *ManagedChannel)
- func (b *Bot) Channel(channelID string) (*discordgo.Channel, error)
- func (b *Bot) ConnectDiscord(shardID, shardCount int) error
- func (b *Bot) GetChannel(channelID string, qos LoadQOS) (*ManagedChannel, error)
- func (b *Bot) GetMsgChGuild(m *discordgo.Message) (*discordgo.Channel, *discordgo.Guild)
- func (b *Bot) HTTPOAuthCallback(w http.ResponseWriter, r *http.Request)
- func (b *Bot) HTTPOAuthStart(w http.ResponseWriter, r *http.Request)
- func (b *Bot) HandleMentions(s *discordgo.Session, m *discordgo.MessageCreate)
- func (b *Bot) IsInShard(guildID string) bool
- func (b *Bot) LoadAllBacklogs()
- func (b *Bot) LoadChannelConfigs() error
- func (b *Bot) OAuthStartURL() string
- func (b *Bot) OnChannelDelete(s *discordgo.Session, ev *discordgo.ChannelDelete)
- func (b *Bot) OnChannelPins(s *discordgo.Session, ev *discordgo.ChannelPinsUpdate)
- func (b *Bot) OnGuildRemove(s *discordgo.Session, ev *discordgo.GuildDelete)
- func (b *Bot) OnMessage(s *discordgo.Session, m *discordgo.MessageCreate)
- func (b *Bot) OnReady(s *discordgo.Session, m *discordgo.Ready)
- func (b *Bot) OnResume(s *discordgo.Session, r *discordgo.Resumed)
- func (b *Bot) QueueLoadBacklog(c *ManagedChannel, qos LoadQOS)
- func (b *Bot) QueueReap(c *ManagedChannel)
- func (b *Bot) ReportToLogChannel(msg string)
- func (b *Bot) SaveAllChannelConfigs() []error
- func (b *Bot) SaveChannelConfig(channelID string) error
- type Config
- type DiskStorage
- func (s *DiskStorage) AddBan(guildID string) error
- func (s *DiskStorage) DeleteChannel(id string) error
- func (s *DiskStorage) GetChannel(channelID string) (ManagedChannelMarshal, error)
- func (s *DiskStorage) IsBanned(guildID string) (bool, error)
- func (s *DiskStorage) ListChannels() ([]string, error)
- func (s *DiskStorage) SaveChannel(conf ManagedChannelMarshal) error
- type LoadQOS
- type ManagedChannel
- func (c *ManagedChannel) AddMessage(m *discordgo.Message)
- func (c *ManagedChannel) Disable()
- func (c *ManagedChannel) DoNotDeleteMessage(msgID string)
- func (c *ManagedChannel) Enabled() bool
- func (c *ManagedChannel) Export() ManagedChannelMarshal
- func (c *ManagedChannel) GetNextDeletionTime() (deadline time.Time)
- func (c *ManagedChannel) IsDisabled() bool
- func (c *ManagedChannel) LoadBacklog() error
- func (c *ManagedChannel) LoadBacklogNow()
- func (c *ManagedChannel) Reap(msgs []string) (int, error)
- func (c *ManagedChannel) SetLiveTime(d time.Duration)
- func (c *ManagedChannel) SetMaxMessages(max int)
- func (c *ManagedChannel) String() string
- func (c *ManagedChannel) UpdatePins(newLpts string)
- type ManagedChannelMarshal
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bot ¶
type Bot struct {
Config
// contains filtered or unexported fields
}
func (*Bot) CancelReap ¶
func (b *Bot) CancelReap(c *ManagedChannel)
Removes the given channel from the reaper, assuming that IsDisabled() will return true for the passed ManagedChannel.
func (*Bot) ConnectDiscord ¶
func (*Bot) GetChannel ¶
func (b *Bot) GetChannel(channelID string, qos LoadQOS) (*ManagedChannel, error)
func (*Bot) GetMsgChGuild ¶
func (*Bot) HTTPOAuthCallback ¶
func (b *Bot) HTTPOAuthCallback(w http.ResponseWriter, r *http.Request)
func (*Bot) HTTPOAuthStart ¶
func (b *Bot) HTTPOAuthStart(w http.ResponseWriter, r *http.Request)
func (*Bot) HandleMentions ¶
func (b *Bot) HandleMentions(s *discordgo.Session, m *discordgo.MessageCreate)
func (*Bot) LoadAllBacklogs ¶
func (b *Bot) LoadAllBacklogs()
Queue up work to reload the backlog of every channel.
We do this by straight-up replacing the queue with a brand new heap, because there's no point in preserving the old entries if we're just doing everything over again.
func (*Bot) LoadChannelConfigs ¶
func (*Bot) OAuthStartURL ¶
func (*Bot) OnChannelDelete ¶
func (b *Bot) OnChannelDelete(s *discordgo.Session, ev *discordgo.ChannelDelete)
func (*Bot) OnChannelPins ¶
func (b *Bot) OnChannelPins(s *discordgo.Session, ev *discordgo.ChannelPinsUpdate)
func (*Bot) OnGuildRemove ¶
func (b *Bot) OnGuildRemove(s *discordgo.Session, ev *discordgo.GuildDelete)
func (*Bot) QueueLoadBacklog ¶
func (b *Bot) QueueLoadBacklog(c *ManagedChannel, qos LoadQOS)
func (*Bot) QueueReap ¶
func (b *Bot) QueueReap(c *ManagedChannel)
func (*Bot) ReportToLogChannel ¶
func (*Bot) SaveAllChannelConfigs ¶
func (*Bot) SaveChannelConfig ¶
type Config ¶
type Config struct {
ClientID string `yaml:"clientid"`
ClientSecret string `yaml:"clientsecret"`
BotToken string `yaml:"bottoken"`
// discord user ID
AdminUser string `yaml:"adminuser"`
// 0: do not use sharding
Shards int `yaml:"shards"`
// discord channel ID
ErrorLogCh string `yaml:"errorlog"`
HTTP struct {
Listen string `yaml:"listen"`
Public string `yaml:"public"`
} `yaml:"http"`
StatusMessage *string `yaml:"statusmessage"`
// discord guild ID
DonorGuild string `yaml:"donor_guild"`
// discord role IDs
DonorRoleIDs []string `yaml:"donor_roles"`
BacklogLengthLimit int `yaml:"backlog_limit"`
DonorBacklogLimit int `yaml:"backlog_limit_donor"`
}
type DiskStorage ¶
type DiskStorage struct {
}
Stores channel configurations on disk as YAML files.
func (*DiskStorage) AddBan ¶
func (s *DiskStorage) AddBan(guildID string) error
func (*DiskStorage) DeleteChannel ¶
func (s *DiskStorage) DeleteChannel(id string) error
func (*DiskStorage) GetChannel ¶
func (s *DiskStorage) GetChannel(channelID string) (ManagedChannelMarshal, error)
func (*DiskStorage) ListChannels ¶
func (s *DiskStorage) ListChannels() ([]string, error)
func (*DiskStorage) SaveChannel ¶
func (s *DiskStorage) SaveChannel(conf ManagedChannelMarshal) error
type LoadQOS ¶
type LoadQOS int8
Quality of service for the load queues. Lower numbers are higher priority.
The reuse of the reap queue for backlog load ordering is a hack - this should really be an ordered list of FIFO queues - but it's easier to just reuse the code. Plus, we get "wait until timestamp" for QOSLoadError for "free".
const ( QOSInteractive LoadQOS = iota // Modify command QOSNewMessage // Saw message in channel QOSInitNoPins // Bot start events QOSLargeDelete // Deleted >25 messages QOSSingleMessageDelete // Saw extremely old messages QOSInitWithPins // Start event with LPTS QOSLoadError // Previous attempt error QOSInvalid QOSInit = QOSInitWithPins )
func (LoadQOS) ApplyBackoff ¶
type ManagedChannel ¶
type ManagedChannel struct {
ChannelID string
ChannelName string
GuildID string
// Messages posted to the channel get deleted after
MessageLiveTime time.Duration
MaxMessages int
KeepMessages []string
// if lower than CriticalMsgSequence, need to send one
LastSentUpdate int
IsDonor bool
// contains filtered or unexported fields
}
A ManagedChannel holds all the NukeBot-related state for a Discord channel.
func InitChannel ¶
func InitChannel(b *Bot, chConf ManagedChannelMarshal) (*ManagedChannel, error)
func (*ManagedChannel) AddMessage ¶
func (c *ManagedChannel) AddMessage(m *discordgo.Message)
func (*ManagedChannel) Disable ¶
func (c *ManagedChannel) Disable()
Remove this channel from all relevant datastructures.
Must be called with no locks held. Takes Bot, self, and reapq locks. Can be called on a fake ManagedChannel instance (e.g. (&ManagedChannel{ChannelID: ...}).Disable()), so the only member assumed valid is bot and ChannelID.
func (*ManagedChannel) DoNotDeleteMessage ¶
func (c *ManagedChannel) DoNotDeleteMessage(msgID string)
DoNotDeleteMessage marks a message ID as not for deletion. only called from UpdatePins()
func (*ManagedChannel) Enabled ¶
func (c *ManagedChannel) Enabled() bool
func (*ManagedChannel) Export ¶
func (c *ManagedChannel) Export() ManagedChannelMarshal
func (*ManagedChannel) GetNextDeletionTime ¶
func (c *ManagedChannel) GetNextDeletionTime() (deadline time.Time)
func (*ManagedChannel) IsDisabled ¶
func (c *ManagedChannel) IsDisabled() bool
func (*ManagedChannel) LoadBacklog ¶
func (c *ManagedChannel) LoadBacklog() error
func (*ManagedChannel) LoadBacklogNow ¶
func (c *ManagedChannel) LoadBacklogNow()
func (*ManagedChannel) SetLiveTime ¶
func (c *ManagedChannel) SetLiveTime(d time.Duration)
func (*ManagedChannel) SetMaxMessages ¶
func (c *ManagedChannel) SetMaxMessages(max int)
func (*ManagedChannel) String ¶
func (c *ManagedChannel) String() string
func (*ManagedChannel) UpdatePins ¶
func (c *ManagedChannel) UpdatePins(newLpts string)
UpdatePins gets called in two situations - a pin was added, a pin was removed, or more than one of those happened too fast for us to notice.
type ManagedChannelMarshal ¶
type ManagedChannelMarshal struct {
ID string `yaml:"id"`
GuildID string `yaml:"guild_id"`
LiveTime time.Duration `yaml:"live_time"`
MaxMessages int `yaml:"max_messages"`
LastSentUpdate int `yaml:"last_critical_msg"`
HasPins bool `yaml:"has_pins,omitempty"`
IsDonor bool `yaml:"is_donor,omitempty"`
// ConfMessageID is deprecated.
ConfMessageID string `yaml:"conf_message_id,omitempty"`
KeepMessages []string `yaml:"keep_messages"`
}
type Storage ¶
type Storage interface {
ListChannels() ([]string, error)
// Special errors:
// - os.IsNotExist() - no configuration for channel
GetChannel(id string) (ManagedChannelMarshal, error)
SaveChannel(conf ManagedChannelMarshal) error
DeleteChannel(id string) error
IsBanned(guildID string) (bool, error)
AddBan(guildID string) error
}
Interface to the storage systems.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
NukeBot
command
|
|
|
Package topk provides a Metric/Collector implementation of a top-K streaming summary algorithm for use with high cardinality data.
|
Package topk provides a Metric/Collector implementation of a top-K streaming summary algorithm for use with high cardinality data. |
