Fixed .resetperms, fixed crashes

This commit is contained in:
Kwoth 2016-10-18 03:03:46 +02:00
parent 73ebb257ab
commit ead27eacc6
6 changed files with 80 additions and 55 deletions

View File

@ -16,6 +16,7 @@ using NadekoBot.Services.Database.Models;
using System.Net.Http; using System.Net.Http;
using ImageProcessorCore; using ImageProcessorCore;
using System.IO; using System.IO;
using static NadekoBot.Modules.Permissions.Permissions;
namespace NadekoBot.Modules.Administration namespace NadekoBot.Modules.Administration
{ {
@ -62,6 +63,14 @@ namespace NadekoBot.Modules.Administration
{ {
var config = uow.GuildConfigs.PermissionsFor(channel.Guild.Id); var config = uow.GuildConfigs.PermissionsFor(channel.Guild.Id);
config.RootPermission = Permission.GetDefaultRoot(); config.RootPermission = Permission.GetDefaultRoot();
var toAdd = new PermissionCache()
{
RootPermission = config.RootPermission,
PermRole = config.PermissionRole,
Verbose = config.VerbosePermissions,
};
Permissions.Permissions.Cache.AddOrUpdate(channel.Guild.Id,
toAdd, (id, old) => toAdd);
await uow.CompleteAsync(); await uow.CompleteAsync();
} }

View File

@ -5,6 +5,7 @@ using NadekoBot.Attributes;
using NadekoBot.Services; using NadekoBot.Services;
using NadekoBot.Services.Database; using NadekoBot.Services.Database;
using NadekoBot.Services.Database.Models; using NadekoBot.Services.Database.Models;
using NLog;
using System; using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -16,9 +17,12 @@ namespace NadekoBot.Modules.Administration
[Group] [Group]
public class AutoAssignRoleCommands public class AutoAssignRoleCommands
{ {
private Logger _log { get; }
public AutoAssignRoleCommands() public AutoAssignRoleCommands()
{ {
var _client = NadekoBot.Client; var _client = NadekoBot.Client;
this._log = LogManager.GetCurrentClassLogger();
_client.UserJoined += (user) => _client.UserJoined += (user) =>
{ {
var t = Task.Run(async () => var t = Task.Run(async () =>
@ -35,7 +39,7 @@ namespace NadekoBot.Modules.Administration
var role = user.Guild.Roles.FirstOrDefault(r => r.Id == conf.AutoAssignRoleId); var role = user.Guild.Roles.FirstOrDefault(r => r.Id == conf.AutoAssignRoleId);
if (role != null) if (role != null)
await user.AddRolesAsync(role); try { await user.AddRolesAsync(role); } catch (Exception ex) { _log.Warn(ex); }
}); });
return Task.CompletedTask; return Task.CompletedTask;
}; };

View File

@ -112,7 +112,7 @@ namespace NadekoBot.Modules.Administration
} }
else else
return; return;
await logChannel.SendMessageAsync(str).ConfigureAwait(false); try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
}); });
return Task.CompletedTask; return Task.CompletedTask;
@ -367,7 +367,7 @@ namespace NadekoBot.Modules.Administration
👤`{msg.Author.Username}`: {msg.Resolve(userHandling:UserMentionHandling.NameAndDiscriminator)}"; 👤`{msg.Author.Username}`: {msg.Resolve(userHandling:UserMentionHandling.NameAndDiscriminator)}";
if (msg.Attachments.Any()) if (msg.Attachments.Any())
str += $"{Environment.NewLine}`Attachements`: {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}"; str += $"{Environment.NewLine}`Attachements`: {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}";
await logChannel.SendMessageAsync(str).ConfigureAwait(false); try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
}); });
return Task.CompletedTask; return Task.CompletedTask;

View File

@ -3,6 +3,7 @@ using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NLog;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Threading; using System.Threading;
@ -16,6 +17,7 @@ namespace NadekoBot.Modules.Administration
public class RatelimitCommand public class RatelimitCommand
{ {
public static ConcurrentDictionary<ulong, Ratelimiter> RatelimitingChannels = new ConcurrentDictionary<ulong, Ratelimiter>(); public static ConcurrentDictionary<ulong, Ratelimiter> RatelimitingChannels = new ConcurrentDictionary<ulong, Ratelimiter>();
private Logger _log { get; }
private ShardedDiscordClient _client { get; } private ShardedDiscordClient _client { get; }
@ -63,6 +65,7 @@ namespace NadekoBot.Modules.Administration
public RatelimitCommand() public RatelimitCommand()
{ {
this._client = NadekoBot.Client; this._client = NadekoBot.Client;
this._log = LogManager.GetCurrentClassLogger();
_client.MessageReceived += (umsg) => _client.MessageReceived += (umsg) =>
{ {
@ -78,7 +81,7 @@ namespace NadekoBot.Modules.Administration
return; return;
if (limiter.CheckUserRatelimit(usrMsg.Author.Id)) if (limiter.CheckUserRatelimit(usrMsg.Author.Id))
await usrMsg.DeleteAsync(); try { await usrMsg.DeleteAsync(); } catch (Exception ex) { _log.Warn(ex); }
}); });
return Task.CompletedTask; return Task.CompletedTask;
}; };

View File

@ -30,6 +30,8 @@ namespace NadekoBot.Modules.Administration
private Task UserLeft(IGuildUser user) private Task UserLeft(IGuildUser user)
{ {
var leftTask = Task.Run(async () => var leftTask = Task.Run(async () =>
{
try
{ {
GuildConfig conf; GuildConfig conf;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
@ -54,11 +56,13 @@ namespace NadekoBot.Modules.Administration
var t = Task.Run(async () => var t = Task.Run(async () =>
{ {
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
await toDelete.DeleteAsync().ConfigureAwait(false); try { await toDelete.DeleteAsync().ConfigureAwait(false); } catch { }
}); });
} }
} }
catch (Exception ex) { _log.Warn(ex); } catch (Exception ex) { _log.Warn(ex); }
}
catch { }
}); });
return Task.CompletedTask; return Task.CompletedTask;
} }
@ -66,6 +70,8 @@ namespace NadekoBot.Modules.Administration
private Task UserJoined(IGuildUser user) private Task UserJoined(IGuildUser user)
{ {
var joinedTask = Task.Run(async () => var joinedTask = Task.Run(async () =>
{
try
{ {
GuildConfig conf; GuildConfig conf;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
@ -89,7 +95,7 @@ namespace NadekoBot.Modules.Administration
var t = Task.Run(async () => var t = Task.Run(async () =>
{ {
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
await toDelete.DeleteAsync().ConfigureAwait(false); try { await toDelete.DeleteAsync().ConfigureAwait(false); } catch { }
}); });
} }
} }
@ -111,6 +117,8 @@ namespace NadekoBot.Modules.Administration
} }
} }
} }
}
catch { }
}); });
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -54,6 +54,7 @@ namespace NadekoBot.Modules.Administration
{ {
uow.GuildConfigs.For(before.Guild.Id).VoicePlusTextEnabled = false; uow.GuildConfigs.For(before.Guild.Id).VoicePlusTextEnabled = false;
voicePlusTextCache.TryUpdate(guild.Id, false, true); voicePlusTextCache.TryUpdate(guild.Id, false, true);
await uow.CompleteAsync().ConfigureAwait(false);
} }
return; return;
} }