Cleanup part1
This commit is contained in:
parent
cdd63786ff
commit
4a2fc087f3
@ -27,12 +27,8 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
RotatingStatusMessages = NadekoBot.BotConfig.RotatingStatusMessages;
|
||||||
{
|
RotatingStatuses = NadekoBot.BotConfig.RotatingStatuses;
|
||||||
var conf = uow.BotConfig.GetOrCreate();
|
|
||||||
RotatingStatusMessages = conf.RotatingStatusMessages;
|
|
||||||
RotatingStatuses = conf.RotatingStatuses;
|
|
||||||
}
|
|
||||||
|
|
||||||
var t = Task.Run(async () =>
|
var t = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
@ -77,7 +77,7 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
|
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
animals = new ConcurrentQueue<string>(uow.BotConfig.GetOrCreate().RaceAnimals.Select(ra => ra.Icon).Shuffle());
|
animals = new ConcurrentQueue<string>(NadekoBot.BotConfig.RaceAnimals.Select(ra => ra.Icon).Shuffle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,14 +20,9 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
|
|
||||||
static Gambling()
|
static Gambling()
|
||||||
{
|
{
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
CurrencyName = NadekoBot.BotConfig.CurrencyName;
|
||||||
{
|
CurrencyPluralName = NadekoBot.BotConfig.CurrencyPluralName;
|
||||||
var conf = uow.BotConfig.GetOrCreate();
|
CurrencySign = NadekoBot.BotConfig.CurrencySign;
|
||||||
|
|
||||||
CurrencyName = conf.CurrencyName;
|
|
||||||
CurrencySign = conf.CurrencySign;
|
|
||||||
CurrencyPluralName = conf.CurrencyPluralName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long GetCurrency(ulong id)
|
public static long GetCurrency(ulong id)
|
||||||
|
@ -38,32 +38,17 @@ namespace NadekoBot.Modules.Games
|
|||||||
|
|
||||||
private static ConcurrentHashSet<ulong> usersRecentlyPicked { get; } = new ConcurrentHashSet<ulong>();
|
private static ConcurrentHashSet<ulong> usersRecentlyPicked { get; } = new ConcurrentHashSet<ulong>();
|
||||||
|
|
||||||
private static float chance { get; }
|
|
||||||
private static int cooldown { get; }
|
|
||||||
private static Logger _log { get; }
|
private static Logger _log { get; }
|
||||||
|
|
||||||
static PlantPickCommands()
|
static PlantPickCommands()
|
||||||
{
|
{
|
||||||
_log = LogManager.GetCurrentClassLogger();
|
_log = LogManager.GetCurrentClassLogger();
|
||||||
var sw = Stopwatch.StartNew();
|
|
||||||
|
|
||||||
|
|
||||||
#if !GLOBAL_NADEKO
|
#if !GLOBAL_NADEKO
|
||||||
NadekoBot.Client.MessageReceived += PotentialFlowerGeneration;
|
NadekoBot.Client.MessageReceived += PotentialFlowerGeneration;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
|
||||||
{
|
|
||||||
var conf = uow.BotConfig.GetOrCreate();
|
|
||||||
var x =
|
|
||||||
generationChannels = new ConcurrentHashSet<ulong>(NadekoBot.AllGuildConfigs
|
generationChannels = new ConcurrentHashSet<ulong>(NadekoBot.AllGuildConfigs
|
||||||
.SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId)));
|
.SelectMany(c => c.GenerateCurrencyChannelIds.Select(obj => obj.ChannelId)));
|
||||||
chance = conf.CurrencyGenerationChance;
|
|
||||||
cooldown = conf.CurrencyGenerationCooldown;
|
|
||||||
}
|
|
||||||
|
|
||||||
sw.Stop();
|
|
||||||
_log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async void PotentialFlowerGeneration(SocketMessage imsg)
|
private static async void PotentialFlowerGeneration(SocketMessage imsg)
|
||||||
@ -84,10 +69,10 @@ namespace NadekoBot.Modules.Games
|
|||||||
var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue);
|
var lastGeneration = lastGenerations.GetOrAdd(channel.Id, DateTime.MinValue);
|
||||||
var rng = new NadekoRandom();
|
var rng = new NadekoRandom();
|
||||||
|
|
||||||
if (DateTime.Now - TimeSpan.FromSeconds(cooldown) < lastGeneration) //recently generated in this channel, don't generate again
|
if (DateTime.Now - TimeSpan.FromSeconds(NadekoBot.BotConfig.CurrencyGenerationCooldown) < lastGeneration) //recently generated in this channel, don't generate again
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var num = rng.Next(1, 101) + chance * 100;
|
var num = rng.Next(1, 101) + NadekoBot.BotConfig.CurrencyGenerationChance * 100;
|
||||||
|
|
||||||
if (num > 100)
|
if (num > 100)
|
||||||
{
|
{
|
||||||
|
@ -13,14 +13,7 @@ namespace NadekoBot.Modules.Games
|
|||||||
[NadekoModule("Games", ">")]
|
[NadekoModule("Games", ">")]
|
||||||
public partial class Games : DiscordModule
|
public partial class Games : DiscordModule
|
||||||
{
|
{
|
||||||
private IEnumerable<string> _8BallResponses {
|
private static IEnumerable<string> _8BallResponses { get; } = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text);
|
||||||
get {
|
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
|
||||||
{
|
|
||||||
return uow.BotConfig.GetOrCreate().EightBallResponses.Select(ebr => ebr.Text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
@ -15,26 +15,10 @@ namespace NadekoBot.Modules.Help
|
|||||||
[NadekoModule("Help", "-")]
|
[NadekoModule("Help", "-")]
|
||||||
public partial class Help : DiscordModule
|
public partial class Help : DiscordModule
|
||||||
{
|
{
|
||||||
private static string helpString { get; }
|
private static string helpString { get; } = NadekoBot.BotConfig.HelpString;
|
||||||
public static string HelpString => String.Format(helpString, NadekoBot.Credentials.ClientId, NadekoBot.ModulePrefixes[typeof(Help).Name]);
|
public static string HelpString => String.Format(helpString, NadekoBot.Credentials.ClientId, NadekoBot.ModulePrefixes[typeof(Help).Name]);
|
||||||
|
|
||||||
public static string DMHelpString { get; }
|
public static string DMHelpString { get; } = NadekoBot.BotConfig.DMHelpString;
|
||||||
|
|
||||||
static Help()
|
|
||||||
{
|
|
||||||
|
|
||||||
//todo don't cache this, just query db when someone wants -h
|
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
|
||||||
{
|
|
||||||
var config = uow.BotConfig.GetOrCreate();
|
|
||||||
helpString = config.HelpString;
|
|
||||||
DMHelpString = config.DMHelpString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Help() : base()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
public async Task Modules()
|
public async Task Modules()
|
||||||
|
@ -40,9 +40,8 @@ namespace NadekoBot.Modules.Utility
|
|||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
reminders = uow.Reminders.GetAll().ToList();
|
reminders = uow.Reminders.GetAll().ToList();
|
||||||
|
|
||||||
RemindMessageFormat = uow.BotConfig.GetOrCreate().RemindMessageFormat;
|
|
||||||
}
|
}
|
||||||
|
RemindMessageFormat = NadekoBot.BotConfig.RemindMessageFormat;
|
||||||
|
|
||||||
foreach (var r in reminders)
|
foreach (var r in reminders)
|
||||||
{
|
{
|
||||||
|
@ -38,6 +38,7 @@ namespace NadekoBot
|
|||||||
public static bool Ready { get; private set; }
|
public static bool Ready { get; private set; }
|
||||||
|
|
||||||
public static IEnumerable<GuildConfig> AllGuildConfigs { get; }
|
public static IEnumerable<GuildConfig> AllGuildConfigs { get; }
|
||||||
|
public static BotConfig BotConfig { get; }
|
||||||
|
|
||||||
static NadekoBot()
|
static NadekoBot()
|
||||||
{
|
{
|
||||||
@ -47,6 +48,7 @@ namespace NadekoBot
|
|||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs();
|
AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs();
|
||||||
|
BotConfig = uow.BotConfig.GetOrCreate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,10 +100,9 @@ namespace NadekoBot
|
|||||||
_log.Info("Connected");
|
_log.Info("Connected");
|
||||||
|
|
||||||
//load commands and prefixes
|
//load commands and prefixes
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
|
||||||
{
|
ModulePrefixes = new ConcurrentDictionary<string, string>(NadekoBot.BotConfig.ModulePrefixes.OrderByDescending(mp => mp.Prefix.Length).ToDictionary(m => m.ModuleName, m => m.Prefix));
|
||||||
ModulePrefixes = new ConcurrentDictionary<string, string>(uow.BotConfig.GetOrCreate().ModulePrefixes.OrderByDescending(mp => mp.Prefix.Length).ToDictionary(m => m.ModuleName, m => m.Prefix));
|
|
||||||
}
|
|
||||||
// start handling messages received in commandhandler
|
// start handling messages received in commandhandler
|
||||||
await CommandHandler.StartHandling().ConfigureAwait(false);
|
await CommandHandler.StartHandling().ConfigureAwait(false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user