;gmod, ;cmd, ;lgp and .resetglobalperms added. Bot owner can disable modules or commands bot-wide.

This commit is contained in:
Kwoth 2017-04-09 22:28:42 +02:00
parent a89d00ff31
commit 98c330d6a6
20 changed files with 2157 additions and 53 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class gmodandcmod : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "BlockedCmdOrMdl",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
BotConfigId = table.Column<int>(nullable: true),
BotConfigId1 = table.Column<int>(nullable: true),
DateAdded = table.Column<DateTime>(nullable: true),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_BlockedCmdOrMdl", x => x.Id);
table.ForeignKey(
name: "FK_BlockedCmdOrMdl_BotConfig_BotConfigId",
column: x => x.BotConfigId,
principalTable: "BotConfig",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_BlockedCmdOrMdl_BotConfig_BotConfigId1",
column: x => x.BotConfigId1,
principalTable: "BotConfig",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_BlockedCmdOrMdl_BotConfigId",
table: "BlockedCmdOrMdl",
column: "BotConfigId");
migrationBuilder.CreateIndex(
name: "IX_BlockedCmdOrMdl_BotConfigId1",
table: "BlockedCmdOrMdl",
column: "BotConfigId1");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BlockedCmdOrMdl");
}
}
}

View File

@ -99,6 +99,28 @@ namespace NadekoBot.Migrations
b.ToTable("BlacklistItem"); b.ToTable("BlacklistItem");
}); });
modelBuilder.Entity("NadekoBot.Services.Database.Models.BlockedCmdOrMdl", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int?>("BotConfigId");
b.Property<int?>("BotConfigId1");
b.Property<DateTime?>("DateAdded");
b.Property<string>("Name");
b.HasKey("Id");
b.HasIndex("BotConfigId");
b.HasIndex("BotConfigId1");
b.ToTable("BlockedCmdOrMdl");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.BotConfig", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.BotConfig", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -1277,6 +1299,17 @@ namespace NadekoBot.Migrations
.HasForeignKey("BotConfigId"); .HasForeignKey("BotConfigId");
}); });
modelBuilder.Entity("NadekoBot.Services.Database.Models.BlockedCmdOrMdl", b =>
{
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
.WithMany("BlockedCommands")
.HasForeignKey("BotConfigId");
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
.WithMany("BlockedModules")
.HasForeignKey("BotConfigId1");
});
modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b => modelBuilder.Entity("NadekoBot.Services.Database.Models.ClashCaller", b =>
{ {
b.HasOne("NadekoBot.Services.Database.Models.ClashWar", "ClashWar") b.HasOne("NadekoBot.Services.Database.Models.ClashWar", "ClashWar")

View File

@ -67,6 +67,23 @@ namespace NadekoBot.Modules.Administration
await ReplyConfirmLocalized("perms_reset").ConfigureAwait(false); await ReplyConfirmLocalized("perms_reset").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public async Task ResetGlobalPermissions()
{
using (var uow = DbHandler.UnitOfWork())
{
var gc = uow.BotConfig.GetOrCreate();
gc.BlockedCommands.Clear();
gc.BlockedModules.Clear();
GlobalPermissionCommands.BlockedCommands.Clear();
GlobalPermissionCommands.BlockedModules.Clear();
await uow.CompleteAsync();
}
await ReplyConfirmLocalized("global_perms_reset").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)] [RequireUserPermission(GuildPermission.Administrator)]

View File

@ -22,7 +22,7 @@ namespace NadekoBot.Modules.Administration
[Group] [Group]
public class GameChannelCommands : NadekoSubmodule public class GameChannelCommands : NadekoSubmodule
{ {
private static readonly Timer _t; //private static readonly Timer _t;
private static readonly ConcurrentHashSet<ulong> gameVoiceChannels = new ConcurrentHashSet<ulong>(); private static readonly ConcurrentHashSet<ulong> gameVoiceChannels = new ConcurrentHashSet<ulong>();

View File

@ -0,0 +1,118 @@
using Discord;
using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.DataStructures;
using NadekoBot.Extensions;
using NadekoBot.Services;
using NadekoBot.Services.Database;
using NadekoBot.TypeReaders;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Permissions
{
public partial class Permissions
{
[Group]
public class GlobalPermissionCommands : NadekoSubmodule
{
public static readonly ConcurrentHashSet<string> BlockedModules;
public static readonly ConcurrentHashSet<string> BlockedCommands;
static GlobalPermissionCommands()
{
BlockedModules = new ConcurrentHashSet<string>(NadekoBot.BotConfig.BlockedModules.Select(x => x.Name));
BlockedCommands = new ConcurrentHashSet<string>(NadekoBot.BotConfig.BlockedCommands.Select(x => x.Name));
}
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public async Task Lgp()
{
if (!BlockedModules.Any() && !BlockedCommands.Any())
{
await ReplyErrorLocalized("lgp_none").ConfigureAwait(false);
return;
}
var embed = new EmbedBuilder().WithOkColor();
if (BlockedModules.Any())
embed.AddField(efb => efb.WithName(GetText("blocked_modules")).WithValue(string.Join("\n", BlockedModules)).WithIsInline(false));
if (BlockedCommands.Any())
embed.AddField(efb => efb.WithName(GetText("blocked_commands")).WithValue(string.Join("\n", BlockedCommands)).WithIsInline(false));
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public async Task Gmod(ModuleInfo module)
{
var moduleName = module.Name.ToLowerInvariant();
if (BlockedModules.Add(moduleName))
{
using (var uow = DbHandler.UnitOfWork())
{
var bc = uow.BotConfig.GetOrCreate();
bc.BlockedModules.Add(new Services.Database.Models.BlockedCmdOrMdl
{
Name = moduleName,
});
uow.Complete();
}
await ReplyConfirmLocalized("gmod_add", Format.Bold(module.Name)).ConfigureAwait(false);
return;
}
else if (BlockedModules.TryRemove(moduleName))
{
using (var uow = DbHandler.UnitOfWork())
{
var bc = uow.BotConfig.GetOrCreate();
bc.BlockedModules.RemoveWhere(x => x.Name == moduleName);
uow.Complete();
}
await ReplyConfirmLocalized("gmod_remove", Format.Bold(module.Name)).ConfigureAwait(false);
return;
}
}
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public async Task Gcmd(CommandOrCrInfo cmd)
{
var commandName = cmd.Name.ToLowerInvariant();
if (BlockedCommands.Add(commandName))
{
using (var uow = DbHandler.UnitOfWork())
{
var bc = uow.BotConfig.GetOrCreate();
bc.BlockedCommands.Add(new Services.Database.Models.BlockedCmdOrMdl
{
Name = commandName,
});
uow.Complete();
}
await ReplyConfirmLocalized("gcmd_add", Format.Bold(cmd.Name)).ConfigureAwait(false);
return;
}
else if (BlockedCommands.TryRemove(commandName))
{
using (var uow = DbHandler.UnitOfWork())
{
var bc = uow.BotConfig.GetOrCreate();
bc.BlockedCommands.RemoveWhere(x => x.Name == commandName);
uow.Complete();
}
await ReplyConfirmLocalized("gcmd_remove", Format.Bold(cmd.Name)).ConfigureAwait(false);
return;
}
}
}
}
}

View File

@ -16,7 +16,6 @@ namespace NadekoBot.Modules.Utility
{ {
public partial class Utility public partial class Utility
{ {
public class CommandAliasEqualityComparer : IEqualityComparer<CommandAlias> public class CommandAliasEqualityComparer : IEqualityComparer<CommandAlias>
{ {
public bool Equals(CommandAlias x, CommandAlias y) => x.Trigger == y.Trigger; public bool Equals(CommandAlias x, CommandAlias y) => x.Trigger == y.Trigger;
@ -41,6 +40,11 @@ namespace NadekoBot.Modules.Utility
.ToDictionary(ca => ca.Trigger, ca => ca.Mapping)))); .ToDictionary(ca => ca.Trigger, ca => ca.Mapping))));
} }
public static void Unload()
{
AliasMaps.Clear();
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireUserPermission(GuildPermission.Administrator)] [RequireUserPermission(GuildPermission.Administrator)]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]

View File

@ -3,6 +3,7 @@ using Discord.Commands;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Services; using NadekoBot.Services;
using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -16,7 +17,15 @@ namespace NadekoBot.Modules.Utility
{ {
static CrossServerTextChannel() static CrossServerTextChannel()
{ {
NadekoBot.Client.MessageReceived += async imsg => NadekoBot.Client.MessageReceived += Client_MessageReceived;
}
public static void Unload()
{
NadekoBot.Client.MessageReceived -= Client_MessageReceived;
}
private static async Task Client_MessageReceived(Discord.WebSocket.SocketMessage imsg)
{ {
try try
{ {
@ -52,7 +61,6 @@ namespace NadekoBot.Modules.Utility
{ {
// ignored // ignored
} }
};
} }
private static string GetMessage(ITextChannel channel, IGuildUser user, IUserMessage message) => private static string GetMessage(ITextChannel channel, IGuildUser user, IUserMessage message) =>

View File

@ -48,7 +48,6 @@ namespace NadekoBot.Modules.Utility
Task.Run(Run); Task.Run(Run);
} }
private async Task Run() private async Task Run()
{ {
source = new CancellationTokenSource(); source = new CancellationTokenSource();
@ -124,7 +123,12 @@ namespace NadekoBot.Modules.Utility
{ {
var _ = Task.Run(async () => var _ = Task.Run(async () =>
{ {
#if !GLOBAL_NADEKO
await Task.Delay(5000).ConfigureAwait(false); await Task.Delay(5000).ConfigureAwait(false);
#else
await Task.Delay(30000).ConfigureAwait(false);
#endif
//todo this is pretty terrible
Repeaters = new ConcurrentDictionary<ulong, ConcurrentQueue<RepeatRunner>>(NadekoBot.AllGuildConfigs Repeaters = new ConcurrentDictionary<ulong, ConcurrentQueue<RepeatRunner>>(NadekoBot.AllGuildConfigs
.ToDictionary(gc => gc.GuildId, .ToDictionary(gc => gc.GuildId,
gc => new ConcurrentQueue<RepeatRunner>(gc.GuildRepeaters gc => new ConcurrentQueue<RepeatRunner>(gc.GuildRepeaters
@ -134,6 +138,21 @@ namespace NadekoBot.Modules.Utility
}); });
} }
public static void Unload()
{
_ready = false;
foreach (var kvp in Repeaters)
{
RepeatRunner r;
while (kvp.Value.TryDequeue(out r))
{
r.Stop();
}
}
Repeaters.Clear();
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageMessages)] [RequireUserPermission(GuildPermission.ManageMessages)]

View File

@ -29,6 +29,11 @@ namespace NadekoBot.Modules.Utility
patreon = PatreonThingy.Instance; patreon = PatreonThingy.Instance;
} }
public static void Unload()
{
patreon.Updater.Change(Timeout.Infinite, Timeout.Infinite);
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[OwnerOnly] [OwnerOnly]
public async Task PatreonRewardsReload() public async Task PatreonRewardsReload()
@ -86,7 +91,7 @@ namespace NadekoBot.Modules.Utility
public ImmutableArray<PatreonUserAndReward> Pledges { get; private set; } public ImmutableArray<PatreonUserAndReward> Pledges { get; private set; }
public DateTime LastUpdate { get; private set; } = DateTime.UtcNow; public DateTime LastUpdate { get; private set; } = DateTime.UtcNow;
private readonly Timer update; public readonly Timer Updater;
private readonly SemaphoreSlim claimLockJustInCase = new SemaphoreSlim(1, 1); private readonly SemaphoreSlim claimLockJustInCase = new SemaphoreSlim(1, 1);
private readonly Logger _log; private readonly Logger _log;
@ -97,7 +102,7 @@ namespace NadekoBot.Modules.Utility
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.PatreonAccessToken)) if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.PatreonAccessToken))
return; return;
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
update = new Timer(async (_) => await LoadPledges(), null, TimeSpan.Zero, Interval); Updater = new Timer(async (_) => await LoadPledges(), null, TimeSpan.Zero, Interval);
} }
public async Task LoadPledges() public async Task LoadPledges()

View File

@ -32,10 +32,15 @@ namespace NadekoBot.Modules.Utility
}; };
private new static readonly Logger _log; private new static readonly Logger _log;
private static readonly CancellationTokenSource cancelSource;
private static readonly CancellationToken cancelAllToken;
static RemindCommands() static RemindCommands()
{ {
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
cancelSource = new CancellationTokenSource();
cancelAllToken = cancelSource.Token;
List<Reminder> reminders; List<Reminder> reminders;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -45,11 +50,17 @@ namespace NadekoBot.Modules.Utility
foreach (var r in reminders) foreach (var r in reminders)
{ {
Task.Run(() => StartReminder(r)); Task.Run(() => StartReminder(r, cancelAllToken));
} }
} }
private static async Task StartReminder(Reminder r) public static void Unload()
{
if (!cancelSource.IsCancellationRequested)
cancelSource.Cancel();
}
private static async Task StartReminder(Reminder r, CancellationToken t)
{ {
var now = DateTime.Now; var now = DateTime.Now;
@ -58,7 +69,7 @@ namespace NadekoBot.Modules.Utility
if (time.TotalMilliseconds > int.MaxValue) if (time.TotalMilliseconds > int.MaxValue)
return; return;
await Task.Delay(time).ConfigureAwait(false); await Task.Delay(time, t).ConfigureAwait(false);
try try
{ {
IMessageChannel ch; IMessageChannel ch;
@ -188,7 +199,7 @@ namespace NadekoBot.Modules.Utility
{ {
// ignored // ignored
} }
await StartReminder(rem); await StartReminder(rem, cancelAllToken);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -49,14 +49,19 @@ namespace NadekoBot.Modules.Utility
} }
Units = data.ToList(); Units = data.ToList();
} }
catch (Exception e) catch (Exception ex)
{ {
_log.Warn("Could not load units: " + e.Message); _log.Warn("Could not load units: " + ex.Message);
} }
_timer = new Timer(async (obj) => await UpdateCurrency(), null, _updateInterval, _updateInterval); _timer = new Timer(async (obj) => await UpdateCurrency(), null, _updateInterval, _updateInterval);
} }
public static void Unload()
{
_timer.Change(Timeout.Infinite, Timeout.Infinite);
}
public static async Task UpdateCurrency() public static async Task UpdateCurrency()
{ {
try try

View File

@ -25,6 +25,12 @@ namespace NadekoBot.Modules.Utility
{ {
private static ConcurrentDictionary<ulong, Timer> _rotatingRoleColors = new ConcurrentDictionary<ulong, Timer>(); private static ConcurrentDictionary<ulong, Timer> _rotatingRoleColors = new ConcurrentDictionary<ulong, Timer>();
public static void Unload()
{
_rotatingRoleColors.ForEach(x => x.Value?.Change(Timeout.Infinite, Timeout.Infinite));
_rotatingRoleColors.Clear();
}
//[NadekoCommand, Usage, Description, Aliases] //[NadekoCommand, Usage, Description, Aliases]
//[RequireContext(ContextType.Guild)] //[RequireContext(ContextType.Guild)]
//public async Task Midorina([Remainder] string arg) //public async Task Midorina([Remainder] string arg)
@ -101,6 +107,7 @@ namespace NadekoBot.Modules.Utility
// })); // }));
//} //}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.ManageRoles)] [RequireUserPermission(GuildPermission.ManageRoles)]

View File

@ -3012,7 +3012,7 @@ namespace NadekoBot.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Toggles game voice channel feature in the voice channel you&apos;re currently in. Users who join the game voice channel will get automatically redirected to the voice channel with the name of their current game if it exists. Can&apos;t move users to channels that the bot has no connect permission for. One per server.. /// Looks up a localized string similar to Toggles game voice channel feature in the voice channel you&apos;re currently in. Users who join the game voice channel will get automatically redirected to the voice channel with the name of their current game, if it exists. Can&apos;t move users to channels that the bot has no connect permission for. One per server..
/// </summary> /// </summary>
public static string gamevoicechannel_desc { public static string gamevoicechannel_desc {
get { get {
@ -3029,6 +3029,33 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to globalcommand gcmd.
/// </summary>
public static string gcmd_cmd {
get {
return ResourceManager.GetString("gcmd_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enables or disables a command from use on all servers..
/// </summary>
public static string gcmd_desc {
get {
return ResourceManager.GetString("gcmd_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}gcmd `.
/// </summary>
public static string gcmd_usage {
get {
return ResourceManager.GetString("gcmd_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to gelbooru. /// Looks up a localized string similar to gelbooru.
/// </summary> /// </summary>
@ -3110,6 +3137,33 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to globalmodule gmod.
/// </summary>
public static string gmod_cmd {
get {
return ResourceManager.GetString("gmod_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enable or disable a module from use on all servers..
/// </summary>
public static string gmod_desc {
get {
return ResourceManager.GetString("gmod_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}gmod nsfw disable`.
/// </summary>
public static string gmod_usage {
get {
return ResourceManager.GetString("gmod_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to google g. /// Looks up a localized string similar to google g.
/// </summary> /// </summary>
@ -4055,6 +4109,33 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to listglobalperms lgp.
/// </summary>
public static string lgp_cmd {
get {
return ResourceManager.GetString("lgp_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Lists global permissions set by the bot owner..
/// </summary>
public static string lgp_desc {
get {
return ResourceManager.GetString("lgp_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}lgp`.
/// </summary>
public static string lgp_usage {
get {
return ResourceManager.GetString("lgp_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to linux. /// Looks up a localized string similar to linux.
/// </summary> /// </summary>
@ -6512,6 +6593,33 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to resetglobalperms.
/// </summary>
public static string resetglobalpermissions_cmd {
get {
return ResourceManager.GetString("resetglobalpermissions_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Resets global permissions set by bot owner..
/// </summary>
public static string resetglobalpermissions_desc {
get {
return ResourceManager.GetString("resetglobalpermissions_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}resetglobalperms`.
/// </summary>
public static string resetglobalpermissions_usage {
get {
return ResourceManager.GetString("resetglobalpermissions_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to resetperms. /// Looks up a localized string similar to resetperms.
/// </summary> /// </summary>

View File

@ -3421,7 +3421,7 @@
<value>gvc</value> <value>gvc</value>
</data> </data>
<data name="gamevoicechannel_desc" xml:space="preserve"> <data name="gamevoicechannel_desc" xml:space="preserve">
<value>Toggles game voice channel feature in the voice channel you're currently in. Users who join the game voice channel will get automatically redirected to the voice channel with the name of their current game if it exists. Can't move users to channels that the bot has no connect permission for. One per server.</value> <value>Toggles game voice channel feature in the voice channel you're currently in. Users who join the game voice channel will get automatically redirected to the voice channel with the name of their current game, if it exists. Can't move users to channels that the bot has no connect permission for. One per server.</value>
</data> </data>
<data name="gamevoicechannel_usage" xml:space="preserve"> <data name="gamevoicechannel_usage" xml:space="preserve">
<value>`{0}gvc`</value> <value>`{0}gvc`</value>
@ -3438,4 +3438,40 @@
<data name="shopremove_usage" xml:space="preserve"> <data name="shopremove_usage" xml:space="preserve">
<value>`{0}shoprm 1`</value> <value>`{0}shoprm 1`</value>
</data> </data>
<data name="gcmd_cmd" xml:space="preserve">
<value>globalcommand gcmd</value>
</data>
<data name="gcmd_desc" xml:space="preserve">
<value>Enables or disables a command from use on all servers.</value>
</data>
<data name="gcmd_usage" xml:space="preserve">
<value>`{0}gcmd `</value>
</data>
<data name="gmod_cmd" xml:space="preserve">
<value>globalmodule gmod</value>
</data>
<data name="gmod_desc" xml:space="preserve">
<value>Enable or disable a module from use on all servers.</value>
</data>
<data name="gmod_usage" xml:space="preserve">
<value>`{0}gmod nsfw disable`</value>
</data>
<data name="lgp_cmd" xml:space="preserve">
<value>listglobalperms lgp</value>
</data>
<data name="lgp_desc" xml:space="preserve">
<value>Lists global permissions set by the bot owner.</value>
</data>
<data name="lgp_usage" xml:space="preserve">
<value>`{0}lgp`</value>
</data>
<data name="resetglobalpermissions_cmd" xml:space="preserve">
<value>resetglobalperms</value>
</data>
<data name="resetglobalpermissions_desc" xml:space="preserve">
<value>Resets global permissions set by bot owner.</value>
</data>
<data name="resetglobalpermissions_usage" xml:space="preserve">
<value>`{0}resetglobalperms`</value>
</data>
</root> </root>

View File

@ -411,6 +411,15 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Global permissions have been reset..
/// </summary>
public static string administration_global_perms_reset {
get {
return ResourceManager.GetString("administration_global_perms_reset", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Greet announcements disabled.. /// Looks up a localized string similar to Greet announcements disabled..
/// </summary> /// </summary>
@ -4711,6 +4720,24 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Blocked Commands.
/// </summary>
public static string permissions_blocked_commands {
get {
return ResourceManager.GetString("permissions_blocked_commands", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Blocked Modules.
/// </summary>
public static string permissions_blocked_modules {
get {
return ResourceManager.GetString("permissions_blocked_modules", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Command {0} now has a {1}s cooldown.. /// Looks up a localized string similar to Command {0} now has a {1}s cooldown..
/// </summary> /// </summary>
@ -4801,6 +4828,42 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to Command {0} has been disabled on all servers..
/// </summary>
public static string permissions_gcmd_add {
get {
return ResourceManager.GetString("permissions_gcmd_add", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Command {0} has been enabled on all servers..
/// </summary>
public static string permissions_gcmd_remove {
get {
return ResourceManager.GetString("permissions_gcmd_remove", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Module {0} has been disabled on all servers..
/// </summary>
public static string permissions_gmod_add {
get {
return ResourceManager.GetString("permissions_gmod_add", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Module {0} has been enabled on all servers..
/// </summary>
public static string permissions_gmod_remove {
get {
return ResourceManager.GetString("permissions_gmod_remove", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Invalid second parameter.(Must be a number between {0} and {1}). /// Looks up a localized string similar to Invalid second parameter.(Must be a number between {0} and {1}).
/// </summary> /// </summary>
@ -4846,6 +4909,15 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to No blocked commands or modules..
/// </summary>
public static string permissions_lgp_none {
get {
return ResourceManager.GetString("permissions_lgp_none", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Moved permission {0} from #{1} to #{2}. /// Looks up a localized string similar to Moved permission {0} from #{1} to #{2}.
/// </summary> /// </summary>

View File

@ -2431,6 +2431,9 @@ Owner ID: {2}</value>
<value>Next update in {0}</value> <value>Next update in {0}</value>
<comment>Next update in 05:30</comment> <comment>Next update in 05:30</comment>
</data> </data>
<data name="administration_global_perms_reset" xml:space="preserve">
<value>Global permissions have been reset.</value>
</data>
<data name="administration_gvc_disabled" xml:space="preserve"> <data name="administration_gvc_disabled" xml:space="preserve">
<value>Game Voice Channel feature has been disabled on this server.</value> <value>Game Voice Channel feature has been disabled on this server.</value>
</data> </data>
@ -2485,4 +2488,25 @@ Owner ID: {2}</value>
<data name="gambling_unique_items_left" xml:space="preserve"> <data name="gambling_unique_items_left" xml:space="preserve">
<value>{0} unique items left.</value> <value>{0} unique items left.</value>
</data> </data>
<data name="permissions_blocked_commands" xml:space="preserve">
<value>Blocked Commands</value>
</data>
<data name="permissions_blocked_modules" xml:space="preserve">
<value>Blocked Modules</value>
</data>
<data name="permissions_gcmd_add" xml:space="preserve">
<value>Command {0} has been disabled on all servers.</value>
</data>
<data name="permissions_gcmd_remove" xml:space="preserve">
<value>Command {0} has been enabled on all servers.</value>
</data>
<data name="permissions_gmod_add" xml:space="preserve">
<value>Module {0} has been disabled on all servers.</value>
</data>
<data name="permissions_gmod_remove" xml:space="preserve">
<value>Module {0} has been enabled on all servers.</value>
</data>
<data name="permissions_lgp_none" xml:space="preserve">
<value>No blocked commands or modules.</value>
</data>
</root> </root>

View File

@ -486,15 +486,22 @@ namespace NadekoBot.Services
} }
} }
int price; //int price;
if (Permissions.CommandCostCommands.CommandCosts.TryGetValue(cmd.Aliases.First().Trim().ToLowerInvariant(), out price) && price > 0) //if (Permissions.CommandCostCommands.CommandCosts.TryGetValue(cmd.Aliases.First().Trim().ToLowerInvariant(), out price) && price > 0)
{ //{
var success = await CurrencyHandler.RemoveCurrencyAsync(context.User.Id, $"Running {cmd.Name} command.", price).ConfigureAwait(false); // var success = await CurrencyHandler.RemoveCurrencyAsync(context.User.Id, $"Running {cmd.Name} command.", price).ConfigureAwait(false);
if (!success) // if (!success)
{ // {
return new ExecuteCommandResult(cmd, pc, SearchResult.FromError(CommandError.Exception, $"Insufficient funds. You need {price}{NadekoBot.BotConfig.CurrencySign} to run this command.")); // return new ExecuteCommandResult(cmd, pc, SearchResult.FromError(CommandError.Exception, $"Insufficient funds. You need {price}{NadekoBot.BotConfig.CurrencySign} to run this command."));
} // }
//}
} }
if (cmd.Name != "resetglobalperms" &&
(GlobalPermissionCommands.BlockedCommands.Contains(cmd.Aliases.First().ToLowerInvariant()) ||
GlobalPermissionCommands.BlockedModules.Contains(module.Name.ToLowerInvariant())))
{
return new ExecuteCommandResult(cmd, null, SearchResult.FromError(CommandError.Exception, $"Command or module is blocked globally by the bot owner."));
} }
// Bot will ignore commands which are ran more often than what specified by // Bot will ignore commands which are ran more often than what specified by

View File

@ -62,6 +62,25 @@ Nadeko Support Server: https://discord.gg/nadekobot";
public string ErrorColor { get; set; } = "ee281f"; public string ErrorColor { get; set; } = "ee281f";
public string Locale { get; set; } = null; public string Locale { get; set; } = null;
public List<StartupCommand> StartupCommands { get; set; } public List<StartupCommand> StartupCommands { get; set; }
public HashSet<BlockedCmdOrMdl> BlockedCommands { get; set; }
public HashSet<BlockedCmdOrMdl> BlockedModules { get; set; }
}
public class BlockedCmdOrMdl : DbEntity
{
public string Name { get; set; }
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
return ((BlockedCmdOrMdl)obj).Name.ToLowerInvariant() == Name.ToLowerInvariant();
}
public override int GetHashCode() => Name.GetHashCode();
} }
public class StartupCommand : DbEntity, IIndexed public class StartupCommand : DbEntity, IIndexed

View File

@ -22,6 +22,8 @@ namespace NadekoBot.Services.Database.Repositories.Impl
.Include(bc => bc.EightBallResponses) .Include(bc => bc.EightBallResponses)
.Include(bc => bc.ModulePrefixes) .Include(bc => bc.ModulePrefixes)
.Include(bc => bc.StartupCommands) .Include(bc => bc.StartupCommands)
.Include(bc => bc.BlockedCommands)
.Include(bc => bc.BlockedModules)
//.Include(bc => bc.CommandCosts) //.Include(bc => bc.CommandCosts)
.FirstOrDefault(); .FirstOrDefault();
else else