From 0e2522279e8671a345c1be6b8b07c0f1a505e23e Mon Sep 17 00:00:00 2001 From: David Hill Date: Wed, 7 Nov 2018 14:36:50 -0500 Subject: Clean up various stuff (#508) * various cleanups --- bridge/discord/discord.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'bridge/discord') diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 116bf86d..0549187f 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -91,6 +91,7 @@ func (b *Bdiscord) Connect() error { } // obtaining guild members and initializing nickname mapping b.Lock() + defer b.Unlock() members, err := b.c.GuildMembers(b.guildID, "", 1000) if err != nil { b.Log.Error("Error obtaining guild members", err) @@ -103,7 +104,6 @@ func (b *Bdiscord) Connect() error { b.nickMemberMap[member.Nick] = member } } - b.Unlock() return nil } @@ -488,9 +488,16 @@ func (b *Bdiscord) handleUploadFile(msg *config.Message, channelID string) (stri var err error for _, f := range msg.Extra["file"] { fi := f.(config.FileInfo) - files := []*discordgo.File{} - files = append(files, &discordgo.File{fi.Name, "", bytes.NewReader(*fi.Data)}) - _, err = b.c.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{Content: msg.Username + fi.Comment, Files: files}) + file := discordgo.File{ + Name: fi.Name, + ContentType: "", + Reader: bytes.NewReader(*fi.Data), + } + m := discordgo.MessageSend{ + Content: msg.Username + fi.Comment, + Files: []*discordgo.File{&file}, + } + _, err = b.c.ChannelMessageSendComplex(channelID, &m) if err != nil { return "", fmt.Errorf("file upload failed: %#v", err) } -- cgit v1.2.3