public static async Task Translate(this ITweetInfo tweet) { if (string.IsNullOrWhiteSpace(tweet.Text) || tweet.Translated) { return; } const string target = "en"; const string source = "ja"; //var link = $"http://104.131.147.227/api/v1/translate?t={target}&s={source}&q={tweet.Text}"; var link = $"http://tensei.moe/api/v1/translate?t={target}&s={source}&q={tweet.Text}"; try { var response = await HttpClient.GetStringAsync(link); if (response == "error") { return; } tweet.Text = response; tweet.Translated = true; } catch (Exception e) { Console.WriteLine(e.Message); } }
private void Copy(ITweetInfo tweetInfo) { try { Clipboard.SetDataObject(tweetInfo.Id); } catch (Exception) { //ignore } tweetInfo.Clicked = !tweetInfo.Clicked; }
private void AddTweet(ITweetInfo tweet) { try { Application.Current.Dispatcher.BeginInvoke(new Action(() => { var follow = _raidsController.Follows.FirstOrDefault( f => f.English.Contains(tweet.Boss.Trim()) || f.Japanese.Contains(tweet.Boss.Trim())); if (_blacklistController.Blacklist.Contains(tweet.User)) { return; } follow?.TweetInfos.Insert(0, tweet); TweetCount++; if (follow != null && follow.AutoCopy && Settings.GlobalCopy) { try { Clipboard.SetDataObject(tweet.Id); } catch (Exception) { //ignore } } if (follow != null && follow.Sound && Settings.GlobalSound) { try { _soudplayer.SoundLocation = follow.SelectedSoundFile?.Path; _soudplayer.Play(); } catch (Exception) { //no file } } if (follow?.TweetInfos.Count > 30) { follow.TweetInfos.RemoveAt(follow.TweetInfos.Count - 1); } })); } catch (Exception e) { Console.WriteLine(e); } }
private async Task TranslateMessage(ITweetInfo tweet) { await tweet.Translate(); }