2017-09-14 22:11:19 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2017-09-15 22:56:03 +02:00
|
|
|
|
using Discord;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
using Discord.Commands;
|
2017-09-27 22:48:09 +02:00
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using Serilog;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
|
|
|
|
|
namespace Geekbot.net.Modules
|
|
|
|
|
{
|
|
|
|
|
[Group("admin")]
|
|
|
|
|
public class AdminCmd : ModuleBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabase redis;
|
2017-09-27 22:48:09 +02:00
|
|
|
|
private readonly DiscordSocketClient client;
|
|
|
|
|
private readonly ILogger logger;
|
|
|
|
|
|
|
|
|
|
public AdminCmd(IDatabase redis, DiscordSocketClient client, ILogger logger)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
|
|
|
|
this.redis = redis;
|
2017-09-27 22:48:09 +02:00
|
|
|
|
this.client = client;
|
|
|
|
|
this.logger = logger;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-15 22:56:03 +02:00
|
|
|
|
[RequireUserPermission(GuildPermission.Administrator)]
|
|
|
|
|
[Command("welcome", RunMode = RunMode.Async)]
|
|
|
|
|
[Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
|
|
|
|
|
public async Task SetWelcomeMessage([Remainder] [Summary("message")] string welcomeMessage)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-09-27 22:48:09 +02:00
|
|
|
|
redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] { new HashEntry("WelcomeMsg", welcomeMessage) });
|
2017-09-14 22:11:19 +02:00
|
|
|
|
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" +
|
2017-09-15 22:56:03 +02:00
|
|
|
|
formatedMessage);
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-15 22:56:03 +02:00
|
|
|
|
[Command("youtubekey", RunMode = RunMode.Async)]
|
|
|
|
|
[Summary("Set the youtube api key")]
|
2017-09-14 22:11:19 +02:00
|
|
|
|
public async Task SetYoutubeKey([Summary("API Key")] string key)
|
|
|
|
|
{
|
2017-09-28 18:55:57 +02:00
|
|
|
|
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.StringGet("botOwner"))).Result;
|
|
|
|
|
if (!Context.User.Id.ToString().Equals(botOwner.Id.ToString()))
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-09-28 18:55:57 +02:00
|
|
|
|
await ReplyAsync($"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})");
|
2017-09-14 22:11:19 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redis.StringSet("youtubeKey", key);
|
|
|
|
|
await ReplyAsync("Apikey has been set");
|
|
|
|
|
}
|
2017-09-27 22:48:09 +02:00
|
|
|
|
|
|
|
|
|
[Command("game", RunMode = RunMode.Async)]
|
|
|
|
|
[Summary("Set the game that the bot is playing")]
|
|
|
|
|
public async Task SetGame([Remainder] [Summary("Game")] string key)
|
|
|
|
|
{
|
2017-09-28 18:55:57 +02:00
|
|
|
|
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.StringGet("botOwner"))).Result;
|
|
|
|
|
if (!Context.User.Id.ToString().Equals(botOwner.Id.ToString()))
|
2017-09-27 22:48:09 +02:00
|
|
|
|
{
|
2017-09-28 18:55:57 +02:00
|
|
|
|
await ReplyAsync($"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})");
|
2017-09-27 22:48:09 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
redis.StringSet("Game", key);
|
|
|
|
|
await client.SetGameAsync(key);
|
|
|
|
|
logger.Information($"[Geekbot] Changed game to {key}");
|
|
|
|
|
await ReplyAsync($"Now Playing {key}");
|
|
|
|
|
}
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
2017-04-14 22:18:22 +02:00
|
|
|
|
}
|