From 8843b259064ee6cd7dfe5cfc96d0fb7876c49a83 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sat, 20 Jun 2020 01:33:45 -0500 Subject: [PATCH] Send embeds! --- src/channel.nim | 11 +++++++---- src/client.nim | 9 ++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/channel.nim b/src/channel.nim index c376afa..d65834b 100644 --- a/src/channel.nim +++ b/src/channel.nim @@ -1,4 +1,4 @@ -import json, discordobject, user, options, nimcordutils, message, httpcore, asyncdispatch, asyncfutures, permission +import json, discordobject, user, options, nimcordutils, message, httpcore, asyncdispatch, asyncfutures, permission, embed type ChannelType* = enum @@ -131,10 +131,13 @@ proc newInvite*(json: JsonNode): Invite {.inline.} = return invite -#TODO: Embeds, and files -proc sendMessage*(channel: Channel, content: string, tts: bool = false): Message = +#TODO: Files +proc sendMessage*(channel: Channel, content: string, tts: bool = false, embed: Embed = nil): Message = ## Send a message through the channel. - let messagePayload = %*{"content": content, "tts": tts} + var messagePayload = %*{"content": content, "tts": tts} + + if (not embed.isNil()): + messagePayload.add("embed", embed.embedJson) return newMessage(sendRequest(endpoint("/channels/" & $channel.id & "/messages"), HttpPost, defaultHeaders(newHttpHeaders({"Content-Type": "application/json"})), channel.id, diff --git a/src/client.nim b/src/client.nim index f589a69..058ca1d 100644 --- a/src/client.nim +++ b/src/client.nim @@ -1,6 +1,6 @@ import websocket, asyncdispatch, json, httpClient, eventdispatcher, strformat import eventhandler, streams, nimcordutils, discordobject, user, cache, clientobjects -import strutils, channel, options, message, emoji, guild +import strutils, channel, options, message, emoji, guild, embed const nimcordMajor = 0 @@ -174,6 +174,13 @@ registerEventListener(EventType.evtMessageCreate, proc(bEvt: BaseEvent) = let emojis = @[newEmoji("⏮️"), newEmoji("⬅️"), newEmoji("⏹️"), newEmoji("➡️"), newEmoji("⏭️")] for emoji in emojis: discard event.message.addReaction(emoji) + elif (event.message.content.startsWith("?testEmbed")): + var channel: Channel = event.message.getMessageChannel(event.client.cache) + if (channel != nil): + var embed = Embed() + embed.setTitle("This embed is being sent from Nimcord!") + embed.setDescription("Nimcord was developed in about a week of actual work so there will likely be issues.") + discard channel.sendMessage("", false, embed) ) waitFor bot.startConnection() \ No newline at end of file