Skip to content

Commit

Permalink
Fixing pinned post being recreated too often
Browse files Browse the repository at this point in the history
  • Loading branch information
wpatter6 committed Aug 23, 2017
1 parent d51d43e commit d8428d2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
56 changes: 28 additions & 28 deletions PokemonGoRaidBot/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,36 +258,29 @@ public async Task MakePost(PokemonRaidPost post, MessageParser parser)
var fromChannel = GetChannel(post.FromChannelId);
var outputChannel = GetChannel(post.OutputChannelId);

if (post.Pin && post.MessageId != default(ulong))
var messages = parser.MakePostStrings(post);
RestUserMessage messageResult;
if (post.Pin && fromChannel != null)
{
if(fromChannel != null)
{
var changed = true;
var fromChannelMessage = Regex.Replace(messages[0], @" in \<\#[0-9]*\>", "");
if (post.MessageId != default(ulong))
{
deleteMessage = await fromChannel.GetMessageAsync(post.MessageId);
if (deleteMessage.IsPinned)
{
await ((RestUserMessage)deleteMessage).UnpinAsync();
}
await deleteMessage.DeleteAsync();
}
}
if(outputChannel != null)
{
foreach (var messageId in post.OutputMessageIds)
{
deleteMessage = await outputChannel.GetMessageAsync(messageId);
await deleteMessage.DeleteAsync();
}
}

RestUserMessage messageResult;

var messages = parser.MakePostStrings(post);
changed = !deleteMessage?.Content.Equals(fromChannelMessage, StringComparison.OrdinalIgnoreCase) ?? true;

if (post.Pin)
{
if(fromChannel != null)
if (changed)
{
if (deleteMessage.IsPinned)
{
await ((RestUserMessage)deleteMessage).UnpinAsync();
}
await deleteMessage.DeleteAsync();
}
}
if (changed)
{
var fromChannelMessage = Regex.Replace(messages[0], @" in \<\#[0-9]*\>", "");
messageResult = await fromChannel.SendMessageAsync(fromChannelMessage);
try
{
Expand All @@ -298,12 +291,19 @@ public async Task MakePost(PokemonRaidPost post, MessageParser parser)
DoError(e);
}
post.MessageId = messageResult.Id;

}
}

post.OutputMessageIds.Clear();
if (outputChannel != null)
}
if(outputChannel != null)
{
foreach (var messageId in post.OutputMessageIds)
{
deleteMessage = await outputChannel.GetMessageAsync(messageId);
await deleteMessage.DeleteAsync();
}
post.OutputMessageIds.Clear();

foreach (var message in messages)
{
messageResult = await outputChannel.SendMessageAsync(message);
Expand Down
18 changes: 17 additions & 1 deletion PokemonGoRaidBot/PokemonGoRaidBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,21 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>


<PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
</PropertyGroup>

<PropertyGroup>
<Authors>wpatter6</Authors>
<Company>wpatter6</Company>
<NeutralLanguage>en-US</NeutralLanguage>
<AssemblyTitle>PokemonGoRaidBot</AssemblyTitle>
<Description>
Discord bot for pokemon go raids.
</Description>
<Copyright>PokemonGoRaidBot</Copyright>
<UserSecretsId>aaabbbcccddd_eeefffggghhh</UserSecretsId>
</PropertyGroup>
</Project>

0 comments on commit d8428d2

Please sign in to comment.