bridge

package
v0.0.0-...-56bbfdb Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMemberNick

func GetMemberNick(m *discordgo.Member) string

GetMemberNick returns the real display name for a Discord GuildMember

func Leftpad

func Leftpad(s string, length int, ch ...rune) string

Leftpad is from github.com/douglarek/leftpad

func SnowflakeToIP

func SnowflakeToIP(base string, snowflake string) string

SnowflakeToIP takes a snowflake and the first half of an IP to make an IP suitable for WEBIRC

Types

type Bridge

type Bridge struct {
	Config *Config
	// contains filtered or unexported fields
}

A Bridge represents a bridging between an IRC server and channels in a Discord server

func New

func New(conf *Config) (*Bridge, error)

New Bridge

func (*Bridge) Close

func (b *Bridge) Close()

Close the Bridge

func (*Bridge) GetIRCChannels

func (b *Bridge) GetIRCChannels() map[string]string

GetIRCChannels returns a list of irc channels in no particular order.

func (*Bridge) GetJoinCommand

func (b *Bridge) GetJoinCommand() string

func (*Bridge) GetMappingByDiscord

func (b *Bridge) GetMappingByDiscord(channel string) *Mapping

GetMappingByDiscord returns a Mapping for a given Discord channel. Returns nil if a Mapping does not exist.

func (*Bridge) GetMappingByIRC

func (b *Bridge) GetMappingByIRC(channel string) *Mapping

GetMappingByIRC returns a Mapping for a given IRC channel. Returns nil if a Mapping does not exist.

func (*Bridge) Open

func (b *Bridge) Open() (err error)

Open all the connections required to run the bridge

func (*Bridge) SetChannelMappings

func (b *Bridge) SetChannelMappings(inMappings map[string]string) error

SetChannelMappings allows you to set (or update) the hashmap containing irc to discord mappings.

Calling this function whilst the bot is running will add or remove IRC bots accordingly.

func (*Bridge) SetDebugMode

func (b *Bridge) SetDebugMode(debug bool)

SetDebugMode allows you to control debug logging.

func (*Bridge) SetIRCListenerName

func (b *Bridge) SetIRCListenerName(name string)

SetIRCListenerName changes the username of the listener bot.

func (*Bridge) SetupIRCConnection

func (b *Bridge) SetupIRCConnection(con *irc.Connection, hostname, ip string)

SetupIRCConnection sets up an IRC connection with config settings like UseTLS, InsecureSkipVerify, and WebIRCPass.

type Config

type Config struct {
	DiscordBotToken, GuildID string

	// Map from Discord to IRC
	ChannelMappings map[string]string

	IRCServer        string
	IRCServerPass    string
	IRCListenerName  string // i.e, "DiscordBot", required to listen for messages in all cases
	WebIRCPass       string
	NickServIdentify string // string: "[account] password"

	// NoTLS constrols whether to use TLS at all when connecting to the IRC server
	NoTLS bool

	// InsecureSkipVerify controls whether a client verifies the
	// server's certificate chain and host name.
	// If InsecureSkipVerify is true, TLS accepts any certificate
	// presented by the server and any host name in that certificate.
	// In this mode, TLS is susceptible to man-in-the-middle attacks.
	// This should be used only for testing.
	InsecureSkipVerify bool

	// SimpleMode, when enabled, will ensure that IRCManager not spawn
	// an IRC connection for each of the online Discord users.
	SimpleMode bool

	// WebhookPrefix is prefixed to each webhook created by the Discord bot.
	WebhookPrefix string

	// WebhookLimit is the max number of webhooks to create
	WebhookLimit int

	Suffix    string // Suffix is the suffix to append to IRC puppets
	Separator string // Separator is used in IRC puppets' username, in fallback situations, between the discriminator and username.

	Debug bool
}

Config to be passed to New

type DiscordMessage

type DiscordMessage struct {
	*discordgo.Message
	Content  string
	IsAction bool
	PmTarget string // target username, for PMs
}

DiscordMessage is a chat message sent to IRC (from Discord)

type DiscordUser

type DiscordUser struct {
	ID            string // globally unique id
	Username      string
	Discriminator string
	Nick          string // still non-unique
	Bot           bool   // are they a bot?
	Online        bool
}

DiscordUser is information that IRC needs to know about a user

type IRCManager

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

IRCManager should only be used from one thread.

func (*IRCManager) Close

func (m *IRCManager) Close()

Close closes all of an IRCManager's connections.

func (*IRCManager) CloseConnection

func (m *IRCManager) CloseConnection(i *ircConnection)

CloseConnection shuts down a particular connection and its channels.

func (*IRCManager) DisconnectUser

func (m *IRCManager) DisconnectUser(userID string)

DisconnectUser immediately disconnects a Discord user if it exists

func (*IRCManager) HandleUser

func (m *IRCManager) HandleUser(user DiscordUser)

HandleUser deals with messages sent from a DiscordUser

func (*IRCManager) RequestChannels

func (m *IRCManager) RequestChannels(userID string) map[string]string

RequestChannels finds all the Discord channels this user belongs to, and then find pairings in the global pairings list Currently just returns all participating IRC channels TODO (?)

func (*IRCManager) SendMessage

func (m *IRCManager) SendMessage(channel string, msg *DiscordMessage)

SendMessage sends a broken down Discord Message to a particular IRC channel.

func (*IRCManager) SetConnectionCooldown

func (m *IRCManager) SetConnectionCooldown(con *ircConnection)

SetConnectionCooldown renews/starts a timer for expiring a connection.

type IRCMessage

type IRCMessage struct {
	IRCChannel string
	Username   string
	Message    string
	IsAction   bool
}

IRCMessage is a chat message sent to Discord (from IRCListener)

type Mapping

type Mapping struct {
	DiscordChannel string
	IRCChannel     string
}

Mapping is a mapping between a Discord channel and an IRC channel (essentially a tuple).

Jump to

Keyboard shortcuts

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