示例#1
0
        public async Task DontTrustThisRole(string roleName, Contexts contexts)
        {
            var query           = new GetServerTrustedRolesQuery(contexts.Server.Id);
            var trustedRolesIds = this._queryBus.Execute(query).TrustedRolesIds;
            var role            = this._usersRolesService.GetRoleByName(roleName, contexts.Server);
            var messagesService = this._messagesServiceFactory.Create(contexts);

            if (role == null)
            {
                throw new RoleNotFoundException(roleName);
            }
            if (!trustedRolesIds.Contains(role.Id))
            {
                await messagesService.SendResponse(x => x.RoleAlreadyIsUntrusted(roleName));

                return;
            }
            var command = new SetRoleAsUntrustedCommand(role.Id, contexts.Server.Id);

            await this._commandBus.ExecuteAsync(command);

            await messagesService.SendResponse(x => x.RoleSetAsUntrusted(roleName));

            await this._checkUserSafetyService.Refresh();
        }
示例#2
0
        private async Task UpdateSafetyUsersStates(IEnumerable <Message> messages)
        {
            var serversWhereBotIs = await this._discordServersService.GetDiscordServersAsync().Select(x => x.Id).ToHashSetAsync();

            var servers = messages.GroupBy(x => x.Server.Id).Where(x => serversWhereBotIs.Contains(x.Key));

            this._safeUsersOnServers = servers
                                       .ToDictionary(x => x.Key, x =>
            {
                var minAverageMessagesPerWeek = this._configurationService.GetConfigurationItem <MinAverageMessagesPerWeek>(x.Key).Value;
                var minAbsoluteMessagesCount  = this._configurationService.GetConfigurationItem <MinAbsoluteMessagesCountToConsiderSafeUser>(x.Key).Value;
                var query           = new GetServerTrustedRolesQuery(x.Key);
                var trustedRolesIds = this._queryBus.Execute(query).TrustedRolesIds;
                return(new ServerSafeUsers(x, x.Key, minAverageMessagesPerWeek, minAbsoluteMessagesCount, trustedRolesIds.ToHashSet(), this._usersService, this._discordServersService));
            });
        }
示例#3
0
        public async Task GetTrustedRoles(TrustedRolesCommand trustedRolesCommand, Contexts contexts)
        {
            var query           = new GetServerTrustedRolesQuery(contexts.Server.Id);
            var trustedRoles    = this._queryBus.Execute(query).TrustedRolesIds.ToList();
            var messagesService = this._messagesServiceFactory.Create(contexts);

            if (!trustedRoles.Any())
            {
                await messagesService.SendResponse(x => x.ServerDoesntHaveAnyTrustedRole());

                return;
            }
            var trustedRolesNames = trustedRoles.Select(x => this._usersRolesService.GetRole(x, contexts.Server.Id));
            await messagesService.SendEmbedMessage(
                "Zaufane role",
                $"Lista zaufanych roli na serwerze {contexts.Server.Name}",
                trustedRolesNames.Select(x => new KeyValuePair <string, string>("Nazwa roli:", x.Name)));
        }