improved welcome message and admin command

This commit is contained in:
dboerlage 2017-04-14 22:18:22 +02:00
parent 1fdbcaa471
commit af9421f2b9
No known key found for this signature in database
GPG key ID: BDA07B7D3FCF147F
3 changed files with 46 additions and 7 deletions

View file

@ -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");
}
}
}
}

View file

@ -10,5 +10,11 @@ namespace Geekbot.net.Modules
{
await ReplyAsync("Pong");
}
[Command("hui"), Summary("hui!!!.")]
public async Task Hui()
{
await ReplyAsync("hui!!!");
}
}
}

View file

@ -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);
}
}
}
}