Beispiel #1
0
        public async Task <bool> TryAuthenticate(string token)
        {
            WeebClient = new WeebClient("Sora", "3.0.0");
            try
            {
                await WeebClient.Authenticate(token, TokenType.Bearer);

                this.IsAuthenticated = true;
                return(true);
            }
            catch (Exception e)
            {
                _log.LogError(e, "Couldn't authenticate WeebClient");
                this.IsAuthenticated = false;
                return(false);
            }
        }
Beispiel #2
0
        internal async Task <DiscordEmbed> GetWeeb(string tipo, string msg)
        {
            WeebClient weeb = new WeebClient();
            await weeb.Authenticate(DependencesSingleton.GetApiWeeb().Key, TokenType.Wolke);

            RandomData imgReceived = await weeb.GetRandomAsync(tipo, new string[] { }, FileType.Any, false, NsfwSearch.False);

            DiscordEmbedBuilder eb = new DiscordEmbedBuilder
            {
                Color    = DiscordColor.HotPink,
                ImageUrl = imgReceived.Url
            };

            if (Auto)
            {
                eb.WithTitle($"{Author.Username} {((UsuarioDestino == null) ? SelfMsg : msg + " " + UsuarioDestino.Username)}.");
            }
            else
            {
                eb.WithTitle(msg);
            }

            return(eb.Build());
        }
Beispiel #3
0
        public async Task AddInteractions(CommandService service)
        {
            if (!this.IsAuthenticated)
            {
                return;
            }
            var types = await WeebClient.GetTypesAsync().ConfigureAwait(false);

            if (types == null || types.Types.Count == 0)
            {
                return;
            }
            await service.CreateModuleAsync("", build =>
            {
                build.Name    = "Interactions";
                build.Summary = "All available interaction commands";

                foreach (var type in types.Types)
                {
                    build.AddCommand(type, async(context, objects, serviceProvider, commandInfo) =>
                    {
                        var image = await this.WeebClient.GetRandomAsync(type, Array.Empty <string>()).ConfigureAwait(false);
                        if (image == null)
                        {
                            await context.Channel.SendMessageAsync("", embed: new EmbedBuilder()
                            {
                                Color = SoraSocketCommandModule.Red,
                                Title = $"{SoraSocketCommandModule.FAILURE_EMOJI} Failed to fetch image :/ Try another one."
                            }.Build());
                            return;
                        }

                        var eb = new EmbedBuilder()
                        {
                            Color  = SoraSocketCommandModule.Purple,
                            Footer = new EmbedFooterBuilder()
                            {
                                Text = "Powered by weeb.sh and the weeb.net wrapper"
                            },
                            ImageUrl = image.Url
                        };

                        var mentions = context.Message.MentionedUserIds
                                       .Where(id => id != context.User.Id && id != context.Client.CurrentUser.Id)
                                       .ToArray();
                        if (mentions.Length == 0)
                        {
                            await context.Channel.SendMessageAsync("", embed: eb.Build());
                            return;
                        }
                        // Otherwise create a nice title
                        var tasks = mentions
                                    .Select(async x => await context.Guild.GetUserAsync(x).ConfigureAwait(false));
                        var res = (await Task.WhenAll(tasks).ConfigureAwait(false))
                                  .Where(u => u != null)
                                  .Select(Formatter.UsernameDiscrim);
                        var title = String.Join(", ", res);
                        if (title.Length > 150)
                        {
                            title = $"{title.Remove(150)}...";
                        }

                        title = GetTitle(type, Formatter.UsernameDiscrim(context.User), title);
                        if (title != null)
                        {
                            eb.Title = title;
                        }
                        await context.Channel.SendMessageAsync("", embed: eb.Build());
                    }, builder =>
                    {
                        builder.AddParameter("users", typeof(string),
                                             parameterBuilder =>
                        {
                            parameterBuilder.IsRemainder = true;
                            parameterBuilder.IsOptional  = true;
                        });
                    });
                }
            });
        }
Beispiel #4
0
 public WeebService()
 {
     _token      = ConfigService.GetConfigData("weebToken");
     _weebClient = new WeebClient("Sora", Utility.SORA_VERSION);
 }