Skip to content

Commit

Permalink
Added separate permission for the SR reward and command. The old User…
Browse files Browse the repository at this point in the history
…Level will be parsed to the new options which are under Settings -> Twitch -> SongRequests

Fixed the notification that Songify is minimized when it's actually closed
  • Loading branch information
Inzaniity committed Mar 31, 2023
1 parent d87aedf commit a490feb
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 30 deletions.
2 changes: 2 additions & 0 deletions Songify Slim/Util/Settings/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ public class AppConfig
public int RewardGoalAmount { get; set; }
public List<TrackItem> SongBlacklist { get; set; } = new List<TrackItem>();
public string SpotifyPlaylistId { get; set; } = "";
public List<int> UserLevelsReward { get; set; } = new List<int>();
public List<int> UserLevelsCommand { get; set; } = new List<int>();
}

public class Config
Expand Down
37 changes: 37 additions & 0 deletions Songify Slim/Util/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,41 @@ public static int TwSrUserLevel
set => SetTwSrUserLevel(value);
}


public static List<int> UserLevelsReward
{
get => GetUserLevelsReward();
set => SetUserLevelsReward(value);
}

private static void SetUserLevelsReward(List<int> value)
{
_currentConfig.AppConfig.UserLevelsReward = value;
ConfigHandler.WriteConfig(ConfigHandler.ConfigTypes.AppConfig, _currentConfig.AppConfig);
}

private static List<int> GetUserLevelsReward()
{
return _currentConfig.AppConfig.UserLevelsReward;
}

public static List<int> UserLevelsCommand
{
get => GetUserLevelsCommand();
set => SetUserLevelsCommand(value);
}

private static void SetUserLevelsCommand(List<int> value)
{
_currentConfig.AppConfig.UserLevelsCommand = value;
ConfigHandler.WriteConfig(ConfigHandler.ConfigTypes.AppConfig, _currentConfig.AppConfig);
}

private static List<int> GetUserLevelsCommand()
{
return _currentConfig.AppConfig.UserLevelsCommand;
}

public static bool UpdateRequired { get => GetUpdateRequired(); set => SetUpdateRequired(value); }

public static bool Upload
Expand Down Expand Up @@ -720,6 +755,8 @@ public static Configuration Export()
Uuid = GetUuid(),
WebServerPort = GetWebServerPort(),
WebUserAgent = GetWebua(),
UserLevelsCommand = GetUserLevelsCommand(),
UserLevelsReward = GetUserLevelsReward(),
};

