예제 #1
0
        /// <summary>
        /// Processing when OK button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Issue ClientID and ClientSecrert of the instance
                Authorize authorize = new Authorize();
                authorize.CreateApp(TextBox.Text, "DANMAKU via Mastodon", Scope.Read).Wait();

                // Set settings
                Default.Instance     = TextBox.Text;
                Default.ClientId     = authorize.ClientId;
                Default.ClientSecret = authorize.ClientSecret;
                Default.AccessToken  = null;

                // Open authentication url
                Process.Start(authorize.GetAuthorizeUri());
            }
            catch
            {
                Default.Instance     = null;
                Default.ClientId     = null;
                Default.ClientSecret = null;
            }

            // Save settings
            Default.Save();

            // Set DialogResult true and close window
            DialogResult = true;
            Close();
        }
예제 #2
0
        /// <summary>
        /// mastodon認証ボタン
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnOpenAuthorizeWindow_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtMastodonInstanceDomain.Text.Trim()))
            {
                return;
            }

            _Authorize = new Authorize()
            {
                ClientId = Properties.Settings.Default.Mastodon_ClientKey
                ,
                ClientSecret = Properties.Settings.Default.Mastodon_ClientSecret
            };

            try
            {
                await _Authorize.CreateApp(txtMastodonInstanceDomain.Text.Trim(), Properties.Settings.Default.AppName, Scope.Write);

                System.Diagnostics.Process.Start(_Authorize.GetAuthorizeUri());

                panel1.Visible = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Name, MessageBoxButtons.OK);
            }
        }
예제 #3
0
        public async Task CreateAppTest()
        {
            var authorize = new Authorize();

            await authorize.CreateApp(AccountInformation.Instance, "TootNet", Scope.Read | Scope.Write | Scope.Follow);

            Assert.NotNull(authorize.Instance);
            Assert.NotNull(authorize.ClientId);
            Assert.NotNull(authorize.ClientSecret);
        }
예제 #4
0
        public static async void Run(BotConfig conf)
        {
            Config = conf;
            //Console.CancelKeyPress += (s, e) =>
            //{
            //    e.Cancel = true;
            //    running = false;
            //};
            var auth = new Authorize();
            await auth.CreateApp(Config.Instance, "Mastodon image Bot (by Kotori7)", Scope.Write, "https://kotori7.com");

            var tokens = await auth.AuthorizeWithEmail(Config.Email, Config.Password);

            running = true;
            while (running)
            {
                string content = await http.GetStringAsync($"https://danbooru.donmai.us/posts.json?limit=1&random=1&tags={Config.Tags}");

                JArray  a     = JArray.Parse(content);
                JObject obj   = JObject.Parse(a[0].ToString());
                string  fPath = $"cache\\{obj["md5"]}.{obj["file_ext"]}";
                string  f**k  = (string)obj["file_url"];
                if (!f**k.StartsWith("http"))
                {
                    f**k = "https://danbooru.donmai.us" + f**k;
                }
                try
                {
                    byte[] fContent = await http.GetByteArrayAsync(f**k);

                    File.WriteAllBytes(fPath, fContent);
                    using (var fs = new FileStream(fPath, FileMode.Open, FileAccess.Read))
                    {
                        var attach = await tokens.Media.PostAsync(file => fs);

                        await tokens.Statuses.PostAsync(status => $"https://danbooru.donmai.us/posts/{obj["id"]}", media_ids => new System.Collections.Generic.List <long>()
                        {
                            attach.Id
                        });
                    }
                    Console.WriteLine($"Posted danbooru post {obj["id"]}. MD5: {obj["md5"]}");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Something f****d up. Oh well, maybe next time.");
                }
                await Task.Delay(Config.PostInterval * 60000);
            }
        }
