discord

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: MIT Imports: 6 Imported by: 0

README

Discord bots

Only for my own use...

Nickname still in use and others deprecated. Can be replaced by adding handler.

At least for now.

Still working on.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot added in v0.3.1

type Bot struct {
	Session *discordgo.Session
	BotName string
	// contains filtered or unexported fields
}

The struct for the bot.

func New

func New(token string, botName string) *Bot

Create a new bot.

func (*Bot) AddReplyRules added in v0.3.1

func (bot *Bot) AddReplyRules(rules ...ReplyRule)

Add reply rules to the bot.

func (*Bot) AllMembers added in v0.3.1

func (bot *Bot) AllMembers(guildID string) (allMembers []*discordgo.Member, err error)

Read all members of a guild.

func (*Bot) ChangeListening added in v0.3.1

func (bot *Bot) ChangeListening(listenTo string) error

Change the bot's "listening" status.

func (*Bot) ChangeNames added in v0.3.1

func (bot *Bot) ChangeNames(nickname string, guilds ...string) error

Change the bot's nicknames in the guilds.

func (*Bot) ChangePlaying added in v0.3.1

func (bot *Bot) ChangePlaying(gameName string) error

Change the bot's "playing" status.

func (*Bot) CheckUserRole added in v0.3.1

func (bot *Bot) CheckUserRole(userID string, guildID string, roleID string) (isRole bool)

Check if the user is the role of the guild.

func (*Bot) Close added in v0.3.1

func (bot *Bot) Close()

Close the bot.

func (*Bot) FilterRole deprecated added in v0.3.1

func (bot *Bot) FilterRole(guildID string, roleID string) (roleMembers []*discordgo.Member, err error)

Deprecated: Use FilterRoles instead. Read all members of a role.

func (*Bot) FilterRoles added in v0.3.1

func (bot *Bot) FilterRoles(guildID string, roleIDs ...string) (roleMembers []*discordgo.Member, err error)

Read all members of some roles.

func (*Bot) Open added in v0.3.1

func (bot *Bot) Open() error

Start the bot.

func (*Bot) ReadGuildMsgs added in v0.3.1

func (bot *Bot) ReadGuildMsgs(guildID string, channelIDs []string, startTimestamp int64, endTimestamp int64) (res []*discordgo.Message, err error)

Read all the msgs of selected channels.

startTimestamp and endTimestamp can either be 0 for no start or end limits.

GuildID is only used when channelIDs is nil, read all the channels of the guild.

func (*Bot) ReadUserActivities added in v0.3.1

func (bot *Bot) ReadUserActivities(guildID string, channelIDs []string, startTimestamp int64, endTimestamp int64) (res map[string]*UserActivity, err error)

Read all the msgs of selected channels.

startTimestamp and endTimestamp can either be 0 for no start or end limits.

GuildID is only used when channelIDs is nil, read all the channels of the guild.

res: map[userID] = UserActivity

func (*Bot) SendDM added in v0.3.1

func (bot *Bot) SendDM(userID string, msg *discordgo.MessageSend) error

func (*Bot) StartReply added in v0.3.1

func (bot *Bot) StartReply()

Start the reply and react and never stop.

type Comp added in v0.3.1

type Comp struct {
	Label string `json:"label"`
	// 1: PrimaryButton is a button with blurple color.
	// 2: SecondaryButton is a button with grey color.
	// 3: SuccessButton is a button with green color.
	// 4: DangerButton is a button with red color.
	// 5: LinkButton is a special type of button which navigates to a URL. Has grey color.
	Style    int  `json:"style"`
	Disabled bool `json:"disabled"`
	// Should not use name and id field in it...
	// Have no idea how to solve.
	Emoji    struct{} `json:"emoji,omitempty"`
	URL      string   `json:"url,omitempty"`
	CustomID string   `json:"custom_id"`
	// 1: TextInputShort
	// 2: TextInputParagraph
	Type int `json:"type"`
}

type ComponentSend added in v0.3.1

type ComponentSend struct {
	Components []Comp `json:"components"`
	// Type = 1. Other options not supported.
	//
	// 1: ActionsRowComponent
	// 2: ButtonComponent
	// 3: SelectMenuComponent
	// 4: TextInputComponent
	// 5: UserSelectMenuComponent
	// 6: RoleSelectMenuComponent
	// 7: MentionableSelectMenuComponent
	// 8: ChannelSelectMenuComponent
	Type int `json:"type"`
}

Type = 1.

type MsgComponents added in v0.3.1

type MsgComponents struct {
	CompSend ComponentSend
}

func (MsgComponents) MarshalJSON added in v0.3.1

func (com MsgComponents) MarshalJSON() ([]byte, error)

func (MsgComponents) Type added in v0.3.1

type ReplyRule

type ReplyRule struct {
	// Channel id in string.
	ChannelIDs []string
	// 0: Equalfold. The msg content must be equalfold as the required text.
	//
	// 1: Contain. The msg content must contain the required text.
	//
	// 2: Start with. The msg content must start with the required text.
	//
	// 3. Any.
	RuleType int
	// Only used when "RuleType" is 2.
	//
	// Msg content after the required text may has a length limit.
	// 0 for no limit.( If limited to 0, use 0 for "RuleType" instead.)
	LengthLimit int
	// Text to check if should reply.
	CheckText string

	// Use function to decide what to reply.
	ReplyFunc func(bot *Bot, msg *discordgo.Message) (replyMsg *discordgo.MessageSend)
	// Use function to decide what to react.
	ReactFunc func(bot *Bot, msg *discordgo.Message) (reactEmojiIDs []string)

	// Whether to reply in DM.
	ReplyInDM bool
	// Whether should reply to the msg user replies to.
	// Meaningless if ReplyInDM is true.
	ReplyToInitialMessage bool

	// Whether the author can be a bot.
	ReplyToBot bool
	// Deprecated: Not in use.
	// Whether reply to the msg sent by the bot itself.
	// Meaningless if ReplyToBot is false.
	ReplyToSelf bool
}

Simple rule for reply.

type UserActivity added in v0.2.12

type UserActivity struct {
	User    *discordgo.User
	Times   int64
	Details []*discordgo.Message
}

Struct for user activities.

Jump to

Keyboard shortcuts

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