From 6d5c6f2ea8db970dee34d9906ee4ae1ce99bf82a Mon Sep 17 00:00:00 2001 From: Runebaas Date: Mon, 17 Apr 2017 16:58:48 +0200 Subject: [PATCH] Karma, Say, Help --- .gitignore | 3 +++ Geekbot.net/Modules/AdminCmd.cs | 21 +++++---------- Geekbot.net/Modules/Counters.cs | 45 +++++++++++++++++++++++++++++++++ Geekbot.net/Modules/Help.cs | 27 ++++++++++++++++++++ Geekbot.net/Modules/Ping.cs | 7 +---- Geekbot.net/Modules/Roll.cs | 6 ++--- Geekbot.net/Modules/Say.cs | 16 ++++++++++++ Geekbot.net/Modules/UserInfo.cs | 18 ++++++++----- Geekbot.net/Program.cs | 41 +++++++++++++++++++----------- 9 files changed, 139 insertions(+), 45 deletions(-) create mode 100644 Geekbot.net/Modules/Counters.cs create mode 100644 Geekbot.net/Modules/Help.cs create mode 100644 Geekbot.net/Modules/Say.cs diff --git a/.gitignore b/.gitignore index 74d293f..eaca9a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ Geekbot.net/bin Geekbot.net/obj +Backup/ +.vs/ +UpgradeLog.htm \ No newline at end of file diff --git a/Geekbot.net/Modules/AdminCmd.cs b/Geekbot.net/Modules/AdminCmd.cs index d1475ea..cf5d71f 100644 --- a/Geekbot.net/Modules/AdminCmd.cs +++ b/Geekbot.net/Modules/AdminCmd.cs @@ -7,23 +7,16 @@ namespace Geekbot.net.Modules [Group("admin")] public class AdminCmd : ModuleBase { + [RequireUserPermission(Discord.GuildPermission.Administrator)] [Command("welcome"), Summary("Set a Welcome Message (use '$user' to mention the new joined user).")] public async Task SetWelcomeMessage([Remainder, Summary("The message")] string welcomeMessage) { - if (Context.Guild.OwnerId.Equals(Context.User.Id)) - { - var redis = new RedisClient().Client; - var key = Context.Guild.Id + "-welcome-msg"; - redis.StringSet(key, welcomeMessage); - var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention); - await ReplyAsync("W!elcome message has been changed\r\nHere is an example of how it would look:\r\n" + - formatedMessage); - } - else - { - await ReplyAsync("Sorry, only the Server Owner can do this"); - } - + var redis = new RedisClient().Client; + var key = Context.Guild.Id + "-welcomeMsg"; + redis.StringSet(key, welcomeMessage); + var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention); + await ReplyAsync("Welcome message has been changed\r\nHere is an example of how it would look:\r\n" + + formatedMessage); } } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Counters.cs b/Geekbot.net/Modules/Counters.cs new file mode 100644 index 0000000..506090b --- /dev/null +++ b/Geekbot.net/Modules/Counters.cs @@ -0,0 +1,45 @@ +using System; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Geekbot.net.Lib; + +namespace Geekbot.net.Modules +{ + public class Counters : ModuleBase + { + [Command("good"), Summary("Increase Someones Karma")] + public async Task Good([Summary("The someone")] IUser user) + { + if (user.Id == Context.User.Id) + { + await ReplyAsync($"Sorry {Context.User.Username}, but you can't give yourself karma"); + } + else + { + var redis = new RedisClient().Client; + var key = Context.Guild.Id + "-" + user.Id + "-karma"; + var badJokes = (int)redis.StringGet(key); + redis.StringSet(key, (badJokes + 1).ToString()); + await ReplyAsync($"{Context.User.Username} gave {user.Mention} karma"); + } + } + + [Command("bad"), Summary("Decrease Someones Karma")] + public async Task Bad([Summary("The someone")] IUser user) + { + if (user.Id == Context.User.Id) + { + await ReplyAsync($"Sorry {Context.User.Username}, but you can't lower your own karma"); + } + else + { + var redis = new RedisClient().Client; + var key = Context.Guild.Id + "-" + user.Id + "-karma"; + var badJokes = (int)redis.StringGet(key); + redis.StringSet(key, (badJokes - 1).ToString()); + await ReplyAsync($"{Context.User.Username} lowered {user.Mention}'s karma"); + } + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Modules/Help.cs b/Geekbot.net/Modules/Help.cs new file mode 100644 index 0000000..2570e7e --- /dev/null +++ b/Geekbot.net/Modules/Help.cs @@ -0,0 +1,27 @@ +using System.Threading.Tasks; +using Discord.Commands; +using System.Reflection; + +namespace Geekbot.net.Modules +{ + public class Help : ModuleBase + { + [Command("help"), Summary("List all Commands")] + public async Task GetHelp() + { + var commands = new CommandService(); + await commands.AddModulesAsync(Assembly.GetEntryAssembly()); + var cmdList = commands.Commands; + var reply = "**Geekbot Command list**\r\n"; + foreach (var cmd in cmdList) + { + var param = string.Join(", !",cmd.Aliases); + if (!param.Contains("admin")) + { + reply = reply + $"**{cmd.Name}** (!{param}) - {cmd.Summary}\r\n"; + } + } + await ReplyAsync(reply); + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Modules/Ping.cs b/Geekbot.net/Modules/Ping.cs index 96f0f52..139a97e 100644 --- a/Geekbot.net/Modules/Ping.cs +++ b/Geekbot.net/Modules/Ping.cs @@ -8,13 +8,8 @@ namespace Geekbot.net.Modules [Command("ping"), Summary("Pong.")] public async Task Say() { + await Task.Delay(5000); await ReplyAsync("Pong"); } - - [Command("hui"), Summary("hui!!!.")] - public async Task Hui() - { - await ReplyAsync("hui!!!"); - } } } \ No newline at end of file diff --git a/Geekbot.net/Modules/Roll.cs b/Geekbot.net/Modules/Roll.cs index a6df75b..31709a9 100644 --- a/Geekbot.net/Modules/Roll.cs +++ b/Geekbot.net/Modules/Roll.cs @@ -14,11 +14,11 @@ namespace Geekbot.net.Modules await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); } - [Command("dice"), Summary("Roll a number between 1 and 100.")] - public async Task DiceCommand() + [Command("dice"), Summary("Roll a dice")] + public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6) { var rnd = new Random(); - var number = rnd.Next(1, 6); + var number = rnd.Next(1, max); await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); } } diff --git a/Geekbot.net/Modules/Say.cs b/Geekbot.net/Modules/Say.cs new file mode 100644 index 0000000..fca9ed2 --- /dev/null +++ b/Geekbot.net/Modules/Say.cs @@ -0,0 +1,16 @@ +using System.Threading.Tasks; +using Discord.Commands; + +namespace Geekbot.net.Modules +{ + public class Say : ModuleBase + { + [RequireUserPermission(Discord.GuildPermission.Administrator)] + [Command("say"), Summary("Say Something.")] + public async Task Echo([Remainder, Summary("What?")] string echo) + { + await Context.Message.DeleteAsync(); + await ReplyAsync(echo); + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Modules/UserInfo.cs b/Geekbot.net/Modules/UserInfo.cs index 3fa9ead..4c63b94 100644 --- a/Geekbot.net/Modules/UserInfo.cs +++ b/Geekbot.net/Modules/UserInfo.cs @@ -8,7 +8,7 @@ namespace Geekbot.net.Modules { public class UserInfo : ModuleBase { - [Alias("stats", "whois")] + [Alias("stats")] [Command("user"), Summary("Get information about this user")] public async Task User([Summary("The (optional) user to get info for")] IUser user = null) { @@ -17,8 +17,8 @@ namespace Geekbot.net.Modules var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays); var redis = new RedisClient().Client; - var key = Context.Guild.Id + "-" + userInfo.Id + "-messages"; - var messages = (int)redis.StringGet(key); + var key = Context.Guild.Id + "-" + userInfo.Id; + var messages = (int)redis.StringGet(key + "-messages"); var level = GetLevelAtExperience(messages); var reply = ""; @@ -33,17 +33,21 @@ namespace Geekbot.net.Modules } 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"; - reply = - reply + - $"Discordian Since: {userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)"; + + var jokeKarma = redis.StringGet(key + "-karma"); + if (!jokeKarma.IsNullOrEmpty) + { + reply = reply + $"Karma: {jokeKarma}\r\n"; + } + reply = reply + $"```"; await ReplyAsync(reply); } - [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)); diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index eb7402e..5e1539a 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -12,22 +12,22 @@ namespace Geekbot.net { class Program { - private CommandService commands; + public CommandService commands; private DiscordSocketClient client; private DependencyMap map; private IDatabase redis; private static void Main(string[] args) { - Console.WriteLine(" ____ _____ _____ _ ______ ___ _____"); - Console.WriteLine(" / ___| ____| ____| |/ / __ ) / _ \\_ _|"); - Console.WriteLine("| | _| _| | _| | ' /| _ \\| | | || |"); - Console.WriteLine("| |_| | |___| |___| . \\| |_) | |_| || |"); - Console.WriteLine(" \\____|_____|_____|_|\\_\\____/ \\___/ |_|"); + Console.WriteLine(@" ____ _____ _____ _ ______ ___ _____"); + Console.WriteLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|"); + Console.WriteLine(@"| | _| _| | _| | ' /| _ \| | | || |"); + Console.WriteLine(@"| |_| | |___| |___| . \| |_) | |_| || |"); + Console.WriteLine(@" \____|_____|_____|_|\_\____/ \___/ |_|"); Console.WriteLine("========================================="); Console.WriteLine("Starting..."); -// Task.WaitAll(BootTasks.CheckSettingsFile()); + //Task.WaitAll(BootTasks.CheckSettingsFile()); Task.WaitAll(new Program().MainAsync()); } @@ -66,13 +66,24 @@ namespace Geekbot.net var message = messageParam as SocketUserMessage; if (message == null) return; int argPos = 0; + if (message.ToString().ToLower().Equals("ping")) + { + await message.Channel.SendMessageAsync("pong"); + return; + } + if (message.ToString().ToLower().Equals("hui")) + { + await message.Channel.SendMessageAsync("hui!!!"); + return; + } if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return; var context = new CommandContext(client, message); - var result = await commands.ExecuteAsync(context, argPos, map); - if (!result.IsSuccess) - { - await context.Channel.SendMessageAsync(result.ErrorReason); - } + commands.ExecuteAsync(context, argPos, map); + //var result = await commands.ExecuteAsync(context, argPos, map); + //if (!result.IsSuccess) + //{ + // await context.Channel.SendMessageAsync(result.ErrorReason); + //} } public async Task HandleMessageReceived(SocketMessage messsageParam) @@ -81,11 +92,11 @@ namespace Geekbot.net if (message == null) return; if (message.Author.Username.Contains("Geekbot")) return; - var channel = (SocketGuildChannel) message.Channel; + var channel = (SocketGuildChannel)message.Channel; Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content); - var statsRecorder = new StatsRecorder(message); + var statsRecorder = new StatsRecorder(message); await statsRecorder.UpdateUserRecordAsync(); await statsRecorder.UpdateGuildRecordAsync(); } @@ -94,7 +105,7 @@ namespace Geekbot.net { if (!user.IsBot) { - var message = redis.StringGet(user.Guild.Id + "-welcome-msg"); + var message = redis.StringGet(user.Guild.Id + "-welcomeMsg"); if (!message.IsNullOrEmpty) { message = message.ToString().Replace("$user", user.Mention);