Send embeds!
This commit is contained in:
parent
b608f7dfd3
commit
8843b25906
|
@ -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
|
type
|
||||||
ChannelType* = enum
|
ChannelType* = enum
|
||||||
|
@ -131,10 +131,13 @@ proc newInvite*(json: JsonNode): Invite {.inline.} =
|
||||||
|
|
||||||
return invite
|
return invite
|
||||||
|
|
||||||
#TODO: Embeds, and files
|
#TODO: Files
|
||||||
proc sendMessage*(channel: Channel, content: string, tts: bool = false): Message =
|
proc sendMessage*(channel: Channel, content: string, tts: bool = false, embed: Embed = nil): Message =
|
||||||
## Send a message through the channel.
|
## 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,
|
return newMessage(sendRequest(endpoint("/channels/" & $channel.id & "/messages"), HttpPost,
|
||||||
defaultHeaders(newHttpHeaders({"Content-Type": "application/json"})), channel.id,
|
defaultHeaders(newHttpHeaders({"Content-Type": "application/json"})), channel.id,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import websocket, asyncdispatch, json, httpClient, eventdispatcher, strformat
|
import websocket, asyncdispatch, json, httpClient, eventdispatcher, strformat
|
||||||
import eventhandler, streams, nimcordutils, discordobject, user, cache, clientobjects
|
import eventhandler, streams, nimcordutils, discordobject, user, cache, clientobjects
|
||||||
import strutils, channel, options, message, emoji, guild
|
import strutils, channel, options, message, emoji, guild, embed
|
||||||
|
|
||||||
const
|
const
|
||||||
nimcordMajor = 0
|
nimcordMajor = 0
|
||||||
|
@ -174,6 +174,13 @@ registerEventListener(EventType.evtMessageCreate, proc(bEvt: BaseEvent) =
|
||||||
let emojis = @[newEmoji("⏮️"), newEmoji("⬅️"), newEmoji("⏹️"), newEmoji("➡️"), newEmoji("⏭️")]
|
let emojis = @[newEmoji("⏮️"), newEmoji("⬅️"), newEmoji("⏹️"), newEmoji("➡️"), newEmoji("⏭️")]
|
||||||
for emoji in emojis:
|
for emoji in emojis:
|
||||||
discard event.message.addReaction(emoji)
|
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()
|
waitFor bot.startConnection()
|
Reference in New Issue