Beispiel #1
0
        public async Task <IActionResult> Index(string guildId)
        {
            Guild g = _db.GetGuildFor(guildId);

            if (g is null)
            {
                return(new NotFoundResult());
            }

            var dGuildAsync = _bot.Client.GetGuildAsync(g.GuildID);

            var quotes = from q in _db.Quotes.Include(q => q.Source)
                         where q.GuildID == g !.ID
                         select q;

            List <QuoteData> quotesList             = new();
            Dictionary <string, UserData> userList  = new();
            Dictionary <string, RoleData> rolesList = new();

            foreach (var quote in quotes)
            {
                quotesList.Add(new QuoteData(quote.Text, quote.SourceName));
                if (quote.Source is not null)
                {
                    var user = quote.Source !;
                    if (!userList.ContainsKey(quote.SourceName))
                    {
                        var dGuild = await dGuildAsync;
                        var dUser  = await dGuild.GetMemberAsync(new Snowflake(user.UserID));

                        var roles = (from r in dUser.Roles
                                     select r.Name.Replace(' ', '_')).ToList();

                        userList.Add(quote.SourceName, new UserData(user.UserID, user.Name, dUser.AvatarUrl, Int32.Parse(dUser.Discriminator), roles));

                        foreach (var role in dUser.Roles)
                        {
                            if (!rolesList.ContainsKey(role.Name.Replace(' ', '_')))
                            {
                                rolesList.Add(role.Name.Replace(' ', '_'), new RoleData(role.Color.ToString(), role.Name));
                            }
                        }
                    }
                }
            }

            var res = new QuotesData()
            {
                Quotes = quotesList.ToList(),
                Users  = userList,
                Roles  = rolesList
            };

            return(new JsonResult(res));
        }
Beispiel #2
0
        public IActionResult Index(string guildId)
        {
            Guild g = _db.GetGuildFor(guildId);

            if (g is null)
            {
                return(new NotFoundResult());
            }


            var quotes = from q in _db.Quotes.Include(q => q.Source)
                         where q.GuildID == g !.ID
                         select q;

            List <Quote> quotesList            = new();
            Dictionary <string, User> userList = new();

            foreach (var quote in quotes)
            {
                quotesList.Add(new Quote(quote.Text, quote.SourceName));
                if (quote.Source is not null)
                {
                    var user = quote.Source !;

                    userList.TryAdd(quote.SourceName, new User(user.UserID, user.Name, ""));
                }
            }

            var res = new QuotesData()
            {
                Quotes = quotesList.ToList(),
                Users  = userList
            };

            return(new JsonResult(res));
        }