Fixed botid, %mention% in custom reactions
This commit is contained in:
parent
dacfc1f8ea
commit
9cc0af1666
@ -14,7 +14,7 @@ namespace NadekoBot.Modules.CustomReactions
|
|||||||
{
|
{
|
||||||
public static Dictionary<string, Func<IUserMessage, string>> placeholders = new Dictionary<string, Func<IUserMessage, string>>()
|
public static Dictionary<string, Func<IUserMessage, string>> placeholders = new Dictionary<string, Func<IUserMessage, string>>()
|
||||||
{
|
{
|
||||||
{"%mention%", (ctx) => { return $"<@{NadekoBot.Client.GetCurrentUserAsync().Id}>"; } },
|
{"%mention%", (ctx) => { return $"<@{NadekoBot.Client.GetCurrentUser().Id}>"; } },
|
||||||
{"%user%", (ctx) => { return ctx.Author.Mention; } },
|
{"%user%", (ctx) => { return ctx.Author.Mention; } },
|
||||||
{"%target%", (ctx) => { return ctx.MentionedUsers.Shuffle().FirstOrDefault()?.Mention ?? "Nobody"; } },
|
{"%target%", (ctx) => { return ctx.MentionedUsers.Shuffle().FirstOrDefault()?.Mention ?? "Nobody"; } },
|
||||||
{"%rng%", (ctx) => { return new NadekoRandom().Next(0,10).ToString(); } }
|
{"%rng%", (ctx) => { return new NadekoRandom().Next(0,10).ToString(); } }
|
||||||
|
@ -11,12 +11,39 @@ using Discord;
|
|||||||
using NadekoBot.Services.Database;
|
using NadekoBot.Services.Database;
|
||||||
using NadekoBot.Services.Database.Models;
|
using NadekoBot.Services.Database.Models;
|
||||||
using Discord.API;
|
using Discord.API;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Permissions
|
namespace NadekoBot.Modules.Permissions
|
||||||
{
|
{
|
||||||
[NadekoModule("Permissions", ";")]
|
[NadekoModule("Permissions", ";")]
|
||||||
public partial class Permissions : DiscordModule
|
public partial class Permissions : DiscordModule
|
||||||
{
|
{
|
||||||
|
public class PermissionCache
|
||||||
|
{
|
||||||
|
public string PermRole { get; set; }
|
||||||
|
public bool Verbose { get; set; } = true;
|
||||||
|
public Permission RootPermission { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
//guildid, root permission
|
||||||
|
public static ConcurrentDictionary<ulong, PermissionCache> Cache;
|
||||||
|
|
||||||
|
static Permissions()
|
||||||
|
{
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
Cache = new ConcurrentDictionary<ulong, PermissionCache>(uow.GuildConfigs
|
||||||
|
.PermissionsForAll()
|
||||||
|
.ToDictionary(k => k.GuildId,
|
||||||
|
v => new PermissionCache()
|
||||||
|
{
|
||||||
|
RootPermission = v.RootPermission,
|
||||||
|
Verbose = v.VerbosePermissions,
|
||||||
|
PermRole = v.PermissionRole
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Permissions(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
|
public Permissions(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -31,6 +58,12 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
var config = uow.GuildConfigs.For(channel.Guild.Id);
|
var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||||
config.VerbosePermissions = action.Value;
|
config.VerbosePermissions = action.Value;
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = Permission.GetDefaultRoot(),
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.Verbose = config.VerbosePermissions; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +85,12 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
config.PermissionRole = role.Name.Trim();
|
config.PermissionRole = role.Name.Trim();
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = Permission.GetDefaultRoot(),
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.PermRole = role.Name.Trim(); return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,6 +146,12 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
{
|
{
|
||||||
p = perms.RemoveAt(index);
|
p = perms.RemoveAt(index);
|
||||||
}
|
}
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +261,12 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
}
|
}
|
||||||
|
|
||||||
config.RootPermission = fromPerm.GetRoot();
|
config.RootPermission = fromPerm.GetRoot();
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"`Moved permission:` \"{fromPerm.GetCommand(channel.Guild)}\" `from #{++from} to #{++to}.`").ConfigureAwait(false);
|
await channel.SendMessageAsync($"`Moved permission:` \"{fromPerm.GetCommand(channel.Guild)}\" `from #{++from} to #{++to}.`").ConfigureAwait(false);
|
||||||
@ -244,7 +295,14 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = command.Text.ToLowerInvariant(),
|
SecondaryTargetName = command.Text.ToLowerInvariant(),
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
|
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command on this server.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command on this server.").ConfigureAwait(false);
|
||||||
@ -266,7 +324,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module on this server.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module on this server.").ConfigureAwait(false);
|
||||||
@ -288,7 +352,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = command.Text.ToLowerInvariant(),
|
SecondaryTargetName = command.Text.ToLowerInvariant(),
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{user}` user.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{user}` user.").ConfigureAwait(false);
|
||||||
@ -310,7 +380,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{user}` user.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{user}` user.").ConfigureAwait(false);
|
||||||
@ -332,7 +408,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = command.Text.ToLowerInvariant(),
|
SecondaryTargetName = command.Text.ToLowerInvariant(),
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{role}` role.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{command.Text}` command for `{role}` role.").ConfigureAwait(false);
|
||||||
@ -354,7 +436,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{role}` role.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{role}` role.").ConfigureAwait(false);
|
||||||
@ -377,7 +465,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = command.Text.ToLowerInvariant(),
|
SecondaryTargetName = command.Text.ToLowerInvariant(),
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -403,7 +497,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
SecondaryTargetName = module.Name.ToLowerInvariant(),
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false);
|
||||||
@ -425,7 +525,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = "*",
|
SecondaryTargetName = "*",
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{chnl}` channel.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{chnl}` channel.").ConfigureAwait(false);
|
||||||
@ -447,7 +553,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = "*",
|
SecondaryTargetName = "*",
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{role}` role.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{role}` role.").ConfigureAwait(false);
|
||||||
@ -469,7 +581,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
SecondaryTargetName = "*",
|
SecondaryTargetName = "*",
|
||||||
State = action.Value,
|
State = action.Value,
|
||||||
};
|
};
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, newPerm);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
await uow.CompleteAsync().ConfigureAwait(false);
|
await uow.CompleteAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{user}` user.").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{(action.Value ? "Allowed" : "Denied")} usage of `ALL MODULES` for `{user}` user.").ConfigureAwait(false);
|
||||||
@ -502,7 +620,13 @@ namespace NadekoBot.Modules.Permissions
|
|||||||
State = true,
|
State = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, allowUser);
|
var config = uow.GuildConfigs.SetNewRootPermission(channel.Guild.Id, allowUser);
|
||||||
|
Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
|
||||||
|
{
|
||||||
|
PermRole = config.PermissionRole,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
Verbose = config.VerbosePermissions
|
||||||
|
}, (id, old) => { old.RootPermission = config.RootPermission; return old; });
|
||||||
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);
|
||||||
|
@ -129,7 +129,7 @@ namespace NadekoBot.Services
|
|||||||
{
|
{
|
||||||
var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, MultiMatchHandling.Best);
|
var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, MultiMatchHandling.Best);
|
||||||
var command = t.Item1;
|
var command = t.Item1;
|
||||||
var verbose = t.Item2;
|
var permCache = t.Item2;
|
||||||
var result = t.Item3;
|
var result = t.Item3;
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
var channel = (usrMsg.Channel as ITextChannel);
|
var channel = (usrMsg.Channel as ITextChannel);
|
||||||
@ -165,7 +165,7 @@ namespace NadekoBot.Services
|
|||||||
);
|
);
|
||||||
if (guild != null && command != null && result.Error == CommandError.Exception)
|
if (guild != null && command != null && result.Error == CommandError.Exception)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (permCache != null && permCache.Verbose)
|
||||||
try { await msg.Channel.SendMessageAsync(":warning: " + result.ErrorReason).ConfigureAwait(false); } catch { }
|
try { await msg.Channel.SendMessageAsync(":warning: " + result.ErrorReason).ConfigureAwait(false); } catch { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,10 +189,10 @@ namespace NadekoBot.Services
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Tuple<Command,bool, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {
|
public async Task<Tuple<Command, PermissionCache, IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {
|
||||||
var searchResult = _commandService.Search(message, input);
|
var searchResult = _commandService.Search(message, input);
|
||||||
if (!searchResult.IsSuccess)
|
if (!searchResult.IsSuccess)
|
||||||
return new Tuple<Command, bool, IResult>(null, false, searchResult);
|
return new Tuple<Command, PermissionCache, IResult>(null, null, searchResult);
|
||||||
|
|
||||||
var commands = searchResult.Commands;
|
var commands = searchResult.Commands;
|
||||||
for (int i = commands.Count - 1; i >= 0; i--)
|
for (int i = commands.Count - 1; i >= 0; i--)
|
||||||
@ -201,7 +201,7 @@ namespace NadekoBot.Services
|
|||||||
if (!preconditionResult.IsSuccess)
|
if (!preconditionResult.IsSuccess)
|
||||||
{
|
{
|
||||||
if (commands.Count == 1)
|
if (commands.Count == 1)
|
||||||
return new Tuple<Command, bool, IResult>(null, false, searchResult);
|
return new Tuple<Command, PermissionCache, IResult>(null, null, searchResult);
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -225,55 +225,55 @@ namespace NadekoBot.Services
|
|||||||
if (!parseResult.IsSuccess)
|
if (!parseResult.IsSuccess)
|
||||||
{
|
{
|
||||||
if (commands.Count == 1)
|
if (commands.Count == 1)
|
||||||
return new Tuple<Command, bool, IResult>(null, false, parseResult);
|
return new Tuple<Command, PermissionCache, IResult>(null, null, parseResult);
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool verbose = false;
|
|
||||||
Permission rootPerm = null;
|
var cmd = commands[i];
|
||||||
string permRole = "";
|
bool resetCommand = cmd.Name == "ResetPermissions";
|
||||||
|
PermissionCache pc;
|
||||||
if (guild != null)
|
if (guild != null)
|
||||||
|
{
|
||||||
|
pc = Permissions.Cache.GetOrAdd(guild.Id, (id) =>
|
||||||
{
|
{
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
{
|
{
|
||||||
var config = uow.GuildConfigs.PermissionsFor(guild.Id);
|
var config = uow.GuildConfigs.PermissionsFor(guild.Id);
|
||||||
verbose = config.VerbosePermissions;
|
return new PermissionCache()
|
||||||
rootPerm = config.RootPermission;
|
|
||||||
permRole = config.PermissionRole.Trim().ToLowerInvariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_log.Info("Permissions retrieved");
|
|
||||||
var cmd = commands[i];
|
|
||||||
bool resetCommand = cmd.Name == "ResetPermissions";
|
|
||||||
//check permissions
|
|
||||||
if (guild != null)
|
|
||||||
{
|
{
|
||||||
|
Verbose = config.VerbosePermissions,
|
||||||
|
RootPermission = config.RootPermission,
|
||||||
|
PermRole = config.PermissionRole.Trim().ToLowerInvariant(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
int index;
|
int index;
|
||||||
if (!resetCommand && !rootPerm.AsEnumerable().CheckPermissions(message, cmd.Text, cmd.Module.Name, out index))
|
if (!resetCommand && !pc.RootPermission.AsEnumerable().CheckPermissions(message, cmd.Text, cmd.Module.Name, out index))
|
||||||
{
|
{
|
||||||
var returnMsg = $"Permission number #{index + 1} **{rootPerm.GetAt(index).GetCommand()}** is preventing this action.";
|
var returnMsg = $"Permission number #{index + 1} **{pc.RootPermission.GetAt(index).GetCommand()}** is preventing this action.";
|
||||||
return new Tuple<Command, bool, IResult>(cmd, verbose, SearchResult.FromError(CommandError.Exception, returnMsg));
|
return new Tuple<Command, PermissionCache, IResult>(cmd, pc, SearchResult.FromError(CommandError.Exception, returnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (cmd.Module.Source.Name == typeof(Permissions).Name) //permissions, you must have special role
|
if (cmd.Module.Source.Name == typeof(Permissions).Name) //permissions, you must have special role
|
||||||
{
|
{
|
||||||
if (!((IGuildUser)user).Roles.Any(r => r.Name.Trim().ToLowerInvariant() == permRole))
|
if (!((IGuildUser)user).Roles.Any(r => r.Name.Trim().ToLowerInvariant() == pc.PermRole.Trim().ToLowerInvariant()))
|
||||||
{
|
{
|
||||||
return new Tuple<Command, bool, IResult>(cmd, false, SearchResult.FromError(CommandError.Exception, $"You need the **{permRole}** role in order to use permission commands."));
|
return new Tuple<Command, PermissionCache, IResult>(cmd, pc, SearchResult.FromError(CommandError.Exception, $"You need the **{pc.PermRole}** role in order to use permission commands."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (CmdCdsCommands.HasCooldown(cmd, guild, user))
|
if (CmdCdsCommands.HasCooldown(cmd, guild, user))
|
||||||
return new Tuple<Command, bool, IResult>(cmd, false, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you."));
|
return new Tuple<Command, PermissionCache, IResult>(cmd, null, SearchResult.FromError(CommandError.Exception, $"That command is on cooldown for you."));
|
||||||
|
|
||||||
return new Tuple<Command, bool, IResult>(commands[i], false, await commands[i].Execute(message, parseResult));
|
return new Tuple<Command, PermissionCache, IResult>(commands[i], null, await commands[i].Execute(message, parseResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<Command, bool, IResult>(null, false, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."));
|
return new Tuple<Command, PermissionCache, IResult>(null, null, SearchResult.FromError(CommandError.UnknownCommand, "This input does not match any overload."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ namespace NadekoBot.Services.Database.Repositories
|
|||||||
{
|
{
|
||||||
GuildConfig For(ulong guildId);
|
GuildConfig For(ulong guildId);
|
||||||
GuildConfig PermissionsFor(ulong guildId);
|
GuildConfig PermissionsFor(ulong guildId);
|
||||||
void SetNewRootPermission(ulong guildId, Permission p);
|
IEnumerable<GuildConfig> PermissionsForAll();
|
||||||
|
GuildConfig SetNewRootPermission(ulong guildId, Permission p);
|
||||||
IEnumerable<FollowedStream> GetAllFollowedStreams();
|
IEnumerable<FollowedStream> GetAllFollowedStreams();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,12 +90,28 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<GuildConfig> PermissionsForAll()
|
||||||
|
{
|
||||||
|
var query = _set.Include(gc => gc.RootPermission);
|
||||||
|
|
||||||
|
//todo this is possibly a disaster for performance
|
||||||
|
//What i could do instead is count the number of permissions in the permission table for this guild
|
||||||
|
// and make a for loop with those.
|
||||||
|
// or just select permissions for this guild and manually chain them
|
||||||
|
for (int i = 0; i < 60; i++)
|
||||||
|
{
|
||||||
|
query = query.ThenInclude(gc => gc.Next);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<FollowedStream> GetAllFollowedStreams() =>
|
public IEnumerable<FollowedStream> GetAllFollowedStreams() =>
|
||||||
_set.Include(gc => gc.FollowedStreams)
|
_set.Include(gc => gc.FollowedStreams)
|
||||||
.SelectMany(gc => gc.FollowedStreams)
|
.SelectMany(gc => gc.FollowedStreams)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
public void SetNewRootPermission(ulong guildId, Permission p)
|
public GuildConfig SetNewRootPermission(ulong guildId, Permission p)
|
||||||
{
|
{
|
||||||
var data = _set
|
var data = _set
|
||||||
.Include(gc => gc.RootPermission)
|
.Include(gc => gc.RootPermission)
|
||||||
@ -103,6 +119,7 @@ namespace NadekoBot.Services.Database.Repositories.Impl
|
|||||||
|
|
||||||
data.RootPermission.Prepend(p);
|
data.RootPermission.Prepend(p);
|
||||||
data.RootPermission = p;
|
data.RootPermission = p;
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,17 +33,17 @@ namespace NadekoBot.Services.Impl
|
|||||||
|
|
||||||
this.client.Disconnected += _ => Reset();
|
this.client.Disconnected += _ => Reset();
|
||||||
}
|
}
|
||||||
public Task<string> Print()
|
public async Task<string> Print()
|
||||||
{
|
{
|
||||||
var curUser = client.GetCurrentUserAsync();
|
var curUser = await client.GetCurrentUserAsync();
|
||||||
return Task.FromResult($@"`Author: Kwoth` `Library: Discord.Net`
|
return $@"`Author: Kwoth` `Library: Discord.Net`
|
||||||
`Bot Version: {BotVersion}`
|
`Bot Version: {BotVersion}`
|
||||||
`Bot id: {curUser.Id}`
|
`Bot id: {curUser.Id}`
|
||||||
`Owners' Ids: {string.Join(", ", NadekoBot.Credentials.OwnerIds)}`
|
`Owners' Ids: {string.Join(", ", NadekoBot.Credentials.OwnerIds)}`
|
||||||
`Uptime: {GetUptimeString()}`
|
`Uptime: {GetUptimeString()}`
|
||||||
`Servers: {client.GetGuilds().Count} | TextChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is ITextChannel)).Count()} | VoiceChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is IVoiceChannel)).Count()}`
|
`Servers: {client.GetGuilds().Count} | TextChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is ITextChannel)).Count()} | VoiceChannels: {client.GetGuilds().SelectMany(g => g.GetChannels().Where(c => c is IVoiceChannel)).Count()}`
|
||||||
`Commands Ran this session: {commandsRan}`
|
`Commands Ran this session: {commandsRan}`
|
||||||
`Messages: {messageCounter} ({messageCounter / (double)GetUptime().TotalSeconds:F2}/sec)` `Heap: {Heap} MB`");
|
`Messages: {messageCounter} ({messageCounter / (double)GetUptime().TotalSeconds:F2}/sec)` `Heap: {Heap} MB`";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Reset()
|
public Task Reset()
|
||||||
|
15
src/NadekoBot/credentials_example.json
Normal file
15
src/NadekoBot/credentials_example.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"ClientId": 123123123,
|
||||||
|
"BotId": null,
|
||||||
|
"Token": "",
|
||||||
|
"OwnerIds": [
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"LoLApiKey": "",
|
||||||
|
"GoogleApiKey": "",
|
||||||
|
"MashapeKey": "",
|
||||||
|
"OsuApiKey": "",
|
||||||
|
"SoundCloudClientId": "",
|
||||||
|
"Db": null,
|
||||||
|
"TotalShards": 1
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user