Fixed some stuff
This commit is contained in:
parent
f97550ee3e
commit
c0562026bc
@ -18,18 +18,43 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
public class CustomReactions : DiscordModule
|
public class CustomReactions : DiscordModule
|
||||||
{
|
{
|
||||||
public static HashSet<CustomReaction> GlobalReactions { get; } = new HashSet<CustomReaction>();
|
public static HashSet<CustomReaction> GlobalReactions { get; } = new HashSet<CustomReaction>();
|
||||||
public static ConcurrentDictionary<ulong, HashSet<CustomReaction>> AllReactions { get; } = new ConcurrentDictionary<ulong, HashSet<CustomReaction>>();
|
public static ConcurrentDictionary<ulong, HashSet<CustomReaction>> GuildReactions { get; } = new ConcurrentDictionary<ulong, HashSet<CustomReaction>>();
|
||||||
static CustomReactions()
|
static CustomReactions()
|
||||||
{
|
{
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
var items = uow.CustomReactions.GetAll();
|
var items = uow.CustomReactions.GetAll();
|
||||||
AllReactions = new ConcurrentDictionary<ulong, HashSet<CustomReaction>>(items.Where(g => g.GuildId != null).GroupBy(k => k.GuildId.Value).ToDictionary(g => g.Key, g => new HashSet<CustomReaction>(g)));
|
GuildReactions = new ConcurrentDictionary<ulong, HashSet<CustomReaction>>(items.Where(g => g.GuildId != null).GroupBy(k => k.GuildId.Value).ToDictionary(g => g.Key, g => new HashSet<CustomReaction>(g)));
|
||||||
GlobalReactions = new HashSet<CustomReaction>(items.Where(g => g.GuildId == null));
|
GlobalReactions = new HashSet<CustomReaction>(items.Where(g => g.GuildId == null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public CustomReactions(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
|
public CustomReactions(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
|
||||||
{
|
{
|
||||||
|
client.MessageReceived += (imsg) =>
|
||||||
|
{
|
||||||
|
var umsg = imsg as IUserMessage;
|
||||||
|
if (umsg == null)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
var channel = umsg.Channel as ITextChannel;
|
||||||
|
if (channel == null)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
var t = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
HashSet<CustomReaction> reactions;
|
||||||
|
GuildReactions.TryGetValue(channel.Guild.Id, out reactions);
|
||||||
|
if (reactions != null && reactions.Any())
|
||||||
|
{
|
||||||
|
var reaction = reactions.Where(cr => cr.Trigger == umsg.Content).Shuffle().FirstOrDefault();
|
||||||
|
if (reaction != null)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync(reaction.Response).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Task.CompletedTask;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -40,7 +65,7 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
if (string.IsNullOrWhiteSpace(message) || string.IsNullOrWhiteSpace(key))
|
if (string.IsNullOrWhiteSpace(message) || string.IsNullOrWhiteSpace(key))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((channel == null && NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && ((IGuildUser)imsg.Author).GuildPermissions.Administrator))
|
if ((channel == null && !NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && !((IGuildUser)imsg.Author).GuildPermissions.Administrator))
|
||||||
{
|
{
|
||||||
try { await channel.SendMessageAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
|
try { await channel.SendMessageAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
|
||||||
return;
|
return;
|
||||||
@ -67,7 +92,7 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var reactions = AllReactions.GetOrAdd(channel.Guild.Id, new HashSet<CustomReaction>());
|
var reactions = GuildReactions.GetOrAdd(channel.Guild.Id, new HashSet<CustomReaction>());
|
||||||
reactions.Add(cr);
|
reactions.Add(cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +110,7 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
if (channel == null)
|
if (channel == null)
|
||||||
customReactions = GlobalReactions;
|
customReactions = GlobalReactions;
|
||||||
else
|
else
|
||||||
customReactions = AllReactions.GetOrAdd(channel.Guild.Id, new HashSet<CustomReaction>());
|
customReactions = GuildReactions.GetOrAdd(channel.Guild.Id, new HashSet<CustomReaction>());
|
||||||
|
|
||||||
if (customReactions == null || !customReactions.Any())
|
if (customReactions == null || !customReactions.Any())
|
||||||
await channel.SendMessageAsync("`No custom reactions found`").ConfigureAwait(false);
|
await channel.SendMessageAsync("`No custom reactions found`").ConfigureAwait(false);
|
||||||
@ -99,7 +124,7 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
{
|
{
|
||||||
var channel = imsg.Channel as ITextChannel;
|
var channel = imsg.Channel as ITextChannel;
|
||||||
|
|
||||||
if ((channel == null && NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && ((IGuildUser)imsg.Author).GuildPermissions.Administrator))
|
if ((channel == null && !NadekoBot.Credentials.IsOwner(imsg.Author)) || (channel != null && !((IGuildUser)imsg.Author).GuildPermissions.Administrator))
|
||||||
{
|
{
|
||||||
try { await channel.SendMessageAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
|
try { await channel.SendMessageAsync("Insufficient permissions. Requires Bot ownership for global custom reactions, and Administrator for guild custom reactions."); } catch { }
|
||||||
return;
|
return;
|
||||||
|
@ -48,6 +48,7 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[Priority(1)]
|
||||||
public async Task Cash(IUserMessage umsg, [Remainder] IUser user = null)
|
public async Task Cash(IUserMessage umsg, [Remainder] IUser user = null)
|
||||||
{
|
{
|
||||||
var channel = umsg.Channel;
|
var channel = umsg.Channel;
|
||||||
@ -64,6 +65,23 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
await channel.SendMessageAsync($"{user.Username} has {amount} {config.CurrencySign}").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{user.Username} has {amount} {config.CurrencySign}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[Priority(0)]
|
||||||
|
public async Task Cash(IUserMessage umsg, ulong userId)
|
||||||
|
{
|
||||||
|
var channel = umsg.Channel;
|
||||||
|
|
||||||
|
long amount;
|
||||||
|
BotConfig config;
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
amount = uow.Currency.GetUserCurrency(userId);
|
||||||
|
config = uow.BotConfig.GetOrCreate();
|
||||||
|
}
|
||||||
|
|
||||||
|
await channel.SendMessageAsync($"`{userId}` has {amount} {config.CurrencySign}").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Give(IUserMessage umsg, long amount, [Remainder] IGuildUser receiver)
|
public async Task Give(IUserMessage umsg, long amount, [Remainder] IGuildUser receiver)
|
||||||
@ -111,9 +129,10 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
if (amount <= 0)
|
if (amount <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await CurrencyHandler.RemoveCurrencyAsync(user, $"Taken by bot owner.({umsg.Author.Username}/{umsg.Author.Id})", amount, true).ConfigureAwait(false);
|
if(await CurrencyHandler.RemoveCurrencyAsync(user, $"Taken by bot owner.({umsg.Author.Username}/{umsg.Author.Id})", amount, true).ConfigureAwait(false))
|
||||||
|
await channel.SendMessageAsync($"{umsg.Author.Mention} successfully took {amount} {Gambling.CurrencyPluralName} from {user}!").ConfigureAwait(false);
|
||||||
await channel.SendMessageAsync($"{umsg.Author.Mention} successfully took {amount} {Gambling.CurrencyName}s from {user}!").ConfigureAwait(false);
|
else
|
||||||
|
await channel.SendMessageAsync($"{umsg.Author.Mention} was unable to take {amount} {Gambling.CurrencyPluralName} from {user} because the user doesn't have that much {Gambling.CurrencyPluralName}!").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -126,9 +145,10 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
if (amount <= 0)
|
if (amount <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await CurrencyHandler.RemoveCurrencyAsync(usrId, $"Taken by bot owner.({umsg.Author.Username}/{umsg.Author.Id})", amount).ConfigureAwait(false);
|
if(await CurrencyHandler.RemoveCurrencyAsync(usrId, $"Taken by bot owner.({umsg.Author.Username}/{umsg.Author.Id})", amount).ConfigureAwait(false))
|
||||||
|
await channel.SendMessageAsync($"{umsg.Author.Mention} successfully took {amount} {Gambling.CurrencyName}s from <@{usrId}>!").ConfigureAwait(false);
|
||||||
await channel.SendMessageAsync($"{umsg.Author.Mention} successfully took {amount} {Gambling.CurrencyName}s from <@{usrId}>!").ConfigureAwait(false);
|
else
|
||||||
|
await channel.SendMessageAsync($"{umsg.Author.Mention} was unable to take {amount} {Gambling.CurrencyPluralName} from `{usrId}` because the user doesn't have that much {Gambling.CurrencyPluralName}!").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
@ -490,6 +490,17 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
|
||||||
|
var allowUser = new Permission
|
||||||
|
{
|
||||||
|
PrimaryTarget = PrimaryPermissionType.User,
|
||||||
|
PrimaryTargetId = imsg.Author.Id,
|
||||||
|
SecondaryTarget = SecondaryPermissionType.AllModules,
|
||||||
|
SecondaryTargetName = "*",
|
||||||
|
State = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, allowUser);
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` on this server.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` on this server.").ConfigureAwait(false);
|
||||||
|
@ -44,7 +44,7 @@ namespace NadekoBot.Services.Database.Models
|
|||||||
|
|
||||||
//permissions
|
//permissions
|
||||||
public Permission RootPermission { get; set; }
|
public Permission RootPermission { get; set; }
|
||||||
public bool VerbosePermissions { get; set; }
|
public bool VerbosePermissions { get; set; } = true;
|
||||||
public string PermissionRole { get; set; } = "Nadeko";
|
public string PermissionRole { get; set; } = "Nadeko";
|
||||||
|
|
||||||
public HashSet<CommandCooldown> CommandCooldowns { get; set; } = new HashSet<CommandCooldown>();
|
public HashSet<CommandCooldown> CommandCooldowns { get; set; } = new HashSet<CommandCooldown>();
|
||||||
|
Loading…
Reference in New Issue
Block a user