예제 #1
0
        private bool LoginUser()
        {
            var appRegistrationString = _helper.Read <string>("AppRegistrationService", null);

            if (string.IsNullOrEmpty(appRegistrationString))
            {
                return(false);
            }
            var appRegistration = JsonConvert.DeserializeObject <AppRegistration>(appRegistrationString);
            var userAuthString  = _helper.Read <string>("UserAuth", null);

            if (string.IsNullOrEmpty(userAuthString))
            {
                return(false);
            }
            var userAuth = JsonConvert.DeserializeObject <Auth>(userAuthString);
            var instance = _helper.Read <string>("ServerInstance", null);

            if (appRegistration == null || userAuth == null)
            {
                return(false);
            }
            appRegistration.Instance = instance;
            _client = new MastodonClient(appRegistration, new Auth()
            {
                AccessToken = userAuth.AccessToken
            });
            return(true);
        }
예제 #2
0
        private void LetsToot(string content)
        {
            var client = new MastodonClient("Mastodon Instance Url that your app registered"
                                            , "AccessToken");

            client.PostNewStatus(status: content).Wait();
        }
예제 #3
0
        public async Task PostResultAsync(Account account, IEnumerable <BattleResult> results)
        {
            if (!results.Any())
            {
                return;
            }

            int    num         = results.Select(x => x.Name).Distinct().Count();
            string users       = string.Join(",", results.Select(x => x.Name).Distinct());
            string lastUser    = results.Last().Name;
            string lastContent = Regex.Replace(results.Last().Content, "<span.*</span>", "");

            lastContent = Regex.Replace(lastContent, "<.*?>", "").Trim();

            string drop = ItemFactory.Create(account.Rank);

            var builder = new StringBuilder()
                          .AppendLine($"【{account.Name}を倒した!】");

            if (drop != "")
            {
                builder.AppendLine($"「{drop}」を手に入れた");
            }
            builder.AppendLine($"参加人数: {num}人 ({users})")
            .AppendLine($"最後の一撃: @{lastUser} 「{lastContent}」");
            string result = builder.ToString();

            await MastodonClient.PostStatus(result, Visibility.Public);
        }
예제 #4
0
 private void ImportAuthenticationData()
 {
     this.client            = this.Auth.Client;
     this.streamingInstance = this.Auth.StreamingUri;
     this.PostStatus        = new PostStatusModel(this.client);
     this.Account           = this.Auth.CurrentUser;
 }
예제 #5
0
        private TimelineStreaming StreamTimeline(MastodonClient client, TimelineType type)
        {
            TimelineStreaming streaming = null;

            switch (type)
            {
            case TimelineType.Home:
                streaming = client.GetUserStreaming();
                break;

            default:
                streaming = client.GetPublicStreaming();
                break;
            }
            Console.WriteLine("\n\nStart fetching " + ((int)type == 0 ? "Local" : (int)type == 1 ? "Home" : "Federation") + " Timeline.");
            Console.WriteLine("================================================\n\n");
            streaming.OnUpdate += (sender, e) =>
            {
                StreamUpdateEventArgs s = type == TimelineType.Local ? !Regex.IsMatch(e.Status.Account.AccountName, ".+@.*") ? e : null : e;
                if (s != null)
                {
                    Console.WriteLine(s.Status.Account.DisplayName);
                    Console.WriteLine("@" + s.Status.Account.AccountName);
                    if (s.Status.SpoilerText != "")
                    {
                        Console.WriteLine("Note: " + s.Status.SpoilerText);
                    }
                    Console.WriteLine(HTML_Perser(s.Status.Content));
                    Console.WriteLine();
                }
            };
            return(streaming);
        }
예제 #6
0
        static async Task Main(string[] args) {
            /*
             * .NET Coreを使ってMastdonへトュートするサンプル
            */
            Console.WriteLine("Hello World!");

            //インスタンスの指定
            var authClient = new AuthenticationClient("mstdn.jp");
            //アプリケーション作成&認証後の権限指定
            var appRegistration = await authClient.CreateApp("テストAPP", Scope.Read | Scope.Write | Scope.Follow);

            //OAuthの認証コード表示URL取得
            var url = authClient.OAuthUrl();
            //取得したURL表示
            Console.WriteLine(url);

            //前段で取得した認証コードをコンソールに入力
            var authCode = Console.ReadLine();
            //認証実行
            var auth = await authClient.ConnectWithCode(authCode);

            //アプリケーション + 認証情報でマストドンクライアントを生成
            var client = new MastodonClient(appRegistration, auth);

            //トュート内容設定
            var post_str = "テスト トュート!";

            //トュート!
            await client.PostStatus(post_str, Visibility.Public);
        }
