bridge

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DevMode = false

DevMode is a hack

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) GetJoinCommand

func (b *Bridge) GetJoinCommand(mappings []Mapping) string

GetJoinCommand produces a JOIN command based on the provided mappings

func (*Bridge) GetMappingByDiscord

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

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, bool)

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 {
	AvatarURL                string
	DiscordBotToken, GuildID string

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

	IRCServer       string
	Discriminator   string
	IRCServerPass   string
	IRCListenerName string // i.e, "DiscordBot", required to listen for messages in all cases
	WebIRCPass      string
	PuppetUsername  string // Username to connect to IRC with
	IRCIgnores      []glob.Glob
	DiscordIgnores  map[string]struct{} // Discord user IDs to not bridge
	DiscordAllowed  map[string]struct{} // Discord user IDs to only bridge
	ConnectionLimit int                 // number of IRC connections we can spawn

	IRCPuppetPrejoinCommands   []string
	IRCListenerPrejoinCommands []string

	// filters
	IRCFilteredMessages     []glob.Glob
	DiscordFilteredMessages []glob.Glob

	// 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

	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.

	// CooldownDuration is the duration in seconds for an IRC puppet to stay online before being disconnected
	CooldownDuration time.Duration

	// ShowJoinQuit determines whether or not to show JOIN, QUIT, KICK messages on Discord
	ShowJoinQuit bool

	// Maximum Nicklength for irc server
	MaxNickLength int

	Debug         bool
	DebugPresence 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

When `user.Online == false`, we make `user.ID` the only other data present in discord.handlePresenceUpdate

func (*IRCManager) RequestChannels

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

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