예제 #5
0
        static async Task MainAsync(string[] args)
        {
            using (var db =
                       new LiteDatabase(
                           @"C:\AdventureBot\MyData.db"))
            {
                var language = new Language();
                var dungeon  = new Dungeon(db);
                dungeon.LoadDungeon();

                var authorize = new Authorize();
                await authorize.CreateApp(Program.InstanceName, "Tootnet", Scope.Read | Scope.Write | Scope.Follow);

                Console.WriteLine("Logging in " + Program.Username);
                var tokens = await authorize.AuthorizeWithEmail(Program.Username, Program.Password);

                Console.WriteLine("toot [message] - toot message as AdventureBot");
                Console.WriteLine("notification - list notifications");
                Console.WriteLine("add - add/upset players from notif list into db... ALSO reomoves unfollow");
                Console.WriteLine("process - process mentions as commands");
                Console.WriteLine("loop - run add and process with pause on endless loop");
                Console.WriteLine("players - list current players");
                Console.WriteLine("createnew - !!!! wipe and create new dungeon");
                Console.WriteLine("createmonsters - !!!! wipe and create monsters");
                Console.WriteLine("createitems - !!!! wipe and create items");
                Console.WriteLine("quit");

                if (Program.Debug)
                {
                    Console.WriteLine("*** DEBUGGING IS ON ***");
                }

                var command     = args;
                var commandWord = (args == null) ? "" : args.FirstOrDefault()?.ToLower();
                Console.WriteLine("...");
                while (commandWord != "exit")
                {
                    switch (commandWord)
                    {
                    case "quit":
                    case "exit":
                        return;

                    case "toot":
                        if (command.Length <= 1)
                        {
                            break;
                        }
                        var text = command[1].Trim();
                        var post = await tokens.Statuses.PostAsync(status => text);

                        Console.WriteLine(post.Account.DisplayName + "<br>" + post.Account.Acct);
                        Console.WriteLine(TagRegex.Replace(post.Content.Replace("<br />", "\n"), "").Trim());
                        Console.WriteLine(post.CreatedAt);
                        break;

                    case "notification":
                        var notifications = await tokens.Notifications.GetAsync();

                        foreach (var notification in notifications)
                        {
                            Console.WriteLine("-----[start]-------");
                            Console.WriteLine(notification.Account.DisplayName + "<br>" + notification.Account.Acct);
                            Console.WriteLine(notification.Type);
                            if (notification.Type == "mention" || notification.Type == "reblog" ||
                                notification.Type == "favourite")
                            {
                                Console.WriteLine(notification.Status.Id + ": " +
                                                  notification.Status.Account.DisplayName + "<br>" +
                                                  notification.Status.Account.Acct);
                                Console.WriteLine(TagRegex
                                                  .Replace(notification.Status.Content.Replace("<br />", "\n"), "").Trim());
                            }
                            Console.WriteLine(notification.CreatedAt);
                            Console.WriteLine("------[end]------");
                        }
                        break;

                    // Add new players
                    case "add":
                        await DoAdds(tokens, db, dungeon);

                        break;

                    // Each player that has mentioned us, process their input
                    case "process":
                        await DoProcess(tokens, db, dungeon);

                        break;

                    // Add and process in andless loop - for task running from scheduler run with dotnet adventurebot.dll loop
                    case "loop":
                        while (true)
                        {
                            await DoAdds(tokens, db, dungeon);
                            await DoProcess(tokens, db, dungeon);

                            Thread.Sleep(900000);      // 15 mins
                        }
                        ;
                        //await Task.Delay(20);
                        return;

                    case "createnew":
                        dungeon.CreateDungeon();
                        break;

                    case "createmonsters":
                        dungeon.CreateMonsters(5);
                        break;

                    case "createitems":
                        dungeon.CreateItems(5);
                        break;

                    case "load":
                        dungeon.LoadDungeon();
                        break;

                    case "players":
                        dungeon.LoadPlayers();
                        break;
                    }
                    Console.Write("command: ");
                    command     = Console.ReadLine().Trim().Split(' ', 2);
                    commandWord = command.First().ToLower();
                }
            } // end of db using
        }
