Exemple #1
0
        private Task <(ulong Id, User?User)[]> GetUsers(IEnumerable <ulong> ids)
        {
            async Task <(ulong Id, User?User)> Inner(ulong id)
            {
                var user = await _cache.GetOrFetchUser(_rest, id);

                return(id, user);
            }

            return(Task.WhenAll(ids.Select(Inner)));
        }
Exemple #2
0
        public async Task GetMessage(Context ctx)
        {
            var messageId = ctx.MatchMessage(true);

            if (messageId == null)
            {
                if (!ctx.HasNext())
                {
                    throw new PKSyntaxError("You must pass a message ID or link.");
                }
                throw new PKSyntaxError($"Could not parse {ctx.PeekArgument().AsCode()} as a message ID or link.");
            }

            var message = await _db.Execute(c => _repo.GetMessage(c, messageId.Value));

            if (message == null)
            {
                throw Errors.MessageNotFound(messageId.Value);
            }

            if (ctx.Match("delete") || ctx.MatchFlag("delete"))
            {
                if (message.System.Id != ctx.System.Id)
                {
                    throw new PKError("You can only delete your own messages.");
                }
                await ctx.Rest.DeleteMessage(message.Message.Channel, message.Message.Mid);

                await ctx.Rest.DeleteMessage(ctx.Message);

                return;
            }
            if (ctx.Match("author") || ctx.MatchFlag("author"))
            {
                var user = await _cache.GetOrFetchUser(_rest, message.Message.Sender);

                var eb = new EmbedBuilder()
                         .Author(new(user != null ? $"{user.Username}#{user.Discriminator}" : $"Deleted user ${message.Message.Sender}", IconUrl: user != null ? user.AvatarUrl() : null))
                         .Description(message.Message.Sender.ToString());

                await ctx.Reply(user != null?$"{user.Mention()} ({user.Id})" : $"*(deleted user {message.Message.Sender})*", embed : eb.Build());

                return;
            }

            await ctx.Reply(embed : await _embeds.CreateMessageInfoEmbed(message));
        }