modules

package
v0.0.0-...-2972d46 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserLevel int = iota
	ModLevel
	BroadcasterLevel
)

Variables

View Source
var PyramidModule = CommandModule{
	Commands: []*Command{
		{
			Regex: *regexp.MustCompile("pyramid$"),
			Arguments: []string{
				"content",
				"height",
			},
			Required: 1,
			Handle: func(
				params *HandlerParams,
				args ...string) {
				height := 3
				if len(args) > 1 {
					parsed, _ := strconv.Atoi(args[1])
					if parsed <= maxHeight {
						height = parsed
					}
				}
				for i := 0; i < height+1; i++ {
					params.module.Client.Say(
						params.message.Channel, strings.Repeat(args[0]+" ", i),
					)
				}
				for i := height - 1; i > 0; i-- {
					params.module.Client.Say(
						params.message.Channel, strings.Repeat(args[0]+" ", i),
					)
				}
			},
		},
	},
}
View Source
var QuoteModule = CommandModule{
	Commands: []*Command{
		{
			Regex: *regexp.MustCompile("q(uote)?(s)?$"),
			Arguments: []string{
				"number",
			},
			Required: 1,
			Handle:   findQuote,
			Commands: []*Command{
				{
					Regex: *regexp.MustCompile("add$"),
					Arguments: []string{
						"\"content\"",
						"author",
					},
					Required: 2,
					Level:    ModLevel,
					Handle:   addQuote,
				},
				{
					Regex: *regexp.MustCompile("del(ete)?$"),
					Arguments: []string{
						"number",
					},
					Required: 1,
					Level:    ModLevel,
					Handle:   deleteQuote,
				},
				{
					Regex: *regexp.MustCompile("search$"),
					Arguments: []string{
						"query",
					},
					Handle: searchQuote,
				},
			},
		},
	},
}
View Source
var RepeatModule = CommandModule{
	Commands: []*Command{
		{
			Regex: *regexp.MustCompile("scs$"),
			Handle: func(params *HandlerParams, args ...string) {
				query := db.Instance.
					Select("content").
					Table("message").
					Where("channel", params.message.Channel)

				includeConditions(params, query)

				var message string
				query.Find(&message)

				params.module.Client.Say(
					params.message.Channel,
					message,
				)
			},
		},
		{
			Regex: *regexp.MustCompile("sc$"),
			Arguments: []string{
				"query",
			},
			Required: 1,
			Handle: func(params *HandlerParams, args ...string) {
				searchQuery := strings.ToLower(ConcatArgs(args...))

				var message string
				query := db.Instance.
					Select("content").
					Table("message_fts").
					Where("content MATCH ?", searchQuery)

				includeConditions(params, query)

				result := query.Scan(&message)

				if result.RowsAffected == 0 {
					params.module.Respond(
						params.message, "No messages found 🔎",
					)
					return
				}

				params.module.Client.Say(params.message.Channel, message)
			},
		},
	},
}
View Source
var StatsModule = CommandModule{
	Commands: []*Command{
		{
			Regex: *regexp.MustCompile("stats$"),
			Handle: func(params *HandlerParams, args ...string) {
				uptime := time.Since(started).Round(time.Minute)

				var count int64
				db.Instance.Table("message").Select("COUNT(*)").Scan(&count)

				params.module.Respond(
					params.message,
					fmt.Sprintf("Current statistics for hambot🍖"+
						"%d 💬 messages | "+
						"%s ⏳ uptime", count, uptime,
					),
				)
			},
		},
	}}

Functions

func ConcatArgs

func ConcatArgs(args ...string) string

Types

type Command

type Command struct {
	Regex  regexp.Regexp
	Handle func(
		params *HandlerParams,
		args ...string,
	)
	Arguments []string
	Required  int
	Level     int
	Cooldown  float64
	LastUsed  time.Time
	Commands  []*Command
}

type CommandModule

type CommandModule struct {
	Module
	Commands []*Command
}

func (*CommandModule) OnMessage

func (h *CommandModule) OnMessage(message *twitch.PrivateMessage)

type EchoMessage

type EchoMessage struct {
	Message string
	Time    time.Time
}

type EchoModule

type EchoModule struct {
	Module
}

func (*EchoModule) OnMessage

func (m *EchoModule) OnMessage(message *twitch.PrivateMessage)

type HandlerParams

type HandlerParams struct {
	// contains filtered or unexported fields
}

type IModule

type IModule interface {
	Hook(client *twitch.Client)
	OnMessage(message *twitch.PrivateMessage)
}

type LogModule

type LogModule struct {
	Module
}

func (*LogModule) OnMessage

func (m *LogModule) OnMessage(message *twitch.PrivateMessage)

type Module

type Module struct {
	Client *twitch.Client
}

func (*Module) Hook

func (m *Module) Hook(client *twitch.Client)

func (*Module) Respond

func (h *Module) Respond(original *twitch.PrivateMessage, message string)

Jump to

Keyboard shortcuts

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