Compare commits
3 commits
master
...
GeekbotBas
Author | SHA1 | Date | |
---|---|---|---|
7fb88bd106 | |||
295a1d575d | |||
8d9c436cfc |
46 changed files with 248 additions and 145 deletions
|
@ -7,6 +7,7 @@ using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.CommandPreconditions;
|
using Geekbot.net.Lib.CommandPreconditions;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
|
@ -17,7 +18,7 @@ namespace Geekbot.net.Commands.Admin
|
||||||
[Group("admin")]
|
[Group("admin")]
|
||||||
[RequireUserPermission(GuildPermission.Administrator)]
|
[RequireUserPermission(GuildPermission.Administrator)]
|
||||||
[DisableInDirectMessage]
|
[DisableInDirectMessage]
|
||||||
public class Admin : ModuleBase
|
public class Admin : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.CommandPreconditions;
|
using Geekbot.net.Lib.CommandPreconditions;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.UserRepository;
|
using Geekbot.net.Lib.UserRepository;
|
||||||
|
@ -15,7 +16,7 @@ namespace Geekbot.net.Commands.Admin
|
||||||
[RequireUserPermission(GuildPermission.ManageMessages)]
|
[RequireUserPermission(GuildPermission.ManageMessages)]
|
||||||
[RequireUserPermission(GuildPermission.ManageRoles)]
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
||||||
[DisableInDirectMessage]
|
[DisableInDirectMessage]
|
||||||
public class Mod : ModuleBase
|
public class Mod : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.GlobalSettings;
|
using Geekbot.net.Lib.GlobalSettings;
|
||||||
using Geekbot.net.Lib.Logger;
|
using Geekbot.net.Lib.Logger;
|
||||||
|
@ -12,7 +13,7 @@ namespace Geekbot.net.Commands.Admin.Owner
|
||||||
{
|
{
|
||||||
[Group("owner")]
|
[Group("owner")]
|
||||||
[RequireOwner]
|
[RequireOwner]
|
||||||
public class Owner : ModuleBase
|
public class Owner : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
|
@ -7,29 +7,27 @@ using Discord.Commands;
|
||||||
using Discord.Net;
|
using Discord.Net;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.CommandPreconditions;
|
using Geekbot.net.Lib.CommandPreconditions;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
using Geekbot.net.Lib.Localization;
|
|
||||||
using Geekbot.net.Lib.ReactionListener;
|
using Geekbot.net.Lib.ReactionListener;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Admin
|
namespace Geekbot.net.Commands.Admin
|
||||||
{
|
{
|
||||||
[Group("role")]
|
[Group("role")]
|
||||||
[DisableInDirectMessage]
|
[DisableInDirectMessage]
|
||||||
public class Role : ModuleBase
|
public class Role : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IReactionListener _reactionListener;
|
private readonly IReactionListener _reactionListener;
|
||||||
private readonly ITranslationHandler _translationHandler;
|
|
||||||
|
|
||||||
public Role(DatabaseContext database, IErrorHandler errorHandler, IReactionListener reactionListener, ITranslationHandler translationHandler)
|
public Role(DatabaseContext database, IErrorHandler errorHandler, IReactionListener reactionListener)
|
||||||
{
|
{
|
||||||
_database = database;
|
_database = database;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
_reactionListener = reactionListener;
|
_reactionListener = reactionListener;
|
||||||
_translationHandler = translationHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(RunMode = RunMode.Async)]
|
[Command(RunMode = RunMode.Async)]
|
||||||
|
@ -38,17 +36,16 @@ namespace Geekbot.net.Commands.Admin
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translationHandler.GetGuildContext(Context);
|
|
||||||
var roles = _database.RoleSelfService.Where(g => g.GuildId.Equals(Context.Guild.Id.AsLong())).ToList();
|
var roles = _database.RoleSelfService.Where(g => g.GuildId.Equals(Context.Guild.Id.AsLong())).ToList();
|
||||||
if (roles.Count == 0)
|
if (roles.Count == 0)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("NoRolesConfigured"));
|
await ReplyAsync(Context.Translations.GetString("NoRolesConfigured"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.AppendLine(transContext.GetString("ListHeader", Context.Guild.Name));
|
sb.AppendLine(Context.Translations.GetString("ListHeader", Context.Guild.Name));
|
||||||
sb.AppendLine(transContext.GetString("ListInstruction"));
|
sb.AppendLine(Context.Translations.GetString("ListInstruction"));
|
||||||
foreach (var role in roles) sb.AppendLine($"- {role.WhiteListName}");
|
foreach (var role in roles) sb.AppendLine($"- {role.WhiteListName}");
|
||||||
await ReplyAsync(sb.ToString());
|
await ReplyAsync(sb.ToString());
|
||||||
}
|
}
|
||||||
|
@ -64,7 +61,6 @@ namespace Geekbot.net.Commands.Admin
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translationHandler.GetGuildContext(Context);
|
|
||||||
var roleName = roleNameRaw.ToLower();
|
var roleName = roleNameRaw.ToLower();
|
||||||
var roleFromDb = _database.RoleSelfService.FirstOrDefault(e =>
|
var roleFromDb = _database.RoleSelfService.FirstOrDefault(e =>
|
||||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName));
|
e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName));
|
||||||
|
@ -74,23 +70,23 @@ namespace Geekbot.net.Commands.Admin
|
||||||
var role = Context.Guild.Roles.First(r => r.Id == roleFromDb.RoleId.AsUlong());
|
var role = Context.Guild.Roles.First(r => r.Id == roleFromDb.RoleId.AsUlong());
|
||||||
if (role == null)
|
if (role == null)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("RoleNotFound"));
|
await ReplyAsync(Context.Translations.GetString("RoleNotFound"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guildUser.RoleIds.Contains(role.Id))
|
if (guildUser.RoleIds.Contains(role.Id))
|
||||||
{
|
{
|
||||||
await guildUser.RemoveRoleAsync(role);
|
await guildUser.RemoveRoleAsync(role);
|
||||||
await ReplyAsync(transContext.GetString("RemovedUserFromRole", role.Name));
|
await ReplyAsync(Context.Translations.GetString("RemovedUserFromRole", role.Name));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await guildUser.AddRoleAsync(role);
|
await guildUser.AddRoleAsync(role);
|
||||||
await ReplyAsync(transContext.GetString("AddedUserFromRole", role.Name));
|
await ReplyAsync(Context.Translations.GetString("AddedUserFromRole", role.Name));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ReplyAsync(transContext.GetString("RoleNotFound"));
|
await ReplyAsync(Context.Translations.GetString("RoleNotFound"));
|
||||||
}
|
}
|
||||||
catch (HttpException e)
|
catch (HttpException e)
|
||||||
{
|
{
|
||||||
|
@ -109,10 +105,9 @@ namespace Geekbot.net.Commands.Admin
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translationHandler.GetGuildContext(Context);
|
|
||||||
if (role.IsManaged)
|
if (role.IsManaged)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("CannotAddManagedRole"));
|
await ReplyAsync(Context.Translations.GetString("CannotAddManagedRole"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +117,7 @@ namespace Geekbot.net.Commands.Admin
|
||||||
|| role.Permissions.BanMembers
|
|| role.Permissions.BanMembers
|
||||||
|| role.Permissions.KickMembers)
|
|| role.Permissions.KickMembers)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("CannotAddDangerousRole"));
|
await ReplyAsync(Context.Translations.GetString("CannotAddDangerousRole"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +128,7 @@ namespace Geekbot.net.Commands.Admin
|
||||||
WhiteListName = roleName
|
WhiteListName = roleName
|
||||||
});
|
});
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await ReplyAsync(transContext.GetString("CannotAddDangerousRole", role.Name));
|
await ReplyAsync(Context.Translations.GetString("CannotAddDangerousRole", role.Name));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -148,18 +143,17 @@ namespace Geekbot.net.Commands.Admin
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translationHandler.GetGuildContext(Context);
|
|
||||||
var roleFromDb = _database.RoleSelfService.FirstOrDefault(e =>
|
var roleFromDb = _database.RoleSelfService.FirstOrDefault(e =>
|
||||||
e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName));
|
e.GuildId.Equals(Context.Guild.Id.AsLong()) && e.WhiteListName.Equals(roleName));
|
||||||
if (roleFromDb != null)
|
if (roleFromDb != null)
|
||||||
{
|
{
|
||||||
_database.RoleSelfService.Remove(roleFromDb);
|
_database.RoleSelfService.Remove(roleFromDb);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await ReplyAsync(transContext.GetString("RemovedRoleFromWhitelist", roleName));
|
await ReplyAsync(Context.Translations.GetString("RemovedRoleFromWhitelist", roleName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ReplyAsync(transContext.GetString("RoleNotFound"));
|
await ReplyAsync(Context.Translations.GetString("RoleNotFound"));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,13 +3,14 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
using PokeAPI;
|
using PokeAPI;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Games
|
namespace Geekbot.net.Commands.Games
|
||||||
{
|
{
|
||||||
public class Pokedex : ModuleBase
|
public class Pokedex : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.AlmostRedis;
|
using Geekbot.net.Lib.AlmostRedis;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
|
@ -13,18 +14,16 @@ using StackExchange.Redis;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Games
|
namespace Geekbot.net.Commands.Games
|
||||||
{
|
{
|
||||||
public class Roll : ModuleBase
|
public class Roll : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IAlmostRedis _redis;
|
private readonly IAlmostRedis _redis;
|
||||||
private readonly ITranslationHandler _translation;
|
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||||
|
|
||||||
public Roll(IAlmostRedis redis, IErrorHandler errorHandler, ITranslationHandler translation, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator)
|
public Roll(IAlmostRedis redis, IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator)
|
||||||
{
|
{
|
||||||
_redis = redis;
|
_redis = redis;
|
||||||
_translation = translation;
|
|
||||||
_database = database;
|
_database = database;
|
||||||
_randomNumberGenerator = randomNumberGenerator;
|
_randomNumberGenerator = randomNumberGenerator;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
|
@ -39,7 +38,6 @@ namespace Geekbot.net.Commands.Games
|
||||||
var number = _randomNumberGenerator.Next(1, 100);
|
var number = _randomNumberGenerator.Next(1, 100);
|
||||||
var guess = 1000;
|
var guess = 1000;
|
||||||
int.TryParse(stuff, out guess);
|
int.TryParse(stuff, out guess);
|
||||||
var transContext = await _translation.GetGuildContext(Context);
|
|
||||||
if (guess <= 100 && guess > 0)
|
if (guess <= 100 && guess > 0)
|
||||||
{
|
{
|
||||||
var prevRoll = _redis.Db.HashGet($"{Context.Guild.Id}:RollsPrevious2", Context.Message.Author.Id).ToString()?.Split('|');
|
var prevRoll = _redis.Db.HashGet($"{Context.Guild.Id}:RollsPrevious2", Context.Message.Author.Id).ToString()?.Split('|');
|
||||||
|
@ -47,17 +45,17 @@ namespace Geekbot.net.Commands.Games
|
||||||
{
|
{
|
||||||
if (prevRoll[0] == guess.ToString() && DateTime.Parse(prevRoll[1]) > DateTime.Now.AddDays(-1))
|
if (prevRoll[0] == guess.ToString() && DateTime.Parse(prevRoll[1]) > DateTime.Now.AddDays(-1))
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("NoPrevGuess", Context.Message.Author.Mention));
|
await ReplyAsync(Context.Translations.GetString("NoPrevGuess", Context.Message.Author.Mention));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_redis.Db.HashSet($"{Context.Guild.Id}:RollsPrevious2", new[] {new HashEntry(Context.Message.Author.Id, $"{guess}|{DateTime.Now}")});
|
_redis.Db.HashSet($"{Context.Guild.Id}:RollsPrevious2", new[] {new HashEntry(Context.Message.Author.Id, $"{guess}|{DateTime.Now}")});
|
||||||
|
|
||||||
await ReplyAsync(transContext.GetString("Rolled", Context.Message.Author.Mention, number, guess));
|
await ReplyAsync(Context.Translations.GetString("Rolled", Context.Message.Author.Mention, number, guess));
|
||||||
if (guess == number)
|
if (guess == number)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("Gratz", Context.Message.Author));
|
await ReplyAsync(Context.Translations.GetString("Gratz", Context.Message.Author));
|
||||||
_redis.Db.HashIncrement($"{Context.Guild.Id}:Rolls", Context.User.Id.ToString());
|
_redis.Db.HashIncrement($"{Context.Guild.Id}:Rolls", Context.User.Id.ToString());
|
||||||
var user = await GetUser(Context.User.Id);
|
var user = await GetUser(Context.User.Id);
|
||||||
user.Rolls += 1;
|
user.Rolls += 1;
|
||||||
|
@ -67,7 +65,7 @@ namespace Geekbot.net.Commands.Games
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("RolledNoGuess", Context.Message.Author.Mention, number));
|
await ReplyAsync(Context.Translations.GetString("RolledNoGuess", Context.Message.Author.Mention, number));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -4,13 +4,14 @@ using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.GlobalSettings;
|
using Geekbot.net.Lib.GlobalSettings;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Integrations.Google
|
namespace Geekbot.net.Commands.Integrations.Google
|
||||||
{
|
{
|
||||||
public class Google : ModuleBase
|
public class Google : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IGlobalSettings _globalSettings;
|
private readonly IGlobalSettings _globalSettings;
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.Converters;
|
using Geekbot.net.Lib.Converters;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
|
@ -11,7 +12,7 @@ using MtgApiManager.Lib.Service;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Integrations
|
namespace Geekbot.net.Commands.Integrations
|
||||||
{
|
{
|
||||||
public class MagicTheGathering : ModuleBase
|
public class MagicTheGathering : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IMtgManaConverter _manaConverter;
|
private readonly IMtgManaConverter _manaConverter;
|
||||||
|
|
|
@ -4,13 +4,14 @@ using System.Web;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.Clients;
|
using Geekbot.net.Lib.Clients;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Integrations
|
namespace Geekbot.net.Commands.Integrations
|
||||||
{
|
{
|
||||||
public class Mal : ModuleBase
|
public class Mal : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IMalClient _malClient;
|
private readonly IMalClient _malClient;
|
||||||
|
|
|
@ -4,13 +4,14 @@ using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Integrations.UbranDictionary
|
namespace Geekbot.net.Commands.Integrations.UbranDictionary
|
||||||
{
|
{
|
||||||
public class UrbanDictionary : ModuleBase
|
public class UrbanDictionary : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
|
@ -14,7 +15,7 @@ using WikipediaApi.Page;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Integrations
|
namespace Geekbot.net.Commands.Integrations
|
||||||
{
|
{
|
||||||
public class Wikipedia : ModuleBase
|
public class Wikipedia : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IWikipediaClient _wikipediaClient;
|
private readonly IWikipediaClient _wikipediaClient;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.GlobalSettings;
|
using Geekbot.net.Lib.GlobalSettings;
|
||||||
using Google.Apis.Services;
|
using Google.Apis.Services;
|
||||||
|
@ -8,7 +9,7 @@ using Google.Apis.YouTube.v3;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Integrations
|
namespace Geekbot.net.Commands.Integrations
|
||||||
{
|
{
|
||||||
public class Youtube : ModuleBase
|
public class Youtube : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IGlobalSettings _globalSettings;
|
private readonly IGlobalSettings _globalSettings;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
|
@ -2,12 +2,13 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.RandomNumberGenerator;
|
using Geekbot.net.Lib.RandomNumberGenerator;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness
|
namespace Geekbot.net.Commands.Randomness
|
||||||
{
|
{
|
||||||
public class BenedictCumberbatchNameGenerator : ModuleBase
|
public class BenedictCumberbatchNameGenerator : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||||
|
|
|
@ -3,12 +3,13 @@ using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness.Cat
|
namespace Geekbot.net.Commands.Randomness.Cat
|
||||||
{
|
{
|
||||||
public class Cat : ModuleBase
|
public class Cat : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,13 @@ using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Media;
|
using Geekbot.net.Lib.Media;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness
|
namespace Geekbot.net.Commands.Randomness
|
||||||
{
|
{
|
||||||
public class CheckEm : ModuleBase
|
public class CheckEm : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IMediaProvider _checkEmImages;
|
private readonly IMediaProvider _checkEmImages;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
|
@ -3,12 +3,13 @@ using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness.Chuck
|
namespace Geekbot.net.Commands.Randomness.Chuck
|
||||||
{
|
{
|
||||||
public class ChuckNorrisJokes : ModuleBase
|
public class ChuckNorrisJokes : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,13 @@ using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness.Dad
|
namespace Geekbot.net.Commands.Randomness.Dad
|
||||||
{
|
{
|
||||||
public class DadJokes : ModuleBase
|
public class DadJokes : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,13 @@ using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness.Dog
|
namespace Geekbot.net.Commands.Randomness.Dog
|
||||||
{
|
{
|
||||||
public class Dog : ModuleBase
|
public class Dog : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness
|
namespace Geekbot.net.Commands.Randomness
|
||||||
{
|
{
|
||||||
public class EightBall : ModuleBase
|
public class EightBall : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.Media;
|
using Geekbot.net.Lib.Media;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness
|
namespace Geekbot.net.Commands.Randomness
|
||||||
{
|
{
|
||||||
public class Fortune : ModuleBase
|
public class Fortune : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IFortunesProvider _fortunes;
|
private readonly IFortunesProvider _fortunes;
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness
|
namespace Geekbot.net.Commands.Randomness
|
||||||
{
|
{
|
||||||
public class Gdq : ModuleBase
|
public class Gdq : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,14 @@ using System.Net.Http.Headers;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Commands.Randomness.Dad;
|
using Geekbot.net.Commands.Randomness.Dad;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Microsoft.AspNetCore.Hosting.Internal;
|
using Microsoft.AspNetCore.Hosting.Internal;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness.Kanye
|
namespace Geekbot.net.Commands.Randomness.Kanye
|
||||||
{
|
{
|
||||||
public class Kanye : ModuleBase
|
public class Kanye : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.Media;
|
using Geekbot.net.Lib.Media;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness
|
namespace Geekbot.net.Commands.Randomness
|
||||||
{
|
{
|
||||||
public class RandomAnimals : ModuleBase
|
public class RandomAnimals : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IMediaProvider _mediaProvider;
|
private readonly IMediaProvider _mediaProvider;
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,14 @@ using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
using Geekbot.net.Lib.RandomNumberGenerator;
|
using Geekbot.net.Lib.RandomNumberGenerator;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness
|
namespace Geekbot.net.Commands.Randomness
|
||||||
{
|
{
|
||||||
public class Ship : ModuleBase
|
public class Ship : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||||
|
|
|
@ -6,12 +6,13 @@ using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Randomness
|
namespace Geekbot.net.Commands.Randomness
|
||||||
{
|
{
|
||||||
public class Slap : ModuleBase
|
public class Slap : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
|
@ -24,7 +25,7 @@ namespace Geekbot.net.Commands.Randomness
|
||||||
|
|
||||||
[Command("slap", RunMode = RunMode.Async)]
|
[Command("slap", RunMode = RunMode.Async)]
|
||||||
[Summary("slap someone")]
|
[Summary("slap someone")]
|
||||||
public async Task Slapper([Summary("@someone")] IUser user)
|
public async Task Slapper([Summary("@someone")] IGuildUser user)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -79,7 +80,7 @@ namespace Geekbot.net.Commands.Randomness
|
||||||
"powerless banhammer"
|
"powerless banhammer"
|
||||||
};
|
};
|
||||||
|
|
||||||
await ReplyAsync($"{Context.User.Username} slapped {user.Username} with a {things[new Random().Next(things.Count - 1)]}");
|
await ReplyAsync($"{Context.GuildUser.Nickname} slapped {user.Nickname} with a {things[new Random().Next(things.Count - 1)]}");
|
||||||
|
|
||||||
await UpdateRecieved(user.Id);
|
await UpdateRecieved(user.Id);
|
||||||
await UpdateGiven(Context.User.Id);
|
await UpdateGiven(Context.User.Id);
|
||||||
|
|
|
@ -5,6 +5,7 @@ using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.CommandPreconditions;
|
using Geekbot.net.Lib.CommandPreconditions;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
|
@ -15,18 +16,16 @@ namespace Geekbot.net.Commands.Rpg
|
||||||
{
|
{
|
||||||
[DisableInDirectMessage]
|
[DisableInDirectMessage]
|
||||||
[Group("cookies")]
|
[Group("cookies")]
|
||||||
public class Cookies : ModuleBase
|
public class Cookies : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly ITranslationHandler _translation;
|
|
||||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||||
|
|
||||||
public Cookies(DatabaseContext database, IErrorHandler errorHandler, ITranslationHandler translation , IRandomNumberGenerator randomNumberGenerator)
|
public Cookies(DatabaseContext database, IErrorHandler errorHandler, IRandomNumberGenerator randomNumberGenerator)
|
||||||
{
|
{
|
||||||
_database = database;
|
_database = database;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
_translation = translation;
|
|
||||||
_randomNumberGenerator = randomNumberGenerator;
|
_randomNumberGenerator = randomNumberGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,18 +35,17 @@ namespace Geekbot.net.Commands.Rpg
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translation.GetGuildContext(Context);
|
|
||||||
var actor = await GetUser(Context.User.Id);
|
var actor = await GetUser(Context.User.Id);
|
||||||
if (actor.LastPayout.Value.AddHours(24) > DateTimeOffset.Now)
|
if (actor.LastPayout.Value.AddHours(24) > DateTimeOffset.Now)
|
||||||
{
|
{
|
||||||
var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.LastPayout.Value.AddHours(24));
|
var formatedWaitTime = Context.Translations.FormatDateTimeAsRemaining(actor.LastPayout.Value.AddHours(24));
|
||||||
await ReplyAsync(transContext.GetString("WaitForMoreCookies", formatedWaitTime));
|
await ReplyAsync(Context.Translations.GetString("WaitForMoreCookies", formatedWaitTime));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
actor.Cookies += 10;
|
actor.Cookies += 10;
|
||||||
actor.LastPayout = DateTimeOffset.Now;
|
actor.LastPayout = DateTimeOffset.Now;
|
||||||
await SetUser(actor);
|
await SetUser(actor);
|
||||||
await ReplyAsync(transContext.GetString("GetCookies", 10, actor.Cookies));
|
await ReplyAsync(Context.Translations.GetString("GetCookies", 10, actor.Cookies));
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -62,9 +60,8 @@ namespace Geekbot.net.Commands.Rpg
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translation.GetGuildContext(Context);
|
|
||||||
var actor = await GetUser(Context.User.Id);
|
var actor = await GetUser(Context.User.Id);
|
||||||
await ReplyAsync(transContext.GetString("InYourJar", actor.Cookies));
|
await ReplyAsync(Context.Translations.GetString("InYourJar", actor.Cookies));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -78,12 +75,11 @@ namespace Geekbot.net.Commands.Rpg
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translation.GetGuildContext(Context);
|
|
||||||
var giver = await GetUser(Context.User.Id);
|
var giver = await GetUser(Context.User.Id);
|
||||||
|
|
||||||
if (giver.Cookies < amount)
|
if (giver.Cookies < amount)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("NotEnoughToGive"));
|
await ReplyAsync(Context.Translations.GetString("NotEnoughToGive"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +91,7 @@ namespace Geekbot.net.Commands.Rpg
|
||||||
await SetUser(giver);
|
await SetUser(giver);
|
||||||
await SetUser(taker);
|
await SetUser(taker);
|
||||||
|
|
||||||
await ReplyAsync(transContext.GetString("Given", amount, user.Username));
|
await ReplyAsync(Context.Translations.GetString("Given", amount, user.Username));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -109,12 +105,11 @@ namespace Geekbot.net.Commands.Rpg
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translation.GetGuildContext(Context);
|
|
||||||
var actor = await GetUser(Context.User.Id);
|
var actor = await GetUser(Context.User.Id);
|
||||||
|
|
||||||
if (actor.Cookies < 5)
|
if (actor.Cookies < 5)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("NotEnoughCookiesToEat"));
|
await ReplyAsync(Context.Translations.GetString("NotEnoughCookiesToEat"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +118,7 @@ namespace Geekbot.net.Commands.Rpg
|
||||||
|
|
||||||
await SetUser(actor);
|
await SetUser(actor);
|
||||||
|
|
||||||
await ReplyAsync(transContext.GetString("AteCookies", amount, actor.Cookies));
|
await ReplyAsync(Context.Translations.GetString("AteCookies", amount, actor.Cookies));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.CommandPreconditions;
|
using Geekbot.net.Lib.CommandPreconditions;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
|
@ -11,7 +12,7 @@ using Geekbot.net.Lib.Levels;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.User
|
namespace Geekbot.net.Commands.User
|
||||||
{
|
{
|
||||||
public class GuildInfo : ModuleBase
|
public class GuildInfo : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
|
|
|
@ -5,25 +5,23 @@ using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.CommandPreconditions;
|
using Geekbot.net.Lib.CommandPreconditions;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
using Geekbot.net.Lib.Localization;
|
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.User
|
namespace Geekbot.net.Commands.User
|
||||||
{
|
{
|
||||||
[DisableInDirectMessage]
|
[DisableInDirectMessage]
|
||||||
public class Karma : ModuleBase
|
public class Karma : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
private readonly ITranslationHandler _translation;
|
|
||||||
|
|
||||||
public Karma(DatabaseContext database, IErrorHandler errorHandler, ITranslationHandler translation)
|
public Karma(DatabaseContext database, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
_database = database;
|
_database = database;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
_translation = translation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("good", RunMode = RunMode.Async)]
|
[Command("good", RunMode = RunMode.Async)]
|
||||||
|
@ -32,16 +30,15 @@ namespace Geekbot.net.Commands.User
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translation.GetGuildContext(Context);
|
|
||||||
var actor = await GetUser(Context.User.Id);
|
var actor = await GetUser(Context.User.Id);
|
||||||
if (user.Id == Context.User.Id)
|
if (user.Id == Context.User.Id)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("CannotChangeOwn", Context.User.Username));
|
await ReplyAsync(Context.Translations.GetString("CannotChangeOwn", Context.User.Username));
|
||||||
}
|
}
|
||||||
else if (TimeoutFinished(actor.TimeOut))
|
else if (TimeoutFinished(actor.TimeOut))
|
||||||
{
|
{
|
||||||
var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
|
var formatedWaitTime = Context.Translations.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
|
||||||
await ReplyAsync(transContext.GetString("WaitUntill", Context.User.Username, formatedWaitTime));
|
await ReplyAsync(Context.Translations.GetString("WaitUntill", Context.User.Username, formatedWaitTime));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -60,10 +57,10 @@ namespace Geekbot.net.Commands.User
|
||||||
.WithName(user.Username));
|
.WithName(user.Username));
|
||||||
|
|
||||||
eb.WithColor(new Color(138, 219, 146));
|
eb.WithColor(new Color(138, 219, 146));
|
||||||
eb.Title = transContext.GetString("Increased");
|
eb.Title = Context.Translations.GetString("Increased");
|
||||||
eb.AddInlineField(transContext.GetString("By"), Context.User.Username);
|
eb.AddInlineField(Context.Translations.GetString("By"), Context.User.Username);
|
||||||
eb.AddInlineField(transContext.GetString("Amount"), "+1");
|
eb.AddInlineField(Context.Translations.GetString("Amount"), "+1");
|
||||||
eb.AddInlineField(transContext.GetString("Current"), target.Karma);
|
eb.AddInlineField(Context.Translations.GetString("Current"), target.Karma);
|
||||||
await ReplyAsync("", false, eb.Build());
|
await ReplyAsync("", false, eb.Build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,16 +76,15 @@ namespace Geekbot.net.Commands.User
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translation.GetGuildContext(Context);
|
|
||||||
var actor = await GetUser(Context.User.Id);
|
var actor = await GetUser(Context.User.Id);
|
||||||
if (user.Id == Context.User.Id)
|
if (user.Id == Context.User.Id)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("CannotChangeOwn", Context.User.Username));
|
await ReplyAsync(Context.Translations.GetString("CannotChangeOwn", Context.User.Username));
|
||||||
}
|
}
|
||||||
else if (TimeoutFinished(actor.TimeOut))
|
else if (TimeoutFinished(actor.TimeOut))
|
||||||
{
|
{
|
||||||
var formatedWaitTime = transContext.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
|
var formatedWaitTime = Context.Translations.FormatDateTimeAsRemaining(actor.TimeOut.AddMinutes(3));
|
||||||
await ReplyAsync(transContext.GetString("WaitUntill", Context.User.Username, formatedWaitTime));
|
await ReplyAsync(Context.Translations.GetString("WaitUntill", Context.User.Username, formatedWaitTime));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -107,10 +103,10 @@ namespace Geekbot.net.Commands.User
|
||||||
.WithName(user.Username));
|
.WithName(user.Username));
|
||||||
|
|
||||||
eb.WithColor(new Color(138, 219, 146));
|
eb.WithColor(new Color(138, 219, 146));
|
||||||
eb.Title = transContext.GetString("Decreased");
|
eb.Title = Context.Translations.GetString("Decreased");
|
||||||
eb.AddInlineField(transContext.GetString("By"), Context.User.Username);
|
eb.AddInlineField(Context.Translations.GetString("By"), Context.User.Username);
|
||||||
eb.AddInlineField(transContext.GetString("Amount"), "-1");
|
eb.AddInlineField(Context.Translations.GetString("Amount"), "-1");
|
||||||
eb.AddInlineField(transContext.GetString("Current"), target.Karma);
|
eb.AddInlineField(Context.Translations.GetString("Current"), target.Karma);
|
||||||
await ReplyAsync("", false, eb.Build());
|
await ReplyAsync("", false, eb.Build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.CommandPreconditions;
|
using Geekbot.net.Lib.CommandPreconditions;
|
||||||
using Geekbot.net.Lib.Converters;
|
using Geekbot.net.Lib.Converters;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
|
@ -15,24 +16,19 @@ using Geekbot.net.Lib.UserRepository;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.User.Ranking
|
namespace Geekbot.net.Commands.User.Ranking
|
||||||
{
|
{
|
||||||
public class Rank : ModuleBase
|
public class Rank : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IEmojiConverter _emojiConverter;
|
private readonly IEmojiConverter _emojiConverter;
|
||||||
private readonly IHighscoreManager _highscoreManager;
|
private readonly IHighscoreManager _highscoreManager;
|
||||||
private readonly ITranslationHandler _translationHandler;
|
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
private readonly IUserRepository _userRepository;
|
|
||||||
|
|
||||||
public Rank(DatabaseContext database, IErrorHandler errorHandler, IUserRepository userRepository,
|
public Rank(DatabaseContext database, IErrorHandler errorHandler, IEmojiConverter emojiConverter, IHighscoreManager highscoreManager)
|
||||||
IEmojiConverter emojiConverter, IHighscoreManager highscoreManager, ITranslationHandler translationHandler)
|
|
||||||
{
|
{
|
||||||
_database = database;
|
_database = database;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
_userRepository = userRepository;
|
|
||||||
_emojiConverter = emojiConverter;
|
_emojiConverter = emojiConverter;
|
||||||
_highscoreManager = highscoreManager;
|
_highscoreManager = highscoreManager;
|
||||||
_translationHandler = translationHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("rank", RunMode = RunMode.Async)]
|
[Command("rank", RunMode = RunMode.Async)]
|
||||||
|
@ -42,7 +38,6 @@ namespace Geekbot.net.Commands.User.Ranking
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translationHandler.GetGuildContext(Context);
|
|
||||||
HighscoreTypes type;
|
HighscoreTypes type;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -51,14 +46,14 @@ namespace Geekbot.net.Commands.User.Ranking
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("InvalidType"));
|
await ReplyAsync(Context.Translations.GetString("InvalidType"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var replyBuilder = new StringBuilder();
|
var replyBuilder = new StringBuilder();
|
||||||
if (amount > 20)
|
if (amount > 20)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("LimitingTo20Warning"));
|
await ReplyAsync(Context.Translations.GetString("LimitingTo20Warning"));
|
||||||
amount = 20;
|
amount = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +65,7 @@ namespace Geekbot.net.Commands.User.Ranking
|
||||||
}
|
}
|
||||||
catch (HighscoreListEmptyException)
|
catch (HighscoreListEmptyException)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("NoTypeFoundForServer", type));
|
await ReplyAsync(Context.Translations.GetString("NoTypeFoundForServer", type));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +80,8 @@ namespace Geekbot.net.Commands.User.Ranking
|
||||||
|
|
||||||
var failedToRetrieveUser = highscoreUsers.Any(e => string.IsNullOrEmpty(e.Key.Username));
|
var failedToRetrieveUser = highscoreUsers.Any(e => string.IsNullOrEmpty(e.Key.Username));
|
||||||
|
|
||||||
if (failedToRetrieveUser) replyBuilder.AppendLine(transContext.GetString("FailedToResolveAllUsernames"));
|
if (failedToRetrieveUser) replyBuilder.AppendLine(Context.Translations.GetString("FailedToResolveAllUsernames"));
|
||||||
replyBuilder.AppendLine(transContext.GetString("HighscoresFor", type.ToString().CapitalizeFirst(), Context.Guild.Name));
|
replyBuilder.AppendLine(Context.Translations.GetString("HighscoresFor", type.ToString().CapitalizeFirst(), Context.Guild.Name));
|
||||||
var highscorePlace = 1;
|
var highscorePlace = 1;
|
||||||
foreach (var user in highscoreUsers)
|
foreach (var user in highscoreUsers)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.AlmostRedis;
|
using Geekbot.net.Lib.AlmostRedis;
|
||||||
using Geekbot.net.Lib.CommandPreconditions;
|
using Geekbot.net.Lib.CommandPreconditions;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
|
@ -12,7 +13,7 @@ using Geekbot.net.Lib.Levels;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.User
|
namespace Geekbot.net.Commands.User
|
||||||
{
|
{
|
||||||
public class Stats : ModuleBase
|
public class Stats : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly ILevelCalc _levelCalc;
|
private readonly ILevelCalc _levelCalc;
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Utils
|
namespace Geekbot.net.Commands.Utils
|
||||||
{
|
{
|
||||||
public class AvatarGetter : ModuleBase
|
public class AvatarGetter : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,13 @@ using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Utils.Changelog
|
namespace Geekbot.net.Commands.Utils.Changelog
|
||||||
{
|
{
|
||||||
public class Changelog : ModuleBase
|
public class Changelog : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Localization;
|
using Geekbot.net.Lib.Localization;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Utils
|
namespace Geekbot.net.Commands.Utils
|
||||||
{
|
{
|
||||||
public class Choose : ModuleBase
|
public class Choose : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly ITranslationHandler _translation;
|
|
||||||
|
|
||||||
public Choose(IErrorHandler errorHandler, ITranslationHandler translation)
|
public Choose(IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
_translation = translation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("choose", RunMode = RunMode.Async)]
|
[Command("choose", RunMode = RunMode.Async)]
|
||||||
|
@ -24,10 +23,9 @@ namespace Geekbot.net.Commands.Utils
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translation.GetGuildContext(Context);
|
|
||||||
var choicesArray = choices.Split(';');
|
var choicesArray = choices.Split(';');
|
||||||
var choice = new Random().Next(choicesArray.Length);
|
var choice = new Random().Next(choicesArray.Length);
|
||||||
await ReplyAsync(transContext.GetString("Choice", choicesArray[choice].Trim()));
|
await ReplyAsync(Context.Translations.GetString("Choice", choicesArray[choice].Trim()));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,11 +4,12 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.RandomNumberGenerator;
|
using Geekbot.net.Lib.RandomNumberGenerator;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Utils.Dice
|
namespace Geekbot.net.Commands.Utils.Dice
|
||||||
{
|
{
|
||||||
public class Dice : ModuleBase
|
public class Dice : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.Converters;
|
using Geekbot.net.Lib.Converters;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Utils
|
namespace Geekbot.net.Commands.Utils
|
||||||
{
|
{
|
||||||
public class Emojify : ModuleBase
|
public class Emojify : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IEmojiConverter _emojiConverter;
|
private readonly IEmojiConverter _emojiConverter;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
|
@ -3,11 +3,12 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Utils
|
namespace Geekbot.net.Commands.Utils
|
||||||
{
|
{
|
||||||
public class Help : ModuleBase
|
public class Help : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ using Geekbot.net.Lib.Extensions;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Utils
|
namespace Geekbot.net.Commands.Utils
|
||||||
{
|
{
|
||||||
public class Info : ModuleBase
|
public class Info : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly CommandService _commands;
|
private readonly CommandService _commands;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
|
|
||||||
namespace Geekbot.net.Commands.Utils
|
namespace Geekbot.net.Commands.Utils
|
||||||
{
|
{
|
||||||
public class Ping : ModuleBase
|
public class Ping : GeekbotBase
|
||||||
{
|
{
|
||||||
[Command("👀", RunMode = RunMode.Async)]
|
[Command("👀", RunMode = RunMode.Async)]
|
||||||
[Summary("Look at the bot.")]
|
[Summary("Look at the bot.")]
|
||||||
|
|
|
@ -5,6 +5,7 @@ using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.CommandPreconditions;
|
using Geekbot.net.Lib.CommandPreconditions;
|
||||||
using Geekbot.net.Lib.ErrorHandling;
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
|
@ -16,19 +17,17 @@ namespace Geekbot.net.Commands.Utils.Quote
|
||||||
{
|
{
|
||||||
[Group("quote")]
|
[Group("quote")]
|
||||||
[DisableInDirectMessage]
|
[DisableInDirectMessage]
|
||||||
public class Quote : ModuleBase
|
public class Quote : GeekbotBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||||
private readonly ITranslationHandler _translationHandler;
|
|
||||||
|
|
||||||
public Quote(IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator, ITranslationHandler translationHandler)
|
public Quote(IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator)
|
||||||
{
|
{
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
_database = database;
|
_database = database;
|
||||||
_randomNumberGenerator = randomNumberGenerator;
|
_randomNumberGenerator = randomNumberGenerator;
|
||||||
_translationHandler = translationHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
|
@ -41,8 +40,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
||||||
|
|
||||||
if (!s.Any())
|
if (!s.Any())
|
||||||
{
|
{
|
||||||
var transContext = await _translationHandler.GetGuildContext(Context);
|
await ReplyAsync(Context.Translations.GetString("NoQuotesFound"));
|
||||||
await ReplyAsync(transContext.GetString("NoQuotesFound"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,16 +62,15 @@ namespace Geekbot.net.Commands.Utils.Quote
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translationHandler.GetGuildContext(Context);
|
|
||||||
if (user.Id == Context.Message.Author.Id)
|
if (user.Id == Context.Message.Author.Id)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("CannotSaveOwnQuotes"));
|
await ReplyAsync(Context.Translations.GetString("CannotSaveOwnQuotes"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.IsBot)
|
if (user.IsBot)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("CannotQuoteBots"));
|
await ReplyAsync(Context.Translations.GetString("CannotQuoteBots"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +82,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
|
|
||||||
var embed = QuoteBuilder(quote);
|
var embed = QuoteBuilder(quote);
|
||||||
await ReplyAsync(transContext.GetString("QuoteAdded"), false, embed.Build());
|
await ReplyAsync(Context.Translations.GetString("QuoteAdded"), false, embed.Build());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -100,17 +97,16 @@ namespace Geekbot.net.Commands.Utils.Quote
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translationHandler.GetGuildContext(Context);
|
|
||||||
var message = await Context.Channel.GetMessageAsync(messageId);
|
var message = await Context.Channel.GetMessageAsync(messageId);
|
||||||
if (message.Author.Id == Context.Message.Author.Id)
|
if (message.Author.Id == Context.Message.Author.Id)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("CannotSaveOwnQuotes"));
|
await ReplyAsync(Context.Translations.GetString("CannotSaveOwnQuotes"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.Author.IsBot)
|
if (message.Author.IsBot)
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("CannotQuoteBots"));
|
await ReplyAsync(Context.Translations.GetString("CannotQuoteBots"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +115,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
|
|
||||||
var embed = QuoteBuilder(quote);
|
var embed = QuoteBuilder(quote);
|
||||||
await ReplyAsync(transContext.GetString("QuoteAdded"), false, embed.Build());
|
await ReplyAsync(Context.Translations.GetString("QuoteAdded"), false, embed.Build());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -174,18 +170,17 @@ namespace Geekbot.net.Commands.Utils.Quote
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var transContext = await _translationHandler.GetGuildContext(Context);
|
|
||||||
var quote = _database.Quotes.Where(e => e.GuildId == Context.Guild.Id.AsLong() && e.InternalId == id)?.FirstOrDefault();
|
var quote = _database.Quotes.Where(e => e.GuildId == Context.Guild.Id.AsLong() && e.InternalId == id)?.FirstOrDefault();
|
||||||
if (quote != null)
|
if (quote != null)
|
||||||
{
|
{
|
||||||
_database.Quotes.Remove(quote);
|
_database.Quotes.Remove(quote);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
var embed = QuoteBuilder(quote);
|
var embed = QuoteBuilder(quote);
|
||||||
await ReplyAsync(transContext.GetString("Removed", id), false, embed.Build());
|
await ReplyAsync(Context.Translations.GetString("Removed", id), false, embed.Build());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await ReplyAsync(transContext.GetString("NotFoundWithId"));
|
await ReplyAsync(Context.Translations.GetString("NotFoundWithId"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -9,7 +9,9 @@ using Discord.WebSocket;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
using Geekbot.net.Lib.AlmostRedis;
|
using Geekbot.net.Lib.AlmostRedis;
|
||||||
|
using Geekbot.net.Lib.Context;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
|
using Geekbot.net.Lib.Localization;
|
||||||
using Geekbot.net.Lib.Logger;
|
using Geekbot.net.Lib.Logger;
|
||||||
using Geekbot.net.Lib.ReactionListener;
|
using Geekbot.net.Lib.ReactionListener;
|
||||||
using Geekbot.net.Lib.UserRepository;
|
using Geekbot.net.Lib.UserRepository;
|
||||||
|
@ -27,11 +29,12 @@ namespace Geekbot.net
|
||||||
private readonly CommandService _commands;
|
private readonly CommandService _commands;
|
||||||
private readonly IUserRepository _userRepository;
|
private readonly IUserRepository _userRepository;
|
||||||
private readonly IReactionListener _reactionListener;
|
private readonly IReactionListener _reactionListener;
|
||||||
|
private readonly ITranslationHandler _translationHandler;
|
||||||
private readonly DatabaseContext _messageCounterDatabaseContext;
|
private readonly DatabaseContext _messageCounterDatabaseContext;
|
||||||
|
|
||||||
public Handlers(DatabaseInitializer databaseInitializer, IDiscordClient client, IGeekbotLogger logger, IAlmostRedis redis,
|
public Handlers(DatabaseInitializer databaseInitializer, IDiscordClient client, IGeekbotLogger logger, IAlmostRedis redis,
|
||||||
IServiceProvider servicesProvider, CommandService commands, IUserRepository userRepository,
|
IServiceProvider servicesProvider, CommandService commands, IUserRepository userRepository,
|
||||||
IReactionListener reactionListener)
|
IReactionListener reactionListener, ITranslationHandler translationHandler)
|
||||||
{
|
{
|
||||||
_database = databaseInitializer.Initialize();
|
_database = databaseInitializer.Initialize();
|
||||||
_messageCounterDatabaseContext = databaseInitializer.Initialize();
|
_messageCounterDatabaseContext = databaseInitializer.Initialize();
|
||||||
|
@ -42,6 +45,7 @@ namespace Geekbot.net
|
||||||
_commands = commands;
|
_commands = commands;
|
||||||
_userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
_reactionListener = reactionListener;
|
_reactionListener = reactionListener;
|
||||||
|
_translationHandler = translationHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -79,7 +83,7 @@ namespace Geekbot.net
|
||||||
|
|
||||||
if (!(message.HasCharPrefix('!', ref argPos) ||
|
if (!(message.HasCharPrefix('!', ref argPos) ||
|
||||||
message.HasMentionPrefix(_client.CurrentUser, ref argPos))) return Task.CompletedTask;
|
message.HasMentionPrefix(_client.CurrentUser, ref argPos))) return Task.CompletedTask;
|
||||||
var context = new CommandContext(_client, message);
|
var context = new GeekbotContext(_client, message, _translationHandler);
|
||||||
var commandExec = _commands.ExecuteAsync(context, argPos, _servicesProvider);
|
var commandExec = _commands.ExecuteAsync(context, argPos, _servicesProvider);
|
||||||
_logger.Information(LogSource.Command,
|
_logger.Information(LogSource.Command,
|
||||||
context.Message.Content.Split(" ")[0].Replace("!", ""),
|
context.Message.Content.Split(" ")[0].Replace("!", ""),
|
||||||
|
|
56
Geekbot.net/Lib/Context/GeekbotContext.cs
Normal file
56
Geekbot.net/Lib/Context/GeekbotContext.cs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
using Discord;
|
||||||
|
using Geekbot.net.Lib.Localization;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Lib.Context
|
||||||
|
{
|
||||||
|
/// <summary> The context of a command which may contain the client, user, guild, channel, and message. </summary>
|
||||||
|
public class GeekbotContext : IGeekbotContext
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IDiscordClient Client { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IGuild Guild { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IMessageChannel Channel { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IUser User { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IUserMessage Message { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IGuildUser GuildUser { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public TranslationGuildContext Translations { get; }
|
||||||
|
|
||||||
|
/// <summary> Indicates whether the channel that the command is executed in is a private channel. </summary>
|
||||||
|
public bool IsPrivate
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.Channel is IPrivateChannel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new <see cref="T:Discord.Commands.CommandContext" /> class with the provided client and message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client">The underlying client.</param>
|
||||||
|
/// <param name="msg">The underlying message.</param>
|
||||||
|
/// <param name="translationHandler">the translation handler</param>
|
||||||
|
public GeekbotContext(IDiscordClient client, IUserMessage msg, ITranslationHandler translationHandler)
|
||||||
|
{
|
||||||
|
this.Client = client;
|
||||||
|
this.Guild = (msg.Channel as IGuildChannel)?.Guild;
|
||||||
|
this.Channel = msg.Channel;
|
||||||
|
this.User = msg.Author;
|
||||||
|
this.GuildUser = msg.Author as IGuildUser;
|
||||||
|
this.Message = msg;
|
||||||
|
this.Translations = translationHandler.GetGuildContext(this.Guild, this.Message).Result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
Geekbot.net/Lib/Context/IGeekbotContext.cs
Normal file
19
Geekbot.net/Lib/Context/IGeekbotContext.cs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
using Discord;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib.Localization;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Lib.Context
|
||||||
|
{
|
||||||
|
public interface IGeekbotContext : ICommandContext
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="T:Discord:IGuildUser"/> who executed the command.
|
||||||
|
/// </summary>
|
||||||
|
IGuildUser GuildUser { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="T:Geekbot:net:Lib:Localization:TranslationGuildContext"/> containing the necessary tools for command localization.
|
||||||
|
/// </summary>
|
||||||
|
TranslationGuildContext Translations { get; }
|
||||||
|
}
|
||||||
|
}
|
9
Geekbot.net/Lib/GeekbotBase.cs
Normal file
9
Geekbot.net/Lib/GeekbotBase.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib.Context;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Lib
|
||||||
|
{
|
||||||
|
public abstract class GeekbotBase : ModuleBase<GeekbotContext>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib.Localization
|
namespace Geekbot.net.Lib.Localization
|
||||||
|
@ -10,6 +11,7 @@ namespace Geekbot.net.Lib.Localization
|
||||||
string GetString(string language, string command, string stringName);
|
string GetString(string language, string command, string stringName);
|
||||||
Task<Dictionary<string, string>> GetDict(ICommandContext context, string command);
|
Task<Dictionary<string, string>> GetDict(ICommandContext context, string command);
|
||||||
Task<TranslationGuildContext> GetGuildContext(ICommandContext context);
|
Task<TranslationGuildContext> GetGuildContext(ICommandContext context);
|
||||||
|
Task<TranslationGuildContext> GetGuildContext(IGuild guild, IUserMessage message);
|
||||||
Task<bool> SetLanguage(ulong guildId, string language);
|
Task<bool> SetLanguage(ulong guildId, string language);
|
||||||
List<string> SupportedLanguages { get; }
|
List<string> SupportedLanguages { get; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,12 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Database;
|
using Geekbot.net.Database;
|
||||||
using Geekbot.net.Database.Models;
|
using Geekbot.net.Database.Models;
|
||||||
using Geekbot.net.Lib.Extensions;
|
using Geekbot.net.Lib.Extensions;
|
||||||
using Geekbot.net.Lib.Logger;
|
using Geekbot.net.Lib.Logger;
|
||||||
using Utf8Json;
|
|
||||||
using YamlDotNet.RepresentationModel;
|
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib.Localization
|
namespace Geekbot.net.Lib.Localization
|
||||||
|
@ -137,12 +136,17 @@ namespace Geekbot.net.Lib.Localization
|
||||||
return translation;
|
return translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Dictionary<string, string>> GetDict(ICommandContext context)
|
private Task<Dictionary<string, string>> GetDict(ICommandContext context)
|
||||||
|
{
|
||||||
|
return GetDict(context.Guild, context.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<Dictionary<string, string>> GetDict(IGuild guild, IUserMessage message)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var command = context.Message.Content.Split(' ').First().TrimStart('!').ToLower();
|
var command = message.Content.Split(' ').First().TrimStart('!').ToLower();
|
||||||
var serverLanguage = await GetServerLanguage(context.Guild?.Id ?? 0);
|
var serverLanguage = await GetServerLanguage(guild?.Id ?? 0);
|
||||||
return _translations[serverLanguage][command];
|
return _translations[serverLanguage][command];
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -159,6 +163,13 @@ namespace Geekbot.net.Lib.Localization
|
||||||
return new TranslationGuildContext(this, language, dict);
|
return new TranslationGuildContext(this, language, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<TranslationGuildContext> GetGuildContext(IGuild guild, IUserMessage message)
|
||||||
|
{
|
||||||
|
var dict = await GetDict(guild, message);
|
||||||
|
var language = await GetServerLanguage(guild?.Id ?? 0);
|
||||||
|
return new TranslationGuildContext(this, language, dict);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<string, string>> GetDict(ICommandContext context, string command)
|
public async Task<Dictionary<string, string>> GetDict(ICommandContext context, string command)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -170,7 +170,7 @@ namespace Geekbot.net
|
||||||
_servicesProvider = _services.BuildServiceProvider();
|
_servicesProvider = _services.BuildServiceProvider();
|
||||||
await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _servicesProvider);
|
await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _servicesProvider);
|
||||||
|
|
||||||
var handlers = new Handlers(_databaseInitializer, _client, _logger, _redis, _servicesProvider, _commands, _userRepository, reactionListener);
|
var handlers = new Handlers(_databaseInitializer, _client, _logger, _redis, _servicesProvider, _commands, _userRepository, reactionListener, translationHandler);
|
||||||
|
|
||||||
_client.MessageReceived += handlers.RunCommand;
|
_client.MessageReceived += handlers.RunCommand;
|
||||||
_client.MessageDeleted += handlers.MessageDeleted;
|
_client.MessageDeleted += handlers.MessageDeleted;
|
||||||
|
|
Loading…
Reference in a new issue