Exemplo n.º 1
0
        public async Task MemberRandom(Context ctx)
        {
            ctx.CheckSystem();

            var randGen = new global::System.Random();
            //Maybe move this somewhere else in the file structure since it doesn't need to get created at every command

            // TODO: don't buffer these, find something else to do ig

            var members = await _db.Execute(c =>
            {
                if (ctx.MatchFlag("all", "a"))
                {
                    return(_repo.GetSystemMembers(c, ctx.System.Id));
                }
                return(_repo.GetSystemMembers(c, ctx.System.Id)
                       .Where(m => m.MemberVisibility == PrivacyLevel.Public));
            }).ToListAsync();

            if (members == null || !members.Any())
            {
                throw Errors.NoMembersError;
            }
            var randInt = randGen.Next(members.Count);
            await ctx.Reply(embed : await _embeds.CreateMemberEmbed(ctx.System, members[randInt], ctx.Guild, ctx.LookupContextFor(ctx.System)));
        }
Exemplo n.º 2
0
        // todo: get postgresql to return one random member/group instead of querying all members/groups

        public async Task Member(Context ctx)
        {
            ctx.CheckSystem();

            var members = await _db.Execute(c =>
            {
                if (ctx.MatchFlag("all", "a"))
                {
                    return(_repo.GetSystemMembers(c, ctx.System.Id));
                }
                return(_repo.GetSystemMembers(c, ctx.System.Id)
                       .Where(m => m.MemberVisibility == PrivacyLevel.Public));
            }).ToListAsync();

            if (members == null || !members.Any())
            {
                throw new PKError("Your system has no members! Please create at least one member before using this command.");
            }

            var randInt = randGen.Next(members.Count);
            await ctx.Reply(embed : await _embeds.CreateMemberEmbed(ctx.System, members[randInt], ctx.Guild, ctx.LookupContextFor(ctx.System)));
        }
Exemplo n.º 3
0
        private async ValueTask HandleQueryReaction(MessageReactionAddEventArgs evt, FullMessage msg)
        {
            // Try to DM the user info about the message
            var member = await evt.Guild.GetMember(evt.User.Id);

            try
            {
                await member.SendMessageAsync(embed : await _embeds.CreateMemberEmbed(msg.System, msg.Member, evt.Guild, LookupContext.ByNonOwner));

                await member.SendMessageAsync(embed : await _embeds.CreateMessageInfoEmbed(evt.Client, msg));
            }
            catch (UnauthorizedException) { } // No permissions to DM, can't check for this :(

            await TryRemoveOriginalReaction(evt);
        }
Exemplo n.º 4
0
        private async ValueTask HandleQueryReaction(MessageReactionAddEventArgs evt, FullMessage msg)
        {
            // Try to DM the user info about the message
            var member = await evt.Guild.GetMemberAsync(evt.User.Id);

            try
            {
                await member.SendMessageAsync(embed : await _embeds.CreateMemberEmbed(msg.System, msg.Member, evt.Guild, LookupContext.ByNonOwner));

                await member.SendMessageAsync(embed : await _embeds.CreateMessageInfoEmbed(evt.Client, msg));
            }
            catch (UnauthorizedException) { } // No permissions to DM, can't check for this :(

            // And finally remove the original reaction (if we can)
            if (evt.Channel.BotHasAllPermissions(Permissions.ManageMessages))
            {
                await evt.Message.DeleteReactionAsync(evt.Emoji, evt.User);
            }
        }
Exemplo n.º 5
0
        private async Task HandleMessageQueryByReaction(Cacheable <IUserMessage, ulong> message,
                                                        ISocketMessageChannel channel, ulong userWhoReacted,
                                                        IEmote reactedEmote)
        {
            // Find the user who sent the reaction, so we can DM them
            var user = await _client.Rest.GetUserAsync(userWhoReacted);

            if (user == null)
            {
                return;
            }

            // Find the message in the DB
            var msg = await _data.GetMessage(message.Id);

            if (msg == null)
            {
                return;
            }

            // DM them the message card
            try
            {
                await user.SendMessageAsync(embed : await _embeds.CreateMemberEmbed(msg.System, msg.Member, (channel as IGuildChannel)?.Guild, LookupContext.ByNonOwner));

                await user.SendMessageAsync(embed : await _embeds.CreateMessageInfoEmbed(msg));
            }
            catch (HttpException e) when(e.DiscordCode == 50007)
            {
                // Ignore exception if it means we don't have DM permission to this user
                // not much else we can do here :/
            }

            // And finally remove the original reaction (if we can)
            var msgObj = await message.GetOrDownloadAsync();

            if (msgObj.Channel.HasPermission(ChannelPermission.ManageMessages))
            {
                await msgObj.RemoveReactionAsync(reactedEmote, user);
            }
        }
Exemplo n.º 6
0
        private async ValueTask HandleQueryReaction(MessageReactionAddEvent evt, FullMessage msg)
        {
            var guild = _cache.GetGuild(evt.GuildId !.Value);

            // Try to DM the user info about the message
            try
            {
                var dm = await _cache.GetOrCreateDmChannel(_rest, evt.UserId);

                await _rest.CreateMessage(dm.Id, new MessageRequest
                {
                    Embed = await _embeds.CreateMemberEmbed(msg.System, msg.Member, guild, LookupContext.ByNonOwner)
                });

                await _rest.CreateMessage(dm.Id, new MessageRequest
                {
                    Embed = await _embeds.CreateMessageInfoEmbed(msg)
                });
            }
            catch (ForbiddenException) { } // No permissions to DM, can't check for this :(

            await TryRemoveOriginalReaction(evt);
        }
Exemplo n.º 7
0
        public async Task ViewMember(Context ctx, PKMember target)
        {
            var system = await _db.Execute(c => _repo.GetSystem(c, target.System));

            await ctx.Reply(embed : await _embeds.CreateMemberEmbed(system, target, ctx.Guild, ctx.LookupContextFor(system)));
        }