예제 #6
0
        static async Task MainAsync()
        {
            var authorize = new Authorize();
            await authorize.CreateApp("mstdn.jp", "Tootnet", Scope.Read | Scope.Write | Scope.Follow);

            var authorizeUrl = authorize.GetAuthorizeUri();

            Console.WriteLine(authorizeUrl);
            Console.Write("code: ");
            var code   = Console.ReadLine().Trim();
            var tokens = await authorize.AuthorizeWithCode(code);

            Console.WriteLine(" -- List of commands -- ");
            Console.WriteLine("toot [status]");
            Console.WriteLine("notification");
            Console.WriteLine("home");
            Console.WriteLine("ftl");
            Console.WriteLine("ltl");
            Console.WriteLine("help");
            Console.WriteLine("quit");
            Console.WriteLine("exit");

            while (true)
            {
                Console.Write("command: ");
                var command = Console.ReadLine().Trim().Split(' ', 2);
                switch (command.First().ToLower())
                {
                case "help":
                    Console.WriteLine(" -- List of commands -- ");
                    Console.WriteLine("toot [status]");
                    Console.WriteLine("notification");
                    Console.WriteLine("home");
                    Console.WriteLine("ftl");
                    Console.WriteLine("ltl");
                    Console.WriteLine("help");
                    Console.WriteLine("quit");
                    Console.WriteLine("exit");
                    break;

                case "quit":
                case "exit":
                    return;

                case "toot":
                    if (command.Length <= 1)
                    {
                        break;
                    }

                    var text = command[1].Trim();
                    var post = await tokens.Statuses.PostAsync(status => text);

                    Console.WriteLine("--------------------");
                    Console.WriteLine(post.Account.DisplayName + "\t\t" + post.Account.Acct);
                    Console.WriteLine(TagRegex.Replace(post.Content.Replace("<br />", "\n"), "").Trim());
                    Console.WriteLine(post.CreatedAt);
                    Console.WriteLine("--------------------");
                    break;

                case "home":
                    var home = await tokens.Timelines.HomeAsync();

                    Console.WriteLine("--------------------");
                    foreach (var status in home)
                    {
                        Console.WriteLine(status.Account.DisplayName + "\t\t" + status.Account.Acct);
                        Console.WriteLine(TagRegex.Replace(status.Content.Replace("<br />", "\n"), "").Trim());
                        Console.WriteLine(status.CreatedAt);
                        Console.WriteLine("--------------------");
                    }
                    break;

                case "ftl":
                    var ftl = await tokens.Timelines.PublicAsync();

                    Console.WriteLine("--------------------");
                    foreach (var status in ftl)
                    {
                        Console.WriteLine(status.Account.DisplayName + "\t\t" + status.Account.Acct);
                        Console.WriteLine(TagRegex.Replace(status.Content.Replace("<br />", "\n"), "").Trim());
                        Console.WriteLine(status.CreatedAt);
                        Console.WriteLine("--------------------");
                    }
                    break;

                case "ltl":
                    var ltl = await tokens.Timelines.PublicAsync(local => true);

                    Console.WriteLine("--------------------");
                    foreach (var status in ltl)
                    {
                        Console.WriteLine(status.Account.DisplayName + "\t\t" + status.Account.Acct);
                        Console.WriteLine(TagRegex.Replace(status.Content.Replace("<br />", "\n"), "").Trim());
                        Console.WriteLine(status.CreatedAt);
                        Console.WriteLine("--------------------");
                    }
                    break;

                case "notification":
                    var notifications = await tokens.Notifications.GetAsync();

                    Console.WriteLine("--------------------");
                    foreach (var notification in notifications)
                    {
                        Console.WriteLine(notification.Account.DisplayName + "\t\t" + notification.Account.Acct);
                        Console.WriteLine(notification.Type);
                        if (notification.Type == "mention" || notification.Type == "reblog" ||
                            notification.Type == "favourite")
                        {
                            Console.WriteLine("==========");
                            Console.WriteLine(notification.Status.Account.DisplayName + "\t\t" +
                                              notification.Status.Account.Acct);
                            Console.WriteLine(TagRegex
                                              .Replace(notification.Status.Content.Replace("<br />", "\n"), "").Trim());
                            Console.WriteLine("==========");
                        }
                        Console.WriteLine(notification.CreatedAt);
                        Console.WriteLine("--------------------");
                    }
                    break;
                }
            }
        }