public Task Start() { _streaming.OnNotification += (sender, args) => { OnNoti?.Invoke(args.Notification.ToCommon()); }; return(_streaming.Start()); }
public override void StreamStart(Client client) { Changed("StreamState"); stream = client.GetStream("public:local"); stream.OnUpdate += this.UpdateListener; StreamState = true; Changed("StreamState"); stream.Start(); }
private async void Start(Task <IEnumerable <Status> > past, TimelineStreaming streaming) { foreach (var status in await past) { OnNext(status); } streaming.OnUpdate += (_, e) => OnNext(e.Status); await streaming.Start(); }
private async Task StartStreamingAsync() { try { streamingStarted.Value = true; await streaming?.Start(); } catch (TaskCanceledException) { } catch (WebSocketException) { } finally { streamingStarted.Value = false; } }
/// <summary> /// ストリーミングを開始します。 /// このメソッドを実行する前にイベントを登録してください。 /// </summary> public void Start() { try { streaming.Start(); } catch (Exception e) { logger.ErrorFormat($"ストリーミングの取得に失敗しました。インターネット接続を確認してください。{e.Message}"); Utilities.ShowError($"ストリーミングの取得に失敗しました。\nインターネット接続を確認してください。"); } }
public async Task Start() { Results = new List <BattleResult>(); AttackCount = 0; IsRunning = true; var postStatus = await MastodonClient.PostStatus(Account.Roar, Visibility.Public); string accoutName = postStatus.Account.UserName; long accountId = postStatus.Account.Id; // 過去トゥートの削除 var statuses = await MastodonClient.GetAccountStatuses(accountId, postStatus.Id); foreach (var status in statuses) { await MastodonClient.DeleteStatus(status.Id); } UserStreaming = MastodonClient.GetUserStreaming(); UserStreaming.OnNotification += async(sender, e) => { var status = e.Notification.Status; if (status == null || !status.Content.Contains($"@<span>{accoutName}</span>")) { return; } AttackCount++; if (AttackCount > Account.LifePoint) { return; } Results.Add(new BattleResult { PostId = status.Id, Name = status.Account.AccountName, Content = status.Content }); if (AttackCount == Account.LifePoint) { await End(true); return; } await MastodonClient.PostStatus($"@{status.Account.AccountName} {Account.Roar}", Visibility.Public); }; await UserStreaming.Start(); }
private async Task Run() { Dictionary <string, string> uri_list = new Dictionary <string, string>(); var appRegistration = new AppRegistration { Instance = hostName, ClientId = clientId, ClientSecret = clientSecret, Scope = Scope.Read | Scope.Write }; var authClient = new AuthenticationClient(appRegistration); var auth = await authClient.ConnectWithPassword(mail, pass); client = new MastodonClient(appRegistration, auth); var account = await client.GetCurrentUser(); this.userId = account.AccountName; // LTL処理 streaming = client.GetLocalStreaming(); streaming.OnUpdate += (sender, e) => { TextWrite(e.Status); }; //通知処理 homeStreaming = client.GetUserStreaming(); homeStreaming.OnNotification += (sender, e) => { NotificationWrite(e.Notification); }; // メディア処理用 media = new MediaEditClass(ref client); Timer timer = new Timer(); timer.Interval = DefaultValues.TOOTS_INTERVAL; timer.Tick += (object sender, EventArgs e) => { // トゥート回数のリセット tootsCounter = 0; }; timer.Start(); streaming.Start(); homeStreaming.Start(); }
public async Task Start() { Results = new List <BattleResult>(); Life = Boss.LifePoint; IsRunning = true; string accoutName = "boss"; int[] mediaIds = null; // アイコンのアップロード using (var stream = File.OpenRead(Boss.ImagePath)) { var attach = await MastodonClient.UploadMedia(stream); mediaIds = new int[] { attach.Id }; } Console.WriteLine("画像をアップロードしました"); string appear = new StringBuilder() .AppendLine($"({Boss.Name}が現れた! LP: {Boss.LifePoint})") .AppendLine(Boss.VoiceAppear) .ToString(); await MastodonClient.PostStatus(appear, Visibility.Public, mediaIds : mediaIds); UserStreaming = MastodonClient.GetUserStreaming(); UserStreaming.OnNotification += async(sender, e) => { Console.WriteLine("通知を受信しました"); if (!IsRunning) { return; } var status = e.Notification.Status; if (status == null || !status.Content.Contains($"@<span>{accoutName}</span>")) { return; } Console.WriteLine(status.Content); string content = DeleteTags(status.Content); if (Boss.Weakness != "") { bool matchWeakness = false; foreach (string weakness in Boss.Weakness.Replace("\r\n", "\n").Split('\n')) { if (weakness != "" && content.Contains(weakness)) { matchWeakness = true; break; } } if (!matchWeakness) { string nodamage = new StringBuilder() .AppendLine($"{Boss.Name} (LP: {Life}/{Boss.LifePoint})") .AppendLine($"({Boss.Name}にダメージを与えられない!)") .AppendLine($"> {GetName(status.Account)}「{content}」") .ToString(); await MastodonClient.PostStatus(nodamage, Visibility.Public); return; } } if (randomizer.Next(99) < Boss.EvadeRate) { string evade = new StringBuilder() .AppendLine($"{Boss.Name} (LP: {Life}/{Boss.LifePoint})") .AppendLine($"({Boss.Name}は攻撃を回避した!)") .AppendLine($"> {GetName(status.Account)}「{content}」") .ToString(); await MastodonClient.PostStatus(evade, Visibility.Public); return; } Life--; if (Life < 0) { return; } Results.Add(new BattleResult { PostId = status.Id, Name = status.Account.AccountName, Content = status.Content }); if (Life == 0) { string dead = new StringBuilder() .AppendLine($"{Boss.Name} (LP: 0/{Boss.LifePoint})") .AppendLine($"{Boss.VoiceDead}") .AppendLine($"> {GetName(status.Account)}「{content}」") .ToString(); await MastodonClient.PostStatus(dead, Visibility.Public, mediaIds : mediaIds); await End(true); return; } string damage = new StringBuilder() .AppendLine($"{Boss.Name} (LP: {Life}/{Boss.LifePoint})") .AppendLine($"{Boss.VoiceDamage}") .AppendLine($"> {GetName(status.Account)}「{content}」") .ToString(); await MastodonClient.PostStatus(damage, Visibility.Public); if (Life % 2 == 1) { string counter = $"@{status.Account.AccountName} {Boss.VoiceCounter}"; await MastodonClient.PostStatus(counter, Visibility.Public); } }; Console.WriteLine("Battleを開始します"); await UserStreaming.Start(); }
/* 主機能の実装 */ static void Main() { Program cliMa = new Program(); Console.SetWindowPosition(0, 0); Console.SetWindowSize(50, 30); Console.Clear(); Console.WriteLine(@" __ __ __ __ ____ / / /_/ / \ / \ ____ / __ \ / / __ / /\ \ / /\ \ / _ \/\ / / \_\ / / / / / / \ V / \ \ \ \ \ \ / / __ / / / / / / \ / \ \ \ \ \ \ / /__/ / / / / / / / | | \ \ \ \_\ \ \_____/ /_/ /_/ /_/ |_| \_\ \____/\_\"); if (!File.Exists(path)) { cliMa.RegistClient(); } MastodonClient client = cliMa.LoginClient(); Console.WriteLine("\nLogin Succeeded."); TimelineStreaming stream = cliMa.StreamTimeline(client, TimelineType.Local); stream.Start(); while (true) { string com = Console.ReadLine(); if (com != String.Empty) { string[] Input = com.Split(' '); switch (Input[0]) { case "timeline": if (Input.Length > 1) { stream.Stop(); switch (Input[1]) { case "-l": stream = cliMa.StreamTimeline(client, TimelineType.Local); break; case "-h": stream = cliMa.StreamTimeline(client, TimelineType.Home); break; case "-f": stream = cliMa.StreamTimeline(client, TimelineType.Federation); break; default: ErrorMsg(); break; } stream.Start(); } else { ErrorMsg(); } break; case "toot": if (Input.Length > 1) { switch (Input.Length) { case 2: client.PostStatus(Input[1], Visibility.Public); break; case 3: switch (Input[1]) { case "-u": client.PostStatus(Input[2], Visibility.Unlisted); break; case "-p": client.PostStatus(Input[2], Visibility.Private); break; case "-d": client.PostStatus(Input[2], Visibility.Direct); break; default: ErrorMsg(); break; } break; case 4: client.PostStatus(Input[3], Visibility.Public, sensitive: true, spoilerText: Input[2]); break; case 5: switch (Input[1]) { case "-u": client.PostStatus(Input[4], Visibility.Unlisted, sensitive: true, spoilerText: Input[3]); break; case "-p": client.PostStatus(Input[4], Visibility.Private, sensitive: true, spoilerText: Input[3]); break; case "-d": client.PostStatus(Input[4], Visibility.Direct, sensitive: true, spoilerText: Input[3]); break; default: ErrorMsg(); break; } break; } } else { ErrorMsg(); } break; case "help": if (Input.Length > 1) { switch (Input[1]) { case "timeline": Console.WriteLine(@" <Command> timeline: 'timeline [-l|-h|-f]' This Command changes Stream type. At Startup, Stream type is 'Local' [Argument] -l: Set Stream type to Local Timeline -h: Set Stream type to Home Timeline -f: Set Stream type to Federation Timeline"); break; case "toot": Console.WriteLine(@" <Command> toot: 'toot [-u|-p|-d] [-s (SpoilerText)] (Content)' This Command sends Toot Content. Cannot Toot if Content is null. Default Toot type is 'Public' [Argument] -u: Set Toot type once to Unlisted -p: Set Toot type once to Private -d: Set Toot type once to Direct -s (SpoilerText): Write SpoilerText to Toot"); break; } } else { Console.WriteLine(@" <Command List> -> timeline [-l|-h|-f] -> toot [-u|-p|-d] [-s (SpoilerText)] (Content) -> help If you want more help, type 'help [timeline|toot]'"); } break; default: ErrorMsg(); break; } } } }
public async Task Start() { UserStreaming = MastodonClient.GetUserStreaming(); UserStreaming.OnNotification += async(sender, e) => { var status = e.Notification.Status; if (status == null || !status.Content.Contains($"@<span>{Name}</span>")) { return; } if (status.Content.Contains("シャッフル")) { cardsSet.Reset(); await MastodonClient.PostStatus($"シャッフルしました", Visibility.Public); return; } int num = 1; var match = Regex.Match(status.Content, "[0-90-9]+"); if (match.Success) { string value = match.Value .Replace("0", "0") .Replace("1", "1") .Replace("2", "2") .Replace("3", "3") .Replace("4", "4") .Replace("5", "5") .Replace("6", "6") .Replace("7", "7") .Replace("8", "8") .Replace("9", "9"); num = int.Parse(match.Value); if (num < 1) { num = 1; } if (num > 5) { num = 5; } } var builder = new StringBuilder(); for (int i = 0; i < num; i++) { if (cardsSet.Empty) { cardsSet.Reset(); builder.AppendLine("シャッフルしました"); } string card = cardsSet.Get(); builder.AppendLine(card); } string post = builder.ToString(); await MastodonClient.PostStatus($"@{status.Account.AccountName} {post}", Visibility.Public); }; await UserStreaming.Start(); }