Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        static private async Task RunAsync(string path)
        {
            string Email    = Constant.InfoEmail;
            string Password = Constant.Password;

            DateTime today = DateTime.UtcNow.AddHours(9);

            var    list       = System.IO.File.ReadAllLines(path).ToList();
            string firstTheme = list.First();

            list.RemoveAt(0);
            list.Add(firstTheme);
            string secondTheme = list.First();

            System.IO.File.WriteAllLines(path, list);

            string message = new StringBuilder()
                             .AppendLine(today.ToString("M月d日(dddd)"))
                             .AppendLine("【本日のテーマ】")
                             .AppendLine("#" + secondTheme)
                             .AppendLine("#" + firstTheme)
                             .AppendLine("")
                             .AppendLine("(これ以外の話題や過去のテーマも大歓迎です!話題のひとつとしてお使いください)")
                             .ToString();

            var authenticationClient = new AuthenticationClient(Constant.Instance);
            var registration         = await authenticationClient.CreateApp("SpaceConsole", Scope.Read | Scope.Write | Scope.Follow);

            var auth = await authenticationClient.ConnectWithPassword(Email, Password);

            var MastodonClient = new MastodonClient(registration, auth);

            var post = await MastodonClient.PostStatus(message, Visibility.Public);

            var statuses = await MastodonClient.GetAccountStatuses(post.Account.Id, post.Id);

            foreach (var status in statuses)
            {
                await MastodonClient.DeleteStatus(status.Id);
            }
        }