.repinv now posts in the channel repeater originates from, not current one
This commit is contained in:
parent
a0e363ff66
commit
bece18dffc
@ -36,6 +36,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
public Repeater Repeater { get; }
|
public Repeater Repeater { get; }
|
||||||
public SocketGuild Guild { get; }
|
public SocketGuild Guild { get; }
|
||||||
public ITextChannel Channel { get; private set; }
|
public ITextChannel Channel { get; private set; }
|
||||||
|
private IUserMessage oldMsg = null;
|
||||||
|
|
||||||
public RepeatRunner(Repeater repeater, ITextChannel channel = null)
|
public RepeatRunner(Repeater repeater, ITextChannel channel = null)
|
||||||
{
|
{
|
||||||
@ -52,49 +53,13 @@ namespace NadekoBot.Modules.Utility
|
|||||||
{
|
{
|
||||||
source = new CancellationTokenSource();
|
source = new CancellationTokenSource();
|
||||||
token = source.Token;
|
token = source.Token;
|
||||||
IUserMessage oldMsg = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
while (!token.IsCancellationRequested)
|
while (!token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
var toSend = "🔄 " + Repeater.Message;
|
|
||||||
await Task.Delay(Repeater.Interval, token).ConfigureAwait(false);
|
await Task.Delay(Repeater.Interval, token).ConfigureAwait(false);
|
||||||
|
|
||||||
//var lastMsgInChannel = (await Channel.GetMessagesAsync(2)).FirstOrDefault();
|
await Trigger().ConfigureAwait(false);
|
||||||
// if (lastMsgInChannel.Id == oldMsg?.Id) //don't send if it's the same message in the channel
|
|
||||||
// continue;
|
|
||||||
|
|
||||||
if (oldMsg != null)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await oldMsg.DeleteAsync();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (Channel == null)
|
|
||||||
Channel = Guild.GetTextChannel(Repeater.ChannelId);
|
|
||||||
|
|
||||||
if (Channel != null)
|
|
||||||
oldMsg = await Channel.SendMessageAsync(toSend).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch (HttpException ex) when (ex.HttpCode == System.Net.HttpStatusCode.Forbidden)
|
|
||||||
{
|
|
||||||
_log.Warn("Missing permissions. Repeater stopped. ChannelId : {0}", Channel?.Id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
catch (HttpException ex) when (ex.HttpCode == System.Net.HttpStatusCode.NotFound)
|
|
||||||
{
|
|
||||||
_log.Warn("Channel not found. Repeater stopped. ChannelId : {0}", Channel?.Id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_log.Warn(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
@ -102,6 +67,46 @@ namespace NadekoBot.Modules.Utility
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task Trigger()
|
||||||
|
{
|
||||||
|
var toSend = "🔄 " + Repeater.Message;
|
||||||
|
//var lastMsgInChannel = (await Channel.GetMessagesAsync(2)).FirstOrDefault();
|
||||||
|
// if (lastMsgInChannel.Id == oldMsg?.Id) //don't send if it's the same message in the channel
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
if (oldMsg != null)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await oldMsg.DeleteAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Channel == null)
|
||||||
|
Channel = Guild.GetTextChannel(Repeater.ChannelId);
|
||||||
|
|
||||||
|
if (Channel != null)
|
||||||
|
oldMsg = await Channel.SendMessageAsync(toSend).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (HttpException ex) when (ex.HttpCode == System.Net.HttpStatusCode.Forbidden)
|
||||||
|
{
|
||||||
|
_log.Warn("Missing permissions. Repeater stopped. ChannelId : {0}", Channel?.Id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (HttpException ex) when (ex.HttpCode == System.Net.HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
_log.Warn("Channel not found. Repeater stopped. ChannelId : {0}", Channel?.Id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.Warn(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
source.Cancel();
|
source.Cancel();
|
||||||
@ -176,9 +181,10 @@ namespace NadekoBot.Modules.Utility
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var repeater = repList[index].Repeater;
|
var repeater = repList[index].Repeater;
|
||||||
|
|
||||||
repList[index].Reset();
|
repList[index].Reset();
|
||||||
await Context.Channel.SendMessageAsync("🔄 " + repeater.Message).ConfigureAwait(false);
|
await repList[index].Trigger();
|
||||||
|
|
||||||
|
await Context.Channel.SendMessageAsync("🔄").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
Loading…
Reference in New Issue
Block a user