public async Task Subscriptions() { using (SubDBContext DBContext = DBFactory.Create <SubDBContext>()) { SimpleStopWatch watch = new SimpleStopWatch(); string channelId = Context.Channel.Id.ToString(); var cnnSub = DBContext.CNNSubscribers.FromSql("SELECT * FROM CNNSubscribers WHERE Id = {0} LIMIT 1", channelId).AsNoTracking().FirstOrDefault(); var redditSubs = DBContext.RedditSubscribers.FromSql("SELECT * FROM RedditSubscribers WHERE Id = {0}", channelId).AsNoTracking().ToList(); EmbedBuilder embedBuilder = new EmbedBuilder(); EmbedService.BuildFeedbackEmbed(embedBuilder); embedBuilder.Title = $"Subscriptions for {Context.Channel.Name.UpperFirstChar()}"; embedBuilder.Description = "\n\n"; embedBuilder.Description += $":newspaper: CNN Subscription Status: {(cnnSub == null ? "Not subscribed." : "Currently subscribed.").Bold()}\n\n"; embedBuilder.Description += ":monkey_face: Reddit Subscriptions: "; if (redditSubs == null || redditSubs.Count == 0) { embedBuilder.Description += "Not subscribed to any subreddits.".Bold(); } else { foreach (RedditSubscriber sub in redditSubs) { embedBuilder.Description += $"{sub.Subreddit.Bold()}, "; } embedBuilder.Description = embedBuilder.Description.Substring(0, embedBuilder.Description.Length - 2); } TimeSpan timeTook = watch.Stop(); embedBuilder.WithFooter(footer => { footer.Text = $"⏰ {"Generated in:"} {Math.Round(timeTook.TotalMilliseconds)}ms"; }); await ReplyAsync("", embed : embedBuilder.Build()); } }
public Service(DiscordSocketClient client, IServiceProvider provider = null) { SimpleStopWatch watch = new SimpleStopWatch(); try { if (provider != null) { this.Provider = provider; } this.DiscordClient = client; Run(); Task.Run(async() => { await RunAsync(); TimeSpan timePassed = watch.Stop(); ConsoleEx.WriteColoredLine(Discord.LogSeverity.Verbose, ConsoleTextFormat.TimeAndText, "Finished loading module ", ConsoleColor.Blue, this.GetType().Name, $" in $[[White]]${timePassed.Milliseconds}$[[Gray]]$ms!"); }); } catch (Exception ex) { ConsoleEx.WriteColoredLine(Discord.LogSeverity.Critical, ConsoleTextFormat.TimeAndText, "Something has gone terribly wrong! Exception below:\n", ConsoleColor.Red, ex.Message, ConsoleColor.Gray); } }
public void BasicStopWatchTest() { SimpleStopWatch sdt = new SimpleStopWatch(); Assert.IsNotNull(sdt); System.Threading.Thread.Sleep(50); long elapsedMs = sdt.Stop(); Assert.Greater(elapsedMs, 48); }
public async Task TopGameTime([Summary("The specified game.")][Remainder] string name) { try { DateTime startTime = DateTime.Now; EmbedBuilder embedBuilder = new EmbedBuilder() { Title = $"{name} Leaderboard" }; EmbedService.BuildSuccessEmbed(embedBuilder); embedBuilder.Description = ""; ImageSearchResult result = await ImageService.SearchImage($"{name} icon", 1); embedBuilder.ThumbnailUrl = result.Url; using (BotDBContext DBContext = DBFactory.Create <BotDBContext>()) { SimpleStopWatch watch = new SimpleStopWatch(); List <DiscordGameTime> playerGameTime = DBContext.GameTime.FromSql("SELECT * FROM GameTime WHERE Name = {0} ORDER BY Minutes DESC LIMIT 5", name).AsNoTracking().ToList(); if (playerGameTime.Count == 0) { await ReplyAsync("", embed : EmbedService.MakeFailFeedbackEmbed($"No Gametime found for the game [{name.Bold()}].")); return; } for (int i = 0; i < Math.Min(5, playerGameTime.Count()); i++) { var gameTime = playerGameTime.ElementAt(i); DiscordUser user = DBContext.Users.FromSql("SELECT * FROM Users WHERE Id = {0} LIMIT 1", gameTime.Id.ToString()).AsNoTracking().ToList().SingleOrDefault(); if (user == null) { continue; } string text = StandardExtensions.GetAgeText(DateTime.Now.AddMinutes(-gameTime.Minutes)); embedBuilder.AddField(x => { x.Name = "#" + (i + 1) + " " + user.Username; x.Value = new TimeSpan(0, (int)gameTime.Minutes, 0).ToNiceTime(); }); } var totalGameTime = DBContext.GameTime.FromSql("SELECT * FROM GameTime WHERE Name = {0}", name).AsNoTracking().Sum(x => x.Minutes); TimeSpan totalMinutes = new TimeSpan(0, (int)totalGameTime, 0); //string txt = StandardExtensions.GetAgeText(DateTime.Now.AddMinutes(-totalMinutes)); //TimeSpan time = new TimeSpan(0, totalMinutes, 0); embedBuilder.WithFooter(footer => { footer.Text = $"⏰ {"Generated in:"} {watch.Stop().TotalMilliseconds}ms"; }); embedBuilder.Description = $"{"Total Gametime:".Code()} {totalMinutes.ToNiceTime().ToString()} \n"; } await ReplyAsync("", embed : embedBuilder); } catch (Exception ex) { Console.WriteLine(ex.Message); } }