Documentation ¶
Index ¶
- Constants
- Variables
- func ChannelMembers(ctx *IrcContext, channelID string) ([]slack.User, error)
- func ExpandText(text string) string
- func HasChannelPrefix(name string) bool
- func IrcAfterLoggingIn(ctx *IrcContext, rtm *slack.RTM) error
- func IrcCapHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcJoinHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcModeHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcNamesHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcNickHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcPartHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcPassHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcPingHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcPrivMsgHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcQuitHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcSendChanInfoAfterJoin(ctx *IrcContext, ch *Channel, members []slack.User)
- func IrcSendChanInfoAfterJoinCustom(ctx *IrcContext, chanName, chanID, topic string, members []slack.User)
- func IrcTopicHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcUserHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcWhoHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func IrcWhoisHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
- func SendIrcNumeric(ctx *IrcContext, code int, args, desc string) error
- func SplitReply(preamble, msg string, chunksize int) []string
- func StripChannelPrefix(name string) string
- func SupportedChannelPrefixes() []string
- func WordWrap(allWords []string, maxLen int) []string
- type Channel
- type Channels
- func (c *Channels) AsMap() map[string]Channel
- func (c *Channels) ByID(id string) *Channel
- func (c *Channels) ByName(name string) *Channel
- func (c *Channels) Count() int
- func (c *Channels) Fetch(client *slack.Client) error
- func (c *Channels) FetchByIDs(client *slack.Client, skipCache bool, channelIDs ...string) ([]Channel, error)
- type FileHandler
- type IrcCommandHandler
- type IrcContext
- func (ic *IrcContext) ExpandUserIds(text string) string
- func (ic IrcContext) GetConversationInfo(conversation string) (*slack.Channel, error)
- func (ic *IrcContext) GetThreadOpener(channel string, threadTimestamp string) (slack.Message, error)
- func (ic *IrcContext) GetUserInfo(userID string) *slack.User
- func (ic *IrcContext) GetUserInfoByName(username string) *slack.User
- func (ic IrcContext) Mask() string
- func (ic *IrcContext) Nick() string
- func (ic *IrcContext) PostTextMessage(target, text, targetTs string)
- func (ic *IrcContext) SendUnknownError(fmtstr string, args ...interface{})
- func (ic *IrcContext) Start()
- func (ic IrcContext) UserID() string
- func (ic *IrcContext) UserName() string
- type Server
- type SlackPostMessage
- type Users
- func (u *Users) ByID(id string) *slack.User
- func (u *Users) ByName(name string) *slack.User
- func (u *Users) Count() int
- func (u *Users) Fetch(client *slack.Client) ([]slack.User, error)
- func (u *Users) FetchByIDs(client *slack.Client, skipCache bool, userIDs ...string) ([]slack.User, error)
- func (u *Users) IDsToNames(userIDs ...string) []string
Constants ¶
const ( ChannelPrefixPublicChannel = "#" ChannelPrefixPrivateChannel = "@" ChannelPrefixMpIM = "&" // NOTE: a thread is not a channel type ChannelPrefixThread = "+" )
Constants for public, private, and multi-party conversation prefixes. Channel threads are prefixed with "+" but they are not conversation types so they do not belong here. A thread is just a message whose destination is within another message in a public, private, or multi-party conversation.
const ( ProjectAuthor = "Andrea Barberio" ProjectAuthorEmail = "insomniac@slackware.it" ProjectURL = "https://github.com/insomniacslk/irc-slack" MaxSlackAPIAttempts = 3 )
Project constants
Variables ¶
var IrcCommandHandlers = map[string]IrcCommandHandler{ "CAP": IrcCapHandler, "NICK": IrcNickHandler, "USER": IrcUserHandler, "PING": IrcPingHandler, "PRIVMSG": IrcPrivMsgHandler, "QUIT": IrcQuitHandler, "MODE": IrcModeHandler, "PASS": IrcPassHandler, "WHOIS": IrcWhoisHandler, "WHO": IrcWhoHandler, "JOIN": IrcJoinHandler, "PART": IrcPartHandler, "TOPIC": IrcTopicHandler, "NAMES": IrcNamesHandler, }
IrcCommandHandlers maps each IRC command to its handler function
var IrcNumericsSafeToChunk = []int{
352,
353,
}
IrcNumericsSafeToChunk is a list of IRC numeric replies that are safe to chunk. As per RFC2182, the maximum message size is 512, including newlines. Sending longer lines breaks some clients like ZNC. See https://github.com/insomniacslk/irc-slack/issues/38 for background. This list is meant to grow if we find more IRC numerics that are safe to split. Being safe to split doesn't mean that it *will* be split. The actual behaviour depends on the IrcContext.ChunkSize value.
var (
UserContexts = map[net.Addr]*IrcContext{}
)
Maps of user contexts and nicknames
Functions ¶
func ChannelMembers ¶
func ChannelMembers(ctx *IrcContext, channelID string) ([]slack.User, error)
ChannelMembers returns a list of users in the given conversation.
func ExpandText ¶
ExpandText expands and unquotes text and URLs from Slack's messages. Slack quotes the text and URLS, and the latter are enclosed in < and >. It also translates potential URLs into actual URLs (e.g. when you type "example.com"), so you will get something like <http://example.com|example.com>. This function tries to detect them and unquote and expand them for a better visualization on IRC.
func HasChannelPrefix ¶
HasChannelPrefix returns true if the channel name starts with one of the supproted channel prefixes.
func IrcAfterLoggingIn ¶
func IrcAfterLoggingIn(ctx *IrcContext, rtm *slack.RTM) error
IrcAfterLoggingIn is called once the user has successfully logged on IRC
func IrcCapHandler ¶
func IrcCapHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcCapHandler is called when a CAP command is sent
func IrcJoinHandler ¶
func IrcJoinHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcJoinHandler is called when a JOIN command is sent
func IrcModeHandler ¶
func IrcModeHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcModeHandler is called when a MODE command is sent
func IrcNamesHandler ¶
func IrcNamesHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcNamesHandler is called when a NAMES command is sent
func IrcNickHandler ¶
func IrcNickHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcNickHandler is called when a NICK command is sent
func IrcPartHandler ¶
func IrcPartHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcPartHandler is called when a PART command is sent
func IrcPassHandler ¶
func IrcPassHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcPassHandler is called when a PASS command is sent
func IrcPingHandler ¶
func IrcPingHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcPingHandler is called when a PING command is sent
func IrcPrivMsgHandler ¶
func IrcPrivMsgHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcPrivMsgHandler is called when a PRIVMSG command is sent
func IrcQuitHandler ¶
func IrcQuitHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcQuitHandler is called when a QUIT command is sent
func IrcSendChanInfoAfterJoin ¶
func IrcSendChanInfoAfterJoin(ctx *IrcContext, ch *Channel, members []slack.User)
IrcSendChanInfoAfterJoin sends channel information to the user about a joined channel.
func IrcSendChanInfoAfterJoinCustom ¶
func IrcSendChanInfoAfterJoinCustom(ctx *IrcContext, chanName, chanID, topic string, members []slack.User)
IrcSendChanInfoAfterJoinCustom sends channel information to the user about a joined channel. It can be used as an alternative to IrcSendChanInfoAfterJoin when you need to specify custom chan name, id, and topic.
func IrcTopicHandler ¶
func IrcTopicHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcTopicHandler is called when a TOPIC command is sent
func IrcUserHandler ¶
func IrcUserHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcUserHandler is called when a USER command is sent
func IrcWhoHandler ¶
func IrcWhoHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcWhoHandler is called when a WHO command is sent
func IrcWhoisHandler ¶
func IrcWhoisHandler(ctx *IrcContext, prefix, cmd string, args []string, trailing string)
IrcWhoisHandler is called when a WHOIS command is sent
func SendIrcNumeric ¶
func SendIrcNumeric(ctx *IrcContext, code int, args, desc string) error
SendIrcNumeric sends a numeric code message to the recipient
func SplitReply ¶
SplitReply will split a reply message if necessary. See IrcNumericSafeToChunk for background on why splitting. The function will return a list of chunks to be sent separately. The first argument is the entire message to be split. The second argument is the chunk size to use to determine whether the message should be split. Any value equal or above 512 will cause splitting. Any other value will return the unmodified string as only item of the list.
func StripChannelPrefix ¶
StripChannelPrefix returns a channel name without its channel prefix. If no channel prefix is present, the string is returned unchanged.
func SupportedChannelPrefixes ¶
func SupportedChannelPrefixes() []string
SupportedChannelPrefixes returns a list of supported channel prefixes.
Types ¶
type Channel ¶
Channel wraps a Slack conversation with a few utility functions.
func (*Channel) IRCName ¶
IRCName returns the channel name as it would appear on IRC. Examples: * #channel for public groups * @channel for private groups * &Gxxxx|nick1-nick2-nick3 for multi-party IMs
func (*Channel) IsPrivateChannel ¶
IsPrivateChannel returns true if the channel is private.
func (*Channel) IsPublicChannel ¶
IsPublicChannel returns true if the channel is public.
type Channels ¶
type Channels struct { Pagination int // contains filtered or unexported fields }
Channels wraps the channel list with convenient operations and cache.
func NewChannels ¶
NewChannels creates a new Channels object.
func (*Channels) AsMap ¶
AsMap returns the channels as a map of name -> channel. The map is copied to avoid data races
func (*Channels) Count ¶
Count returns the number of channels. This method must be called after `Fetch`.
type FileHandler ¶
FileHandler downloads files from slack
type IrcCommandHandler ¶
type IrcCommandHandler func(*IrcContext, string, string, []string, string)
IrcCommandHandler is the prototype that every IRC command handler has to implement
type IrcContext ¶
type IrcContext struct { Conn net.Conn User *slack.User // TODO make RealName a function RealName string OrigName string SlackClient *slack.Client SlackRTM *slack.RTM SlackAPIKey string SlackDebug bool SlackConnected bool ServerName string Channels *Channels Users *Users ChunkSize int FileHandler *FileHandler // contains filtered or unexported fields }
IrcContext holds the client context information
func (*IrcContext) ExpandUserIds ¶
func (ic *IrcContext) ExpandUserIds(text string) string
ExpandUserIds will convert slack user tags with user's nicknames
func (IrcContext) GetConversationInfo ¶
func (ic IrcContext) GetConversationInfo(conversation string) (*slack.Channel, error)
GetConversationInfo is cached version of slack.GetConversationInfo
func (*IrcContext) GetThreadOpener ¶
func (ic *IrcContext) GetThreadOpener(channel string, threadTimestamp string) (slack.Message, error)
GetThreadOpener returns text of the first message in a thread that provided message belongs to
func (*IrcContext) GetUserInfo ¶
func (ic *IrcContext) GetUserInfo(userID string) *slack.User
GetUserInfo returns a slack.User instance from a given user ID, or nil if no user with that ID was found
func (*IrcContext) GetUserInfoByName ¶
func (ic *IrcContext) GetUserInfoByName(username string) *slack.User
GetUserInfoByName returns a slack.User instance from a given user name, or nil if no user with that name was found
func (IrcContext) Mask ¶
func (ic IrcContext) Mask() string
Mask returns the IRC mask for the current user
func (*IrcContext) Nick ¶
func (ic *IrcContext) Nick() string
Nick returns the nickname of the user, if known
func (*IrcContext) PostTextMessage ¶
func (ic *IrcContext) PostTextMessage(target, text, targetTs string)
PostTextMessage batches all messages that should be posted to slack
func (*IrcContext) SendUnknownError ¶
func (ic *IrcContext) SendUnknownError(fmtstr string, args ...interface{})
SendUnknownError sends an IRC 400 (ERR_UNKNOWNERROR) message to the client and prints a warning about it.
func (*IrcContext) Start ¶
func (ic *IrcContext) Start()
Start handles batching of messages to slack
func (*IrcContext) UserName ¶
func (ic *IrcContext) UserName() string
UserName returns the user's name. Currently this is equivalent to the user's Slack ID
type Server ¶
type Server struct { Name string LocalAddr net.Addr Listener net.Listener SlackAPIKey string SlackDebug bool ChunkSize int FileDownloadLocation string FileProxyPrefix string Pagination int TLSConfig *tls.Config }
Server is the server object that exposes the Slack API with an IRC interface.
func (Server) HandleRequest ¶
HandleRequest handle IRC client connections
type SlackPostMessage ¶
SlackPostMessage represents a message sent to slack api
type Users ¶
type Users struct {
// contains filtered or unexported fields
}
Users wraps the user list with convenient operations and cache.
func (*Users) Fetch ¶
Fetch retrieves all the users on a given Slack team. The Slack client has to be valid and connected.
func (*Users) FetchByIDs ¶
func (u *Users) FetchByIDs(client *slack.Client, skipCache bool, userIDs ...string) ([]slack.User, error)
FetchByIDs fetches the users with the specified IDs and updates the internal user mapping.
func (*Users) IDsToNames ¶
IDsToNames returns a list of user names from the given IDs. The returned list could be shorter if there are invalid user IDs. Warning: this method is probably only useful for NAMES commands where a non-exact mapping is acceptable.