Fixed .resetperms, fixed crashes
This commit is contained in:
parent
73ebb257ab
commit
ead27eacc6
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
@ -31,34 +31,38 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
var leftTask = Task.Run(async () =>
|
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
|
try
|
||||||
{
|
{
|
||||||
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
|
GuildConfig conf;
|
||||||
if (conf.AutoDeleteByeMessages)
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
var t = Task.Run(async () =>
|
conf = uow.GuildConfigs.For(user.Guild.Id);
|
||||||
{
|
|
||||||
await Task.Delay(conf.AutoDeleteGreetMessagesTimer * 1000).ConfigureAwait(false); // 5 minutes
|
|
||||||
await toDelete.DeleteAsync().ConfigureAwait(false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
@ -67,50 +71,54 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
var joinedTask = Task.Run(async () =>
|
var joinedTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
GuildConfig conf;
|
try
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
|
||||||
{
|
{
|
||||||
conf = uow.GuildConfigs.For(user.Guild.Id);
|
GuildConfig conf;
|
||||||
}
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
|
||||||
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
|
|
||||||
{
|
{
|
||||||
var msg = conf.ChannelGreetMessageText.Replace("%user%", user.Mention).Replace("%id%", user.Id.ToString()).Replace("%server%", user.Guild.Name);
|
conf = uow.GuildConfigs.For(user.Guild.Id);
|
||||||
if (!string.IsNullOrWhiteSpace(msg))
|
}
|
||||||
|
|
||||||
|
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);
|
try
|
||||||
if (conf.AutoDeleteGreetMessages)
|
|
||||||
{
|
{
|
||||||
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
|
var t = Task.Run(async () =>
|
||||||
await toDelete.DeleteAsync().ConfigureAwait(false);
|
{
|
||||||
});
|
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)
|
if (conf.SendDmGreetMessage)
|
||||||
{
|
|
||||||
var channel = await user.CreateDMChannelAsync();
|
|
||||||
|
|
||||||
if (channel != null)
|
|
||||||
{
|
{
|
||||||
var msg = conf.DmGreetMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name);
|
var channel = await user.CreateDMChannelAsync();
|
||||||
if (!string.IsNullOrWhiteSpace(msg))
|
|
||||||
|
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;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user