From ea59fab28aeb4b35220bfccc44665e0b1eb5dd05 Mon Sep 17 00:00:00 2001 From: dboerlage Date: Mon, 15 May 2017 20:43:50 +0200 Subject: [PATCH 1/3] Adds choose command --- Geekbot.net/Modules/Choose.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Geekbot.net/Modules/Choose.cs diff --git a/Geekbot.net/Modules/Choose.cs b/Geekbot.net/Modules/Choose.cs new file mode 100644 index 0000000..b7114a4 --- /dev/null +++ b/Geekbot.net/Modules/Choose.cs @@ -0,0 +1,24 @@ +using System; +using System.Threading.Tasks; +using Discord.Commands; +using Geekbot.net.Lib.IClients; + +namespace Geekbot.net.Modules +{ + public class Choose : ModuleBase + { + private readonly IRandomClient rnd; + public Choose(IRandomClient randomClient) + { + rnd = randomClient; + } + + [Command("choose", RunMode = RunMode.Async), Summary("Let the bot make a choice for you.")] + public async Task Command([Remainder, Summary("The choices, sepperated by a ;")] string choices) + { + var choicesArray = choices.Split(';'); + var choice = rnd.Client.Next(choicesArray.Length); + ReplyAsync($"I choose **{choicesArray[choice]}**"); + } + } +} \ No newline at end of file From 6a33bddadbefa55945ce03bac1cc9c66b79c147e Mon Sep 17 00:00:00 2001 From: dboerlage Date: Mon, 15 May 2017 21:14:38 +0200 Subject: [PATCH 2/3] Adds shipping command --- Geekbot.net/Modules/Ship.cs | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Geekbot.net/Modules/Ship.cs diff --git a/Geekbot.net/Modules/Ship.cs b/Geekbot.net/Modules/Ship.cs new file mode 100644 index 0000000..2f4c562 --- /dev/null +++ b/Geekbot.net/Modules/Ship.cs @@ -0,0 +1,75 @@ +using System; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Geekbot.net.Lib.IClients; + +namespace Geekbot.net.Modules +{ + public class Ship : ModuleBase + { + + private readonly IRedisClient redis; + private readonly IRandomClient rnd; + public Ship(IRedisClient redisClient, IRandomClient randomClient) + { + redis = redisClient; + rnd = randomClient; + } + + [Command("Ship", RunMode = RunMode.Async), Summary("Ask the Shipping meter")] + public async Task Command([Summary("User 1")] IUser user1, [Summary("User 2")] IUser user2) + { + // Create a String + var dbstring = ""; + if (user1.Id > user2.Id) + { + dbstring = $"{user1.Id}-{user2.Id}"; + } + else + { + dbstring = $"{user2.Id}-{user1.Id}"; + } + dbstring = $"{Context.Guild.Id}-{dbstring}"; + Console.WriteLine(dbstring); + + var dbval = redis.Client.StringGet(dbstring); + var shippingRate = 0; + if (dbval.IsNullOrEmpty) + { + shippingRate = rnd.Client.Next(1, 100); + redis.Client.StringSet(dbstring, shippingRate); + } + else + { + shippingRate = int.Parse(dbval.ToString()); + } + + var reply = ""; + reply = reply + $"{user1.Username} :heart: {user2.Username}\r\n"; + reply = reply + $"0% [----{shippingRate}%----] 100% - {determinateSuccess(shippingRate)}"; + ReplyAsync(reply); + } + + private string determinateSuccess(int rate) + { + if (rate < 20) + { + return "Not gonna happen"; + } if (rate >= 20 && rate < 40) + { + return "A slight chance"; + } if (rate >= 40 && rate < 60) + { + return "Perhaps it could work"; + } if (rate >= 60 && rate < 80) + { + return "A good match"; + } if (rate >= 80) + { + return "10/10"; + } + return "a"; + } + } +} \ No newline at end of file From 9e6773a02257123c78ddba406f7b5693b6e26422 Mon Sep 17 00:00:00 2001 From: Runebaas Date: Mon, 15 May 2017 23:38:23 +0200 Subject: [PATCH 3/3] finishing ship command and adding await in choose --- Geekbot.net/Modules/Choose.cs | 2 +- Geekbot.net/Modules/Ship.cs | 40 +++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Geekbot.net/Modules/Choose.cs b/Geekbot.net/Modules/Choose.cs index b7114a4..28a8be2 100644 --- a/Geekbot.net/Modules/Choose.cs +++ b/Geekbot.net/Modules/Choose.cs @@ -18,7 +18,7 @@ namespace Geekbot.net.Modules { var choicesArray = choices.Split(';'); var choice = rnd.Client.Next(choicesArray.Length); - ReplyAsync($"I choose **{choicesArray[choice]}**"); + await ReplyAsync($"I choose **{choicesArray[choice]}**"); } } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Ship.cs b/Geekbot.net/Modules/Ship.cs index 2f4c562..f22ed1b 100644 --- a/Geekbot.net/Modules/Ship.cs +++ b/Geekbot.net/Modules/Ship.cs @@ -45,31 +45,53 @@ namespace Geekbot.net.Modules shippingRate = int.Parse(dbval.ToString()); } - var reply = ""; - reply = reply + $"{user1.Username} :heart: {user2.Username}\r\n"; - reply = reply + $"0% [----{shippingRate}%----] 100% - {determinateSuccess(shippingRate)}"; - ReplyAsync(reply); + var reply = ":heartpulse: **Matchmaking** :heartpulse:\r\n"; + reply = reply + $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n"; + reply = reply + $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}"; + await ReplyAsync(reply); } - private string determinateSuccess(int rate) + private string DeterminateSuccess(int rate) { if (rate < 20) { return "Not gonna happen"; } if (rate >= 20 && rate < 40) { - return "A slight chance"; + return "Not such a good idea"; } if (rate >= 40 && rate < 60) { - return "Perhaps it could work"; + return "There might be a chance"; } if (rate >= 60 && rate < 80) { - return "A good match"; + return "Almost a match, but could work"; } if (rate >= 80) { - return "10/10"; + return "It's a match"; } return "a"; } + + private string BlockCounter(int rate) + { + var amount = Math.Floor(decimal.Floor(rate / 10)); + Console.WriteLine(amount); + var blocks = ""; + for(int i = 1; i <= 10; i++) + { + if(i <= amount) + { + blocks = blocks + ":white_medium_small_square:"; + if(i == amount) + { + blocks = blocks + $" {rate}% "; + } + } else + { + blocks = blocks + ":black_medium_small_square:"; + } + } + return blocks; + } } } \ No newline at end of file