owner channel bugs fixed, you can now see files sent to the bot
This commit is contained in:
parent
e65e47ba1f
commit
cf686a20c3
@ -72,23 +72,42 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
if (_forwardDMs && ownerChannels.Any())
|
if (_forwardDMs && ownerChannels.Any())
|
||||||
{
|
{
|
||||||
var title =
|
var title = GetTextStatic("dm_from",
|
||||||
GetTextStatic("dm_from", NadekoBot.Localization.DefaultCultureInfo,
|
NadekoBot.Localization.DefaultCultureInfo,
|
||||||
typeof(Administration).Name.ToLowerInvariant()) + $" [{msg.Author}]({msg.Author.Id})";
|
typeof(Administration).Name.ToLowerInvariant()) +
|
||||||
|
$" [{msg.Author}]({msg.Author.Id})";
|
||||||
|
|
||||||
|
var attachamentsTxt = GetTextStatic("attachments",
|
||||||
|
NadekoBot.Localization.DefaultCultureInfo,
|
||||||
|
typeof(Administration).Name.ToLowerInvariant());
|
||||||
|
|
||||||
|
var toSend = msg.Content;
|
||||||
|
|
||||||
|
if (msg.Attachments.Count > 0)
|
||||||
|
{
|
||||||
|
toSend += $"\n\n{Format.Code(attachamentsTxt)}:\n" +
|
||||||
|
string.Join("\n", msg.Attachments.Select(a => a.ProxyUrl));
|
||||||
|
}
|
||||||
|
|
||||||
if (_forwardDMsToAllOwners)
|
if (_forwardDMsToAllOwners)
|
||||||
{
|
{
|
||||||
await Task.WhenAll(ownerChannels.Where(ch => ch.Recipient.Id != msg.Author.Id)
|
await Task.WhenAll(ownerChannels.Where(ch => ch.Recipient.Id != msg.Author.Id)
|
||||||
.Select(ch => ch.SendConfirmAsync(title, msg.Content))).ConfigureAwait(false);
|
.Select(ch => ch.SendConfirmAsync(title, toSend))).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var firstOwnerChannel = ownerChannels.First();
|
var firstOwnerChannel = ownerChannels.First();
|
||||||
if (firstOwnerChannel.Recipient.Id != msg.Author.Id)
|
if (firstOwnerChannel.Recipient.Id != msg.Author.Id)
|
||||||
try { await firstOwnerChannel.SendConfirmAsync(title, msg.Content).ConfigureAwait(false); }
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await firstOwnerChannel.SendConfirmAsync(title, toSend).ConfigureAwait(false);
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ namespace NadekoBot.Services
|
|||||||
private readonly CommandService _commandService;
|
private readonly CommandService _commandService;
|
||||||
private readonly Logger _log;
|
private readonly Logger _log;
|
||||||
|
|
||||||
private List<IDMChannel> ownerChannels { get; set; }
|
private List<IDMChannel> ownerChannels { get; set; } = new List<IDMChannel>();
|
||||||
|
|
||||||
public event Func<SocketUserMessage, CommandInfo, Task> CommandExecuted = delegate { return Task.CompletedTask; };
|
public event Func<SocketUserMessage, CommandInfo, Task> CommandExecuted = delegate { return Task.CompletedTask; };
|
||||||
|
|
||||||
@ -61,21 +61,36 @@ namespace NadekoBot.Services
|
|||||||
UsersOnShortCooldown.Clear();
|
UsersOnShortCooldown.Clear();
|
||||||
}, null, GlobalCommandsCooldown, GlobalCommandsCooldown);
|
}, null, GlobalCommandsCooldown, GlobalCommandsCooldown);
|
||||||
}
|
}
|
||||||
public async Task StartHandling()
|
public Task StartHandling()
|
||||||
{
|
{
|
||||||
ownerChannels = (await Task.WhenAll(_client.GetGuilds().SelectMany(g => g.Users)
|
var _ = Task.Run(async () =>
|
||||||
.Where(u => NadekoBot.Credentials.OwnerIds.Contains(u.Id))
|
{
|
||||||
.Distinct(new IGuildUserComparer())
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
.Select(async u => { try { return await u.CreateDMChannelAsync(); } catch { return null; } })))
|
ownerChannels = (await Task.WhenAll(_client.GetGuilds().SelectMany(g => g.Users)
|
||||||
.Where(ch => ch != null)
|
.Where(u => NadekoBot.Credentials.OwnerIds.Contains(u.Id))
|
||||||
.ToList();
|
.Distinct(new IGuildUserComparer())
|
||||||
|
.Select(async u =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await u.CreateDMChannelAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})))
|
||||||
|
.Where(ch => ch != null)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
if (!ownerChannels.Any())
|
if (!ownerChannels.Any())
|
||||||
_log.Warn("No owner channels created! Make sure you've specified correct OwnerId in the credentials.json file.");
|
_log.Warn("No owner channels created! Make sure you've specified correct OwnerId in the credentials.json file.");
|
||||||
else
|
else
|
||||||
_log.Info($"Created {ownerChannels.Count} out of {NadekoBot.Credentials.OwnerIds.Count} owner message channels.");
|
_log.Info($"Created {ownerChannels.Count} out of {NadekoBot.Credentials.OwnerIds.Count} owner message channels.");
|
||||||
|
});
|
||||||
|
|
||||||
_client.MessageReceived += MessageReceivedHandler;
|
_client.MessageReceived += MessageReceivedHandler;
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> TryRunCleverbot(SocketUserMessage usrMsg, IGuild guild)
|
private async Task<bool> TryRunCleverbot(SocketUserMessage usrMsg, IGuild guild)
|
||||||
|
Loading…
Reference in New Issue
Block a user