예제 #7
0
        private async void OnAddAccountClickAsync(object sender, RoutedEventArgs e)
        {
            var progdiag = await this.ShowProgressAsync("認証中", "認証処理をしています。しばらくお待ちください。");

            try
            {
                var tokens = await authClient.ConnectWithCode(PinCodeTextBox.Text);

                await Task.Run(() =>
                {
                    var client    = new MastodonClient(registeredApp, tokens);
                    var container = new MastodonAccount(client);
                    Core.ConfigStore.StaticConfig.accountList.Add(container);
                });

                await progdiag.CloseAsync();

                this.Close();
            }
            catch (Exception ex)
            {
                await this.ShowMessageAsync("エラー",
                                            $"何らかのエラーで認証を開始することが出来ませんでした。\n\n{ex}");

                await progdiag.CloseAsync();
            }
        }
예제 #8
0
        /// <summary>
        /// bot を初期化します。
        /// </summary>
        /// <returns>初期化された <see cref="Shell"/> のインスタンス。</returns>
        public static async Task <Shell> InitializeAsync()
        {
            MastodonClient don;
            var            logger = new Logger();

            try
            {
                var cred = File.ReadAllText("./token");
                don = new MastodonClient(JsonConvert.DeserializeObject <Disboard.Models.Credential>(cred));
                logger.Info("Mastodon に接続しました。");
            }
            catch (Exception ex)
            {
                logger.Error($"認証中にエラーが発生しました {ex.GetType().Name} {ex.Message}\n{ex.StackTrace}");
                Write("Mastodon URL> ");
                var domain = ReadLine();
                don = new MastodonClient(domain);
                await AuthorizeAsync(don, logger);
            }

            var myself = await don.Account.VerifyCredentialsAsync();

            logger.Info($"bot ユーザーを取得しました (@{myself.Username}");

            var sh = new Shell(don, myself, logger);

            return(sh);
        }
예제 #9
0
        public void SetupTimelineModel(MastodonClient mastodonClient)
        {
            this._mastodonClient = mastodonClient;

            this.GetFirstPageTimelineAsync();
            this.GetFirstPageTimelineAsync();
        }
        public async Task ClearNotification()
        {
            var tokenInfo = await GetAccessToken();

            var client = new MastodonClient(Settings.InstanceName);
            await client.ClearNotificationsAsync(tokenInfo);
        }
예제 #11
0
        public async Task <bool> Login()
        {
            Mastonet.Entities.Auth auth;
            if (auth_client?.AuthToken == null)
            {
                var d = DialogLogin.Dialog();
                if (d?.DialogResult != true)
                {
                    return(false);
                }
                var instance = d.instance;
                var id       = d.id;
                var pw       = d.password;

                this.instance = instance;
                auth_client   = new AuthenticationClient(instance);
                await LoadAppAsync();

                auth = await auth_client.ConnectWithPassword(id, pw);
            }
            else
            {
                auth = auth_client.AuthToken;
            }
            if (app != null && auth != null)
            {
                client = new MastodonClient(app, auth);
            }
            else
            {
                throw new System.Security.SecurityException("Login Failed");
            }
            return(true);
        }
 public TimelineScrollingCollection(MastodonClient client, string path, int accountId = 0)
 {
     HasMoreItems = true;
     IsLoading    = false;
     _client      = client;
     _path        = path;
     _accountId   = accountId;
 }
예제 #13
0
 public Shell(MastodonClient don, Account myself, Logger logger)
 {
     Core        = new Server(this);
     Mastodon    = don;
     Myself      = new DonUser(myself);
     this.logger = logger;
     SubscribeStreams();
 }
        public async Task GetInstance()
        {
            var client   = new MastodonClient(Settings.InstanceName);
            var instance = await client.GetInstanceAsync();

            Assert.IsNotNull(instance);
            Assert.IsFalse(string.IsNullOrWhiteSpace(instance.uri));
        }
