From d3662b99346e550b789de4fde5d63030979a054e Mon Sep 17 00:00:00 2001 From: dboerlage Date: Thu, 13 Apr 2017 00:03:03 +0200 Subject: [PATCH] 8ball and architectural stuff --- Geekbot.net/Lib/StatsRecorder.cs | 26 +++++++++++++++++++++ Geekbot.net/Modules/EightBall.cs | 40 ++++++++++++++++++++++++++++++++ Geekbot.net/Modules/UserInfo.cs | 28 ++++++++++++++++++++++ Geekbot.net/Program.cs | 7 +++++- 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 Geekbot.net/Lib/StatsRecorder.cs create mode 100644 Geekbot.net/Modules/EightBall.cs diff --git a/Geekbot.net/Lib/StatsRecorder.cs b/Geekbot.net/Lib/StatsRecorder.cs new file mode 100644 index 0000000..3920976 --- /dev/null +++ b/Geekbot.net/Lib/StatsRecorder.cs @@ -0,0 +1,26 @@ +using System; +using System.Threading.Tasks; +using Discord.WebSocket; + +namespace Geekbot.net.Lib +{ + public class StatsRecorder + { + + public static async Task Record(SocketMessage message) + { + await UpdateUserRecordTask(message); + } + + private static Task UpdateUserRecordTask(SocketMessage message) + { + return Task.Run(() => UpdateUserRecord(message)); + + } + + private static void UpdateUserRecord(SocketMessage message) + { + Console.WriteLine(message.Author.Username + " earned a point"); + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Modules/EightBall.cs b/Geekbot.net/Modules/EightBall.cs new file mode 100644 index 0000000..a29e451 --- /dev/null +++ b/Geekbot.net/Modules/EightBall.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Discord.Commands; + +namespace Geekbot.net.Modules +{ + public class EightBall : ModuleBase + { + [Command("8ball"), Summary("Ask 8Ball a Question.")] + public async Task Ball([Remainder, Summary("The Question")] string echo) + { + var replies = new List { + "It is certain", + "It is decidedly so", + "Without a doubt", + "Yes, definitely", + "You may rely on it", + "As I see it, yes", + "Most likely", + "Outlook good", + "Yes", + "Signs point to yes", + "Reply hazy try again", + "Ask again later", + "Better not tell you now", + "Cannot predict now", + "Concentrate and ask again", + "Don't count on it", + "My reply is no", + "My sources say no", + "Outlook not so good", + "Very doubtful"}; + + var rnd = new Random(); + var answer = rnd.Next(replies.Count); + await ReplyAsync(replies[answer]); + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Modules/UserInfo.cs b/Geekbot.net/Modules/UserInfo.cs index 36f8acf..5a9cdac 100644 --- a/Geekbot.net/Modules/UserInfo.cs +++ b/Geekbot.net/Modules/UserInfo.cs @@ -19,5 +19,33 @@ namespace Geekbot.net.Modules $"Account created at {userInfo.CreatedAt.Day}.{userInfo.CreatedAt.Month}.{userInfo.CreatedAt.Year}, that is {age} days ago\r\n" + $"Currently {userInfo.Status}"); } + + [Command("level"), Summary("Get a level based on a number")] + public async Task GetLevel([Summary("The (optional) user to get info for")] 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/Program.cs b/Geekbot.net/Program.cs index e230556..7c7f682 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Discord; using Discord.Commands; using Discord.WebSocket; +using Geekbot.net.Lib; namespace Geekbot.net { @@ -70,7 +71,11 @@ namespace Geekbot.net if (message == null) return; if (message.Author.Username.Contains("Geekbot")) return; - Console.WriteLine(message.Channel + " - " + message.Author + " - " + message.Content); + var channel = (SocketGuildChannel) message.Channel; + + Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content); + + await StatsRecorder.Record(message); } } } \ No newline at end of file