/// <summary> /// Add an auto role for the given server /// </summary> /// <param name="serverId">The id of the sercer</param> /// <param name="roleId">The id of the role to add</param> /// <returns></returns> public async Task AddAutoRole(ulong serverId, ulong roleId) { var server = await _serverRepository.GetByServerId(serverId); if (server == null) { await _serverRepository.AddAsync(new Server { GuildId = serverId, Prefix = _settings.DefaultPrefix }); } await _autoRoleRepository.AddAsync(new AutoRole { RoleId = roleId, ServerId = server.Id }); }
public async static Task <Server> GetOrAddServer(ulong serverId, IServerRepository serverRepository) { var server = await serverRepository.GetByServerId(serverId); if (server == null) { server = new Server { GuildId = serverId }; await serverRepository.AddAsync(server); } return(server); }
public async Task <CreateServerCommandResponse> Handle(CreateServerCommand request, CancellationToken cancellationToken) { var validationResult = await _validator.ValidateAsync(request); if (!validationResult.IsValid) { var errors = validationResult.Errors .Select(x => x.ErrorMessage); return(new CreateServerCommandResponse(null, errors)); } _logger.LogInformation("Adicionando novo servidor {0}", request.Name); var newServer = new Server(request.Name, request.IP, request.Port); var createdServer = await _serverRepository.AddAsync(newServer); await _serverRepository.SaveChangesAsync(); _logger.LogInformation("Servidor {0} criado.", createdServer.Name); return(new CreateServerCommandResponse(createdServer, null)); }
public async Task WarnAction([Summary("Action: none, kick or ban")] string action = null, [Summary("The number of warnings before the action is performed")] int maxWarns = -1) { await Context.Channel.TriggerTypingAsync(); _logger.LogInformation("{user}#{discriminator} invoked warnaction ({action}, {maxWarns}) messages in {channel} on {server}", Context.User.Username, Context.User.Discriminator, action, maxWarns, Context.Channel.Name, Context.Guild?.Name ?? "DM"); var server = await _serverRepository.GetByServerId(Context.Guild.Id); if (server == null) { server = new Server { GuildId = Context.Guild.Id }; await _serverRepository.AddAsync(server); } if (action == null && maxWarns < 0) { var wAction = await _warningRepository.GetWarningAction(server); if (wAction == null) { await ReplyAsync("The warn action has not been set."); return; } await Context.Channel.SendEmbedAsync("Warn Action", $"The warn action is set to: `{ Enum.GetName(typeof(WarningAction), wAction.Action)}`. The threshold is: `{wAction.ActionThreshold}`", ColorHelper.GetColor(server)); return; } var message = $"Warn action set to `{action.ToLowerInvariant()}`, Max Warnings { maxWarns} by {Context.User.Mention}"; bool valid = false; WarnAction warnAction = null; if (action.ToLowerInvariant() == "none" && maxWarns > 0) { valid = true; warnAction = new WarnAction { ServerId = server.Id, Action = WarningAction.NoAction, ActionThreshold = maxWarns }; } else if (action.ToLowerInvariant() == "kick" && maxWarns > 0) { valid = true; warnAction = new WarnAction { ServerId = server.Id, Action = WarningAction.Kick, ActionThreshold = maxWarns }; } else if (action.ToLowerInvariant() == "ban" && maxWarns > 0) { valid = true; warnAction = new WarnAction { ServerId = server.Id, Action = WarningAction.Ban, ActionThreshold = maxWarns }; } if (valid) { await _warningRepository.SetWarnAction(warnAction); await _servers.SendLogsAsync(Context.Guild, $"Warn Action Set", message, ImageLookupUtility.GetImageUrl("LOGGING_IMAGES")); await Context.Channel.SendEmbedAsync("Warn Action Set", $"Warn action set to: `{action.ToLowerInvariant()}`. Threshold set to: `{maxWarns}`", ColorHelper.GetColor(server)); } else { await ReplyAsync("Please provide a valid option: `none`, `kick`, `ban` and positive maximum warnings."); } }