public static async Task <Discord.IUserMessage> SendFileAsync(this Discord.IMessageChannel self, Image <Rgba32> img, System.Drawing.Imaging.ImageFormat format, string name) { return(await Task.Run(async() => { MemoryStream imgStream = new MemoryStream(); img.Save(imgStream); imgStream.Seek(0, SeekOrigin.Begin); return await self.SendFileAsync(imgStream, name); })); }
public SlateBotControllerLifecycleStates OnMessageReadyToSend(Commands.Response message, Discord.IMessageChannel destination) { bool tts = message.ResponseType == ResponseType.Default_TTS; if (message.ResponseType == Commands.ResponseType.PleaseWaitMessage) { // We need to run this asynchronously. Task.Run(async() => { try { Discord.IUserMessage m; if (message.Embed == null) { if (message.FilePath == null) { m = await destination.SendMessageAsync(message.Message); } else { m = await destination.SendFileAsync(message.FilePath, message.Message); } } else { if (message.FilePath == null) { m = await destination.SendMessageAsync("", false, message.Embed.Build()); } else { m = await destination.SendFileAsync(message.FilePath, "", false, message.Embed.Build()); } } lifecycle.PleaseWaitHandler.PushToStack(m); } catch (Exception ex) { lifecycle.ErrorLogger.LogException(ex, ErrorSeverity.Error); } }); } else { // This can be fired and forgotten. if (message.Embed == null) { if (message.FilePath == null) { destination.SendMessageAsync(message.Message, tts); } else { destination.SendFileAsync(message.FilePath, message.Message, tts); } } else { if (message.FilePath == null) { destination.SendMessageAsync("", tts, message.Embed.Build()); } else { destination.SendFileAsync(message.FilePath, "", tts, message.Embed.Build()); } } } return(StateId); }