Removed module projects because it can't work like that atm. Commented out package commands.
This commit is contained in:
@ -11,7 +11,6 @@ namespace NadekoBot.Core.Services.Database
|
||||
IQuoteRepository Quotes { get; }
|
||||
IGuildConfigRepository GuildConfigs { get; }
|
||||
IDonatorsRepository Donators { get; }
|
||||
IClashOfClansRepository ClashOfClans { get; }
|
||||
IReminderRepository Reminders { get; }
|
||||
ISelfAssignedRolesRepository SelfAssignedRoles { get; }
|
||||
IBotConfigRepository BotConfig { get; }
|
||||
|
@ -12,8 +12,6 @@ namespace NadekoBot.Core.Services.Database.Models
|
||||
public float CurrencyGenerationChance { get; set; } = 0.02f;
|
||||
public int CurrencyGenerationCooldown { get; set; } = 10;
|
||||
|
||||
public HashSet<ModulePrefix> ModulePrefixes { get; set; } = new HashSet<ModulePrefix>();
|
||||
|
||||
public List<PlayingStatus> RotatingStatusMessages { get; set; } = new List<PlayingStatus>();
|
||||
|
||||
public bool RotatingStatuses { get; set; } = false;
|
||||
@ -70,6 +68,7 @@ Nadeko Support Server: https://discord.gg/nadekobot";
|
||||
public bool CustomReactionsStartWith { get; set; } = false;
|
||||
public int XpPerMessage { get; set; } = 3;
|
||||
public int XpMinutesTimeout { get; set; } = 5;
|
||||
public HashSet<LoadedPackage> LoadedPackages { get; set; } = new HashSet<LoadedPackage>();
|
||||
}
|
||||
|
||||
public class BlockedCmdOrMdl : DbEntity
|
||||
@ -155,23 +154,4 @@ Nadeko Support Server: https://discord.gg/nadekobot";
|
||||
return ((RaceAnimal)obj).Icon == Icon;
|
||||
}
|
||||
}
|
||||
|
||||
public class ModulePrefix : DbEntity
|
||||
{
|
||||
public string ModuleName { get; set; }
|
||||
public string Prefix { get; set; }
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ModuleName.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if(!(obj is ModulePrefix))
|
||||
return base.Equals(obj);
|
||||
|
||||
return ((ModulePrefix)obj).ModuleName == ModuleName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace NadekoBot.Core.Services.Database.Models
|
||||
{
|
||||
public class ClashCaller : DbEntity
|
||||
{
|
||||
public int? SequenceNumber { get; set; } = null;
|
||||
public string CallUser { get; set; }
|
||||
|
||||
public DateTime TimeAdded { get; set; }
|
||||
|
||||
public bool BaseDestroyed { get; set; }
|
||||
|
||||
public int Stars { get; set; } = 3;
|
||||
|
||||
public int ClashWarId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(ClashWarId))]
|
||||
public ClashWar ClashWar { get; set; }
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using Discord;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace NadekoBot.Core.Services.Database.Models
|
||||
{
|
||||
public class ClashWar : DbEntity
|
||||
{
|
||||
public string EnemyClan { get; set; }
|
||||
public int Size { get; set; }
|
||||
public StateOfWar WarState { get; set; } = StateOfWar.Created;
|
||||
public DateTime StartedAt { get; set; }
|
||||
|
||||
public ulong GuildId { get; set; }
|
||||
public ulong ChannelId { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public ITextChannel Channel { get; set; }
|
||||
|
||||
public List<ClashCaller> Bases { get; set; } = new List<ClashCaller>();
|
||||
}
|
||||
|
||||
public enum DestroyStars
|
||||
{
|
||||
One, Two, Three
|
||||
}
|
||||
public enum StateOfWar
|
||||
{
|
||||
Started, Ended, Created
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ using System;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System.IO;
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
|
||||
namespace NadekoBot.Core.Services.Database
|
||||
{
|
||||
@ -170,16 +169,7 @@ namespace NadekoBot.Core.Services.Database
|
||||
// .HasForeignKey(mp => mp.BotConfigId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region ClashOfClans
|
||||
|
||||
var callersEntity = modelBuilder.Entity<ClashCaller>();
|
||||
callersEntity
|
||||
.HasOne(c => c.ClashWar)
|
||||
.WithMany(c => c.Bases);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Self Assignable Roles
|
||||
|
||||
var selfassignableRolesEntity = modelBuilder.Entity<SelfAssignedRole>();
|
||||
|
@ -1,10 +0,0 @@
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NadekoBot.Core.Services.Database.Repositories
|
||||
{
|
||||
public interface IClashOfClansRepository : IRepository<ClashWar>
|
||||
{
|
||||
IEnumerable<ClashWar> GetAllWars(List<long> guilds);
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
using NadekoBot.Core.Services.Database.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
||||
{
|
||||
public class ClashOfClansRepository : Repository<ClashWar>, IClashOfClansRepository
|
||||
{
|
||||
public ClashOfClansRepository(DbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<ClashWar> GetAllWars(List<long> guilds)
|
||||
{
|
||||
var toReturn = _set
|
||||
.Where(cw => guilds.Contains((long)cw.GuildId))
|
||||
.Include(cw => cw.Bases)
|
||||
.ToList();
|
||||
toReturn.ForEach(cw => cw.Bases = cw.Bases.Where(w => w.SequenceNumber != null).OrderBy(w => w.SequenceNumber).ToList());
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
}
|
@ -18,9 +18,6 @@ namespace NadekoBot.Core.Services.Database
|
||||
private IDonatorsRepository _donators;
|
||||
public IDonatorsRepository Donators => _donators ?? (_donators = new DonatorsRepository(_context));
|
||||
|
||||
private IClashOfClansRepository _clashOfClans;
|
||||
public IClashOfClansRepository ClashOfClans => _clashOfClans ?? (_clashOfClans = new ClashOfClansRepository(_context));
|
||||
|
||||
private IReminderRepository _reminders;
|
||||
public IReminderRepository Reminders => _reminders ?? (_reminders = new ReminderRepository(_context));
|
||||
|
||||
|
@ -380,94 +380,113 @@ namespace NadekoBot
|
||||
return sub.PublishAsync(Client.CurrentUser.Id + "_status.game_set", JsonConvert.SerializeObject(obj));
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, (IEnumerable<ModuleInfo> Modules, IEnumerable<Type> Types)> _loadedPackages = new Dictionary<string, (IEnumerable<ModuleInfo>, IEnumerable<Type>)>();
|
||||
private readonly SemaphoreSlim _packageLocker = new SemaphoreSlim(1, 1);
|
||||
public IEnumerable<string> LoadedPackages => _loadedPackages.Keys;
|
||||
//private readonly Dictionary<string, (IEnumerable<ModuleInfo> Modules, IEnumerable<Type> Types)> _loadedPackages = new Dictionary<string, (IEnumerable<ModuleInfo>, IEnumerable<Type>)>();
|
||||
//private readonly SemaphoreSlim _packageLocker = new SemaphoreSlim(1, 1);
|
||||
//public IEnumerable<string> LoadedPackages => _loadedPackages.Keys;
|
||||
|
||||
/// <summary>
|
||||
/// Unloads a package
|
||||
/// </summary>
|
||||
/// <param name="name">Package name. Case sensitive.</param>
|
||||
/// <returns>Whether the unload is successful.</returns>
|
||||
public async Task<bool> UnloadPackage(string name)
|
||||
{
|
||||
await _packageLocker.WaitAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
if (!_loadedPackages.TryGetValue(name, out var data))
|
||||
return false;
|
||||
///// <summary>
|
||||
///// Unloads a package
|
||||
///// </summary>
|
||||
///// <param name="name">Package name. Case sensitive.</param>
|
||||
///// <returns>Whether the unload is successful.</returns>
|
||||
//public async Task<bool> UnloadPackage(string name)
|
||||
//{
|
||||
// await _packageLocker.WaitAsync().ConfigureAwait(false);
|
||||
// try
|
||||
// {
|
||||
// if (!_loadedPackages.Remove(name, out var data))
|
||||
// return false;
|
||||
|
||||
var modules = data.Modules;
|
||||
var types = data.Types;
|
||||
// var modules = data.Modules;
|
||||
// var types = data.Types;
|
||||
|
||||
var i = 0;
|
||||
foreach (var m in modules)
|
||||
{
|
||||
await CommandService.RemoveModuleAsync(m).ConfigureAwait(false);
|
||||
i++;
|
||||
}
|
||||
_log.Info("Unloaded {0} modules.", i);
|
||||
// var i = 0;
|
||||
// foreach (var m in modules)
|
||||
// {
|
||||
// await CommandService.RemoveModuleAsync(m).ConfigureAwait(false);
|
||||
// i++;
|
||||
// }
|
||||
// _log.Info("Unloaded {0} modules.", i);
|
||||
|
||||
if (types != null && types.Any())
|
||||
{
|
||||
i = 0;
|
||||
foreach (var t in types)
|
||||
{
|
||||
var obj = Services.Unload(t);
|
||||
if (obj is IUnloadableService s)
|
||||
await s.Unload().ConfigureAwait(false);
|
||||
i++;
|
||||
}
|
||||
// if (types != null && types.Any())
|
||||
// {
|
||||
// i = 0;
|
||||
// foreach (var t in types)
|
||||
// {
|
||||
// var obj = Services.Unload(t);
|
||||
// if (obj is IUnloadableService s)
|
||||
// await s.Unload().ConfigureAwait(false);
|
||||
// i++;
|
||||
// }
|
||||
|
||||
_log.Info("Unloaded {0} types.", i);
|
||||
}
|
||||
// _log.Info("Unloaded {0} types.", i);
|
||||
// }
|
||||
// using (var uow = _db.UnitOfWork)
|
||||
// {
|
||||
// uow.BotConfig.GetOrCreate().LoadedPackages.Remove(new LoadedPackage
|
||||
// {
|
||||
// Name = name,
|
||||
// });
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// _packageLocker.Release();
|
||||
// }
|
||||
//}
|
||||
///// <summary>
|
||||
///// Loads a package
|
||||
///// </summary>
|
||||
///// <param name="name">Name of the package to load. Case sensitive.</param>
|
||||
///// <returns>Whether the load is successful.</returns>
|
||||
//public async Task<bool> LoadPackage(string name)
|
||||
//{
|
||||
// await _packageLocker.WaitAsync().ConfigureAwait(false);
|
||||
// try
|
||||
// {
|
||||
// if (_loadedPackages.ContainsKey(name))
|
||||
// return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_packageLocker.Release();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Loads a package
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the package to load. Case sensitive.</param>
|
||||
/// <returns>Whether the load is successful.</returns>
|
||||
public async Task<bool> LoadPackage(string name)
|
||||
{
|
||||
await _packageLocker.WaitAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
if (_loadedPackages.ContainsKey(name))
|
||||
return false;
|
||||
// var startingGuildIdList = Client.Guilds.Select(x => (long)x.Id).ToList();
|
||||
// using (var uow = _db.UnitOfWork)
|
||||
// {
|
||||
// AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
|
||||
// }
|
||||
|
||||
var startingGuildIdList = Client.Guilds.Select(x => (long)x.Id).ToList();
|
||||
using (var uow = _db.UnitOfWork)
|
||||
{
|
||||
AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
|
||||
}
|
||||
var package = Assembly.LoadFile(Path.Combine(AppContext.BaseDirectory,
|
||||
"modules",
|
||||
$"NadekoBot.Modules.{name}",
|
||||
$"NadekoBot.Modules.{name}.dll"));
|
||||
var types = Services.LoadFrom(package);
|
||||
var added = await CommandService.AddModulesAsync(package).ConfigureAwait(false);
|
||||
var trs = LoadTypeReaders(package);
|
||||
/* i don't have to unload typereaders
|
||||
* (and there's no api for it)
|
||||
* because they get overwritten anyway, and since
|
||||
* the only time I'd unload typereaders, is when unloading a module
|
||||
* which means they won't have a chance to be used
|
||||
* */
|
||||
_log.Info("Loaded {0} modules and {1} types.", added.Count(), types.Count());
|
||||
_loadedPackages.Add(name, (added, types));
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_packageLocker.Release();
|
||||
}
|
||||
}
|
||||
// var domain = new Context();
|
||||
// var package = domain.LoadFromAssemblyPath(Path.Combine(AppContext.BaseDirectory,
|
||||
// "modules",
|
||||
// $"NadekoBot.Modules.{name}",
|
||||
// $"NadekoBot.Modules.{name}.dll"));
|
||||
// //var package = Assembly.LoadFile(Path.Combine(AppContext.BaseDirectory,
|
||||
// // "modules",
|
||||
// // $"NadekoBot.Modules.{name}",
|
||||
// // $"NadekoBot.Modules.{name}.dll"));
|
||||
// var types = Services.LoadFrom(package);
|
||||
// var added = await CommandService.AddModulesAsync(package).ConfigureAwait(false);
|
||||
// var trs = LoadTypeReaders(package);
|
||||
// /* i don't have to unload typereaders
|
||||
// * (and there's no api for it)
|
||||
// * because they get overwritten anyway, and since
|
||||
// * the only time I'd unload typereaders, is when unloading a module
|
||||
// * which means they won't have a chance to be used
|
||||
// * */
|
||||
// _log.Info("Loaded {0} modules and {1} types.", added.Count(), types.Count());
|
||||
// _loadedPackages.Add(name, (added, types));
|
||||
// using (var uow = _db.UnitOfWork)
|
||||
// {
|
||||
// uow.BotConfig.GetOrCreate().LoadedPackages.Add(new LoadedPackage
|
||||
// {
|
||||
// Name = name,
|
||||
// });
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// _packageLocker.Release();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -110,8 +110,12 @@ namespace NadekoBot.Core.Services
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
//todo change to 0
|
||||
for (int i = 1; i < _creds.TotalShards; i++)
|
||||
int i = 0;
|
||||
#if DEBUG
|
||||
i = 1;
|
||||
#endif
|
||||
|
||||
for (; i < _creds.TotalShards; i++)
|
||||
{
|
||||
var p = StartShard(i);
|
||||
|
||||
|
Reference in New Issue
Block a user