From 735a4a81d4264f32858d06b3b808a8be6013c601 Mon Sep 17 00:00:00 2001 From: Runebaas Date: Mon, 17 Apr 2017 23:58:43 +0200 Subject: [PATCH] Embeds, Cleanup and Improvements to Roll, Userinfo the init process --- Geekbot.net/Lib/RedisClient.cs | 4 ---- Geekbot.net/Modules/Info.cs | 21 +++++++++++++++++++ Geekbot.net/Modules/Roll.cs | 17 +++++++++++++-- Geekbot.net/Modules/UserInfo.cs | 37 +++++++++++++-------------------- Geekbot.net/Program.cs | 19 +++++++++++++---- 5 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 Geekbot.net/Modules/Info.cs diff --git a/Geekbot.net/Lib/RedisClient.cs b/Geekbot.net/Lib/RedisClient.cs index 15ae88c..f0f051a 100644 --- a/Geekbot.net/Lib/RedisClient.cs +++ b/Geekbot.net/Lib/RedisClient.cs @@ -18,10 +18,6 @@ namespace Geekbot.net.Lib // { // get // { -// if (_instance.IsValueCreated) -// { -// return _instance.Value; -// } // lock (ThreadLock) // { // if (Client == null) diff --git a/Geekbot.net/Modules/Info.cs b/Geekbot.net/Modules/Info.cs new file mode 100644 index 0000000..0b89cbc --- /dev/null +++ b/Geekbot.net/Modules/Info.cs @@ -0,0 +1,21 @@ +using System; +using System.Threading.Tasks; +using Discord.Commands; +using Discord; + +namespace Geekbot.net.Modules +{ + public class Info : ModuleBase + { + [Command("info"), Summary("Show some info about the bot.")] + public async Task getInfo() + { + var eb = new EmbedBuilder(); + eb.WithAuthor(new EmbedAuthorBuilder() + .WithIconUrl(Context.User.GetAvatarUrl()) + .WithName(Context.User.Username)); + eb.AddField("Test", "Some testing stuff here..."); + await ReplyAsync("", false, eb.Build()); + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Modules/Roll.cs b/Geekbot.net/Modules/Roll.cs index 31709a9..b7e4636 100644 --- a/Geekbot.net/Modules/Roll.cs +++ b/Geekbot.net/Modules/Roll.cs @@ -7,11 +7,24 @@ namespace Geekbot.net.Modules public class Roll : ModuleBase { [Command("roll"), Summary("Roll a number between 1 and 100.")] - public async Task RollCommand() + public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing") { var rnd = new Random(); var number = rnd.Next(1, 100); - await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); + var guess = 1000; + int.TryParse(stuff, out guess); + if (guess <= 100 && guess > 0) + { + await ReplyAsync($"{Context.Message.Author.Mention} you rolled {number}, your guess was {guess}"); + if (guess == number) + { + await ReplyAsync($"Congratulations {Context.User.Username}, your guess was correct!"); + } + } + else + { + await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); + } } [Command("dice"), Summary("Roll a dice")] diff --git a/Geekbot.net/Modules/UserInfo.cs b/Geekbot.net/Modules/UserInfo.cs index 4c63b94..f02f1c8 100644 --- a/Geekbot.net/Modules/UserInfo.cs +++ b/Geekbot.net/Modules/UserInfo.cs @@ -21,34 +21,25 @@ namespace Geekbot.net.Modules var messages = (int)redis.StringGet(key + "-messages"); var level = GetLevelAtExperience(messages); - var reply = ""; - - if (Context.Message.Author.Id == userInfo.Id) - { - reply = reply + $"here are your stats {userInfo.Mention}\r\n"; - } - else - { - reply = reply + $"here are {userInfo.Mention}'s stats\r\n"; - } - - reply = reply + $"```\r\n"; - reply = reply + $"Discordian Since: {userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)\r\n"; - reply = reply + $"Level: {level}\r\n"; - reply = reply + $"Messages Sent: {messages}\r\n"; + var eb = new EmbedBuilder(); + eb.WithAuthor(new EmbedAuthorBuilder() + .WithIconUrl(userInfo.GetAvatarUrl()) + .WithName(userInfo.Username)); - var jokeKarma = redis.StringGet(key + "-karma"); - if (!jokeKarma.IsNullOrEmpty) + eb.AddField("Discordian Since", $"{userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)"); + eb.AddField("Level", level); + eb.AddField("Messages Sent", messages); + + var karma = redis.StringGet(key + "-karma"); + if (!karma.IsNullOrEmpty) { - reply = reply + $"Karma: {jokeKarma}\r\n"; + eb.AddField("Karma", karma); } - - reply = reply + $"```"; - - await ReplyAsync(reply); + + await ReplyAsync("", false, eb.Build()); } - public async Task GetLevel([Summary("The (optional) user to get info for")] string xp) + public async Task GetLevel(string xp) { var level = GetLevelAtExperience(int.Parse(xp)); await ReplyAsync(level.ToString()); diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index 5e1539a..ae9abc3 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -12,7 +12,7 @@ namespace Geekbot.net { class Program { - public CommandService commands; + private CommandService commands; private DiscordSocketClient client; private DependencyMap map; private IDatabase redis; @@ -28,7 +28,6 @@ namespace Geekbot.net Console.WriteLine("Starting..."); //Task.WaitAll(BootTasks.CheckSettingsFile()); - Task.WaitAll(new Program().MainAsync()); } @@ -36,8 +35,20 @@ namespace Geekbot.net { client = new DiscordSocketClient(); commands = new CommandService(); + redis = new RedisClient().Client; - const string token = "MTgxMDkyOTgxMDUzNDU2Mzg0.C8_UTw.PvXLAVOTccbrWKLMeyvN9WqRPlU"; + var token = redis.StringGet("discordToken"); + if (token.IsNullOrEmpty) + { + Console.Write("Your bot Token: "); + var newToken = Console.ReadLine(); + redis.StringSet("discordToken", newToken); + token = newToken; + + Console.Write("Bot Owner User ID: "); + var ownerId = Console.ReadLine(); + redis.StringSet("botOwner", ownerId); + } map = new DependencyMap(); map.Add(new CatClient()); @@ -90,7 +101,7 @@ namespace Geekbot.net { var message = messsageParam; if (message == null) return; - if (message.Author.Username.Contains("Geekbot")) return; + if (message.Author.Username.Equals(client.CurrentUser.Username)) return; var channel = (SocketGuildChannel)message.Channel;