NukeBot

package module
v0.0.0-...-97b5758 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

README

NukeBot

retention policies for 'gamers'

NukeBot is a Discord bot that will automatically delete messages from a designated channel.

Messages are deleted on a "rolling" basis -- if you set a 24-hour live time, each message will be deleted 24 hours after it is posted (as opposed to all messages being deleted every 24 hours).

If you have an urgent message about the operation of the bot, say @Nuke adminhelp ... your message here ... and I'll get back to you as soon as I see it.

Add it to your server here: https://NukeBot.riking.org/discord_auto_delete/oauth/start

Support me on Patreon if you enjoy the bot or to help keep it running! https://www.patreon.com/riking

Announcements server: https://discord.gg/FUGn8yE

Usage

Create a new "purged" channel where messages will automatically be deleted. Someone with MANAGE_MESSAGES permission (usually an admin) needs to say @Nuke start 100 24h to start the bot and tell it which channel you are using.

The 100 in the start command is the maximum number of live messages in the channel before the oldest is deleted. The 24h is a duration after which every message will be deleted. Acceptable units are h for hours, m for minutes, s for seconds. Warning: Durations of a day or longer still need to be specified in hours.

Make sure to mention the bot user and not the role alias!

A "voice-text" channel might want a shorter duration, e.g. 30m or 10m, when you just want "immediate" chat with no memory.

The bot must have permission to read (obviously) and send messages in the channel you are using, in addition to the Manage Messages permission. If the bot is missing permissions, it will disable itself and attempt to tell you, though this usually won't work when it can't send messages.

To turn off the bot, use @Nuke set 0 to turn off auto-deletion.

For a quick reminder of these rules, just say @Nuke help.

If you need extra help, say @Nuke adminhelp ... message ... to send a message to the support guild.

Deployment

Custom

See the docs directory for setup scripts and the configuration files that run the official bot instance.

Docker

How to build the docker containers:

docker build -t myimages/NukeBot:tag .

Pre-built docker containers have been uploaded by the community to https://hub.docker.com/ if you wish to use them. These image owners should also be contactable over the support Discord server.

Required Mounts:

/path/to/storage/config.yml:/NukeBot/config.yml
/path/to/storage/data/:/NukeBot/data/

Example:

docker run -d -p 2202:2202/tcp \
 --name NukeBot \
 -v /opt/NukeBot/config.yml:/NukeBot/config.yml \
 -v /opt/NukeBot/data/:/NukeBot/data/ \
 --restart=always \
 myimages/NukeBot:tag

Policy

The following two sections apply only to the hosted, community instance that can be invited to your server at the link above, as well as the help server and this GitHub repository.

Any changes to the following policies will be announced on the support server in the #announce channel.

Privacy

The following section is a DRAFT and may be incomplete and is subject to change, though the information present is correct to the best of my knowledge.

No message content is ever retained, except in the case when a message "@-mentions" the bot, where it may be retained to provide support or improve the bot. The "adminhelp" command transmits the provided message content to a channel in Discord and is subject to Discord's retention policies. Deleting a command invocation via the Discord interface has no effect on how long the bot's information about the invocation is stored.

The "community instance" of the bot will retain operational usage data, including data that identifies a particular guild or channel ID and/or with high-resolution timestamps. The full form of this data will be retained for 45 days (cite), and aggregated or summarized forms will be retained for up to 1.5 years. Usage data will not be used for commercial purposes except for the purpose of encouraging people to financially support the bot in a non-automated manner (in particular, usage data will not be sold or provided to any third party).

In order to faciliate product support, and response and detection of violations of the Acceptable Use Policy, an automated scan of your Guild structure will be performed and a report produced, with a focus on users and roles carrying the Manage Messages permission and channels where the bot is or was active. These reports may be shared with a limited audience to the extent necessary to identify or cure violations of the Acceptable Use Policy.

Contact Riking via the announcements server if you would like to request a copy of this data under the GDPR or equivalent consumer rights legislation.

The settings for a channel are kept on disk with the channel ID, guild ID, pinned message IDs, pin version timestamp, and time / count settings together. In the case that a channel is removed from the bot, either through set 0 or kicking the bot from the server, these settings are deleted. Backup or archival copies of the settings may be retained indefinitely but will not be used except for the purposes of disaster recovery.

Acceptable Use

The bot may not be used to perform or to assist with any of the following actions:

  • improperly use support channels to make false reports;
  • engage in conduct that is fraudulent or illegal;
  • generally, to cover up, hide, or perform any violation of the Discord Terms of Service;
  • to cause the bot to violate the Discord Terms of Service if it would not have violated those terms without your actions;
  • strain the technical infrastructure of the bot with an unreasonable volume or rate of requests, or requests designed to create an unreasonable load, except with explicit permission to conduct a specific technical or security test;
  • any use of the bot in a role where malfunction, improper operation, or normal operation of the bot could cause damages that exceed the greater of (a) $100 US Dollars or (b) the amount you have paid to the Operator of the bot;

