94 lines
No EOL
3.5 KiB
C#
94 lines
No EOL
3.5 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Discord;
|
|
using Discord.Commands;
|
|
using Discord.WebSocket;
|
|
using Geekbot.net.Lib;
|
|
using Geekbot.net.Lib.ErrorHandling;
|
|
using Geekbot.net.Lib.Logger;
|
|
using Geekbot.net.Lib.UserRepository;
|
|
using StackExchange.Redis;
|
|
|
|
namespace Geekbot.net.Commands.Admin
|
|
{
|
|
[Group("owner")]
|
|
[RequireOwner]
|
|
public class Owner : ModuleBase
|
|
{
|
|
private readonly DiscordSocketClient _client;
|
|
private readonly IErrorHandler _errorHandler;
|
|
private readonly IGeekbotLogger _logger;
|
|
private readonly IDatabase _redis;
|
|
private readonly IUserRepository _userRepository;
|
|
|
|
public Owner(IDatabase redis, DiscordSocketClient client, IGeekbotLogger logger, IUserRepository userRepositry, IErrorHandler errorHandler)
|
|
{
|
|
_redis = redis;
|
|
_client = client;
|
|
_logger = logger;
|
|
_userRepository = userRepositry;
|
|
_errorHandler = errorHandler;
|
|
}
|
|
|
|
[Command("youtubekey", RunMode = RunMode.Async)]
|
|
[Remarks(CommandCategories.Admin)]
|
|
[Summary("Set the youtube api key")]
|
|
public async Task SetYoutubeKey([Summary("API Key")] string key)
|
|
{
|
|
_redis.StringSet("youtubeKey", key);
|
|
await ReplyAsync("Apikey has been set");
|
|
}
|
|
|
|
[Command("game", RunMode = RunMode.Async)]
|
|
[Remarks(CommandCategories.Admin)]
|
|
[Summary("Set the game that the bot is playing")]
|
|
public async Task SetGame([Remainder] [Summary("Game")] string key)
|
|
{
|
|
_redis.StringSet("Game", key);
|
|
await _client.SetGameAsync(key);
|
|
_logger.Information(LogSource.Geekbot, $"Changed game to {key}");
|
|
await ReplyAsync($"Now Playing {key}");
|
|
}
|
|
|
|
[Command("popuserrepo", RunMode = RunMode.Async)]
|
|
[Remarks(CommandCategories.Admin)]
|
|
[Summary("Populate user cache")]
|
|
public async Task PopUserRepoCommand()
|
|
{
|
|
var success = 0;
|
|
var failed = 0;
|
|
try
|
|
{
|
|
_logger.Warning(LogSource.UserRepository, "Populating User Repositry");
|
|
await ReplyAsync("Starting Population of User Repository");
|
|
foreach (var guild in _client.Guilds)
|
|
{
|
|
_logger.Information(LogSource.UserRepository, $"Populating users from {guild.Name}");
|
|
foreach (var user in guild.Users)
|
|
{
|
|
var succeded = await _userRepository.Update(user);
|
|
var inc = succeded ? success++ : failed++;
|
|
}
|
|
}
|
|
|
|
_logger.Warning(LogSource.UserRepository, "Finished Updating User Repositry");
|
|
await ReplyAsync(
|
|
$"Successfully Populated User Repository with {success} Users in {_client.Guilds.Count} Guilds (Failed: {failed})");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_errorHandler.HandleCommandException(e, Context,
|
|
"Couldn't complete User Repository, see console for more info");
|
|
}
|
|
}
|
|
|
|
[Command("error", RunMode = RunMode.Async)]
|
|
[Remarks(CommandCategories.Admin)]
|
|
[Summary("Throw an error un purpose")]
|
|
public void PurposefulError()
|
|
{
|
|
var e = new Exception("Error Generated by !owner error");
|
|
_errorHandler.HandleCommandException(e, Context);
|
|
}
|
|
}
|
|
} |