Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Plerx2493 committed Jul 3, 2023
1 parent 55ae601 commit 7ee7e63
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
21 changes: 13 additions & 8 deletions ModularAssistentForDiscordServer/Commands/Slash/MessageSnipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ private async Task DoSnipeAsync(InteractionContext ctx, bool edit)
{
await ctx.DeferAsync(true);
DiscordMessage message;

var result = edit switch
bool result;

if (!edit)
{
result = MessageSnipeService.TryGetMessage(ctx.Channel.Id, out message);
}
else
{
true => MessageSnipeService.TryGetEditedMessage(ctx.Channel.Id, out message),
false => MessageSnipeService.TryGetMessage(ctx.Channel.Id, out message)
};
result = MessageSnipeService.TryGetEditedMessage(ctx.Channel.Id, out message);
}

if (!result)
{
Expand All @@ -58,14 +62,15 @@ await ctx.EditResponseAsync(
}

var content = message.Content;
if (content.Length > 500) content = content.Substring(0, 500) + "...";
if (content.Length > 500) content = content.Substring(0, 497) + "...";
var member = await ctx.Guild.GetMemberAsync(message.Author.Id);

var embed = new DiscordEmbedBuilder()
.WithAuthor(
$"{message.Author.Username}#{message.Author.Discriminator}" + (edit ? " (Edited)" : ""),
$"{member.DisplayName}" + (edit ? " (Edited)" : ""),
iconUrl: message.Author.GetAvatarUrl(ImageFormat.Png))
.WithFooter(
$"{(edit ? "Edit" : "Deletion")} sniped by {ctx.User.Username}#{ctx.User.Discriminator}",
$"{(edit ? "Edit" : "Deletion")} sniped by {ctx.Member.DisplayName}",
ctx.User.AvatarUrl);

if (!string.IsNullOrEmpty(content)) embed.WithDescription(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ await ctx.EditResponseAsync(
//Get the initial response an wait for a component interaction
var response = await ctx.GetOriginalResponseAsync();
var selectResponse = await response.WaitForSelectAsync(ctx.Member, "roleSelectionStart-" + ctx.Channel.Id,
TimeSpan.FromSeconds(60));
TimeSpan.FromSeconds(60 * 3));

//Notify the user when the interaction times out and abort
if (selectResponse.TimedOut)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder
{
Content = "Timed out (60 seconds)"
Content = "Timed out (180 seconds)"
});
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.1-dev-00910" />
<PackageReference Include="DSharpPlus" Version="4.4.1" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.4.1" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.4.1" />
<PackageReference Include="DSharpPlus.Rest" Version="4.4.1" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.4.1" />
<PackageReference Include="DSharpPlus.VoiceNext" Version="4.4.1" />
<PackageReference Include="DSharpPlus" Version="4.4.2" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.4.2" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.4.2" />
<PackageReference Include="DSharpPlus.Rest" Version="4.4.2" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.4.2" />
<PackageReference Include="DSharpPlus.VoiceNext" Version="4.4.2" />
</ItemGroup>
</Project>
24 changes: 16 additions & 8 deletions ModularAssistentForDiscordServer/Services/MessageSnipeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ private static void PostEvictionCallback(object key, object value, EvictionReaso
public void AddMessage(DiscordMessage message)
{
var id = CacheHelper.GetMessageSnipeKey(message.ChannelId);
_memoryCache.Remove(id);
_memoryCache.Set(id, message, _options);
}

public void AddEditedMessage(DiscordMessage message)
{
var id = CacheHelper.GetMessageEditSnipeKey(message.ChannelId);
_memoryCache.Remove(id);
_memoryCache.Set(id, message, _options);
}

Expand All @@ -130,16 +128,26 @@ public void DeleteMessage(ulong channel)
public bool TryGetMessage(ulong channelId, out DiscordMessage message)
{
var id = CacheHelper.GetMessageSnipeKey(channelId);
var result = _memoryCache.TryGetValue(id, out message);
if (result) _memoryCache.Remove(id);
return result;
message = _memoryCache.Get<DiscordMessage?>(id);

Check warning on line 131 in ModularAssistentForDiscordServer/Services/MessageSnipeService.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 131 in ModularAssistentForDiscordServer/Services/MessageSnipeService.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
if (message is not null)
{
_memoryCache.Remove(id);
return true;
}

return false;
}

public bool TryGetEditedMessage(ulong channelId, out DiscordMessage message)
{
var id = CacheHelper.GetMessageEditSnipeKey(channelId);
var result = _memoryCache.TryGetValue(id, out message);
if (result) _memoryCache.Remove(id);
return result;
message = _memoryCache.Get<DiscordMessage?>(id);

Check warning on line 144 in ModularAssistentForDiscordServer/Services/MessageSnipeService.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 144 in ModularAssistentForDiscordServer/Services/MessageSnipeService.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
if (message is not null)
{
_memoryCache.Remove(id);
return true;
}

return false;
}
}

0 comments on commit 7ee7e63

Please sign in to comment.