Violations of the Acceptable Use Policy may be dealt with in one or more of the following manners:

  • An informal warning from the Operator, sent via the help server, via Discord DM, or from the bot's account through Discord.
  • A formal warning from the Operator, sent from the bot's account through Discord.
  • Removal of service from your guild, with or without warning.
  • Refusal of service to any guilds a particular user operates or has moderation capabilities on.
  • Referral of incident details to Discord, law enforcement, or other competent authorities.
  • Cooperating with investigations by Discord, law enforcement, or other competent authorities.

While the above list of remedies is generally ordered by severity, the Operator has no obligation to respect the ordering of the list, to enact any specific remedy, or to take action against any specific violation. Lack of action in response to a violation is not a waiver against future remedial action (in particular, note limited investigational capacity).

If you cannot comply with the Acceptable Use Policy, you must download the code of the bot and run it on your own infrastructure, accepting all responsibility for your actions.

Limitation of Liability

Under no circumstance will Operators's total liability arising from your use of the service exceed the greater of (a) the amount of fees Operator received from you or (b) $100 US dollars. This includes consequential, incidential, special, punitive, or indirect damages, based on any legal theory, even if the side liable is advised that the other may suffer damages, and even if You paid no fees at all. Some jurisdictions do not allow the exclusion of implied warranties or limitation of liability for incidental or consequential damages. In these jurisdictions, Operator's liability will be limited to the greatest extent permitted by law.

The service is provided to you without obligation of payment, and it is your responsibility to take actions to account for potentially harmful actions it may perform.

As a reminder, the Apache License, Version 2, and not the above paragraphs, applies to source distributions of this software:

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandAdminHelp

func CommandAdminHelp(b *Bot, m *discordgo.Message, rest []string)

func CommandAdminSay

func CommandAdminSay(b *Bot, m *discordgo.Message, rest []string)

func CommandCheck

func CommandCheck(b *Bot, m *discordgo.Message, rest []string)

func CommandHelp

func CommandHelp(b *Bot, m *discordgo.Message, rest []string)

func CommandLeave

func CommandLeave(b *Bot, m *discordgo.Message, rest []string)

func CommandModify

func CommandModify(b *Bot, m *discordgo.Message, rest []string)

func CommandSetDonor

func CommandSetDonor(b *Bot, m *discordgo.Message, rest []string)

Types

type BansFile

type BansFile struct {
	Guilds []string `yaml:"guilds"`
}

type Bot

type Bot struct {
	Config
	// contains filtered or unexported fields
}

func New

func New(c Config) *Bot

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) Channel

func (b *Bot) Channel(channelID string) (*discordgo.Channel, error)

Get a discord Channel. Results are cached in the library State.

func (*Bot) ConnectDiscord

func (b *Bot) ConnectDiscord(shardID, shardCount int) error

func (*Bot) GetChannel

func (b *Bot) GetChannel(channelID string, qos LoadQOS) (*ManagedChannel, error)

func (*Bot) GetMsgChGuild

func (b *Bot) GetMsgChGuild(m *discordgo.Message) (*discordgo.Channel, *discordgo.Guild)

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) IsInShard

func (b *Bot) IsInShard(guildID string) bool

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 (b *Bot) LoadChannelConfigs() error

func (*Bot) OAuthStartURL

func (b *Bot) OAuthStartURL() string

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) OnMessage

func (b *Bot) OnMessage(s *discordgo.Session, m *discordgo.MessageCreate)

func (*Bot) OnReady

func (b *Bot) OnReady(s *discordgo.Session, m *discordgo.Ready)

func (*Bot) OnResume

func (b *Bot) OnResume(s *discordgo.Session, r *discordgo.Resumed)

func (*Bot) QueueLoadBacklog

func (b *Bot) QueueLoadBacklog(c *ManagedChannel, qos LoadQOS)

func (*Bot) QueueReap

func (b *Bot) QueueReap(c *ManagedChannel)

func (*Bot) ReportToLogChannel

func (b *Bot) ReportToLogChannel(msg string)

func (*Bot) SaveAllChannelConfigs

func (b *Bot) SaveAllChannelConfigs() []error

func (*Bot) SaveChannelConfig

func (b *Bot) SaveChannelConfig(channelID string) error

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) IsBanned

func (s *DiskStorage) IsBanned(guildID string) (bool, 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

func (q LoadQOS) ApplyBackoff() bool

func (LoadQOS) Time

func (q LoadQOS) Time() time.Time

func (LoadQOS) Upgrade

func (q LoadQOS) Upgrade(to LoadQOS) LoadQOS

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 (*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) Reap

func (c *ManagedChannel) Reap(msgs []string) (int, error)

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.

Directories

Path Synopsis
cmd
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL