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())
|
||||
{
|
||||
var title =
|
||||
GetTextStatic("dm_from", NadekoBot.Localization.DefaultCultureInfo,
|
||||
typeof(Administration).Name.ToLowerInvariant()) + $" [{msg.Author}]({msg.Author.Id})";
|
||||
var title = GetTextStatic("dm_from",
|
||||
NadekoBot.Localization.DefaultCultureInfo,
|
||||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
var firstOwnerChannel = ownerChannels.First();
|
||||
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
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ namespace NadekoBot.Services
|
||||
private readonly CommandService _commandService;
|
||||
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; };
|
||||
|
||||
@ -61,21 +61,36 @@ namespace NadekoBot.Services
|
||||
UsersOnShortCooldown.Clear();
|
||||
}, null, GlobalCommandsCooldown, GlobalCommandsCooldown);
|
||||
}
|
||||
public async Task StartHandling()
|
||||
public Task StartHandling()
|
||||
{
|
||||
ownerChannels = (await Task.WhenAll(_client.GetGuilds().SelectMany(g => g.Users)
|
||||
.Where(u => NadekoBot.Credentials.OwnerIds.Contains(u.Id))
|
||||
.Distinct(new IGuildUserComparer())
|
||||
.Select(async u => { try { return await u.CreateDMChannelAsync(); } catch { return null; } })))
|
||||
.Where(ch => ch != null)
|
||||
.ToList();
|
||||
var _ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(5000).ConfigureAwait(false);
|
||||
ownerChannels = (await Task.WhenAll(_client.GetGuilds().SelectMany(g => g.Users)
|
||||
.Where(u => NadekoBot.Credentials.OwnerIds.Contains(u.Id))
|
||||
.Distinct(new IGuildUserComparer())
|
||||
.Select(async u =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return await u.CreateDMChannelAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
})))
|
||||
.Where(ch => ch != null)
|
||||
.ToList();
|
||||
|
||||
if (!ownerChannels.Any())
|
||||
_log.Warn("No owner channels created! Make sure you've specified correct OwnerId in the credentials.json file.");
|
||||
else
|
||||
_log.Info($"Created {ownerChannels.Count} out of {NadekoBot.Credentials.OwnerIds.Count} owner message channels.");
|
||||
if (!ownerChannels.Any())
|
||||
_log.Warn("No owner channels created! Make sure you've specified correct OwnerId in the credentials.json file.");
|
||||
else
|
||||
_log.Info($"Created {ownerChannels.Count} out of {NadekoBot.Credentials.OwnerIds.Count} owner message channels.");
|
||||
});
|
||||
|
||||
_client.MessageReceived += MessageReceivedHandler;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task<bool> TryRunCleverbot(SocketUserMessage usrMsg, IGuild guild)
|
||||
|
Loading…
Reference in New Issue
Block a user