Prefix stuff almost complete, and i just realized permissions are getting screwed because of this
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Administration;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
public partial class Administration
|
||||
{
|
||||
[Group]
|
||||
public class PrefixCommands : NadekoSubmodule
|
||||
{
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[Priority(0)]
|
||||
public new async Task Prefix()
|
||||
{
|
||||
await ReplyConfirmLocalized("prefix_current", Format.Code(_cmdHandler.GetPrefix(Context.Guild))).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[RequireUserPermission(GuildPermission.Administrator)]
|
||||
[Priority(1)]
|
||||
public new async Task Prefix([Remainder]string prefix)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(prefix))
|
||||
return;
|
||||
|
||||
var oldPrefix = base.Prefix;
|
||||
var newPrefix = _cmdHandler.SetPrefix(Context.Guild, prefix);
|
||||
|
||||
await ReplyConfirmLocalized("prefix_new", Format.Code(oldPrefix), Format.Code(newPrefix)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[OwnerOnly]
|
||||
public async Task DefPrefix([Remainder]string prefix)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(prefix))
|
||||
{
|
||||
await ReplyConfirmLocalized("defprefix_current", _cmdHandler.DefaultPrefix).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var oldPrefix = _cmdHandler.DefaultPrefix;
|
||||
var newPrefix = _cmdHandler.SetDefaultPrefix(prefix);
|
||||
|
||||
await ReplyConfirmLocalized("defprefix_new", Format.Code(oldPrefix), Format.Code(newPrefix)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,14 +22,16 @@ namespace NadekoBot.Modules.Games.Models
|
||||
private readonly List<ulong> finishedUserIds;
|
||||
private readonly DiscordShardedClient _client;
|
||||
private readonly GamesService _games;
|
||||
private readonly string _prefix;
|
||||
|
||||
private Logger _log { get; }
|
||||
|
||||
public TypingGame(GamesService games, DiscordShardedClient client, ITextChannel channel)
|
||||
public TypingGame(GamesService games, DiscordShardedClient client, ITextChannel channel, string prefix) //kek@prefix
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
_games = games;
|
||||
_client = client;
|
||||
_prefix = prefix;
|
||||
|
||||
this.Channel = channel;
|
||||
IsActive = false;
|
||||
@@ -96,7 +98,7 @@ namespace NadekoBot.Modules.Games.Models
|
||||
if (_games.TypingArticles.Any())
|
||||
return _games.TypingArticles[new NadekoRandom().Next(0, _games.TypingArticles.Count)].Text;
|
||||
else
|
||||
return $"No typing articles found. Use {NadekoBot.Prefix}typeadd command to add a new article for typing.";
|
||||
return $"No typing articles found. Use {_prefix}typeadd command to add a new article for typing.";
|
||||
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,7 @@ namespace NadekoBot.Modules.Games
|
||||
{
|
||||
var channel = (ITextChannel)Context.Channel;
|
||||
|
||||
var game = RunningContests.GetOrAdd(channel.Guild.Id, id => new TypingGame(_games, _client, channel));
|
||||
var game = RunningContests.GetOrAdd(channel.Guild.Id, id => new TypingGame(_games, _client, channel, Prefix));
|
||||
|
||||
if (game.IsActive)
|
||||
{
|
||||
|
@@ -10,6 +10,7 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NadekoBot.Services.Permissions;
|
||||
|
||||
namespace NadekoBot.Modules.Help
|
||||
{
|
||||
@@ -20,15 +21,17 @@ namespace NadekoBot.Modules.Help
|
||||
private readonly IBotCredentials _creds;
|
||||
private readonly BotConfig _config;
|
||||
private readonly CommandService _cmds;
|
||||
private readonly GlobalPermissionService _perms;
|
||||
|
||||
public string HelpString => String.Format(_config.HelpString, _creds.ClientId, NadekoBot.Prefix);
|
||||
public string HelpString => String.Format(_config.HelpString, _creds.ClientId, Prefix);
|
||||
public string DMHelpString => _config.DMHelpString;
|
||||
|
||||
public Help(IBotCredentials creds, BotConfig config, CommandService cmds)
|
||||
public Help(IBotCredentials creds, GlobalPermissionService perms, BotConfig config, CommandService cmds)
|
||||
{
|
||||
_creds = creds;
|
||||
_config = config;
|
||||
_cmds = cmds;
|
||||
_perms = perms;
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@@ -39,8 +42,7 @@ namespace NadekoBot.Modules.Help
|
||||
.WithTitle(GetText("list_of_modules"))
|
||||
.WithDescription(string.Join("\n",
|
||||
_cmds.Modules.GroupBy(m => m.GetTopLevelModule())
|
||||
//todo perms
|
||||
//.Where(m => !Permissions.Permissions.GlobalPermissionCommands.BlockedModules.Contains(m.Key.Name.ToLowerInvariant()))
|
||||
.Where(m => !_perms.BlockedModules.Contains(m.Key.Name.ToLowerInvariant()))
|
||||
.Select(m => "• " + m.Key.Name)
|
||||
.OrderBy(s => s)));
|
||||
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
@@ -55,8 +57,7 @@ namespace NadekoBot.Modules.Help
|
||||
if (string.IsNullOrWhiteSpace(module))
|
||||
return;
|
||||
var cmds = _cmds.Commands.Where(c => c.Module.GetTopLevelModule().Name.ToUpperInvariant().StartsWith(module))
|
||||
//todo perms
|
||||
//.Where(c => !Permissions.Permissions.GlobalPermissionCommands.BlockedCommands.Contains(c.Aliases.First().ToLowerInvariant()))
|
||||
.Where(c => !_perms.BlockedCommands.Contains(c.Aliases.First().ToLowerInvariant()))
|
||||
.OrderBy(c => c.Aliases.First())
|
||||
.Distinct(new CommandTextEqualityComparer())
|
||||
.AsEnumerable();
|
||||
@@ -154,8 +155,8 @@ namespace NadekoBot.Modules.Help
|
||||
lastModule = module.Name;
|
||||
}
|
||||
helpstr.AppendLine($"{string.Join(" ", com.Aliases.Select(a => "`" + a + "`"))} |" +
|
||||
$" {string.Format(com.Summary, NadekoBot.Prefix)} {GetCommandRequirements(com)} |" +
|
||||
$" {string.Format(com.Remarks, NadekoBot.Prefix)}");
|
||||
$" {string.Format(com.Summary, Prefix)} {GetCommandRequirements(com)} |" +
|
||||
$" {string.Format(com.Remarks, Prefix)}");
|
||||
}
|
||||
File.WriteAllText("../../docs/Commands List.md", helpstr.ToString());
|
||||
await ReplyConfirmLocalized("commandlist_regen").ConfigureAwait(false);
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Administration;
|
||||
using NLog;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
@@ -12,19 +13,21 @@ namespace NadekoBot.Modules
|
||||
{
|
||||
protected readonly Logger _log;
|
||||
protected CultureInfo _cultureInfo;
|
||||
public readonly string Prefix;
|
||||
|
||||
public readonly string ModuleTypeName;
|
||||
public readonly string LowerModuleTypeName;
|
||||
|
||||
public NadekoStrings _strings { get; set; }
|
||||
public CommandHandler _cmdHandler { get; set; }
|
||||
public ILocalization _localization { get; set; }
|
||||
|
||||
public string Prefix => _cmdHandler.GetPrefix(Context.Guild);
|
||||
|
||||
protected NadekoTopLevelModule(bool isTopLevelModule = true)
|
||||
{
|
||||
//if it's top level module
|
||||
ModuleTypeName = isTopLevelModule ? this.GetType().Name : this.GetType().DeclaringType.Name;
|
||||
LowerModuleTypeName = ModuleTypeName.ToLowerInvariant();
|
||||
Prefix = NadekoBot.Prefix;
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
||||
|
@@ -13,11 +13,11 @@ namespace NadekoBot.Modules.Permissions.Commands
|
||||
[Group]
|
||||
public class ResetPermissionsCommands : NadekoSubmodule
|
||||
{
|
||||
private readonly PermissionsService _service;
|
||||
private readonly PermissionService _service;
|
||||
private readonly DbService _db;
|
||||
private readonly GlobalPermissionService _globalPerms;
|
||||
|
||||
public ResetPermissionsCommands(PermissionsService service, GlobalPermissionService globalPerms, DbService db)
|
||||
public ResetPermissionsCommands(PermissionService service, GlobalPermissionService globalPerms, DbService db)
|
||||
{
|
||||
_service = service;
|
||||
_db = db;
|
||||
|
@@ -16,9 +16,9 @@ namespace NadekoBot.Modules.Permissions
|
||||
public partial class Permissions : NadekoTopLevelModule
|
||||
{
|
||||
private readonly DbService _db;
|
||||
private readonly PermissionsService _service;
|
||||
private readonly PermissionService _service;
|
||||
|
||||
public Permissions(PermissionsService service, DbService db)
|
||||
public Permissions(PermissionService service, DbService db)
|
||||
{
|
||||
_db = db;
|
||||
_service = service;
|
||||
|
@@ -29,7 +29,7 @@ namespace NadekoBot.Modules.Searches
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
public async Task Placelist()
|
||||
{
|
||||
await Context.Channel.SendConfirmAsync(GetText("list_of_place_tags", NadekoBot.Prefix),
|
||||
await Context.Channel.SendConfirmAsync(GetText("list_of_place_tags", Prefix),
|
||||
typesStr)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Utility
|
||||
return;
|
||||
}
|
||||
var rem = (_patreon.Interval - (DateTime.UtcNow - _patreon.LastUpdate));
|
||||
var helpcmd = Format.Code(NadekoBot.Prefix + "donate");
|
||||
var helpcmd = Format.Code(Prefix + "donate");
|
||||
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
||||
.WithDescription(GetText("clpa_fail"))
|
||||
.AddField(efb => efb.WithName(GetText("clpa_fail_already_title")).WithValue(GetText("clpa_fail_already")))
|
||||
|
Reference in New Issue
Block a user