bugfix, added option in config to forward messages to all owners.

This commit is contained in:
Master Kwoth 2016-07-11 12:28:43 +02:00
parent f1b839337a
commit 57bc26dd46
3 changed files with 29 additions and 14 deletions

View File

@ -92,7 +92,7 @@ namespace NadekoBot.Modules.Games.Commands
e.Channel.SendMessage($"There is already a {NadekoBot.Config.CurrencyName} in this channel.");
return;
}
var removed = FlowersHandler.RemoveFlowers(e.User, "Planted a flower.", 1);
var removed = FlowersHandler.RemoveFlowers(e.User, "Planted a flower.", 1).GetAwaiter().GetResult();
if (!removed)
{
e.Channel.SendMessage($"You don't have any {NadekoBot.Config.CurrencyName}s.").Wait();

View File

@ -42,7 +42,7 @@ namespace NadekoBot
public static string BotMention { get; set; } = "";
public static bool Ready { get; set; } = false;
private static Channel OwnerPrivateChannel { get; set; }
private static List<Channel> OwnerPrivateChannels { get; set; }
private static void Main()
{
@ -205,15 +205,19 @@ namespace NadekoBot
Console.WriteLine(await NadekoStats.Instance.GetStats().ConfigureAwait(false));
Console.WriteLine("-----------------");
OwnerPrivateChannels = new List<Channel>(Creds.OwnerIds.Length);
foreach (var id in Creds.OwnerIds)
{
try
{
OwnerPrivateChannel = await Client.CreatePrivateChannel(Creds.OwnerIds[0]).ConfigureAwait(false);
OwnerPrivateChannels.Add(await Client.CreatePrivateChannel(id).ConfigureAwait(false));
}
catch
{
Console.WriteLine("Failed creating private channel with the first owner listed in credentials.json");
Console.WriteLine($"Failed creating private channel with the owner {id} listed in credentials.json");
}
}
Client.ClientAPI.SendingRequest += (s, e) =>
{
var request = e.Request as Discord.API.Client.Rest.SendMessageRequest;
@ -234,8 +238,18 @@ namespace NadekoBot
public static async Task SendMessageToOwner(string message)
{
if (Config.ForwardMessages && OwnerPrivateChannel != null)
await OwnerPrivateChannel.SendMessage(message).ConfigureAwait(false);
if (Config.ForwardMessages && OwnerPrivateChannels.Any())
if (Config.ForwardToAllOwners)
OwnerPrivateChannels.ForEach(async c =>
{
try { await c.SendMessage(message).ConfigureAwait(false); } catch { }
});
else
{
var c = OwnerPrivateChannels.FirstOrDefault();
if (c != null)
await c.SendMessage(message).ConfigureAwait(false);
}
}
private static bool repliedRecently = false;
@ -248,8 +262,8 @@ namespace NadekoBot
if (ConfigHandler.IsBlackListed(e))
return;
if (Config.ForwardMessages && !NadekoBot.Creds.OwnerIds.Contains(e.User.Id) && OwnerPrivateChannel != null)
await OwnerPrivateChannel.SendMessage(e.User + ": ```\n" + e.Message.Text + "\n```").ConfigureAwait(false);
if (Config.ForwardMessages && !NadekoBot.Creds.OwnerIds.Contains(e.User.Id) && OwnerPrivateChannels.Any())
await SendMessageToOwner(e.User + ": ```\n" + e.Message.Text + "\n```").ConfigureAwait(false);
if (repliedRecently) return;

View File

@ -84,6 +84,7 @@ namespace NadekoBot.Classes.JSONModels
public bool DontJoinServers { get; set; } = false;
public bool ForwardMessages { get; set; } = true;
public bool ForwardToAllOwners { get; set; } = false;
public bool IsRotatingStatus { get; set; } = false;
public int BufferSize { get; set; } = 4.MiB();