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<string>("CurrencySign");
b.Property<bool>("CustomReactionsStartWith");
b.Property<string>("DMHelpString"); b.Property<string>("DMHelpString");
b.Property<DateTime?>("DateAdded"); b.Property<DateTime?>("DateAdded");

View File

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

View File

@ -145,7 +145,7 @@ namespace NadekoBot
var clashService = new ClashOfClansService(Client, Db, Localization, Strings); var clashService = new ClashOfClansService(Client, Db, Localization, Strings);
var musicService = new MusicService(GoogleApi, Strings, Localization, Db, soundcloudApiService, Credentials, AllGuildConfigs); 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 #region Games
var gamesService = new GamesService(Client, BotConfig, AllGuildConfigs, Strings, Images, CommandHandler); 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) => private string GetText(IGuild guild, string key, params object[] replacements) =>
_strings.GetText(key, guild.Id, "Administration".ToLowerInvariant(), 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -164,11 +163,11 @@ namespace NadekoBot.Services.Administration
// ignored // 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -212,11 +211,11 @@ namespace NadekoBot.Services.Administration
// ignored // 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 () => var _ = Task.Run(async () =>
{ {
try 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 () => var _ = Task.Run(async () =>
{ {
try 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -348,11 +345,11 @@ namespace NadekoBot.Services.Administration
// ignored // 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -397,11 +394,11 @@ namespace NadekoBot.Services.Administration
// ignored // 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -448,11 +445,11 @@ namespace NadekoBot.Services.Administration
// ignored // ignored
} }
}); });
return Task.CompletedTask;
} }
private async Task _client_ChannelDestroyed(IChannel ich) private Task _client_ChannelDestroyed(IChannel ich)
{ {
await Task.Yield();
var _ = Task.Run(async () => var _ = Task.Run(async () =>
{ {
try try
@ -487,11 +484,11 @@ namespace NadekoBot.Services.Administration
// ignored // ignored
} }
}); });
return Task.CompletedTask;
} }
private async Task _client_ChannelCreated(IChannel ich) private Task _client_ChannelCreated(IChannel ich)
{ {
await Task.Yield();
var _ = Task.Run(async () => var _ = Task.Run(async () =>
{ {
try try
@ -522,11 +519,11 @@ namespace NadekoBot.Services.Administration
} }
catch (Exception ex) { _log.Warn(ex); } 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -576,11 +573,11 @@ namespace NadekoBot.Services.Administration
// ignored // 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -619,11 +616,11 @@ namespace NadekoBot.Services.Administration
// ignored // ignored
} }
}); });
return Task.CompletedTask;
} }
private async Task _client_UserLeft(IGuildUser usr) private Task _client_UserLeft(IGuildUser usr)
{ {
await Task.Yield();
var _ = Task.Run(async () => var _ = Task.Run(async () =>
{ {
try try
@ -649,6 +646,7 @@ namespace NadekoBot.Services.Administration
// ignored // ignored
} }
}); });
return Task.CompletedTask;
} }
private Task _client_UserJoined(IGuildUser usr) private Task _client_UserJoined(IGuildUser usr)
@ -678,9 +676,8 @@ namespace NadekoBot.Services.Administration
return Task.CompletedTask; 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -703,11 +700,11 @@ namespace NadekoBot.Services.Administration
} }
catch (Exception ex) { _log.Warn(ex); } 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -729,11 +726,11 @@ namespace NadekoBot.Services.Administration
} }
catch (Exception ex) { _log.Warn(ex); } 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -772,11 +769,11 @@ namespace NadekoBot.Services.Administration
// ignored // 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 () => var _ = Task.Run(async () =>
{ {
try try
@ -821,6 +818,7 @@ namespace NadekoBot.Services.Administration
// ignored // ignored
} }
}); });
return Task.CompletedTask;
} }
public enum LogType public enum LogType

View File

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

View File

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

View File

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