mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-05-22 08:45:08 +00:00
Add a setting to control whether to respect advisory rate limits (#1342)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Avalonia.Data.Converters;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Converters;
|
||||
|
||||
public class RateLimitPreferenceToStringConverter : IValueConverter
|
||||
{
|
||||
public static RateLimitPreferenceToStringConverter Instance { get; } = new();
|
||||
|
||||
public object? Convert(
|
||||
object? value,
|
||||
Type targetType,
|
||||
object? parameter,
|
||||
CultureInfo culture
|
||||
) =>
|
||||
value is RateLimitPreference rateLimitPreference
|
||||
? rateLimitPreference.GetDisplayName()
|
||||
: default;
|
||||
|
||||
public object ConvertBack(
|
||||
object? value,
|
||||
Type targetType,
|
||||
object? parameter,
|
||||
CultureInfo culture
|
||||
) => throw new NotSupportedException();
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Text.Json.Serialization;
|
||||
using Cogwheel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Gui.Framework;
|
||||
using DiscordChatExporter.Gui.Models;
|
||||
@@ -28,6 +29,10 @@ public partial class SettingsService()
|
||||
[ObservableProperty]
|
||||
public partial bool IsTokenPersisted { get; set; } = true;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial RateLimitPreference RateLimitPreference { get; set; } =
|
||||
RateLimitPreference.RespectAll;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial ThreadInclusionMode ThreadInclusionMode { get; set; }
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ public partial class DashboardViewModel : ViewModelBase
|
||||
AvailableChannels = null;
|
||||
SelectedChannels.Clear();
|
||||
|
||||
_discord = new DiscordClient(token);
|
||||
_discord = new DiscordClient(token, _settingsService.RateLimitPreference);
|
||||
_settingsService.LastToken = token;
|
||||
|
||||
var guilds = await _discord.GetUserGuildsAsync();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using DiscordChatExporter.Gui.Framework;
|
||||
using DiscordChatExporter.Gui.Models;
|
||||
@@ -42,6 +43,15 @@ public class SettingsViewModel : DialogViewModelBase
|
||||
set => _settingsService.IsTokenPersisted = value;
|
||||
}
|
||||
|
||||
public IReadOnlyList<RateLimitPreference> AvailableRateLimitPreferences { get; } =
|
||||
Enum.GetValues<RateLimitPreference>();
|
||||
|
||||
public RateLimitPreference RateLimitPreference
|
||||
{
|
||||
get => _settingsService.RateLimitPreference;
|
||||
set => _settingsService.RateLimitPreference = value;
|
||||
}
|
||||
|
||||
public IReadOnlyList<ThreadInclusionMode> AvailableThreadInclusionModes { get; } =
|
||||
Enum.GetValues<ThreadInclusionMode>();
|
||||
|
||||
|
||||
@@ -54,6 +54,25 @@
|
||||
<ToggleSwitch DockPanel.Dock="Right" IsChecked="{Binding IsTokenPersisted}" />
|
||||
</DockPanel>
|
||||
|
||||
<!-- Rate limit preference -->
|
||||
<DockPanel
|
||||
Margin="16,8"
|
||||
LastChildFill="False"
|
||||
ToolTip.Tip="Whether to respect advisory rate limits. If disabled, only hard rate limits (i.e. 429 responses) will be respected.">
|
||||
<TextBlock DockPanel.Dock="Left" Text="Rate limit preference" />
|
||||
<ComboBox
|
||||
Width="150"
|
||||
DockPanel.Dock="Right"
|
||||
ItemsSource="{Binding AvailableRateLimitPreferences}"
|
||||
SelectedItem="{Binding RateLimitPreference}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={x:Static converters:RateLimitPreferenceToStringConverter.Instance}}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</DockPanel>
|
||||
|
||||
<!-- Thread inclusion mode -->
|
||||
<DockPanel
|
||||
Margin="16,8"
|
||||
|
||||
Reference in New Issue
Block a user