public async Task TrandlateTask(string toLang, [Remainder] string query) { string[] dataStrings = TranslatorApi.Translate(toLang, query); var embed = new EmbedBuilder(); var rand = new Random(); if (dataStrings.Length == 1) { embed.WithDescription(dataStrings[0]); } else { embed.WithDescription(dataStrings[2]); embed.WithTitle($"Translated from {dataStrings[0]} to {dataStrings[1]}"); } embed.WithFooter($"Requested by {Context.User}"); embed.WithColor(new Color(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256))); await ReplyAsync("", false, embed.Build()); }
public string Evaluate(Context context) { try { var targetAttribute = context.Element.Attribute("Target"); if (targetAttribute != null) { var translator = new TranslatorApi { SourceLanguage = _plugin.Settings["Source-Language"].Value, SourceText = context.Element.Value, TargetLanguage = targetAttribute.Value }; Task.Factory.StartNew(() => { var result = translator.Translate(); var dispatcher = VirtualAssistant.Instance.Components.Get<Dispatcher>(); dispatcher.Invoke(() => { context.User.Vars["translation-query"].Value = context.Element.Value; if (!string.IsNullOrEmpty(result)) { context.User.Vars["translation-text"].Value = result; context.Bot.Trigger("translation-found"); } else { context.Bot.Trigger("translation-not-found"); } }); }); } } catch (Exception exception) { VirtualAssistant.Instance.Logger.Error(exception); } return string.Empty; }