public async Task <Result> Handle(Command request, CancellationToken cancellationToken)
        {
            try
            {
                var id     = request.ServerId.ToUpperInvariant();
                var server = _polychatService.GetOnlineServerOrDefault(id);

                if (server is null)
                {
                    return(new NotFoundError($"Could not find server with ID: {id}"));
                }

                var msg = new GenericCommand
                {
                    DiscordCommandName = "tps",
                    DefaultCommand     = "forge tps",
                    DiscordChannelId   = request.ChannelId.ToString()
                };

                await _polychatService.SendMessage(server, msg);

                return(Result.FromSuccess());
            }
            catch (Exception e)
            {
                return(e);
            }
        }
Esempio n. 2
0
            public async Task <Result> Handle(Command request, CancellationToken cancellationToken)
            {
                try
                {
                    var msg = new GenericCommand
                    {
                        DiscordCommandName = "exec",
                        DefaultCommand     = "$args",
                        Args             = { request.McCmdArgs },
                        DiscordChannelId = request.ChannelId.ToString()
                    };

                    if (request.ServerId.Equals("<all>"))
                    {
                        await _polychatService.BroadcastMessage(msg);

                        return(Result.FromSuccess());
                    }

                    var server = _polychatService.GetOnlineServerOrDefault(request.ServerId.ToUpperInvariant());

                    if (server is null)
                    {
                        return(new NotFoundError($"Could not find server with ID: {request.ServerId}"));
                    }

                    await _polychatService.SendMessage(server, msg);

                    return(Result.FromSuccess());
                }
                catch (Exception e)
                {
                    return(e);
                }
            }
Esempio n. 3
0
        /// <inheritdoc />
        public async Task <Result <MemberApplication> > Handle(Command request, CancellationToken cancellationToken)
        {
            var app = await _context.MemberApplications
                      .FirstOrDefaultAsync(
                a => a.MemberApplicationId == request.Id && a.GuildId == request.GuildId.Value,
                cancellationToken);

            if (app is null)
            {
                return(new NotFoundError($"Application with ID `{request.Id}` does not exist"));
            }

            var getRoles = await _guildApi.GetGuildRolesAsync(request.GuildId, cancellationToken);

            if (!getRoles.IsSuccess)
            {
                return(Result <MemberApplication> .FromError(getRoles.Error));
            }

            var role = getRoles.Entity
                       .FirstOrDefault(r =>
                                       r.Name.Contains($"[{request.ServerPrefix.ToUpper()}]"));

            if (role is null)
            {
                return(new NotFoundError(
                           $"Could not find a role corresponding to the server prefix: `{request.ServerPrefix}`."));
            }

            var userId = new Snowflake(app.AuthorDiscordId);
            var getUserToPromoteResult =
                await _guildApi.GetGuildMemberAsync(request.GuildId, userId, cancellationToken);

            if (!getUserToPromoteResult.IsSuccess)
            {
                return(Result <MemberApplication> .FromError(getUserToPromoteResult.Error));
            }
            if (getUserToPromoteResult.Entity is null)
            {
                return(new NotFoundError($"Could not find a user with ID: `{app.AuthorDiscordId}`."));
            }

            foreach (var ign in request.Igns)
            {
                var proto = new GenericCommand
                {
                    DiscordChannelId   = request.ChannelId.ToString(),
                    DiscordCommandName = "promote",
                    DefaultCommand     = "ranks add $1 member",
                    Args = { ign }
                };
                var id     = request.ServerPrefix.ToUpperInvariant();
                var server = _ps.GetOnlineServerOrDefault(id);

                if (server is null)
                {
                    return(Result <MemberApplication> .FromError(
                               new NotFoundError($"Could not find server with ID {id}")));
                }

                await _ps.SendMessage(server, proto);
            }

            var addRoleResult =
                await _guildApi.AddGuildMemberRoleAsync(request.GuildId, userId, role.ID, new(), cancellationToken);

            if (!addRoleResult.IsSuccess)
            {
                return(Result <MemberApplication> .FromError(addRoleResult));
            }

            app.AppStatus = ApplicationStatus.Approved;
            await _context.SaveChangesAsync(cancellationToken);

            return(Result <MemberApplication> .FromSuccess(app));
        }