Disabled log commands on the public bot, added something for xnaas, closes #1245

This commit is contained in:
Master Kwoth 2017-06-16 17:47:02 +02:00
parent 6bc4bb7803
commit 8801a7451b
9 changed files with 1648 additions and 44 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace NadekoBot.Migrations
{
public partial class crstartswith : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "CustomReactionsStartWith",
table: "BotConfig",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CustomReactionsStartWith",
table: "BotConfig");
}
}
}

View File

@ -149,6 +149,8 @@ namespace NadekoBot.Migrations
b.Property<string>("CurrencySign");
b.Property<bool>("CustomReactionsStartWith");
b.Property<string>("DMHelpString");
b.Property<DateTime?>("DateAdded");

View File

@ -1,6 +1,7 @@
using Discord;
using Discord.Commands;
using NadekoBot.Attributes;
using NadekoBot.DataStructures;
using NadekoBot.Extensions;
using NadekoBot.Modules.Permissions;
using NadekoBot.Services;
@ -16,6 +17,7 @@ namespace NadekoBot.Modules.Administration
public partial class Administration
{
[Group]
[NoPublicBot]
public class LogCommands : NadekoSubmodule
{
private readonly LogCommandService _lc;

View File

@ -145,7 +145,7 @@ namespace NadekoBot
var clashService = new ClashOfClansService(Client, Db, Localization, Strings);
var musicService = new MusicService(GoogleApi, Strings, Localization, Db, soundcloudApiService, Credentials, AllGuildConfigs);
var crService = new CustomReactionsService(permissionsService, Db, Client, CommandHandler);
var crService = new CustomReactionsService(permissionsService, Db, Client, CommandHandler, BotConfig);
#region Games
var gamesService = new GamesService(Client, BotConfig, AllGuildConfigs, Strings, Images, CommandHandler);

View File

@ -94,9 +94,8 @@ namespace NadekoBot.Services.Administration
private string GetText(IGuild guild, string key, params object[] replacements) =>
_strings.GetText(key, guild.Id, "Administration".ToLowerInvariant(), replacements);
private async Task _client_UserUpdated(SocketUser before, SocketUser uAfter)
private Task _client_UserUpdated(SocketUser before, SocketUser uAfter)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -164,11 +163,11 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private async Task _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
private Task _client_UserVoiceStateUpdated_TTS(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -212,11 +211,11 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private async void MuteCommands_UserMuted(IGuildUser usr, MuteType muteType)
private void MuteCommands_UserMuted(IGuildUser usr, MuteType muteType)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -257,9 +256,8 @@ namespace NadekoBot.Services.Administration
});
}
private async void MuteCommands_UserUnmuted(IGuildUser usr, MuteType muteType)
private void MuteCommands_UserUnmuted(IGuildUser usr, MuteType muteType)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -301,9 +299,8 @@ namespace NadekoBot.Services.Administration
});
}
public async Task TriggeredAntiProtection(PunishmentAction action, ProtectionType protection, params IGuildUser[] users)
public Task TriggeredAntiProtection(PunishmentAction action, ProtectionType protection, params IGuildUser[] users)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -348,11 +345,11 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private async Task _client_GuildUserUpdated(SocketGuildUser before, SocketGuildUser after)
private Task _client_GuildUserUpdated(SocketGuildUser before, SocketGuildUser after)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -397,11 +394,11 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private async Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
private Task _client_ChannelUpdated(IChannel cbefore, IChannel cafter)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -448,11 +445,11 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private async Task _client_ChannelDestroyed(IChannel ich)
private Task _client_ChannelDestroyed(IChannel ich)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -487,11 +484,11 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private async Task _client_ChannelCreated(IChannel ich)
private Task _client_ChannelCreated(IChannel ich)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -522,11 +519,11 @@ namespace NadekoBot.Services.Administration
}
catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
}
private async Task _client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
private Task _client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState before, SocketVoiceState after)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -576,11 +573,11 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private async Task _client_UserPresenceUpdated(Optional<SocketGuild> optGuild, SocketUser usr, SocketPresence before, SocketPresence after)
private Task _client_UserPresenceUpdated(Optional<SocketGuild> optGuild, SocketUser usr, SocketPresence before, SocketPresence after)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -619,11 +616,11 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private async Task _client_UserLeft(IGuildUser usr)
private Task _client_UserLeft(IGuildUser usr)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -649,6 +646,7 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private Task _client_UserJoined(IGuildUser usr)
@ -678,9 +676,8 @@ namespace NadekoBot.Services.Administration
return Task.CompletedTask;
}
private async Task _client_UserUnbanned(IUser usr, IGuild guild)
private Task _client_UserUnbanned(IUser usr, IGuild guild)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -703,11 +700,11 @@ namespace NadekoBot.Services.Administration
}
catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
}
private async Task _client_UserBanned(IUser usr, IGuild guild)
private Task _client_UserBanned(IUser usr, IGuild guild)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -729,11 +726,11 @@ namespace NadekoBot.Services.Administration
}
catch (Exception ex) { _log.Warn(ex); }
});
return Task.CompletedTask;
}
private async Task _client_MessageDeleted(Cacheable<IMessage, ulong> optMsg, ISocketMessageChannel ch)
private Task _client_MessageDeleted(Cacheable<IMessage, ulong> optMsg, ISocketMessageChannel ch)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -772,11 +769,11 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
private async Task _client_MessageUpdated(Cacheable<IMessage, ulong> optmsg, SocketMessage imsg2, ISocketMessageChannel ch)
private Task _client_MessageUpdated(Cacheable<IMessage, ulong> optmsg, SocketMessage imsg2, ISocketMessageChannel ch)
{
await Task.Yield();
var _ = Task.Run(async () =>
{
try
@ -821,6 +818,7 @@ namespace NadekoBot.Services.Administration
// ignored
}
});
return Task.CompletedTask;
}
public enum LogType

