示例#1
0
        public async Task AuthorizeWithEmailTest()
        {
            var authorize = new Authorize
            {
                Instance     = AccountInformation.Instance,
                ClientId     = AccountInformation.ClientId,
                ClientSecret = AccountInformation.ClientSecret
            };

            var tokens = await authorize.AuthorizeWithEmail(AccountInformation.Username, AccountInformation.Password);

            Assert.NotNull(tokens);
            Assert.NotNull(tokens.AccessToken);
        }
示例#2
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);
            }
        }
示例#3
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
        }