From af9421f2b94f82382fd23cd8be438c9bb79503df Mon Sep 17 00:00:00 2001 From: dboerlage Date: Fri, 14 Apr 2017 22:18:22 +0200 Subject: [PATCH] improved welcome message and admin command --- Geekbot.net/Modules/AdminCmd.cs | 29 +++++++++++++++++++++++++++++ Geekbot.net/Modules/Ping.cs | 6 ++++++ Geekbot.net/Program.cs | 18 +++++++++++------- 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 Geekbot.net/Modules/AdminCmd.cs diff --git a/Geekbot.net/Modules/AdminCmd.cs b/Geekbot.net/Modules/AdminCmd.cs new file mode 100644 index 0000000..d1475ea --- /dev/null +++ b/Geekbot.net/Modules/AdminCmd.cs @@ -0,0 +1,29 @@ +using System.Threading.Tasks; +using Discord.Commands; +using Geekbot.net.Lib; + +namespace Geekbot.net.Modules +{ + [Group("admin")] + public class AdminCmd : ModuleBase + { + [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"); + } + + } + } +} \ No newline at end of file diff --git a/Geekbot.net/Modules/Ping.cs b/Geekbot.net/Modules/Ping.cs index 86f0507..96f0f52 100644 --- a/Geekbot.net/Modules/Ping.cs +++ b/Geekbot.net/Modules/Ping.cs @@ -10,5 +10,11 @@ namespace Geekbot.net.Modules { 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/Program.cs b/Geekbot.net/Program.cs index d409636..fa9372f 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -3,10 +3,10 @@ using System.Reflection; using System.Threading.Tasks; using Discord; using Discord.Commands; -using Discord.Net.Queue; using Discord.WebSocket; using Geekbot.net.Lib; using Geekbot.net.Modules; +using StackExchange.Redis; namespace Geekbot.net { @@ -15,6 +15,7 @@ namespace Geekbot.net private CommandService commands; private DiscordSocketClient client; private DependencyMap map; + private IDatabase redis; private static void Main(string[] args) { @@ -42,6 +43,7 @@ namespace Geekbot.net Console.WriteLine("Connecting to Discord..."); await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); + redis = new RedisClient().Client; Console.WriteLine("Done and ready for use...\n"); await Task.Delay(-1); @@ -81,18 +83,20 @@ namespace Geekbot.net Console.WriteLine(channel.Guild.Name + " - " + message.Channel + " - " + message.Author.Username + " - " + message.Content); var statsRecorder = new StatsRecorder(message); -#pragma warning disable 4014 - statsRecorder.UpdateUserRecordAsync(); - statsRecorder.UpdateGuildRecordAsync(); -#pragma warning restore 4014 + await statsRecorder.UpdateUserRecordAsync(); + await statsRecorder.UpdateGuildRecordAsync(); } public async Task HandleUserJoined(SocketGuildUser user) { if (!user.IsBot) { - var message = $"Sali und wilkomme {user.Mention}"; - await user.Guild.DefaultChannel.SendMessageAsync(message); + var message = redis.StringGet(user.Guild.Id + "-welcome-msg"); + if (!message.IsNullOrEmpty) + { + message = message.ToString().Replace("$user", user.Mention); + await user.Guild.DefaultChannel.SendMessageAsync(message); + } } } }