Documentation
¶
Overview ¶
Package hbot is IRCv3 enabled framework for writing IRC bots
Index ¶
- Constants
- func DiscardLogf(format string, args ...interface{})
- type Bot
- func (bot *Bot) Action(who, text string)
- func (bot *Bot) AddTrigger(h Handler)
- func (bot *Bot) CapStatus(cap string) (enabled, present bool)
- func (bot *Bot) ChMode(user, channel, mode string)
- func (bot *Bot) Close()
- func (bot *Bot) Join(ch string)
- func (bot *Bot) Joined() <-chan struct{}
- func (bot *Bot) Msg(who, text string)
- func (bot *Bot) MsgMaxSize(who string) int
- func (bot *Bot) Nick() string
- func (bot *Bot) Notice(who, text string)
- func (bot *Bot) NoticeMaxSize(who string) int
- func (bot *Bot) Part(ch, msg string)
- func (bot *Bot) Prefix() Prefix
- func (bot *Bot) Reply(m *Message, text string)
- func (bot *Bot) ReplyMaxSize(m *Message) int
- func (bot *Bot) Run()
- func (bot *Bot) Send(command string)
- func (bot *Bot) SetNick(nick string)
- func (bot *Bot) Topic(c, topic string)
- type Config
- type Handler
- type Logger
- type Message
- type Prefix
- type TLSKnob
- type Tags
- type Trigger
Examples ¶
Constants ¶
const CapAccountNotify = "account-notify"
CapAccountNotify is account-notify CAP
const CapAccountTag = "account-tag"
CapAccountTag is account-tag CAP
const CapAwayNotify = "away-notify"
CapAwayNotify is away-notify CAP
const CapCapNotify = "cap-notify"
CapCapNotify is cap-notify CAP
const CapChghost = "chghost"
CapChghost is chghost CAP
const CapExtendedJoin = "extended-join"
CapExtendedJoin is extended-join CAP
const CapIdentifyMsg = "identify-msg"
CapIdentifyMsg is identify-msg CAP
const CapInviteNotify = "invite-notify"
CapInviteNotify is invite-notify CAP
const CapMessageTags = "message-tags"
CapMessageTags is message-tags CAP
const CapMultiPrefix = "multi-prefix"
CapMultiPrefix is multi-prefix CAP
const CapSASL = "sasl"
CapSASL is SASL CAP
const CapServerTime = "server-time"
CapServerTime is server-time CAP
const CapSetName = "setname"
CapSetName is setname CAP
const CapTLS = "tls"
CapTLS is tls CAP
const CapUserhostInNames = "userhost-in-names"
CapUserhostInNames is userhost-in-names CAP
const CommonBotUserPrefix = "botsan-"
CommonBotUserPrefix may be optionally used as a user prefix or realname to identify as a bot. e.g. `/mode #CHANNEL +q $~x:*!~botsan-*@*` or `/mode #CHANNEL +q $~r:botsan-*`.
Variables ¶
This section is empty.
Functions ¶
func DiscardLogf ¶
func DiscardLogf(format string, args ...interface{})
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot implements an irc bot to be connected to a given server
func (*Bot) AddTrigger ¶
AddTrigger adds a trigger to the bot's handlers
func (*Bot) ChMode ¶
ChMode is used to change users modes in a channel operator = "+o" deop = "-o" ban = "+b"
func (*Bot) Joined ¶
func (bot *Bot) Joined() <-chan struct{}
Joined returns a channel that closes after channels are joined
func (*Bot) MsgMaxSize ¶
MsgMaxSize returns maximum number of bytes that fit into one message. Useful, for example, if you want to generate a wall of emojis that fit into one message, or you want to cap some output to one message
func (*Bot) NoticeMaxSize ¶
NoticeMaxSize returns maximum number of bytes that fit into one message. Useful, for example, if you want to generate a wall of emojis that fit into one message, or you want to cap some output to one message
func (*Bot) ReplyMaxSize ¶
ReplyMaxSize is just like MsgMaxSize but calculates message size for the reply target
func (*Bot) Run ¶
func (bot *Bot) Run()
Run starts the bot and connects to the server. Blocks until we disconnect from the server.
type Config ¶
type Config struct { Host string Nick string Realname string User string Password string Channels []string SASL bool MsgSafetyBuffer bool // Set it if long messages get truncated on the receiving end Dial func(network, addr string) (net.Conn, error) // An optional custom function for connecting to the server ThrottleDelay time.Duration // Duration to wait between sending of messages to avoid being kicked by the server for flooding (default 200ms) PingTimeout time.Duration // Maximum time between incoming data UseTLS TLSKnob TLSConfig tls.Config Logger Logger }
type Message ¶
Message represents an IRC protocol message. See RFC1459 section 2.3.1.
<message> ::= [':' <prefix> <SPACE> ] <command> <params> <crlf> <prefix> ::= <servername> | <nick> [ '!' <user> ] [ '@' <host> ] <command> ::= <letter> { <letter> } | <number> <number> <number> <SPACE> ::= ' ' { ' ' } <params> ::= <SPACE> [ ':' <trailing> | <middle> <params> ] <middle> ::= <Any *non-empty* sequence of octets not including SPACE or NUL or CR or LF, the first of which may not be ':'> <trailing> ::= <Any, possibly *empty*, sequence of octets not including NUL or CR or LF> <crlf> ::= CR LF
func ParseMessage ¶
ParseMessage takes a string and attempts to create a Message struct. Returns nil if the Message is invalid.
Example ¶
message := ParseMessage("JOIN #help") fmt.Println(message.Params[0])
Output: #help
func (*Message) Bytes ¶
Bytes returns a []byte representation of this message.
As noted in rfc2812 section 2.3, messages should not exceed 512 characters in length. This method forces that limit by discarding any characters exceeding the length limit.
func (*Message) Param ¶
Param returns the i'th parameter. Returns the empty string if the requested parameter does not exist.
func (*Message) String ¶
String returns a string representation of this message.
As noted in rfc2812 section 2.3, messages should not exceed 512 characters in length. This method forces that limit by discarding any characters exceeding the length limit.
Example ¶
message := &Message{ Prefix: Prefix{ Name: "sorcix", User: "sorcix", Host: "myhostname", }, Command: "PRIVMSG", Params: []string{"This is an example!"}, } fmt.Println(message.String())
Output: :sorcix!sorcix@myhostname PRIVMSG :This is an example!
type Prefix ¶
type Prefix struct { Name string // Nick- or servername User string // Username Host string // Hostname }
Prefix represents the prefix (sender) of an IRC message. See RFC1459 section 2.3.1.
<servername> | <nick> [ '!' <user> ] [ '@' <host> ]
func ParsePrefix ¶
ParsePrefix takes a string and attempts to create a Prefix struct.
func (*Prefix) IsHostmask ¶
IsHostmask returns true if this prefix looks like a user hostmask.
type Tags ¶
Tags represents (optional) tags added to the start of each message See IRCv3.2 Message Tags (http://ircv3.net/specs/core/message-tags-3.2.html)
<message> ::= ['@' <tags> <SPACE>] [':' <prefix> <SPACE> ] <command> <params> <crlf> <tags> ::= <tag> [';' <tag>]* <tag> ::= <key> ['=' <escaped value>] <key> ::= [ <vendor> '/' ] <sequence of letters, digits, hyphens (`-`)> <escaped value> ::= <sequence of any characters except NUL, CR, LF, semicolon (`;`) and SPACE> <vendor> ::= <host>
type Trigger ¶
type Trigger struct { // Returns true if this trigger applies to the passed in message Condition func(*Bot, *Message) bool // The action to perform if Condition is true Action func(*Bot, *Message) }
Trigger is a Handler which is guarded by a condition. DO NOT alter *Message in your triggers or you'll have strange things happen.