autodelete

package module
v0.0.0-...-e0d4ad7 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2019 License: Apache-2.0 Imports: 15 Imported by: 1

README

ClipCleaner

ClipCleaner is forked from riking's fantastic AutoDelete bot, with some modifications to the code to ignore messages containing Twitch Clip Links.

AutoDelete 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).

Usage

Create a new "purged" channel where messages will automatically be deleted. Someone with MANAGE_MESSAGES permission (usually an admin) needs to say @ClipCleaner 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.

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 @ClipCleaner set 0 to turn off auto-deletion.

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandAdminSay

func CommandAdminSay(b *Bot, m *discordgo.Message, rest []string)
func CommandAdminHelp(b *Bot, m *discordgo.Message, rest []string) {
	plainContent, err := m.ContentWithMoreMentionsReplaced(b.s)
	if err != nil {
		plainContent = m.Content
	}
	ch, guild := b.GetMsgChGuild(m)
	if guild == nil {
		return
	}
	b.ReportToLogChannel(fmt.Sprintf(
		"Adminhelp command from %s (%s#%s) in #%s (ch id %s) of '%s' (guild id %s):\n%s",
		m.Author.Mention(), m.Author.Username, m.Author.Discriminator,
		ch.Name, m.ChannelID,
		guild.Name, guild.ID,
		plainContent,
	))
}

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)

Types

type Bot

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

func New

func New(c Config) *Bot

func (*Bot) ConnectDiscord

func (b *Bot) ConnectDiscord() 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) LoadAllBacklogs

func (b *Bot) LoadAllBacklogs()

func (*Bot) LoadChannelConfigs

func (b *Bot) LoadChannelConfigs() error

func (*Bot) OAuthStartURL

func (b *Bot) OAuthStartURL() string

func (*Bot) OnChannelCreate

func (b *Bot) OnChannelCreate(s *discordgo.Session, ch *discordgo.ChannelCreate)

func (*Bot) OnChannelPins

func (b *Bot) OnChannelPins(s *discordgo.Session, ev *discordgo.ChannelPinsUpdate)

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, didFail bool)

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"`
	ErrorLogCh   string `yaml:"errorlog"`
	HTTP         struct {
		Listen string `yaml:"listen"`
		Public string `yaml:"public"`
	} `yaml:"http"`
}

type DiskStorage

type DiskStorage struct {
}

Stores channel configurations on disk as YAML files.

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 ManagedChannel

type ManagedChannel struct {
	Channel *discordgo.Channel
	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
}

func InitChannel

func InitChannel(b *Bot, chConf ManagedChannelMarshal) (*ManagedChannel, error)

func (*ManagedChannel) AddMessage

func (c *ManagedChannel) AddMessage(m *discordgo.Message)

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() time.Time

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

Interface to the storage systems.

Directories

Path Synopsis
cmd
autodelete command

Jump to

Keyboard shortcuts

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