diff --git a/Geekbot.net/Lib/LevelCalc.cs b/Geekbot.net/Lib/LevelCalc.cs new file mode 100644 index 0000000..1298319 --- /dev/null +++ b/Geekbot.net/Lib/LevelCalc.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Geekbot.net.Lib +{ + class LevelCalc + { + private static int GetExperienceAtLevel(int level) + { + double total = 0; + for (int i = 1; i < level; i++) + { + total += Math.Floor(i + 300 * Math.Pow(2, i / 7.0)); + } + + return (int)Math.Floor(total / 16); + } + + public static int GetLevelAtExperience(int experience) + { + int index; + + for (index = 0; index < 120; index++) + { + if (GetExperienceAtLevel(index + 1) > experience) + break; + } + + return index; + } + } +} diff --git a/Geekbot.net/Modules/Counters.cs b/Geekbot.net/Modules/Counters.cs index 07317e6..fc3d549 100644 --- a/Geekbot.net/Modules/Counters.cs +++ b/Geekbot.net/Modules/Counters.cs @@ -18,7 +18,6 @@ namespace Geekbot.net.Modules public async Task Good([Summary("The someone")] IUser user) { var lastKarma = GetLastKarma(); - Console.WriteLine(lastKarma.ToString()); if (user.Id == Context.User.Id) { await ReplyAsync($"Sorry {Context.User.Username}, but you can't give yourself karma"); diff --git a/Geekbot.net/Modules/Info.cs b/Geekbot.net/Modules/Info.cs index 3752242..37dfa90 100644 --- a/Geekbot.net/Modules/Info.cs +++ b/Geekbot.net/Modules/Info.cs @@ -3,6 +3,8 @@ using System.Threading.Tasks; using Discord.Commands; using Discord; using Geekbot.net.Lib; +using System.Collections.Generic; +using System.Linq; namespace Geekbot.net.Modules { @@ -14,16 +16,33 @@ namespace Geekbot.net.Modules redis = redisClient; } - [Command("info"), Summary("Show some info about the bot.")] + [Command("serverstats"), Summary("Show some info about the bot.")] public async Task getInfo() { var eb = new EmbedBuilder(); - eb.WithTitle("Geekbot Information"); + eb.WithAuthor(new EmbedAuthorBuilder() + .WithIconUrl(Context.Guild.IconUrl) + .WithName(Context.Guild.Name)); eb.WithColor(new Color(110, 204, 147)); + + var created = Context.Guild.CreatedAt; + var age = Math.Floor((DateTime.Now - created).TotalDays); + + var messages = redis.Client.StringGet($"{Context.Guild.Id}-messages"); + var level = LevelCalc.GetLevelAtExperience((int)messages); + + eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)"); + eb.AddInlineField("Level", level) + .AddInlineField("Messages", messages); - eb.AddInlineField("Version", "3.1") - .AddInlineField("Uptime", "Not Calculated..."); await ReplyAsync("", false, eb.Build()); } + + public static string FirstCharToUpper(string input) + { + if (String.IsNullOrEmpty(input)) + throw new ArgumentException("ARGH!"); + return input.First().ToString().ToUpper() + input.Substring(1); + } } } \ No newline at end of file diff --git a/Geekbot.net/Modules/UserInfo.cs b/Geekbot.net/Modules/UserInfo.cs index c047e2f..55aaba1 100644 --- a/Geekbot.net/Modules/UserInfo.cs +++ b/Geekbot.net/Modules/UserInfo.cs @@ -24,7 +24,7 @@ namespace Geekbot.net.Modules var key = Context.Guild.Id + "-" + userInfo.Id; var messages = (int)redis.Client.StringGet(key + "-messages"); - var level = GetLevelAtExperience(messages); + var level = LevelCalc.GetLevelAtExperience(messages); var eb = new EmbedBuilder(); eb.WithAuthor(new EmbedAuthorBuilder() @@ -45,31 +45,6 @@ namespace Geekbot.net.Modules await ReplyAsync("", false, eb.Build()); } - public async Task GetLevel(string xp) - { - var level = GetLevelAtExperience(int.Parse(xp)); - await ReplyAsync(level.ToString()); - } - - public int GetExperienceAtLevel(int level){ - double total = 0; - for (int i = 1; i < level; i++) - { - total += Math.Floor(i + 300 * Math.Pow(2, i / 7.0)); - } - - return (int) Math.Floor(total / 16); - } - - public int GetLevelAtExperience(int experience) { - int index; - - for (index = 0; index < 120; index++) { - if (GetExperienceAtLevel(index + 1) > experience) - break; - } - - return index; - } + } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Youtube.cs b/Geekbot.net/Modules/Youtube.cs index 621b755..6f3c07f 100644 --- a/Geekbot.net/Modules/Youtube.cs +++ b/Geekbot.net/Modules/Youtube.cs @@ -20,7 +20,6 @@ namespace Geekbot.net.Modules [Command("yt"), Summary("Search for something on youtube.")] public async Task Yt([Remainder, Summary("A Song Title")] string searchQuery) { - // AIzaSyDQoJvtNXPVwIcUbSeeDEchnA4a-q1go0E var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "AIzaSyDQoJvtNXPVwIcUbSeeDEchnA4a-q1go0E", @@ -36,7 +35,7 @@ namespace Geekbot.net.Modules var result = searchListResponse.Items[0]; - await ReplyAsync($"'{result.Snippet.Title}' from '{result.Snippet.ChannelTitle}' https://youtu.be/{result.Id.VideoId}"); + await ReplyAsync($"\"{result.Snippet.Title}\" from \"{result.Snippet.ChannelTitle}\" https://youtu.be/{result.Id.VideoId}"); } } } \ No newline at end of file