return new Configuration
Expand Down
8 changes: 4 additions & 4 deletions Songify Slim/Util/Songify/TwitchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -889,10 +889,10 @@ private static async void Client_OnMessageReceived(object sender, OnMessageRecei
if (e.ChatMessage.CustomRewardId == Settings.Settings.TwRewardId && !PubSubEnabled)
{
int userlevel = CheckUserLevel(e.ChatMessage);
if (userlevel < Settings.Settings.TwSrUserLevel)
if (!Settings.Settings.UserLevelsReward.Contains(userlevel) && !Settings.Settings.UserLevelsReward.Contains(0))
{
//Send a Message to the user, that his Userlevel is too low
SendChatMessage(e.ChatMessage.Channel, $"Sorry, only {Enum.GetName(typeof(TwitchUserLevels), Settings.Settings.TwSrUserLevel)} or higher are allowed request songs.");
SendChatMessage(e.ChatMessage.Channel, $"Sorry, {Enum.GetName(typeof(TwitchUserLevels), userlevel)}s are not allowed to request songs.");
return;
}
// Do nothing if the user is blocked, don't even reply
Expand All @@ -917,10 +917,10 @@ private static async void Client_OnMessageReceived(object sender, OnMessageRecei
if (Settings.Settings.TwSrCommand && e.ChatMessage.Message.StartsWith($"!{Settings.Settings.BotCmdSsrTrigger}"))
{
int userlevel = CheckUserLevel(e.ChatMessage);
if (userlevel < Settings.Settings.TwSrUserLevel)
if (!Settings.Settings.UserLevelsCommand.Contains(userlevel) && !Settings.Settings.UserLevelsCommand.Contains(0))
{
//Send a Message to the user, that his Userlevel is too low
SendChatMessage(e.ChatMessage.Channel, $"Sorry, only {Enum.GetName(typeof(TwitchUserLevels), Settings.Settings.TwSrUserLevel)} or higher are allowed request songs.");
SendChatMessage(e.ChatMessage.Channel, $"Sorry, {Enum.GetName(typeof(TwitchUserLevels), userlevel)}s are not allowed to request songs.");
return;
}
// Do nothing if the user is blocked, don't even reply
Expand Down
14 changes: 13 additions & 1 deletion Songify Slim/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e

private void MetroWindow_Closing(object sender, CancelEventArgs e)
{
// If Systray is enabled [X] minimizes to systray
if (_forceClose)
return;
if (!Settings.Systray)
{
NotifyIcon.Visible = false;
Expand Down Expand Up @@ -603,6 +604,16 @@ private async void MetroWindowLoaded(object sender, RoutedEventArgs e)
await TwitchHandler.CheckStreamIsUp();

if (!Settings.UpdateRequired) return;

List<int> userLevels = new List<int>();
for (int i = 0; i <= Settings.TwSrUserLevel; i++)
{
userLevels.Add(i);
}

if (Settings.UserLevelsCommand.Count == 0) Settings.UserLevelsCommand = userLevels;
if (Settings.UserLevelsReward.Count == 0) Settings.UserLevelsReward = userLevels;

OpenPatchNotes();
Settings.UpdateRequired = false;
}
Expand Down Expand Up @@ -648,6 +659,7 @@ private void Mi_Blacklist_Click(object sender, RoutedEventArgs e)

private void mi_Exit_Click(object sender, RoutedEventArgs e)
{
_forceClose = true;
Application.Current.Shutdown();
}

Expand Down
82 changes: 66 additions & 16 deletions Songify Slim/Views/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -615,25 +615,75 @@
Width="355" Height="36" />
<Button x:Name="BtnFocusRewards" Content="{x:Static local:Resources.Sw_Integration_ManageRewards}" Click="BtnFocusRewards_Click"></Button>
</DockPanel>
<Grid>
<controls:ToggleSwitch IsEnabled="False" x:Name="ChbxTwCommand"
Content="{x:Static local:Resources.sw_SpotifySR_SRCommand}"
HorizontalAlignment="Left" VerticalAlignment="Top" Toggled="Chbx_TwCommand_Checked"
Focusable="False" FontFamily="Segoe UI"
FontSize="12"
ContentPadding="0"
Width="470" Height="36" Opacity="0.1" />
<Label Content="{x:Static local:Resources.sw_SpotifySR_SsrMovedToBotConfig}" Margin="50,0,0,4" VerticalAlignment="Center" HorizontalAlignment="Left"></Label>
</Grid>
<controls:ToggleSwitch x:Name="ChbxAutoClear"
Content="{x:Static local:Resources.sw_SpotifySR_ClearQ}" VerticalAlignment="Top" Toggled="Chbx_AutoClear_Checked"
Focusable="False" FontFamily="Segoe UI"
FontSize="12"
ContentPadding="0"
Width="470" Height="36" />
Content="{x:Static local:Resources.sw_SpotifySR_ClearQ}" VerticalAlignment="Top" Toggled="Chbx_AutoClear_Checked"
Focusable="False" FontFamily="Segoe UI"
FontSize="12"
ContentPadding="0"
Width="470" Height="36" />
</StackPanel>
<StackPanel Orientation="Vertical" VerticalAlignment="Top">
<DockPanel>
<DockPanel LastChildFill="True">
<Label Content="Allowed user levels for SR command" Padding="0,5,5,5" VerticalAlignment="Center"/>
<ComboBox x:Name="CbxAllowedUserLevelsCommand" SelectionChanged="Selector_OnSelectionChanged" IsReadOnly="True" SelectedIndex="0" HorizontalAlignment="Right" Width="185">
<ComboBox.Items>
<ComboBoxItem Content="User Levels (Command)">
<ComboBoxItem.Style>
<Style BasedOn="{StaticResource {x:Type ComboBoxItem}}" TargetType="ComboBoxItem">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDropDownOpen, ElementName=CbxAllowedUserLevelsCommand}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBoxItem.Style>
</ComboBoxItem>
<ComboBoxItem Margin="0" Padding="0">
<CheckBox Tag="0" Content="Viewer (everyone)" x:Name="ChckULCommandViewer" Checked="CbxUserLevelsCommandChecked" Unchecked="CbxUserLevelsCommandUnchecked" Width="180" Height="22" Margin="1,0,0,0"/>
</ComboBoxItem>
<ComboBoxItem Margin="0" Padding="0">
<CheckBox Tag="2" Content="Subscriber" x:Name="ChckULCommandSub" Checked="CbxUserLevelsCommandChecked" Unchecked="CbxUserLevelsCommandUnchecked" Width="180" Height="22" Margin="1,0,0,0"/>
</ComboBoxItem>
<ComboBoxItem Margin="0" Padding="0">
<CheckBox Tag="1" Content="VIP" x:Name="ChckULCommandVip" Checked="CbxUserLevelsCommandChecked" Unchecked="CbxUserLevelsCommandUnchecked" Width="180" Height="22" Margin="1,0,0,0"/>
</ComboBoxItem>
<ComboBoxItem Margin="0" Padding="0">
<CheckBox Tag="3" Content="Moderator" x:Name="ChckULCommandMod" Checked="CbxUserLevelsCommandChecked" Unchecked="CbxUserLevelsCommandUnchecked" Width="180" Height="22" Margin="1,0,0,0"/>
</ComboBoxItem>
</ComboBox.Items>
</ComboBox>
</DockPanel>
<DockPanel LastChildFill="True" Margin="0,6,0,0">
<Label Content="Allowed user levels for SR reward" Padding="0,5,5,5" VerticalAlignment="Center"/>
<ComboBox x:Name="CbxAllowedUserLevelsReward" SelectionChanged="Selector_OnSelectionChanged" IsReadOnly="True" SelectedIndex="0" HorizontalAlignment="Right" Width="185">
<ComboBox.Items>
<ComboBoxItem Content="User Levels (Reward)">
<ComboBoxItem.Style>
<Style BasedOn="{StaticResource {x:Type ComboBoxItem}}" TargetType="ComboBoxItem">
<Style.Triggers>
<DataTrigger Binding="{Binding IsDropDownOpen, ElementName=CbxAllowedUserLevelsReward}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBoxItem.Style>
</ComboBoxItem>
<ComboBoxItem Margin="0" Padding="0">
<CheckBox Tag="0" Content="Viewer (everyone)" x:Name="ChckULRewardViewer" Unchecked="CbxUserLevelsRewardUnchecked" Checked="CbxUserLevelsRewardChecked" Width="180" Height="22" Margin="1,0,0,0"/>
</ComboBoxItem>
<ComboBoxItem Margin="0" Padding="0">
<CheckBox Tag="2" Content="Subscriber" x:Name="ChckULRewardSub" Unchecked="CbxUserLevelsRewardUnchecked" Checked="CbxUserLevelsRewardChecked" Width="180" Height="22" Margin="1,0,0,0"/>
</ComboBoxItem>
<ComboBoxItem Margin="0" Padding="0">
<CheckBox Tag="1" Content="VIP" x:Name="ChckULRewardVip" Unchecked="CbxUserLevelsRewardUnchecked" Checked="CbxUserLevelsRewardChecked" Width="180" Height="22" Margin="1,0,0,0"/>
</ComboBoxItem>
<ComboBoxItem Margin="0" Padding="0">
<CheckBox Tag="3" Content="Moderator" x:Name="ChckULRewardMod" Unchecked="CbxUserLevelsRewardUnchecked" Checked="CbxUserLevelsRewardChecked" Width="180" Height="22" Margin="1,0,0,0"/>
</ComboBoxItem>
</ComboBox.Items>
</ComboBox>
</DockPanel>
<DockPanel Margin="0,6,0,0" Visibility="Collapsed">
<Label Content="{x:Static local:Resources.Sw_Integration_MinUserLevel}" HorizontalAlignment="Left"
VerticalAlignment="Center" Padding="0,5,5,5" />
<ComboBox x:Name="CbxUserLevels" Width="151" HorizontalAlignment="Right" VerticalAlignment="Top" SelectionChanged="CbxUserLevels_SelectionChanged" DockPanel.Dock="Right" />
Expand Down
70 changes: 63 additions & 7 deletions Songify Slim/Views/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public async void SetControls()
ChbxAutoClear.IsOn = Settings.AutoClearQueue;
ChbxMessageLogging.IsChecked = Settings.MsgLoggingEnabled;
ChbxTwAutoconnect.IsOn = Settings.TwAutoConnect;
ChbxTwCommand.IsOn = Settings.TwSrCommand;
ChbxTwReward.IsOn = Settings.TwSrReward;
ChbxAutostart.IsOn = Settings.Autostart;
ChbxCover.IsOn = Settings.DownloadCover;
Expand Down Expand Up @@ -158,6 +157,26 @@ public async void SetControls()
TextBoxTriggerRemove.Text = string.IsNullOrWhiteSpace(Settings.BotCmdRemoveTrigger) ? "remove" : Settings.BotCmdRemoveTrigger;
TextBoxTriggerSonglike.Text = string.IsNullOrWhiteSpace(Settings.BotCmdSonglikeTrigger) ? "songlike" : Settings.BotCmdSonglikeTrigger;

if (Settings.UserLevelsCommand == null)
{
Settings.UserLevelsCommand = new List<int>();
}

if (Settings.UserLevelsReward == null)
{
Settings.UserLevelsReward = new List<int>();
}

ChckULCommandViewer.IsChecked = Settings.UserLevelsCommand.Contains(0);
ChckULCommandVip.IsChecked = Settings.UserLevelsCommand.Contains(1);
ChckULCommandSub.IsChecked = Settings.UserLevelsCommand.Contains(2);
ChckULCommandMod.IsChecked = Settings.UserLevelsCommand.Contains(3);

ChckULRewardViewer.IsChecked = Settings.UserLevelsReward.Contains(0);
ChckULRewardVip.IsChecked = Settings.UserLevelsReward.Contains(1);
ChckULRewardSub.IsChecked = Settings.UserLevelsReward.Contains(2);
ChckULRewardMod.IsChecked = Settings.UserLevelsReward.Contains(3);

if (ApiHandler.Spotify != null)
{
try
Expand Down Expand Up @@ -437,12 +456,6 @@ private void Chbx_TwAutoconnect_Checked(object sender, RoutedEventArgs e)
Settings.TwAutoConnect = ChbxTwAutoconnect.IsOn;
}

private void Chbx_TwCommand_Checked(object sender, RoutedEventArgs e)
{
// enables / disables telemetry
Settings.TwSrCommand = ChbxTwCommand.IsOn;
}

private void Chbx_TwReward_Checked(object sender, RoutedEventArgs e)
{
// enables / disables telemetry
Expand Down Expand Up @@ -1278,5 +1291,48 @@ private void Tgl_botcmd_PlayPause_OnToggled_Toggled(object sender, RoutedEventAr
{
Settings.BotCmdPlayPause = ((ToggleSwitch)sender).IsOn;
}

private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
e.Handled = true;
((ComboBox)sender).SelectedIndex = 0;
}

private void CbxUserLevelsRewardChecked(object sender, RoutedEventArgs e)
{
if (!(sender is CheckBox checkBox)) return;
int value = Convert.ToInt32(checkBox.Tag);
if (Settings.UserLevelsReward.Contains(value)) return;
List<int> list = new List<int>(Settings.UserLevelsReward) { value };
Settings.UserLevelsReward = list;
}

private void CbxUserLevelsRewardUnchecked(object sender, RoutedEventArgs e)
{
if (!(sender is CheckBox checkBox)) return;
int value = Convert.ToInt32(checkBox.Tag);
if (!Settings.UserLevelsReward.Contains(value)) return;
List<int> list = new List<int>(Settings.UserLevelsReward);
list.Remove(value);
Settings.UserLevelsReward = list;
}
private void CbxUserLevelsCommandChecked(object sender, RoutedEventArgs e)
{
if (!(sender is CheckBox checkBox)) return;
int value = Convert.ToInt32(checkBox.Tag);
if (Settings.UserLevelsCommand.Contains(value)) return;
List<int> list = new List<int>(Settings.UserLevelsCommand) { value };
Settings.UserLevelsCommand = list;
}

private void CbxUserLevelsCommandUnchecked(object sender, RoutedEventArgs e)
{
if (!(sender is CheckBox checkBox)) return;
int value = Convert.ToInt32(checkBox.Tag);
if (!Settings.UserLevelsCommand.Contains(value)) return;
List<int> list = new List<int>(Settings.UserLevelsCommand);
list.Remove(value);
Settings.UserLevelsCommand = list;
}
}
}
2 changes: 0 additions & 2 deletions Songify Slim/Views/Window_Patchnotes.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
xmlns:local="clr-namespace:Songify_Slim"
mc:Ignorable="d"
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:mdXaml="clr-namespace:MdXaml;assembly=MdXaml"
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
WindowStartupLocation="CenterOwner"
Title="Patch Notes" Height="450" Width="800" ShowMaxRestoreButton="False" ShowMinButton="False" Loaded="MetroWindow_Loaded">
Expand Down

0 comments on commit a490feb

Please sign in to comment.