Esempio n. 1
0
        // ReSharper disable once SuggestBaseTypeForParameter
        public DanbooruModule(Danbooru booru, BooruRepository repository, SubscriptionService service, IOptionsSnapshot <BooruOptions> options) : base(repository)
        {
            this._service = service;
            this.Booru    = booru;

            var opts = options.Get("danbooru");

            if (!opts.Username.IsEmpty())
            {
                this.Booru.WithAuthentication(opts.Username, opts.ApiKey);
            }
        }
Esempio n. 2
0
        static BooruHelper()
        {
            HttpClient = new HttpClient(new SocketsHttpHandler
            {
                AutomaticDecompression = DecompressionMethods.All,
            });

            Danbooru       = new Danbooru(HttpClient);
            Gelbooru       = new Gelbooru(HttpClient);
            Konachan       = new Konachan(HttpClient);
            SankakuComplex = new SankakuComplex(HttpClient);
            Yandere        = new Yandere(HttpClient);

            TaskCancellationDelay = TimeSpan.FromMilliseconds(50);
        }
Esempio n. 3
0
File: Main.cs Progetto: ylt/Wolfbox
        private void listb_Click(object sender, EventArgs e)
        {
            double num;

            if (pageb.Value == 0 || !double.TryParse(pageb.Text, out num))
            {
                pageb.ForeColor = Color.Black;
                pageb.Value     = 1;
            }
            if (tagsb.Text == "Tags...")
            {
                tagsb.Text = "";
            }

            statusl.Text = "Loading posts...";

            //list.Rows.Clear();
            list.AutoGenerateColumns = false;

            Site site = null;

            if (serverlist.Text == "Konachan")
            {
                site = new Moebooru("http://konachan.com", "page=" + pageb.Text + "&tags=" + tagsb.Text);
            }
            else if (serverlist.Text == "Danbooru")
            {
                site = new Danbooru("http://danbooru.donmai.us", "page=" + pageb.Text + "&tags=" + tagsb.Text);
            }
            else if (serverlist.Text == "Gelbooru")
            {
                site = new Gelbooru("http://gelbooru.com", tagsb.Text);
            }

            list.DataSource = site.bs;

            site.ProgressChange += site_ProgressChange;

            statusl.Text = "Posts loaded!";
        }
