some small fixes

This commit is contained in:
Kwoth 2016-10-12 17:35:27 +02:00
parent 557450fefa
commit 4954d44b5a
7 changed files with 138 additions and 102 deletions

View File

@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Administration
switch (i)
{
case 0:
await Migrate0_9To1_0();
Migrate0_9To1_0();
break;
}
}
@ -64,19 +64,20 @@ namespace NadekoBot.Modules.Administration
}
}
private async Task Migrate0_9To1_0()
private void Migrate0_9To1_0()
{
using (var uow = DbHandler.UnitOfWork())
{
var botConfig = uow.BotConfig.GetOrCreate();
MigrateConfig0_9(uow, botConfig);
MigratePermissions0_9(uow);
//MigratePermissions0_9(uow);
MigrateServerSpecificConfigs0_9(uow);
MigrateDb0_9(uow);
//MigrateDb0_9(uow);
//NOW save it
botConfig.MigrationVersion = 1;
await uow.CompleteAsync().ConfigureAwait(false);
_log.Warn("Writing to disc");
uow.Complete();
}
}
@ -95,6 +96,7 @@ namespace NadekoBot.Modules.Administration
com.CommandText = "SELECT * FROM Announcement";
var reader = com.ExecuteReader();
var i = 0;
while (reader.Read())
{
var gid = (ulong)(long)reader["ServerId"];
@ -106,7 +108,7 @@ namespace NadekoBot.Modules.Administration
var byeDM = (long)reader["ByePM"] == 1;
var byeChannel = (ulong)(long)reader["ByeChannelId"];
var byeMsg = (string)reader["ByeText"];
bool grdel = (long)reader["DeleteGreetMessages"] == 1;
var grdel = false;
var byedel = grdel;
var gc = uow.GuildConfigs.For(gid);
@ -122,14 +124,17 @@ namespace NadekoBot.Modules.Administration
gc.ChannelByeMessageText = byeMsg;
gc.AutoDeleteByeMessages = gc.AutoDeleteGreetMessages = grdel;
_log.Info(++i);
}
var com2 = db.CreateCommand();
com.CommandText = "SELECT * FROM CurrencyState";
i = 0;
var reader2 = com.ExecuteReader();
while (reader2.Read())
{
_log.Info(++i);
uow.Currency.Add(new Currency()
{
Amount = (long)reader2["Value"],
@ -171,20 +176,24 @@ namespace NadekoBot.Modules.Administration
_log.Warn(ex, "ServerSpecificConfig deserialization failed");
return;
}
foreach (var config in configs)
var i = 0;
var selfAssRoles = new ConcurrentHashSet<SelfAssignedRole>();
configs
.Select(p => new { data = p.Value, gconfig = uow.GuildConfigs.For(p.Key) })
.AsParallel()
.ForAll(config =>
{
var guildId = config.Key;
var data = config.Value;
var guildConfig = uow.GuildConfigs.For(guildId);
try
{
var guildConfig = config.gconfig;
var data = config.data;
guildConfig.AutoAssignRoleId = data.AutoAssignedRole;
guildConfig.DeleteMessageOnCommand = data.AutoDeleteMessagesOnCommand;
guildConfig.DefaultMusicVolume = data.DefaultMusicVolume;
guildConfig.ExclusiveSelfAssignedRoles = data.ExclusiveSelfAssignedRoles;
guildConfig.GenerateCurrencyChannelIds = new HashSet<GCChannelId>(data.GenerateCurrencyChannels.Select(gc => new GCChannelId() { ChannelId = gc.Key }));
uow.SelfAssignedRoles.AddRange(data.ListOfSelfAssignableRoles.Select(r => new SelfAssignedRole() { GuildId = guildId, RoleId = r }).ToArray());
selfAssRoles.AddRange(data.ListOfSelfAssignableRoles.Select(r => new SelfAssignedRole() { GuildId = guildConfig.GuildId, RoleId = r }).ToArray());
var logSetting = guildConfig.LogSetting;
guildConfig.LogSetting.IsLogging = data.LogChannel != null;
guildConfig.LogSetting.ChannelId = data.LogChannel ?? 0;
@ -215,13 +224,20 @@ namespace NadekoBot.Modules.Administration
return new FollowedStream()
{
ChannelId = x.ChannelId,
GuildId = guildId,
GuildId = guildConfig.GuildId,
Username = x.Username.ToLowerInvariant(),
Type = type
};
}));
guildConfig.VoicePlusTextEnabled = data.VoicePlusTextEnabled;
_log.Info("Migrating SpecificConfig for {0} done ({1})", guildConfig.GuildId, ++i);
}
catch (Exception ex)
{
_log.Error(ex);
}
});
uow.SelfAssignedRoles.AddRange(selfAssRoles.ToArray());
try { File.Move("data/ServerSpecificConfigs.json", "data/DELETE_ME_ServerSpecificCOnfigs.json"); } catch { }
}
@ -245,14 +261,16 @@ namespace NadekoBot.Modules.Administration
}
catch { }
}
foreach (var perms in PermissionsDict)
var i = 0;
PermissionsDict
.Select(p => new { data = p.Value, gconfig = uow.GuildConfigs.For(p.Key) })
.AsParallel()
.ForAll(perms =>
{
var guildId = perms.Key;
var data = perms.Value;
_log.Info("Migrating data from permissions folder for {0}", guildId);
var gconfig = uow.GuildConfigs.For(guildId);
try
{
var data = perms.data;
var gconfig = perms.gconfig;
gconfig.PermissionRole = data.PermissionsControllerRole;
gconfig.VerbosePermissions = data.Verbose;
@ -283,10 +301,15 @@ namespace NadekoBot.Modules.Administration
CommandName = cc.Key,
Seconds = cc.Value
}));
var smodules = data.Permissions.Modules.Where(m => !m.Value);
try { Directory.Move("data/permissions","data/DELETE_ME_permissions"); } catch { }
_log.Info("Migrating data from permissions folder for {0} done ({1})", gconfig.GuildId, ++i);
}
catch (Exception ex)
{
_log.Error(ex);
}
});
try { Directory.Move("data/permissions", "data/DELETE_ME_permissions"); } catch { }
}

