some small fixes
This commit is contained in:
parent
557450fefa
commit
4954d44b5a
@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
await Migrate0_9To1_0();
|
Migrate0_9To1_0();
|
||||||
break;
|
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())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
var botConfig = uow.BotConfig.GetOrCreate();
|
var botConfig = uow.BotConfig.GetOrCreate();
|
||||||
MigrateConfig0_9(uow, botConfig);
|
MigrateConfig0_9(uow, botConfig);
|
||||||
MigratePermissions0_9(uow);
|
//MigratePermissions0_9(uow);
|
||||||
MigrateServerSpecificConfigs0_9(uow);
|
MigrateServerSpecificConfigs0_9(uow);
|
||||||
MigrateDb0_9(uow);
|
//MigrateDb0_9(uow);
|
||||||
|
|
||||||
//NOW save it
|
//NOW save it
|
||||||
botConfig.MigrationVersion = 1;
|
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";
|
com.CommandText = "SELECT * FROM Announcement";
|
||||||
|
|
||||||
var reader = com.ExecuteReader();
|
var reader = com.ExecuteReader();
|
||||||
|
var i = 0;
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
var gid = (ulong)(long)reader["ServerId"];
|
var gid = (ulong)(long)reader["ServerId"];
|
||||||
@ -106,7 +108,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
var byeDM = (long)reader["ByePM"] == 1;
|
var byeDM = (long)reader["ByePM"] == 1;
|
||||||
var byeChannel = (ulong)(long)reader["ByeChannelId"];
|
var byeChannel = (ulong)(long)reader["ByeChannelId"];
|
||||||
var byeMsg = (string)reader["ByeText"];
|
var byeMsg = (string)reader["ByeText"];
|
||||||
bool grdel = (long)reader["DeleteGreetMessages"] == 1;
|
var grdel = false;
|
||||||
var byedel = grdel;
|
var byedel = grdel;
|
||||||
var gc = uow.GuildConfigs.For(gid);
|
var gc = uow.GuildConfigs.For(gid);
|
||||||
|
|
||||||
@ -122,14 +124,17 @@ namespace NadekoBot.Modules.Administration
|
|||||||
gc.ChannelByeMessageText = byeMsg;
|
gc.ChannelByeMessageText = byeMsg;
|
||||||
|
|
||||||
gc.AutoDeleteByeMessages = gc.AutoDeleteGreetMessages = grdel;
|
gc.AutoDeleteByeMessages = gc.AutoDeleteGreetMessages = grdel;
|
||||||
|
_log.Info(++i);
|
||||||
}
|
}
|
||||||
|
|
||||||
var com2 = db.CreateCommand();
|
var com2 = db.CreateCommand();
|
||||||
com.CommandText = "SELECT * FROM CurrencyState";
|
com.CommandText = "SELECT * FROM CurrencyState";
|
||||||
|
|
||||||
|
i = 0;
|
||||||
var reader2 = com.ExecuteReader();
|
var reader2 = com.ExecuteReader();
|
||||||
while (reader2.Read())
|
while (reader2.Read())
|
||||||
{
|
{
|
||||||
|
_log.Info(++i);
|
||||||
uow.Currency.Add(new Currency()
|
uow.Currency.Add(new Currency()
|
||||||
{
|
{
|
||||||
Amount = (long)reader2["Value"],
|
Amount = (long)reader2["Value"],
|
||||||
@ -171,57 +176,68 @@ namespace NadekoBot.Modules.Administration
|
|||||||
_log.Warn(ex, "ServerSpecificConfig deserialization failed");
|
_log.Warn(ex, "ServerSpecificConfig deserialization failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var i = 0;
|
||||||
foreach (var config in configs)
|
var selfAssRoles = new ConcurrentHashSet<SelfAssignedRole>();
|
||||||
{
|
configs
|
||||||
var guildId = config.Key;
|
.Select(p => new { data = p.Value, gconfig = uow.GuildConfigs.For(p.Key) })
|
||||||
var data = config.Value;
|
.AsParallel()
|
||||||
|
.ForAll(config =>
|
||||||
var guildConfig = uow.GuildConfigs.For(guildId);
|
|
||||||
|
|
||||||
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());
|
|
||||||
var logSetting = guildConfig.LogSetting;
|
|
||||||
guildConfig.LogSetting.IsLogging = data.LogChannel != null;
|
|
||||||
guildConfig.LogSetting.ChannelId = data.LogChannel ?? 0;
|
|
||||||
guildConfig.LogSetting.IgnoredChannels = new HashSet<IgnoredLogChannel>(data.LogserverIgnoreChannels.Select(id => new IgnoredLogChannel() { ChannelId = id }));
|
|
||||||
|
|
||||||
guildConfig.LogSetting.LogUserPresence = data.LogPresenceChannel != null;
|
|
||||||
guildConfig.LogSetting.UserPresenceChannelId = data.LogPresenceChannel ?? 0;
|
|
||||||
|
|
||||||
|
|
||||||
guildConfig.FollowedStreams = new HashSet<FollowedStream>(data.ObservingStreams.Select(x =>
|
|
||||||
{
|
{
|
||||||
FollowedStream.FollowedStreamType type = FollowedStream.FollowedStreamType.Twitch;
|
try
|
||||||
switch (x.Type)
|
|
||||||
{
|
{
|
||||||
case StreamNotificationConfig0_9.StreamType.Twitch:
|
var guildConfig = config.gconfig;
|
||||||
type = FollowedStream.FollowedStreamType.Twitch;
|
var data = config.data;
|
||||||
break;
|
|
||||||
case StreamNotificationConfig0_9.StreamType.Beam:
|
|
||||||
type = FollowedStream.FollowedStreamType.Beam;
|
|
||||||
break;
|
|
||||||
case StreamNotificationConfig0_9.StreamType.Hitbox:
|
|
||||||
type = FollowedStream.FollowedStreamType.Hitbox;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new FollowedStream()
|
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 }));
|
||||||
|
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;
|
||||||
|
guildConfig.LogSetting.IgnoredChannels = new HashSet<IgnoredLogChannel>(data.LogserverIgnoreChannels.Select(id => new IgnoredLogChannel() { ChannelId = id }));
|
||||||
|
|
||||||
|
guildConfig.LogSetting.LogUserPresence = data.LogPresenceChannel != null;
|
||||||
|
guildConfig.LogSetting.UserPresenceChannelId = data.LogPresenceChannel ?? 0;
|
||||||
|
|
||||||
|
|
||||||
|
guildConfig.FollowedStreams = new HashSet<FollowedStream>(data.ObservingStreams.Select(x =>
|
||||||
|
{
|
||||||
|
FollowedStream.FollowedStreamType type = FollowedStream.FollowedStreamType.Twitch;
|
||||||
|
switch (x.Type)
|
||||||
|
{
|
||||||
|
case StreamNotificationConfig0_9.StreamType.Twitch:
|
||||||
|
type = FollowedStream.FollowedStreamType.Twitch;
|
||||||
|
break;
|
||||||
|
case StreamNotificationConfig0_9.StreamType.Beam:
|
||||||
|
type = FollowedStream.FollowedStreamType.Beam;
|
||||||
|
break;
|
||||||
|
case StreamNotificationConfig0_9.StreamType.Hitbox:
|
||||||
|
type = FollowedStream.FollowedStreamType.Hitbox;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FollowedStream()
|
||||||
|
{
|
||||||
|
ChannelId = x.ChannelId,
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
ChannelId = x.ChannelId,
|
_log.Error(ex);
|
||||||
GuildId = guildId,
|
}
|
||||||
Username = x.Username.ToLowerInvariant(),
|
});
|
||||||
Type = type
|
uow.SelfAssignedRoles.AddRange(selfAssRoles.ToArray());
|
||||||
};
|
|
||||||
}));
|
|
||||||
guildConfig.VoicePlusTextEnabled = data.VoicePlusTextEnabled;
|
|
||||||
}
|
|
||||||
try { File.Move("data/ServerSpecificConfigs.json", "data/DELETE_ME_ServerSpecificCOnfigs.json"); } catch { }
|
try { File.Move("data/ServerSpecificConfigs.json", "data/DELETE_ME_ServerSpecificCOnfigs.json"); } catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,48 +261,55 @@ namespace NadekoBot.Modules.Administration
|
|||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
foreach (var perms in PermissionsDict)
|
var i = 0;
|
||||||
{
|
PermissionsDict
|
||||||
var guildId = perms.Key;
|
.Select(p => new { data = p.Value, gconfig = uow.GuildConfigs.For(p.Key) })
|
||||||
var data = perms.Value;
|
.AsParallel()
|
||||||
|
.ForAll(perms =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var data = perms.data;
|
||||||
|
var gconfig = perms.gconfig;
|
||||||
|
|
||||||
_log.Info("Migrating data from permissions folder for {0}", guildId);
|
gconfig.PermissionRole = data.PermissionsControllerRole;
|
||||||
|
gconfig.VerbosePermissions = data.Verbose;
|
||||||
|
gconfig.FilteredWords = new HashSet<FilteredWord>(data.Words.Select(w => w.ToLowerInvariant())
|
||||||
|
.Distinct()
|
||||||
|
.Select(w => new FilteredWord() { Word = w }));
|
||||||
|
gconfig.FilterWords = data.Permissions.FilterWords;
|
||||||
|
gconfig.FilterInvites = data.Permissions.FilterInvites;
|
||||||
|
|
||||||
var gconfig = uow.GuildConfigs.For(guildId);
|
gconfig.FilterInvitesChannelIds = new HashSet<FilterChannelId>();
|
||||||
|
gconfig.FilterInvitesChannelIds.AddRange(data.ChannelPermissions.Where(kvp => kvp.Value.FilterInvites)
|
||||||
|
.Select(cp => new FilterChannelId()
|
||||||
|
{
|
||||||
|
ChannelId = cp.Key
|
||||||
|
}));
|
||||||
|
|
||||||
gconfig.PermissionRole = data.PermissionsControllerRole;
|
gconfig.FilterWordsChannelIds = new HashSet<FilterChannelId>();
|
||||||
gconfig.VerbosePermissions = data.Verbose;
|
gconfig.FilterWordsChannelIds.AddRange(data.ChannelPermissions.Where(kvp => kvp.Value.FilterWords)
|
||||||
gconfig.FilteredWords = new HashSet<FilteredWord>(data.Words.Select(w => w.ToLowerInvariant())
|
.Select(cp => new FilterChannelId()
|
||||||
.Distinct()
|
{
|
||||||
.Select(w => new FilteredWord() { Word = w }));
|
ChannelId = cp.Key
|
||||||
gconfig.FilterWords = data.Permissions.FilterWords;
|
}));
|
||||||
gconfig.FilterInvites = data.Permissions.FilterInvites;
|
|
||||||
|
|
||||||
gconfig.FilterInvitesChannelIds = new HashSet<FilterChannelId>();
|
gconfig.CommandCooldowns = new HashSet<CommandCooldown>(data.CommandCooldowns
|
||||||
gconfig.FilterInvitesChannelIds.AddRange(data.ChannelPermissions.Where(kvp => kvp.Value.FilterInvites)
|
.Where(cc => !string.IsNullOrWhiteSpace(cc.Key) && cc.Value > 0)
|
||||||
.Select(cp => new FilterChannelId()
|
.Select(cc => new CommandCooldown()
|
||||||
{
|
{
|
||||||
ChannelId = cp.Key
|
CommandName = cc.Key,
|
||||||
}));
|
Seconds = cc.Value
|
||||||
|
}));
|
||||||
|
_log.Info("Migrating data from permissions folder for {0} done ({1})", gconfig.GuildId, ++i);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.Error(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
gconfig.FilterWordsChannelIds = new HashSet<FilterChannelId>();
|
try { Directory.Move("data/permissions", "data/DELETE_ME_permissions"); } catch { }
|
||||||
gconfig.FilterWordsChannelIds.AddRange(data.ChannelPermissions.Where(kvp => kvp.Value.FilterWords)
|
|
||||||
.Select(cp => new FilterChannelId()
|
|
||||||
{
|
|
||||||
ChannelId = cp.Key
|
|
||||||
}));
|
|
||||||
|
|
||||||
gconfig.CommandCooldowns = new HashSet<CommandCooldown>(data.CommandCooldowns
|
|
||||||
.Where(cc => !string.IsNullOrWhiteSpace(cc.Key) && cc.Value > 0)
|
|
||||||
.Select(cc => new CommandCooldown()
|
|
||||||
{
|
|
||||||
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 { }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
//need to do this the first time
|
//need to do this the first time
|
||||||
if (uow.ConverterUnits.Empty())
|
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,
|
Modifier = u.Modifier,
|
||||||
UnitType = u.UnitType,
|
UnitType = u.UnitType,
|
||||||
|
@ -15,5 +15,8 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<DnxInvisibleFolder Include="data\permissions\" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
</Project>
|
</Project>
|
@ -38,16 +38,17 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public GuildConfig For(ulong guildId)
|
public GuildConfig For(ulong guildId)
|
||||||
{
|
{
|
||||||
var config = _set.Include(gc => gc.FollowedStreams)
|
var config = _set
|
||||||
.Include(gc => gc.LogSetting)
|
//.Include(gc => gc.FollowedStreams)
|
||||||
.ThenInclude(ls => ls.IgnoredChannels)
|
// .Include(gc => gc.LogSetting)
|
||||||
.Include(gc => gc.LogSetting)
|
// .ThenInclude(ls => ls.IgnoredChannels)
|
||||||
.ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds)
|
//.Include(gc => gc.LogSetting)
|
||||||
.Include(gc => gc.FilterInvitesChannelIds)
|
// .ThenInclude(ls => ls.IgnoredVoicePresenceChannelIds)
|
||||||
.Include(gc => gc.FilterWordsChannelIds)
|
//.Include(gc => gc.FilterInvitesChannelIds)
|
||||||
.Include(gc => gc.FilteredWords)
|
//.Include(gc => gc.FilterWordsChannelIds)
|
||||||
.Include(gc => gc.GenerateCurrencyChannelIds)
|
//.Include(gc => gc.FilteredWords)
|
||||||
.Include(gc => gc.CommandCooldowns)
|
//.Include(gc => gc.GenerateCurrencyChannelIds)
|
||||||
|
//.Include(gc => gc.CommandCooldowns)
|
||||||
.FirstOrDefault(c => c.GuildId == guildId);
|
.FirstOrDefault(c => c.GuildId == guildId);
|
||||||
|
|
||||||
if (config == null)
|
if (config == null)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using ImageProcessorCore;
|
using ImageProcessorCore;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
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 bool IsInteger(this decimal number) => number == Math.Truncate(number);
|
||||||
|
|
||||||
public static string SanitizeMentions(this string str) =>
|
public static string SanitizeMentions(this string str) =>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"emitEntryPoint": true,
|
"emitEntryPoint": true,
|
||||||
"allowUnsafe": true,
|
"allowUnsafe": true,
|
||||||
"compile": {
|
"compile": {
|
||||||
"exclude": [ ],
|
"exclude": [ "data" ]
|
||||||
},
|
},
|
||||||
"copyToOutput": {
|
"copyToOutput": {
|
||||||
"include": [ "data", "libs" ],
|
"include": [ "data", "libs" ],
|
||||||
|
Loading…
Reference in New Issue
Block a user