Esempio n. 4
0
        public static void Setup()
        {
            StartedTime = new TimeSpan(DateTime.Now.Ticks);
            Random      = new TRandom(new NR3Generator(TMath.Seed()));
            Logger      = new BaseLogger();
            Logger.Log(ConsoleColor.Cyan, LogType.NoDisplay, "Info", "Welcome to Chino-chan!");

            CheckExternalLibs();

            LoadSettings();

            Gelbooru = new Gelbooru();
            Danbooru = new Danbooru();
            Yandere  = new Yandere();

            if (!Settings.Credentials.IsEmpty(CredentialType.Sankaku))
            {
                Sankaku = new Sankaku(Settings.Credentials.Sankaku.Username, Settings.Credentials.Sankaku.Password);
            }

            if (!Settings.Credentials.IsEmpty(CredentialType.Imgur))
            {
                Imgur = new Image.Imgur();
            }

            if (!string.IsNullOrWhiteSpace(Settings.Credentials.Google.ClientSecret) &&
                !string.IsNullOrWhiteSpace(Settings.Credentials.Google.ClientId))
            {
                Logger.Log(ConsoleColor.Green, LogType.GoogleDrive, null, "Logging into GoogleDrive...");
                var Credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets()
                {
                    ClientId     = Settings.Credentials.Google.ClientId,
                    ClientSecret = Settings.Credentials.Google.ClientSecret
                }, new string[] { DriveService.Scope.Drive }, "user", CancellationToken.None).Result;

                GoogleDrive = new DriveService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = Credential,
                    ApplicationName       = "Chino-chan"
                });
                Logger.Log(ConsoleColor.Green, LogType.GoogleDrive, null, "Logged in!");
            }

            if (!string.IsNullOrWhiteSpace(Settings.Credentials.Google.Token))
            {
                Logger.Log(ConsoleColor.Red, LogType.YouTubeAPI, null, "Creating YouTube service...");

                YouTube = new YouTubeService(new BaseClientService.Initializer()
                {
                    ApiKey          = Settings.Credentials.Google.Token,
                    ApplicationName = "Chino-chan"
                });

                Logger.Log(ConsoleColor.Red, LogType.YouTubeAPI, null, "Done!");
            }

            LanguageHandler = new LanguageHandler();
            GuildSettings   = new GuildSettings();

            Updater = new Updater();

            Client = new DiscordSocketClient(new DiscordSocketConfig()
            {
                AlwaysDownloadUsers = true,
                DefaultRetryMode    = RetryMode.AlwaysRetry,
                LargeThreshold      = 250,
                LogLevel            = LogSeverity.Verbose
            });

            Client.Log += (Log) =>
            {
                Logger.Log(ConsoleColor.White, LogType.Discord, Log.Severity.ToString(), Log.Message);
                return(Task.CompletedTask);
            };
            Client.Ready += () =>
            {
                if (Sankaku != null)
                {
                    Logger.Log(ConsoleColor.DarkYellow, LogType.Sankaku, "Login", "Logging in...");

                    var LoggedIn = Sankaku.Login(out bool TooManyRequests);
                    if (LoggedIn)
                    {
                        Logger.Log(ConsoleColor.DarkYellow, LogType.Sankaku, "Login", "Logged in!");
                    }
                    else
                    {
                        Logger.Log(ConsoleColor.Red, LogType.Sankaku, "Login", "Couldn't log in due to " + (TooManyRequests ? "rate limitation!" : "wrong credentials!"));
                    }
                }

                return(Task.CompletedTask);
            };

            if (osuAPIEnabled)
            {
                osuAPI = new osuApi();
            }

            CommandService = new CommandService(new CommandServiceConfig()
            {
                CaseSensitiveCommands = false,
                LogLevel       = LogSeverity.Verbose,
                DefaultRunMode = RunMode.Async
            });
            Logger.Log(ConsoleColor.Cyan, LogType.Commands, null, "Loading Commands...");

            Services = new ServiceCollection().BuildServiceProvider();

            CommandService.AddModulesAsync(Assembly.GetEntryAssembly(), Services).ContinueWith((ModuleInfo) =>
            {
                Logger.Log(ConsoleColor.Cyan, LogType.Commands, null, "Loaded Commands!");
                var Modules      = ModuleInfo.Result;
                var Text         = "";
                var HelpNotFound = new List <string>();

                var English = LanguageHandler.GetLanguage("en");

                foreach (var Module in Modules)
                {
                    Text += Environment.NewLine + "- " + Module.Name + Environment.NewLine;
                    foreach (var Command in Module.Commands)
                    {
                        Text += "-- " + Command.Name + Environment.NewLine;
                        if (!English.Help.ContainsKey(Command.Name))
                        {
                            HelpNotFound.Add(Command.Name);
                        }
                    }
                }
                Logger.Log(ConsoleColor.Cyan, LogType.Commands, null, "Available modules and commands: " + Text);
                if (HelpNotFound.Count != 0)
                {
                    Logger.Log(ConsoleColor.Cyan, LogType.Commands, "Warning", "Help not found for these commands: " + string.Join(", ", HelpNotFound));
                }
            });

            Client.MessageReceived += async(ReceivedMessage) =>
            {
                var Message = ReceivedMessage as SocketUserMessage;
                if (Message == null)
                {
                    return;
                }

                var Context = new CommandContext(Client, Message);

                var Settings = GuildSettings.GetSettings(Context.Guild != null ? Context.Guild.Id : Context.User.Id);

                if (Global.Settings.SayPreferences.ContainsKey(Context.User.Id) && !Message.Content.StartsWith(Settings.Prefix + "say"))
                {
                    var Prefs = Global.Settings.SayPreferences[Context.User.Id];
                    if (Prefs.Listening.ContainsKey(Context.Channel.Id))
                    {
                        if (Client.GetChannel(Prefs.Listening[Context.Channel.Id]) is ITextChannel Channel)
                        {
                            await Channel.SendMessageAsync(Message.Content);

                            if (Prefs.AutoDel)
                            {
                                var Dm = await Context.User.GetOrCreateDMChannelAsync();

                                if (Dm.Id != Context.Channel.Id)
                                {
                                    await Message.DeleteAsync();
                                }
                            }
                        }
                        else
                        {
                            Global.Settings.SayPreferences[Context.User.Id].Listening.Remove(Context.Channel.Id);
                            SaveSettings();
                        }
                    }
                }


                if (Message.Content == "/gamerescape")
                {
                    var Name = Message.Author.Username;
                    if (!Context.IsPrivate)
                    {
                        await Message.DeleteAsync();

                        Name = (await Context.Guild.GetUserAsync(Message.Author.Id)).Nickname ?? Name;
                    }
                    await Message.Channel.SendMessageAsync($"{ Name } ¯\\_(ツ)_/¯");

                    return;
                }
                else if (Message.Content == "/lenny")
                {
                    var Name = Message.Author.Username;
                    if (!Context.IsPrivate)
                    {
                        await Message.DeleteAsync();

                        Name = (await Context.Guild.GetUserAsync(Message.Author.Id)).Nickname ?? Name;
                    }
                    await Message.Channel.SendMessageAsync($"{ Name } ( ͡° ͜ʖ ͡°)");

                    return;
                }

                int Position = 0;

                if (!(Message.HasStringPrefix(Settings.Prefix, ref Position) ||
                      Message.HasMentionPrefix(Client.CurrentUser, ref Position)))
                {
                    return;
                }

                var MessageCommand = Message.Content.Substring(Position).ToLower();

                if (Images.Images.ContainsKey(MessageCommand))
                {
                    new Task(async() =>
                    {
                        var Pair = Images.Images[MessageCommand];
                        if (Pair.IsNsfw && !(Context.IsPrivate || IsNsfwChannel(Settings, Message.Channel.Id)))
                        {
                            await Message.Channel.SendMessageAsync(LanguageHandler.GetLanguage(Settings.LanguageId).OnlyNsfw);
                            return;
                        }
                        bool Success = false;
                        var File     = "";
                        do
                        {
                            if (!string.IsNullOrWhiteSpace(File))
                            {
                                Images.Images[MessageCommand].Files.Remove(File);

                                if (Images.Images[MessageCommand].Files.Count == 0)
                                {
                                    await Message.Channel.SendMessageAsync(LanguageHandler.GetLanguage(Settings.LanguageId).CantUploadImage);
                                    break;
                                }
                            }
                            File    = Pair.RandomFile();
                            Success = await SendImageAsync(File, Context.Channel, Pair.TitleIncludeName ? Pair.Name : null);
                        }while (!Success);
                    }).Start();
                    return;
                }

                var Result = await CommandService.ExecuteAsync(Context, Position, Services);

                if (!Result.IsSuccess)
                {
                    switch (Result.Error)
                    {
                    case CommandError.BadArgCount:
                        break;

                    case CommandError.ParseFailed:
                        break;

                    case CommandError.UnmetPrecondition:
                        if (Result.ErrorReason == "Owner")
                        {
                            await Context.Channel.SendMessageAsync(Context.GetLanguage().NoOwnerPermission);
                        }
                        else if (Result.ErrorReason == "ServerSide")
                        {
                            await Context.Channel.SendMessageAsync(Context.GetLanguage().OnlyServer);
                        }
                        else
                        {
                            await Context.Channel.SendMessageAsync(Context.GetLanguage().NoPermission);
                        }
                        break;

                    case CommandError.UnknownCommand:
                        if (IsOwner(Context.User.Id))
                        {
                            var Command = Tools.ConvertHighlightsBack(Message.Content.Substring(Position));

                            new Thread(() => Entrance.HandleCommand(Command, Context.Channel as ITextChannel)).Start();
                        }
                        break;

                    default:
                        await Context.Channel.SendMessageAsync($"```css\nAn error happened! Please report this to { Global.Settings.OwnerName }!\n\nError type: { Result.Error }\nReason: { Result.ErrorReason }```");

                        break;
                    }
                }
                else
                {
                    Logger.Log(ConsoleColor.DarkYellow, LogType.Commands, Context.Guild != null ? Context.Guild.Name : Context.Channel.Name, $"#{ Context.Channel.Name } { Context.User.Username } executed { Context.Message.Content }");
                }
            };

            MusicClients = new Dictionary <ulong, Modules.Music>();

            SysInfo = new SysInfo();
            SysInfo.Load();

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }