@ -12,7 +12,7 @@ import (
"sync"
)
type b discord struct {
type B discord struct {
c * discordgo . Session
Channels [ ] * discordgo . Channel
Nick string
@ -33,8 +33,8 @@ func init() {
flog = log . WithFields ( log . Fields { "prefix" : protocol } )
}
func New ( cfg * config . BridgeConfig ) * b discord {
b := & b discord{ BridgeConfig : cfg }
func New ( cfg * config . BridgeConfig ) * B discord {
b := & B discord{ BridgeConfig : cfg }
b . userMemberMap = make ( map [ string ] * discordgo . Member )
b . channelInfoMap = make ( map [ string ] * config . ChannelInfo )
if b . Config . WebhookURL != "" {
@ -44,7 +44,7 @@ func New(cfg *config.BridgeConfig) *bdiscord {
return b
}
func ( b * b discord) Connect ( ) error {
func ( b * B discord) Connect ( ) error {
var err error
flog . Info ( "Connecting" )
if b . Config . WebhookURL == "" {
@ -89,11 +89,11 @@ func (b *bdiscord) Connect() error {
return nil
}
func ( b * b discord) Disconnect ( ) error {
func ( b * B discord) Disconnect ( ) error {
return nil
}
func ( b * b discord) JoinChannel ( channel config . ChannelInfo ) error {
func ( b * B discord) JoinChannel ( channel config . ChannelInfo ) error {
b . channelInfoMap [ channel . ID ] = & channel
idcheck := strings . Split ( channel . Name , "ID:" )
if len ( idcheck ) > 1 {
@ -102,7 +102,7 @@ func (b *bdiscord) JoinChannel(channel config.ChannelInfo) error {
return nil
}
func ( b * b discord) Send ( msg config . Message ) ( string , error ) {
func ( b * B discord) Send ( msg config . Message ) ( string , error ) {
flog . Debugf ( "Receiving %#v" , msg )
channelID := b . getChannelID ( msg . Channel )
@ -181,7 +181,7 @@ func (b *bdiscord) Send(msg config.Message) (string, error) {
return res . ID , err
}
func ( b * b discord) messageDelete ( s * discordgo . Session , m * discordgo . MessageDelete ) {
func ( b * B discord) messageDelete ( s * discordgo . Session , m * discordgo . MessageDelete ) {
rmsg := config . Message { Account : b . Account , ID : m . ID , Event : config . EVENT_MSG_DELETE , Text : config . EVENT_MSG_DELETE }
rmsg . Channel = b . getChannelName ( m . ChannelID )
if b . UseChannelID {
@ -192,7 +192,7 @@ func (b *bdiscord) messageDelete(s *discordgo.Session, m *discordgo.MessageDelet
b . Remote <- rmsg
}
func ( b * b discord) messageUpdate ( s * discordgo . Session , m * discordgo . MessageUpdate ) {
func ( b * B discord) messageUpdate ( s * discordgo . Session , m * discordgo . MessageUpdate ) {
if b . Config . EditDisable {
return
}
@ -204,7 +204,7 @@ func (b *bdiscord) messageUpdate(s *discordgo.Session, m *discordgo.MessageUpdat
}
}
func ( b * b discord) messageCreate ( s * discordgo . Session , m * discordgo . MessageCreate ) {
func ( b * B discord) messageCreate ( s * discordgo . Session , m * discordgo . MessageCreate ) {
var err error
// not relay our own messages
@ -273,7 +273,7 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
b . Remote <- rmsg
}
func ( b * b discord) memberUpdate ( s * discordgo . Session , m * discordgo . GuildMemberUpdate ) {
func ( b * B discord) memberUpdate ( s * discordgo . Session , m * discordgo . GuildMemberUpdate ) {
b . Lock ( )
if _ , ok := b . userMemberMap [ m . Member . User . ID ] ; ok {
flog . Debugf ( "%s: memberupdate: user %s (nick %s) changes nick to %s" , b . Account , m . Member . User . Username , b . userMemberMap [ m . Member . User . ID ] . Nick , m . Member . Nick )
@ -282,7 +282,7 @@ func (b *bdiscord) memberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUp
b . Unlock ( )
}
func ( b * b discord) getNick ( user * discordgo . User ) string {
func ( b * B discord) getNick ( user * discordgo . User ) string {
var err error
b . Lock ( )
defer b . Unlock ( )
@ -309,7 +309,7 @@ func (b *bdiscord) getNick(user *discordgo.User) string {
return user . Username
}
func ( b * b discord) getChannelID ( name string ) string {
func ( b * B discord) getChannelID ( name string ) string {
idcheck := strings . Split ( name , "ID:" )
if len ( idcheck ) > 1 {
return idcheck [ 1 ]
@ -322,7 +322,7 @@ func (b *bdiscord) getChannelID(name string) string {
return ""
}
func ( b * b discord) getChannelName ( id string ) string {
func ( b * B discord) getChannelName ( id string ) string {
for _ , channel := range b . Channels {
if channel . ID == id {
return channel . Name
@ -331,7 +331,7 @@ func (b *bdiscord) getChannelName(id string) string {
return ""
}
func ( b * b discord) replaceChannelMentions ( text string ) string {
func ( b * B discord) replaceChannelMentions ( text string ) string {
var err error
re := regexp . MustCompile ( "<#[0-9]+>" )
text = re . ReplaceAllStringFunc ( text , func ( m string ) string {
@ -350,21 +350,21 @@ func (b *bdiscord) replaceChannelMentions(text string) string {
return text
}
func ( b * b discord) replaceAction ( text string ) ( string , bool ) {
func ( b * B discord) replaceAction ( text string ) ( string , bool ) {
if strings . HasPrefix ( text , "_" ) && strings . HasSuffix ( text , "_" ) {
return strings . Replace ( text , "_" , "" , - 1 ) , true
}
return text , false
}
func ( b * b discord) stripCustomoji ( text string ) string {
func ( b * B discord) stripCustomoji ( text string ) string {
// <:doge:302803592035958784>
re := regexp . MustCompile ( "<(:.*?:)[0-9]+>" )
return re . ReplaceAllString ( text , ` $1 ` )
}
// splitURL splits a webhookURL and returns the id and token
func ( b * b discord) splitURL ( url string ) ( string , string ) {
func ( b * B discord) splitURL ( url string ) ( string , string ) {
webhookURLSplit := strings . Split ( url , "/" )
if len ( webhookURLSplit ) != 7 {
log . Fatalf ( "%s is no correct discord WebhookURL" , url )
@ -373,7 +373,7 @@ func (b *bdiscord) splitURL(url string) (string, string) {
}
// useWebhook returns true if we have a webhook defined somewhere
func ( b * b discord) useWebhook ( ) bool {
func ( b * B discord) useWebhook ( ) bool {
if b . Config . WebhookURL != "" {
return true
}
@ -386,7 +386,7 @@ func (b *bdiscord) useWebhook() bool {
}
// isWebhookID returns true if the specified id is used in a defined webhook
func ( b * b discord) isWebhookID ( id string ) bool {
func ( b * B discord) isWebhookID ( id string ) bool {
if b . Config . WebhookURL != "" {
wID , _ := b . splitURL ( b . Config . WebhookURL )
if wID == id {
@ -405,7 +405,7 @@ func (b *bdiscord) isWebhookID(id string) bool {
}
// handleUploadFile handles native upload of files
func ( b * b discord) handleUploadFile ( msg * config . Message , channelID string ) ( string , error ) {
func ( b * B discord) handleUploadFile ( msg * config . Message , channelID string ) ( string , error ) {
var err error
for _ , f := range msg . Extra [ "file" ] {
fi := f . ( config . FileInfo )