protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); NinjectModule studentModule = new StudentModule(); NinjectModule postModule = new PostModule(); NinjectModule serviceModule = new ServiceModule(); NinjectModule tagModule = new TagModule(); NinjectModule commentModule = new CommentModule(); NinjectModule autoMapper = new AutoMapperModule(); var kernel = new StandardKernel(studentModule, postModule, serviceModule, tagModule, commentModule, autoMapper); DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel)); }
public void Create(ArticleDTO article) { //<Tag> tags = TagModule.ReturnTags(article.Tags); string[] newTags = TagModule.ReturnTags(article.Tags); List <Tag> tags = new List <Tag>(); if (newTags != null) { foreach (var t in newTags) { var tagFromDB = Database.Tags.GetAll().FirstOrDefault(tag => tag.Name == t); if (tagFromDB != null) { tags.Add(tagFromDB); } else { Tag newTag = new Tag { Name = t }; tags.Add(newTag); } } } else { tags = null; } Article art = new Article { Title = article.Title, ArticleText = article.ArticleText, CreationDate = DateTime.Now, BlogId = article.BlogId, Tags = tags }; Database.Articles.Create(art); Database.Save(); }
private async Task ReactionAdded(Cacheable <IUserMessage, ulong> cacheable, ISocketMessageChannel channelParam, SocketReaction reaction) { // remove user reaction if rate limited if (reaction.User.IsSpecified && IsRateLimited(reaction.UserId)) { var msg = await cacheable.DownloadAsync(); await msg.RemoveReactionAsync(reaction.Emote, reaction.User.Value, new RequestOptions { AuditLogReason = $"User is rate limited until {RateLimitedUsers[reaction.User.Value.Id].ToString()}" }); } // vote deletion here else if (channelParam is SocketTextChannel channel) { GuildConfig config; if ((config = ConfigManager.GetManagedConfig(channel.Guild.Id)) == null) { return; } if (reaction.Emote.Name == "⛔") { var msg = await cacheable.DownloadAsync(); if (config.IsVoteDeleteImmune(msg.Author.Id) || msg.Author is SocketGuildUser gu && gu.Roles.Any(x => config.IsVoteDeleteImmune(x.Id))) { return; } // get the emote, count the total reactions, and get those users var emote = msg.Reactions.FirstOrDefault(x => x.Key.Name.Equals("⛔")); var count = emote.Value.ReactionCount; var users = (await msg.GetReactionUsersAsync(emote.Key, limit: count)) .Select(x => channel.Guild.GetUser(x.Id)) .Where(x => x != null) .Cast <IGuildUser>(); // if we match the requirements for vote removal, proceed if (config.MatchesVoteDeleteRequirements(users.ToArray())) { await msg.DeleteAsync(new RequestOptions { AuditLogReason = "Message was voted to be deleted." }); } } else { // tag list controlling by emoji var msg = await cacheable.DownloadAsync(); var cachedTagList = config.TagListCache.FirstOrDefault(x => x.message.Id == msg.Id); // valid reactor if (cachedTagList != null && cachedTagList.originalMessage.Author.Id == reaction.UserId && reaction.UserId != _client.CurrentUser.Id) { // print a selected tag 0..9 if (TagModule._tagsNumberStrings.Values.Contains(reaction.Emote.Name)) { var tags = cachedTagList.containedTags; int index = TagModule._tagsNumberStrings.Select(x => x.Value).ToList().IndexOf(reaction.Emote.Name); KeyValTag theTag = tags[index + 10 * (cachedTagList.currentPage - 1)]; await channel.SendMessageAsync(TagModule.WriteTag(theTag, channel.Guild.GetUser(theTag.OwnerId).FullName())); await msg.DeleteAsync(); await cachedTagList.originalMessage.DeleteAsync(); config.TagListCache.Remove(cachedTagList); } // paginate else if (reaction.Emote.Name.Equals("\u25c0") || reaction.Emote.Name.Equals("\u25b6")) { var tags = cachedTagList.containedTags.AsEnumerable(); int totalPages = (int)Math.Ceiling((float)tags.Count() / 10f); int page; bool flag; if (reaction.Emote.Name.Equals("\u25c0")) { page = cachedTagList.currentPage - 1; flag = page >= 1; } else { page = cachedTagList.currentPage + 1; flag = page <= totalPages; } if (flag) { TagModule.Paginate(tags.Count(), ref page, ref tags, ref totalPages); var sb = new StringBuilder(); TagModule.AppendTags(sb, tags, page, totalPages, channel.Guild); await msg.ModifyAsync(x => x.Content = sb.ToString()); cachedTagList.currentPage = page; cachedTagList.RefreshExpiry(); } } } } } }