Beispiel #1
0
    public async Task ReproxyMessage(Context ctx)
    {
        var msg = await GetMessageToEdit(ctx, ReproxyTimeout, true);

        if (ctx.System.Id != msg.System?.Id)
        {
            throw new PKError("Can't reproxy a message sent by a different system.");
        }

        // Get target member ID
        var target = await ctx.MatchMember(restrictToSystem : ctx.System.Id);

        if (target == null)
        {
            throw new PKError("Could not find a member to reproxy the message with.");
        }

        // Fetch members and get the ProxyMember for `target`
        List <ProxyMember> members;

        using (_metrics.Measure.Timer.Time(BotMetrics.ProxyMembersQueryTime))
            members = (await _repo.GetProxyMembers(ctx.Author.Id, msg.Message.Guild !.Value)).ToList();
        var match = members.Find(x => x.Id == target.Id);

        if (match == null)
        {
            throw new PKError("Could not find a member to reproxy the message with.");
        }

        try
        {
            await _proxy.ExecuteReproxy(ctx.Message, msg.Message, match);

            if (ctx.Guild == null)
            {
                await _rest.CreateReaction(ctx.Channel.Id, ctx.Message.Id, new Emoji { Name = Emojis.Success });
            }
            if ((await ctx.BotPermissions).HasFlag(PermissionSet.ManageMessages))
            {
                await _rest.DeleteMessage(ctx.Channel.Id, ctx.Message.Id);
            }
        }
        catch (NotFoundException)
        {
            throw new PKError("Could not reproxy message.");
        }
    }