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 ImageProcessorCore;
using System.IO;
using static NadekoBot.Modules.Permissions.Permissions;
namespace NadekoBot.Modules.Administration
{
@ -62,6 +63,14 @@ namespace NadekoBot.Modules.Administration
{
var config = uow.GuildConfigs.PermissionsFor(channel.Guild.Id);
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();
}

View File

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

View File

@ -112,7 +112,7 @@ namespace NadekoBot.Modules.Administration
}
else
return;
await logChannel.SendMessageAsync(str).ConfigureAwait(false);
try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
@ -367,7 +367,7 @@ namespace NadekoBot.Modules.Administration
👤`{msg.Author.Username}`: {msg.Resolve(userHandling:UserMentionHandling.NameAndDiscriminator)}";
if (msg.Attachments.Any())
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;

View File

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

View File

@ -31,34 +31,38 @@ namespace NadekoBot.Modules.Administration
{
var leftTask = Task.Run(async () =>
{
GuildConfig conf;
using (var uow = DbHandler.UnitOfWork())
{
conf = uow.GuildConfigs.For(user.Guild.Id);
}
if (!conf.SendChannelByeMessage) return;
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.ByeMessageChannelId);
if (channel == null) //maybe warn the server owner that the channel is missing
return;
var msg = conf.ChannelByeMessageText.Replace("%user%", user.Username).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
if (string.IsNullOrWhiteSpace(msg))
return;
try
{
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
if (conf.AutoDeleteByeMessages)
GuildConfig conf;
using (var uow = DbHandler.UnitOfWork())
{
var t = Task.Run(async () =>
{
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
await toDelete.DeleteAsync().ConfigureAwait(false);
});
conf = uow.GuildConfigs.For(user.Guild.Id);
}
if (!conf.SendChannelByeMessage) return;
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.ByeMessageChannelId);
if (channel == null) //maybe warn the server owner that the channel is missing
return;
var msg = conf.ChannelByeMessageText.Replace("%user%", user.Username).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
if (string.IsNullOrWhiteSpace(msg))
return;
try
{
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
if (conf.AutoDeleteByeMessages)
{
var t = Task.Run(async () =>
{
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
try { await toDelete.DeleteAsync().ConfigureAwait(false); } catch { }
});
}
}
catch (Exception ex) { _log.Warn(ex); }
}
catch (Exception ex) { _log.Warn(ex); }
catch { }
});
return Task.CompletedTask;
}
@ -67,50 +71,54 @@ namespace NadekoBot.Modules.Administration
{
var joinedTask = Task.Run(async () =>
{
GuildConfig conf;
using (var uow = DbHandler.UnitOfWork())
try
{
conf = uow.GuildConfigs.For(user.Guild.Id);
}
if (conf.SendChannelGreetMessage)
{
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId);
if (channel != null) //maybe warn the server owner that the channel is missing
GuildConfig conf;
using (var uow = DbHandler.UnitOfWork())
{
var msg = conf.ChannelGreetMessageText.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
if (!string.IsNullOrWhiteSpace(msg))
conf = uow.GuildConfigs.For(user.Guild.Id);
}
if (conf.SendChannelGreetMessage)
{
var channel = (await user.Guild.GetTextChannelsAsync()).SingleOrDefault(c => c.Id == conf.GreetMessageChannelId);
if (channel != null) //maybe warn the server owner that the channel is missing
{
try
var msg = conf.ChannelGreetMessageText.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
if (!string.IsNullOrWhiteSpace(msg))
{
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
if (conf.AutoDeleteGreetMessages)
try
{
var t = Task.Run(async () =>
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
if (conf.AutoDeleteGreetMessages)
{
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
await toDelete.DeleteAsync().ConfigureAwait(false);
});
var t = Task.Run(async () =>
{
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
try { await toDelete.DeleteAsync().ConfigureAwait(false); } catch { }
});
}
}
catch (Exception ex) { _log.Warn(ex); }
}
catch (Exception ex) { _log.Warn(ex); }
}
}
}
if (conf.SendDmGreetMessage)
{
var channel = await user.CreateDMChannelAsync();
if (channel != null)
if (conf.SendDmGreetMessage)
{
var msg = conf.DmGreetMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name);
if (!string.IsNullOrWhiteSpace(msg))
var channel = await user.CreateDMChannelAsync();
if (channel != null)
{
await channel.SendMessageAsync(msg).ConfigureAwait(false);
var msg = conf.DmGreetMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name);
if (!string.IsNullOrWhiteSpace(msg))
{
await channel.SendMessageAsync(msg).ConfigureAwait(false);
}
}
}
}
catch { }
});
return Task.CompletedTask;
}

View File

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