watcher

package
v0.0.0-...-87369cd Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Watcher

type Watcher struct {
	// The database instance.
	DB *gorm.DB

	// The discord session.
	Session *discordgo.Session

	// A custom HTTP client.
	Client *http.Client

	// The discord command Prefix. Usually '!'.
	Prefix string

	// The web page changes ratio. Must be between 0 and 1.
	// Every x minutes the watcher will fetch the website page and compares it with the previous version.
	// It will check changes and convert these changes to a ratio. If page are identical, this ratio is equals to 1.0,
	// and it will decrease for every detected change.
	ChangeRatio float64

	// The WatchInterval determines the interval at which the watcher will crawl web pages.
	WatchInterval time.Duration

	// A list of running tasks.
	Tasks map[string]context.CancelFunc
}

func New

func New(watchInterval time.Duration, changeRatio float64, discordToken string, prefix string) (*Watcher, error)

func (*Watcher) NewTask

func (w *Watcher) NewTask(task *models.Task)

Add a new task to the list and run it. If a task already exits for the given URL then cancel it and override it.

func (*Watcher) Run

func (w *Watcher) Run() error

Fetch existing tasks in database and run them, then connect to Discord API.

Jump to

Keyboard shortcuts

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