protected override async Task OneTimeSetup() { _userQueryBuilder = new PgUserQueryBuilder(EFContext); var identityUserId = Guid.NewGuid(); _userIdentity = new UserIdentity { Id = identityUserId }; EFContext.CostUser.Add(new CostUser { Id = identityUserId }); await EFContext.SaveChangesAsync(); _userSearchService = new UserSearchService( ElasticClient, new[] { new Lazy <IUserQueryBuilder, PluginMetadata>( () => _userQueryBuilder, new PluginMetadata { BuType = BuType.Pg } ) }, AppSettingsOptionsMock.Object, EFContext ); }
public async Task LogMessageEditedAsync(Cacheable <IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel, SocketGuild guild) { var oldMessage = before.HasValue ? before.Value : MessageCache.Get(before.Id); if (!IsMessageEdited(oldMessage, after)) { return; } var userId = await UserSearchService.GetUserIDFromDiscordUserAsync(guild, after.Author); var entity = new AuditLogItem() { Type = AuditLogType.MessageEdited, CreatedAt = DateTime.Now, GuildIdSnowflake = guild.Id, UserId = userId }; entity.SetData(MessageEditedAuditData.Create(channel, oldMessage, after)); await GrillBotRepository.AddAsync(entity); await GrillBotRepository.CommitAsync(); MessageCache.Update(after); }
public async Task <List <InviteModel> > GetStoredInvitesAsync(InvitesListFilter filter) { var guild = Discord.GetGuild(filter.GuildID); var usersFromQuery = await UserSearchService.FindUsersAsync(guild, filter.UserQuery); var userIds = (await UserSearchService.ConvertUsersToIDsAsync(usersFromQuery)) .Select(o => o.Value).Where(o => o != null).Select(o => o.Value).ToList(); var invites = await GrillBotRepository.InviteRepository.GetInvitesQuery(filter.GuildID, filter.CreatedFrom, filter.CreatedTo, userIds, filter.Desc).ToListAsync(); var result = new List <InviteModel>(); foreach (var invite in invites) { if (invite.Creator == null) { result.Add(new InviteModel(invite, null, invite.UsedUsers.Count)); continue; } var creator = await guild.GetUserFromGuildAsync(invite.Creator.UserIDSnowflake); result.Add(new InviteModel(invite, creator, invite.UsedUsers.Count)); } return(result); }
private async Task ProcessMessageDeletedWithCacheAsync(AuditLogItem entity, ISocketMessageChannel channel, IMessage message, SocketGuild guild) { entity.SetData(MessageDeletedAuditData.Create(channel, message)); var auditLog = (await guild.GetAuditLogDataAsync(actionType: ActionType.MessageDeleted)).Find(o => { var data = (MessageDeleteAuditLogData)o.Data; return(data.Target.Id == message.Author.Id && data.ChannelId == channel.Id); }); entity.UserId = await UserSearchService.GetUserIDFromDiscordUserAsync(guild, auditLog?.User ?? message.Author); if (message.Attachments.Count > 0) { foreach (var attachment in message.Attachments.Where(o => o.Size < 10 * 1024 * 1024)) // Max 10MB { var fileContent = await attachment.DownloadFileAsync(); if (fileContent == null) { continue; } entity.Files.Add(new Database.Entity.File() { Content = fileContent, Filename = $"{Path.GetFileNameWithoutExtension(attachment.Filename)}_{attachment.Id}{Path.GetExtension(attachment.Filename)}" }); } } }
private async Task <AuditLogQueryFilter> CreateQueryFilterAsync(LogsFilter filter, SocketGuild guild) { var users = await UserSearchService.FindUsersAsync(guild, filter.UserQuery); var userIds = users != null ? (await UserSearchService.ConvertUsersToIDsAsync(users)).Select(o => o.Value).Where(o => o != null).Select(o => (long)o) : null; var botAccounts = filter.IgnoreBots ? await guild.GetBotsAsync() : new List <SocketGuildUser>(); var botAccountIds = (await UserSearchService.ConvertUsersToIDsAsync(botAccounts)).Select(o => o.Value).Where(o => o != null).Select(o => (long)o); if (filter.Page < 0) { filter.Page = 0; } var types = filter.GetSelectedTypes(); return(new AuditLogQueryFilter() { From = filter.From, GuildId = filter.GuildId.ToString(), Skip = (filter.Page == 0 ? 0 : filter.Page - 1) * PaginationInfo.DefaultPageSize, SortDesc = filter.SortDesc, Take = PaginationInfo.DefaultPageSize, To = filter.To, Types = types.ToArray(), UserIds = userIds?.ToList(), IgnoredIds = botAccountIds.ToList() }); }
public UserService(IGrillBotRepository grillBotRepository, DiscordSocketClient client, BotState botState, UserSearchService userSearchService) { GrillBotRepository = grillBotRepository; DiscordClient = client; BotState = botState; UserSearchService = userSearchService; }
public ActionResult Search(SearchForm SearchForm) { // 検索実施 UserSearchService service = new UserSearchService(); SearchForm.UserDtoList = service.SearchUser(SearchForm); return(View("Search", SearchForm)); }
public HomePage() { _userService = new UserService(); _userSearchService = new UserSearchService(_userService); InitializeComponent(); _searchResult = new UserSearchResult(); }
private async Task <IQueryable <Invite> > GetInvitesQueryAsync(InvitesListFilter filter) { var guild = Discord.GetGuild(filter.GuildID); var usersFromQuery = await UserSearchService.FindUsersAsync(guild, filter.UserQuery); var userIds = usersFromQuery != null ? (await UserSearchService.ConvertUsersToIDsAsync(usersFromQuery)).Select(o => o.Value).Where(o => o != null).Select(o => o.Value).ToList() : null; return(GrillBotRepository.InviteRepository.GetInvitesQuery(filter.GuildID, filter.CreatedFrom, filter.CreatedTo, userIds, filter.Desc)); }
public ReminderService(DiscordSocketClient discord, IMessageCache messageCache, ILogger <ReminderService> logger, UserSearchService searchService, IGrillBotRepository grillBotRepository, BackgroundTaskQueue queue) { Discord = discord; MessageCache = messageCache; Logger = logger; UserSearchService = searchService; GrillBotRepository = grillBotRepository; Queue = queue; }
public InviteTrackerService(DiscordSocketClient discord, BotState botState, ILogger <InviteTrackerService> logger, ConfigurationService configurationService, UserSearchService userSearchService, IGrillBotRepository grillBotRepository) { Discord = discord; BotState = botState; Logger = logger; ConfigurationService = configurationService; UserSearchService = userSearchService; GrillBotRepository = grillBotRepository; }
public AuditService(IGrillBotRepository grillBotRepository, UserSearchService userSearchService, DiscordSocketClient client, BotState botState, IMessageCache messageCache, ConfigurationService configurationService) { GrillBotRepository = grillBotRepository; UserSearchService = userSearchService; Client = client; BotState = botState; MessageCache = messageCache; ConfigurationService = configurationService; }
public async Task <List <ReminderEntity> > GetRemindersAsync(IGuild guild, IUser user) { var userId = await UserSearchService.GetUserIDFromDiscordUserAsync(guild, user); if (userId == null) { throw new NotFoundException("Žádná data pro tohoto uživatele nebyly nalezeny."); } return(await GrillBotRepository.ReminderRepository.GetReminders(userId).ToListAsync()); }
private async Task ValidateIfNotUnverifiedAsync(SocketGuild guild, SocketGuildUser user) { var userID = await UserSearchService.GetUserIDFromDiscordUserAsync(guild, user); var haveUnverify = await GrillBotRepository.UnverifyRepository.HaveUnverifyAsync(userID.Value); if (haveUnverify) { throw new ValidationException($"Nelze provést odebrání přístupu, protože uživatel **{user.GetFullName()}** již má odebraný přístup."); } }
private async Task <long> GetOrCreateUserId(SocketGuild guild, IUser user) { var userId = await UserSearchService.GetUserIDFromDiscordUserAsync(guild, user); if (userId != null) { return(userId.Value); } var entity = await GrillBotRepository.UsersRepository.CreateAndGetUserAsync(guild.Id, user.Id); return(entity.ID); }
public ActionResult Delete(string DeleteUserId, SearchForm SearchForm) { UserSearchService SearchService = new UserSearchService(); UserDto UserInfoDto = SearchService.SearchUserWithPrimaryKeyUserId(DeleteUserId); if (UserInfoDto == null) { // 削除対象のユーザ情報がない場合、検索画面を再表示 return(View("Search", SearchForm)); } UserDeleteService DeleteService = new UserDeleteService(); DeleteService.DeleteUserWithPrimaryKeyUserId(DeleteUserId); return(View("DeleteComplete")); }
public ActionResult Edit(string EditUserId, SearchForm SearchForm) { UserSearchService service = new UserSearchService(); UserDto UserInfoDto = service.SearchUserWithPrimaryKeyUserId(EditUserId); if (UserInfoDto == null) { // 編集対象のユーザ情報がない場合、検索画面を再表示 return(View("Search", SearchForm)); } EditForm EditForm = new EditForm(); EditForm.UserId = UserInfoDto.UserId; EditForm.UserName = UserInfoDto.UserName; EditForm.UserGender = UserInfoDto.UserGender; return(View(EditForm)); }
public async Task LogUserLeftAsync(SocketGuildUser user) { if (user == null) { return; } var ban = await user.Guild.FindBanAsync(user); RestAuditLogEntry dcAuditLogItem; if (ban != null) { dcAuditLogItem = (await user.Guild.GetAuditLogDataAsync(actionType: ActionType.Ban))? .FirstOrDefault(o => (o.Data as BanAuditLogData)?.Target.Id == user.Id); } else { dcAuditLogItem = (await user.Guild.GetAuditLogDataAsync(actionType: ActionType.Kick))? .FirstOrDefault(o => (o.Data as KickAuditLogData)?.Target.Id == user.Id); } long?executor = null; if (dcAuditLogItem != null) { executor = await UserSearchService.GetUserIDFromDiscordUserAsync(user.Guild, dcAuditLogItem.User); } var entity = new AuditLogItem() { Type = AuditLogType.UserLeft, CreatedAt = DateTime.Now, GuildIdSnowflake = user.Guild.Id, UserId = executor }; entity.SetData(UserLeftAuditData.Create(user.Guild, user, ban != null, ban?.Reason)); await GrillBotRepository.AddAsync(entity); await GrillBotRepository.CommitAsync(); }
public async Task LogCommandAsync(Optional <CommandInfo> command, ICommandContext context) { if (context.Guild == null || !command.IsSpecified) { return; } var userId = await UserSearchService.GetUserIDFromDiscordUserAsync(context.Guild, context.User); var entity = new AuditLogItem() { Type = AuditLogType.Command, CreatedAt = DateTime.Now, GuildIdSnowflake = context.Guild.Id, UserId = userId }; entity.SetData(CommandAuditData.CreateDbItem(context, command.Value)); await GrillBotRepository.AddAsync(entity); await GrillBotRepository.CommitAsync(); }
public UserSearchController() { // todo インスタンス管理 this.workerService = new UserSearchService(this.com); this.systemDatetimeService = new SystemDatetimeService(); }
public SearchRepository() { TaskSearch = new TaskSearchService(); UserSearch = new UserSearchService(); }
public UnverifyChecker(UserSearchService searchService, IGrillBotRepository grillBotRepository) { UserSearchService = searchService; GrillBotRepository = grillBotRepository; }
public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName) { IController controller = null; if (string.Compare(controllerName, EnumControllerName.Account.ToString(), true) == 0) { IBaseAsyncService <IHireThingsUser> service = new UserService(); controller = new AccountController((IUserService)service); } else if (string.Compare(controllerName, EnumControllerName.Error.ToString(), true) == 0) { IBaseAsyncService <IErrorViewModel> service = new ErrorService(); controller = new ErrorController((IErrorService)service); } else if (string.Compare(controllerName, EnumControllerName.Country.ToString(), true) == 0) { IBaseAsyncService <ICountryModel> service = new CountryService(); controller = new CountryController((ICountryService)service); } else if (string.Compare(controllerName, EnumControllerName.CountrySearch.ToString(), true) == 0) { IBaseAsyncService <ICountrySearchViewModel> service = new CountrySearchService(); controller = new CountrySearchController((ICountrySearchService)service); } else if (string.Compare(controllerName, EnumControllerName.LocationSearch.ToString(), true) == 0) { IBaseAsyncService <ILocationSearchViewModel> service = new LocationSearchService(); controller = new LocationSearchController((ILocationSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.Location.ToString(), true) == 0) { IBaseAsyncService <ILocationModel> service = new LocationService(); controller = new LocationController((ILocationService)service); } else if (string.Compare(controllerName, EnumControllerName.Theme.ToString(), true) == 0) { IBaseAsyncService <IThemeModel> service = new ThemeService(); controller = new ThemeController((IThemeService)service); } else if (string.Compare(controllerName, EnumControllerName.ThemeSearch.ToString(), true) == 0) { IBaseAsyncService <IThemeSearchViewModel> service = new ThemeSearchService(); controller = new ThemeSearchController((IThemeSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.Category.ToString(), true) == 0) { IBaseAsyncService <ICategoryModel> service = new CategoryService(); controller = new CategoryController((ICategoryService)service); } else if (string.Compare(controllerName, EnumControllerName.CategorySearch.ToString(), true) == 0) { IBaseAsyncService <ICategorySearchViewModel> service = new CategorySearchService(); controller = new CategorySearchController((ICategorySearchService)service); } else if (string.Compare(controllerName, EnumControllerName.EmailServerSearch.ToString(), true) == 0) { IBaseAsyncService <IEmailServerSearchViewModel> service = new EmailServerSearchService(); controller = new EmailServerSearchController((IEmailServerSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.EmailServer.ToString(), true) == 0) { IBaseAsyncService <IEmailServerModel> service = new EmailServerService(); controller = new EmailServerController((IEmailServerService)service); } else if (string.Compare(controllerName, EnumControllerName.UserSearch.ToString(), true) == 0) { IBaseAsyncService <IUserSearchViewModel> service = new UserSearchService(); controller = new UserSearchController((IUserSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.User.ToString(), true) == 0) { IBaseAsyncService <IHireThingsUser> service = new UserService(); controller = new UserController((IUserService)service); } else if (string.Compare(controllerName, EnumControllerName.SecurityQuestion.ToString(), true) == 0) { IBaseAsyncService <ISecurityQuestionModel> service = new SecurityQuestionService(); controller = new SecurityQuestionController((ISecurityQuestionService)service); } else if (string.Compare(controllerName, EnumControllerName.SecurityInfo.ToString(), true) == 0) { IBaseAsyncService <ISecurityInfoViewModel> service = new SecurityInfoService(); controller = new SecurityInfoController((ISecurityInfoService)service); } else if (string.Compare(controllerName, EnumControllerName.RoleSearch.ToString(), true) == 0) { IBaseAsyncService <IRoleSearchViewModel> service = new RoleSearchService(); controller = new RoleSearchController((IRoleSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.Role.ToString(), true) == 0) { IBaseAsyncService <IRoleModel> service = new RoleService(); controller = new RoleController((IRoleService)service); } else if (string.Compare(controllerName, EnumControllerName.ObjectSearch.ToString(), true) == 0) { IBaseAsyncService <IObjectSearchViewModel> service = new ObjectSearchService(); controller = new ObjectSearchController((IObjectSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.Object.ToString(), true) == 0) { IBaseAsyncService <IObjectModel> service = new ObjectService(); controller = new ObjectController((IObjectService)service); } else if (string.Compare(controllerName, EnumControllerName.Dropdown.ToString(), true) == 0) { IBaseAsyncService <IDropdownModel> service = new DropdownService(); controller = new DropdownController((IDropdownService)service); } else if (string.Compare(controllerName, EnumControllerName.RoleObject.ToString(), true) == 0) { IBaseAsyncService <IRoleObjectViewModel> service = new RoleObjectService(); controller = new RoleObjectController((IRoleObjectService)service); } else if (string.Compare(controllerName, EnumControllerName.Home.ToString(), true) == 0) { IBaseAsyncService <IHomeModel> service = new HomeService(); controller = new HomeController((HomeService)service); } else if (string.Compare(controllerName, EnumControllerName.ItemDelete.ToString(), true) == 0) { IBaseAsyncService <IItemDeleteModel> service = new ItemDeleteService(); controller = new ItemDeleteController((ItemDeleteService)service); } else if (string.Compare(controllerName, EnumControllerName.WebApiRoleSearch.ToString(), true) == 0) { IBaseAsyncService <IWebApiRoleSearchViewModel> service = new WebApiRoleSearchService(); controller = new WebApiRoleSearchController((IWebApiRoleSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.WebApiRole.ToString(), true) == 0) { IBaseAsyncService <IWebApiRoleModel> service = new WebApiRoleService(); controller = new WebApiRoleController((IWebApiRoleService)service); } else if (string.Compare(controllerName, EnumControllerName.WebApiObjectSearch.ToString(), true) == 0) { IBaseAsyncService <IWebApiObjectSearchViewModel> service = new WebApiObjectSearchService(); controller = new WebApiObjectSearchController((IWebApiObjectSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.WebApiObject.ToString(), true) == 0) { IBaseAsyncService <IWebApiObjectModel> service = new WebApiObjectService(); controller = new WebApiObjectController((IWebApiObjectService)service); } else if (string.Compare(controllerName, EnumControllerName.WebApiUserSearch.ToString(), true) == 0) { IBaseAsyncService <IWebApiUserSearchViewModel> service = new WebApiUserSearchService(); controller = new WebApiUserSearchController((IWebApiUserSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.WebApiUser.ToString(), true) == 0) { IBaseAsyncService <IWebApiUser> service = new WebApiUserService(); controller = new WebApiUserController((IWebApiUserService)service); } else if (string.Compare(controllerName, EnumControllerName.WebAPIRoleObject.ToString(), true) == 0) { IBaseAsyncService <IWebAPIRoleObjectViewModel> service = new WebAPIRoleObjectService(); controller = new WebAPIRoleObjectController((IWebAPIRoleObjectService)service); } else if (string.Compare(controllerName, EnumControllerName.Main.ToString(), true) == 0) { IBaseAsyncService <IMainModel> service = new MainService(); controller = new MainController((MainService)service); } else if (string.Compare(controllerName, EnumControllerName.Advertisement.ToString(), true) == 0) { IBaseAsyncService <IAdvertisementModel> service = new AdvertisementService(); controller = new AdvertisementController((AdvertisementService)service); } else if (string.Compare(controllerName, EnumControllerName.PublicAdvertisement.ToString(), true) == 0) { IBaseAsyncService <IAdvertisementModel> service = new AdvertisementService(); controller = new PublicAdvertisementController((AdvertisementService)service); } else if (string.Compare(controllerName, EnumControllerName.PublicAdvertisementSearch.ToString(), true) == 0) { IBaseAsyncService <IAdvertisementSearchViewModel> service = new AdvertisementSearchService(); controller = new PublicAdvertisementSearchController((AdvertisementSearchService)service); } else if (string.Compare(controllerName, EnumControllerName.PublicAccount.ToString(), true) == 0) { IBaseAsyncService <IHireThingsUser> service = new UserService(); controller = new PublicAccountController((UserService)service); } else { throw new HttpException(404, "Page not Found"); } return(controller); }
public UnverifyModelConverter(DiscordSocketClient discord, UserSearchService userSearchService) { DiscordClient = discord; UserSearch = userSearchService; }
public EmoteStats(IGrillBotRepository grillBotRepository, UserSearchService userSearchService) { GrillBotRepository = grillBotRepository; UserSearchService = userSearchService; }