View File

@ -38,7 +38,7 @@ namespace NadekoBot.Modules.Utility
//need to do this the first time
if (uow.ConverterUnits.Empty())
{
var content = JsonConvert.DeserializeObject<List<MeasurementUnit>>(File.ReadAllText("units.json")).Select(u => new ConvertUnit()
var content = JsonConvert.DeserializeObject<List<MeasurementUnit>>(File.ReadAllText("data/units.json")).Select(u => new ConvertUnit()
{
Modifier = u.Modifier,
UnitType = u.UnitType,

View File

@ -15,5 +15,8 @@
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<DnxInvisibleFolder Include="data\permissions\" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -38,16 +38,17 @@ namespace NadekoBot.Services.Database.Repositories.Impl
/// <returns></returns>
public GuildConfig For(ulong guildId)
{
var config = _set.Include(gc => gc.FollowedStreams)
.Include(gc => gc.LogSetting)
.ThenInclude(ls => ls.IgnoredChannels)
.Include(gc => gc.LogSetting)
.ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds)
.Include(gc => gc.FilterInvitesChannelIds)
.Include(gc => gc.FilterWordsChannelIds)
.Include(gc => gc.FilteredWords)
.Include(gc => gc.GenerateCurrencyChannelIds)
.Include(gc => gc.CommandCooldowns)
var config = _set
//.Include(gc => gc.FollowedStreams)
// .Include(gc => gc.LogSetting)
// .ThenInclude(ls => ls.IgnoredChannels)
//.Include(gc => gc.LogSetting)
// .ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds)
//.Include(gc => gc.FilterInvitesChannelIds)
//.Include(gc => gc.FilterWordsChannelIds)
//.Include(gc => gc.FilteredWords)
//.Include(gc => gc.GenerateCurrencyChannelIds)
//.Include(gc => gc.CommandCooldowns)
.FirstOrDefault(c => c.GuildId == guildId);
if (config == null)

View File

@ -2,6 +2,7 @@
using Discord.WebSocket;
using ImageProcessorCore;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -31,6 +32,14 @@ namespace NadekoBot.Extensions
}
}
public static void AddRange<T>(this ConcurrentHashSet<T> target, IEnumerable<T> elements) where T : class
{
foreach (var item in elements)
{
target.Add(item);
}
}
public static bool IsInteger(this decimal number) => number == Math.Truncate(number);
public static string SanitizeMentions(this string str) =>

View File

@ -7,7 +7,7 @@
"emitEntryPoint": true,
"allowUnsafe": true,
"compile": {
"exclude": [ ],
"exclude": [ "data" ]
},
"copyToOutput": {
"include": [ "data", "libs" ],