public async Task ServerAlert(string link) { var mangaCrawlerService = crawlerService.SiteCrawler; var mangaId = mangaCrawlerService.GetMangaId(); var mangaName = mangaCrawlerService.GetMangaName(); var lastRelease = mangaCrawlerService.GetLastChapter(); var manga = await mangaService.GetOrCreateIfNew(mangaId, lastRelease, mangaName, mangaCrawlerService.MangaSite); await serverAlertService.Create(Context.Guild.Id, manga); await dbContext.SaveChangesAsync(); await ReplyAsync(string.Format(resourceManager.GetString( nameof(ServerAlertModuleResource.ServerAlertSuccess)), manga.Name, manga.LastRelease, mangaCrawlerService.MangaSite.ToString())); }
public async Task UserAlert(string link, params IGuildUser[] users) { if (!users.Any()) { await ReplyAsync(resourceManager.GetString( nameof(UserAlertModuleResource.UserNotFound))); return; } if (!(Context.Message.Author as IGuildUser).Guild.Roles.Any(x => x.Permissions.Administrator) && users.Any(x => x.Id != Context.Message.Author.Id)) { await ReplyAsync(resourceManager.GetString( nameof(UserAlertModuleResource.OnlyAdminAlertSomeoneElse))); return; } var mangaCrawlerService = crawlerService.SiteCrawler; users = users.GroupBy(x => x.Id).Select(x => x.First()).ToArray(); var mangaId = mangaCrawlerService.GetMangaId(); var mangaName = mangaCrawlerService.GetMangaName(); var lastRelease = mangaCrawlerService.GetLastChapter(); var manga = await mangaService.GetOrCreateIfNew(mangaId, lastRelease, mangaName, mangaCrawlerService.MangaSite); await userAlertService.Create( userIds : users.Select(x => x.Id), serverId : Context.Guild.Id, manga : manga); await dbContext.SaveChangesAsync(); await ReplyAsync(string.Format(resourceManager.GetString( nameof(UserAlertModuleResource.UserAlertSuccess)), $"{Consts.BotCommand}{ServerAlertModule.AlertListAllCommand}", manga.Name, string.Join(", ", users.Select(x => x.Nickname ?? x.Username)), manga.LastRelease, mangaCrawlerService.MangaSite.ToString())); }
public async Task PrivateAlert(string link) { var mangaCrawlerService = crawlerService.SiteCrawler; var mangaId = mangaCrawlerService.GetMangaId(); var mangaName = mangaCrawlerService.GetMangaName(); var lastRelease = mangaCrawlerService.GetLastChapter(); var manga = await mangaService.GetOrCreateIfNew(mangaId, lastRelease, mangaName, mangaCrawlerService.MangaSite); await privateAlertService.Create( userId : Context.User.Id, manga : manga); await dbContext.SaveChangesAsync(); var message = string.Format( resourceManager.GetString(nameof(PrivateAlertModuleResource.UserAlertSuccess)), $"{Consts.BotCommand}{AlertListCommand}", mangaName, lastRelease, mangaCrawlerService.MangaSite.ToString()); await ReplyAsync(message); }