diff --git a/Geekbot.net/Modules/Counters.cs b/Geekbot.net/Modules/Counters.cs index 2f3b8b0..07317e6 100644 --- a/Geekbot.net/Modules/Counters.cs +++ b/Geekbot.net/Modules/Counters.cs @@ -17,15 +17,23 @@ namespace Geekbot.net.Modules [Command("good"), Summary("Increase Someones Karma")] 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"); } + else if (lastKarma > GetUnixTimestamp()) + { + await ReplyAsync($"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can give karma again..."); + } else { var key = Context.Guild.Id + "-" + user.Id + "-karma"; var badJokes = (int)redis.Client.StringGet(key); redis.Client.StringSet(key, (badJokes + 1).ToString()); + var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout"; + redis.Client.StringSet(lastKey, GetNewLastKarma()); await ReplyAsync($"{Context.User.Username} gave {user.Mention} karma"); } } @@ -33,17 +41,54 @@ namespace Geekbot.net.Modules [Command("bad"), Summary("Decrease Someones Karma")] public async Task Bad([Summary("The someone")] IUser user) { + var lastKarma = GetLastKarma(); if (user.Id == Context.User.Id) { await ReplyAsync($"Sorry {Context.User.Username}, but you can't lower your own karma"); } + else if (lastKarma > GetUnixTimestamp()) + { + await ReplyAsync($"Sorry {Context.User.Username}, but you have to wait {GetTimeLeft(lastKarma)} before you can take karma again..."); + } else { var key = Context.Guild.Id + "-" + user.Id + "-karma"; var badJokes = (int)redis.Client.StringGet(key); redis.Client.StringSet(key, (badJokes - 1).ToString()); + var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout"; + redis.Client.StringSet(lastKey, GetNewLastKarma()); await ReplyAsync($"{Context.User.Username} lowered {user.Mention}'s karma"); } } + + private int GetLastKarma() + { + var lastKey = Context.Guild.Id + "-" + Context.User.Id + "-karma-timeout"; + var redisReturn = redis.Client.StringGet(lastKey); + if (!int.TryParse(redisReturn.ToString(), out var i)) + { + i = GetUnixTimestamp(); + } + return i; + } + + private int GetNewLastKarma() + { + var timeout = TimeSpan.FromMinutes(3); + return (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).Add(timeout)).TotalSeconds; + } + + private int GetUnixTimestamp() + { + return (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; + } + + private string GetTimeLeft(int time) + { + DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,DateTimeKind.Utc); + dtDateTime = dtDateTime.AddSeconds( time ).ToLocalTime(); + var dt = dtDateTime.Subtract(DateTime.Now); + return $"{dt.Minutes} Minutes and {dt.Seconds} Seconds"; + } } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Ping.cs b/Geekbot.net/Modules/Ping.cs index 139a97e..6b80c63 100644 --- a/Geekbot.net/Modules/Ping.cs +++ b/Geekbot.net/Modules/Ping.cs @@ -1,15 +1,15 @@ using System.Threading.Tasks; +using Discord; using Discord.Commands; namespace Geekbot.net.Modules { public class Ping : ModuleBase { - [Command("ping"), Summary("Pong.")] - public async Task Say() + [Command("👀"), Summary("Look at the bot.")] + public async Task Eyes() { - await Task.Delay(5000); - await ReplyAsync("Pong"); + await ReplyAsync("S... Stop looking at me... baka!"); } } } \ No newline at end of file diff --git a/Geekbot.net/Modules/UserInfo.cs b/Geekbot.net/Modules/UserInfo.cs index c207510..a120436 100644 --- a/Geekbot.net/Modules/UserInfo.cs +++ b/Geekbot.net/Modules/UserInfo.cs @@ -32,8 +32,8 @@ namespace Geekbot.net.Modules .WithName(userInfo.Username)); eb.AddField("Discordian Since", $"{userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)"); - eb.AddField("Level", level); - eb.AddField("Messages Sent", messages); + eb.AddInlineField("Level", level) + .AddInlineField("Messages Sent", messages); var karma = redis.Client.StringGet(key + "-karma"); if (!karma.IsNullOrEmpty) diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index d5b4b03..6e0bb94 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -60,8 +60,16 @@ namespace Geekbot.net await InstallCommands(); Console.WriteLine("Connecting to Discord..."); - await client.LoginAsync(TokenType.Bot, token); - await client.StartAsync(); + try + { + await client.LoginAsync(TokenType.Bot, token); + await client.StartAsync(); + } + catch (AggregateException) + { + Console.WriteLine("Could not connect to discord..."); + Environment.Exit(1); + } Console.WriteLine("Done and ready for use...\n"); await Task.Delay(-1);