예제 #15
0
        private static async Task Execute()
        {
            MastodonClient mastoClient = await PrepareClient();

            _client = mastoClient;

            await Start(mastoClient);
        }
        public async Task GetFollowRequests()
        {
            var tokenInfo = await GetAccessToken();

            var client         = new MastodonClient(Settings.InstanceName);
            var followRequests = await client.GetFollowRequestsAsync(tokenInfo);

            Assert.IsNotNull(followRequests);
        }
        public async Task PostNewStatus()
        {
            var tokenInfo = await GetAccessToken();

            var client = new MastodonClient(Settings.InstanceName);
            var status = await client.PostNewStatusAsync(tokenInfo, "Cool status for testing purpose", StatusVisibilityEnum.Private, -1, null, true, "TESTING SPOILER");

            Assert.IsTrue(!string.IsNullOrWhiteSpace(status.content));
        }
        public async Task DeleteStatus()
        {
            var tokenInfo = await GetAccessToken();

            var client = new MastodonClient(Settings.InstanceName);
            var status = await client.PostNewStatusAsync(tokenInfo, "Cool status for testing purpose", StatusVisibilityEnum.Private, -1, null, true, "TESTING SPOILER");

            await client.DeleteStatusAsync(tokenInfo, status.id);
        }
예제 #19
0
        public async Task InitializeAsync()
        {
            var authenticationClient = new AuthenticationClient(Constant.Instance);
            var registration         = await authenticationClient.CreateApp("SakabaConsole", Scope.Read | Scope.Write | Scope.Follow);

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

            MastodonClient = new MastodonClient(registration, auth);
        }
        private async Task <Status> GetToot()
        {
            var tokenInfo = await GetAccessToken();

            var client   = new MastodonClient(Settings.InstanceName);
            var timeline = await client.GetPublicTimelineAsync(tokenInfo);

            return(timeline.First());
        }
        public async Task GetHomeTimeline()
        {
            var tokenInfo = await GetAccessToken();

            var client   = new MastodonClient(Settings.InstanceName);
            var timeline = await client.GetHomeTimelineAsync(tokenInfo);

            Assert.IsNotNull(timeline);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(timeline.First().id));
        }
        public async Task GetNotifications()
        {
            var tokenInfo = await GetAccessToken();

            var client        = new MastodonClient(Settings.InstanceName);
            var notifications = await client.GetNotificationsAsync(tokenInfo);

            Assert.IsNotNull(notifications);
            Assert.IsFalse(string.IsNullOrWhiteSpace(notifications.First().type));
        }
        public async Task GetCurrentAccount()
        {
            var tokenInfo = await GetAccessToken();

            var client  = new MastodonClient(Settings.InstanceName);
            var account = await client.GetCurrentAccountAsync(tokenInfo);

            Assert.IsNotNull(account.url);
            Assert.IsNotNull(account.username);
        }
        public async Task GetAccountFollowing()
        {
            var tokenInfo = await GetAccessToken();

            var client   = new MastodonClient(Settings.InstanceName);
            var accounts = await client.GetAccountFollowingAsync(1, tokenInfo, 4);

            Assert.IsNotNull(accounts);
            Assert.AreEqual(4, accounts.Length);
        }
        public async Task GetAccountRelationships()
        {
            var tokenInfo = await GetAccessToken();

            var client        = new MastodonClient(Settings.InstanceName);
            var relationships = await client.GetAccountRelationshipsAsync(1, tokenInfo); //TODO pass a array Ids

            Assert.IsNotNull(relationships);
            Assert.IsTrue(relationships.First().id != default(int));
        }
        public async Task GetFavorites()
        {
            var tokenInfo = await GetAccessToken();

            var client = new MastodonClient(Settings.InstanceName);
            var favs   = await client.GetFavoritesAsync(tokenInfo);

            Assert.IsNotNull(favs);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(favs.First().id));
        }
        public async Task Mute()
        {
            var tokenInfo = await GetAccessToken();

            var client       = new MastodonClient(Settings.InstanceName);
            var mutedAccount = await client.MuteAsync(1, tokenInfo);

            Assert.IsNotNull(mutedAccount);
            Assert.IsTrue(mutedAccount.muting);
        }
        public async Task Unmuted()
        {
            var tokenInfo = await GetAccessToken();

            var client         = new MastodonClient(Settings.InstanceName);
            var unmutedAccount = await client.UnmuteAsync(1, tokenInfo);

            Assert.IsNotNull(unmutedAccount);
            Assert.IsFalse(unmutedAccount.muting);
        }
예제 #29
0
        public Battle(Boss boss)
        {
            Boss           = boss;
            MastodonClient = boss.MastodonClient;

            Task.Run(async() => {
                await Task.Delay(limmitTime);
                await End(false);
            });
        }
        public async Task Block()
        {
            var tokenInfo = await GetAccessToken();

            var client         = new MastodonClient(Settings.InstanceName);
            var blockedAccount = await client.BlockAsync(10, tokenInfo);

            Assert.IsNotNull(blockedAccount);
            Assert.IsTrue(blockedAccount.blocking);
        }