View File

@ -25,15 +25,17 @@ namespace NadekoBot.Services.CustomReactions
private readonly DiscordShardedClient _client;
private readonly PermissionService _perms;
private readonly CommandHandler _cmd;
private readonly BotConfig _bc;
public CustomReactionsService(PermissionService perms, DbService db,
DiscordShardedClient client, CommandHandler cmd)
DiscordShardedClient client, CommandHandler cmd, BotConfig bc)
{
_log = LogManager.GetCurrentClassLogger();
_db = db;
_client = client;
_perms = perms;
_cmd = cmd;
_bc = bc;
var sw = Stopwatch.StartNew();
using (var uow = _db.UnitOfWork)
@ -66,7 +68,7 @@ namespace NadekoBot.Services.CustomReactions
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant();
return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.CustomReactionsStartWith && content.StartsWith(trigger)) || content == trigger);
}).ToArray();
if (rs.Length != 0)
@ -87,7 +89,7 @@ namespace NadekoBot.Services.CustomReactions
return false;
var hasTarget = cr.Response.ToLowerInvariant().Contains("%target%");
var trigger = cr.TriggerWithContext(umsg, _client).Trim().ToLowerInvariant();
return ((hasTarget && content.StartsWith(trigger + " ")) || content == trigger);
return ((hasTarget && content.StartsWith(trigger + " ")) || (_bc.CustomReactionsStartWith && content.StartsWith(trigger)) || content == trigger);
}).ToArray();
if (grs.Length == 0)
return null;

View File

@ -67,6 +67,7 @@ Nadeko Support Server: https://discord.gg/nadekobot";
public HashSet<BlockedCmdOrMdl> BlockedModules { get; set; }
public int PermissionVersion { get; set; } = 1;
public string DefaultPrefix { get; set; } = ".";
public bool CustomReactionsStartWith { get; set; } = false;
}
public class BlockedCmdOrMdl : DbEntity

View File

@ -46,21 +46,27 @@ namespace NadekoBot.Services.Impl
cmdHandler.CommandExecuted += (_, e) => Task.FromResult(Interlocked.Increment(ref _commandsRan));
_client.ChannelCreated += (c) =>
{
var _ = Task.Run(() =>
{
if (c is ITextChannel)
Interlocked.Increment(ref _textChannels);
else if (c is IVoiceChannel)
Interlocked.Increment(ref _voiceChannels);
});
return Task.CompletedTask;
};
_client.ChannelDestroyed += (c) =>
{
var _ = Task.Run(() =>
{
if (c is ITextChannel)
Interlocked.Decrement(ref _textChannels);
else if (c is IVoiceChannel)
Interlocked.Decrement(ref _voiceChannels);
});
return Task.CompletedTask;
};