Skip to content

Commit cabe28d

Browse files
committed
Some code cleanup
1 parent 4715ab6 commit cabe28d

24 files changed

+402
-167
lines changed

.editorconfig

+51
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,63 @@ insert_final_newline = true
88
charset = utf-8
99

1010
[*.cs]
11+
# General Formatting
1112
indent_style = tab
1213
indent_size = tab
1314
tab_width = 4
1415
trim_trailing_whitespace = true
1516

17+
#### .NET Coding Conventions ####
18+
19+
# Organize usings
20+
dotnet_separate_import_directive_groups = false
21+
dotnet_sort_system_directives_first = false
22+
23+
# this. and Me. preferences
24+
dotnet_style_qualification_for_event = false:silent
25+
dotnet_style_qualification_for_field = false:silent
26+
dotnet_style_qualification_for_method = false:suggestion
27+
dotnet_style_qualification_for_property = false:silent
28+
29+
# Language keywords vs BCL types preferences
30+
dotnet_style_predefined_type_for_locals_parameters_members = true
31+
dotnet_style_predefined_type_for_member_access = true
32+
# var preferences
33+
csharp_style_var_elsewhere = false:silent
34+
csharp_style_var_for_built_in_types = false:silent
35+
csharp_style_var_when_type_is_apparent = true:suggestion
36+
37+
# Expression-bodied members
38+
csharp_style_expression_bodied_accessors = true:silent
39+
csharp_style_expression_bodied_constructors = false:silent
40+
csharp_style_expression_bodied_methods = true:silent
41+
csharp_style_expression_bodied_properties = true:silent
42+
43+
# Expression-level preferences
44+
csharp_style_inlined_variable_declaration = true:suggestion
45+
46+
# 'using' directive preferences
47+
csharp_using_directive_placement = outside_namespace:suggestion
48+
49+
#### C# Formatting Rules ####
50+
51+
# Indentation preferences
1652
csharp_indent_switch_labels = false
1753

54+
# Space preferences
55+
csharp_space_after_cast = false
56+
csharp_space_after_colon_in_inheritance_clause = true
57+
csharp_space_after_keywords_in_control_flow_statements = true
58+
csharp_space_before_colon_in_inheritance_clause = true
59+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
60+
csharp_space_between_method_call_name_and_opening_parenthesis = false
61+
csharp_space_between_method_call_parameter_list_parentheses = false
62+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
63+
csharp_space_between_method_declaration_parameter_list_parentheses = false
64+
65+
# Wrapping preferences
66+
csharp_preserve_single_line_blocks = true
67+
csharp_preserve_single_line_statements = true
68+
1869
[*.{tt,ttinclude}]
1970
insert_final_newline = false

TS3ABotUnitTests/TS3ABotUnitTests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ItemGroup>
1414
<PackageReference Include="NUnit" Version="3.12.0" />
1515
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

TS3AudioBot.ruleset

-97
This file was deleted.

TS3AudioBot.sln

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
appveyor.yml = appveyor.yml
1515
GitVersion.yml = GitVersion.yml
1616
README.md = README.md
17-
TS3AudioBot.ruleset = TS3AudioBot.ruleset
1817
EndProjectSection
1918
EndProject
2019
Global

TS3AudioBot/Bot.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ private void EnableIdleTickWorker()
522522
return;
523523
}
524524
idleTickWorker.Interval = idleTime;
525-
idleTickWorker.Active = true;
525+
idleTickWorker.Enable();
526526
}
527527

528-
private void DisableIdleTickWorker() => idleTickWorker.Active = false;
528+
private void DisableIdleTickWorker() => idleTickWorker.Disable();
529529

530530
#endregion
531531

TS3AudioBot/Environment/Stats.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private void UpdateMeta()
100100
public void StartTimer(bool upload)
101101
{
102102
uploadParamEnabled = upload;
103-
ticker.Active = true;
103+
ticker.Enable();
104104
}
105105

106106
private async Task SendStats(StatsPing sendPacket)

TS3AudioBot/Helper/WebWrapper.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
// You should have received a copy of the Open Software License along with this
88
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
99

10+
using Newtonsoft.Json;
1011
using System;
1112
using System.IO;
13+
using System.Linq;
1214
using System.Net;
1315
using System.Net.Http;
16+
using System.Net.Http.Headers;
1417
using System.Threading.Tasks;
1518
using TS3AudioBot.Localization;
16-
using System.Net.Http.Headers;
17-
using Newtonsoft.Json;
18-
using System.Linq;
1919

2020
namespace TS3AudioBot.Helper
2121
{

TS3AudioBot/ResourceFactories/ISearchResolver.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
// You should have received a copy of the Open Software License along with this
88
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
99

10+
using System.Collections.Generic;
11+
using System.Threading.Tasks;
12+
1013
namespace TS3AudioBot.ResourceFactories
1114
{
12-
using System.Collections.Generic;
13-
using System.Threading.Tasks;
14-
1515
public interface ISearchResolver : IResolver
1616
{
1717
Task<IList<AudioResource>> Search(ResolveContext ctx, string keyword);

TS3AudioBot/ResourceFactories/MediaResolver.cs

+8-22
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
// You should have received a copy of the Open Software License along with this
88
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
99

10-
using Heijden.DNS;
1110
using PlaylistsNET.Content;
1211
using System;
1312
using System.Collections.Generic;
1413
using System.IO;
1514
using System.Linq;
16-
using System.Net;
1715
using System.Threading.Tasks;
1816
using TS3AudioBot.Config;
1917
using TS3AudioBot.Helper;
@@ -66,18 +64,18 @@ public async Task<PlayResource> GetResourceById(ResolveContext ctx, AudioResourc
6664

6765
public string RestoreLink(ResolveContext _, AudioResource resource) => resource.ResourceId;
6866

69-
private async Task<ResData> ValidateFromString(ConfBot config, string uriStr)
67+
private Task<ResData> ValidateFromString(ConfBot config, string uriStr)
7068
{
7169
var uri = GetUri(config, uriStr);
72-
return await ValidateUri(uri);
70+
return ValidateUri(uri);
7371
}
7472

75-
private async Task<ResData> ValidateUri(Uri uri)
73+
private Task<ResData> ValidateUri(Uri uri)
7674
{
7775
if (uri.IsWeb())
78-
return await ValidateWeb(uri);
76+
return ValidateWeb(uri);
7977
if (uri.IsFile())
80-
return ValidateFile(uri);
78+
return Task.Run(() => ValidateFile(uri));
8179

8280
throw Error.LocalStr(strings.error_media_invalid_uri);
8381
}
@@ -211,11 +209,8 @@ public async Task<Playlist> GetPlaylist(ResolveContext ctx, string url)
211209
{
212210
if (uri.IsFile())
213211
{
214-
if (File.Exists(url))
215-
{
216-
using var stream = File.OpenRead(uri.AbsolutePath);
217-
return await GetPlaylistContentAsync(stream, url);
218-
}
212+
using var stream = File.OpenRead(uri.AbsolutePath);
213+
return await GetPlaylistContentAsync(stream, url);
219214
}
220215
else if (uri.IsWeb())
221216
{
@@ -252,15 +247,6 @@ private Playlist GetPlaylistContent(Stream stream, string url, string? mime = nu
252247
switch (anyId)
253248
{
254249
case ".m3u":
255-
{
256-
var parser = new M3uContent();
257-
var list = parser.GetFromStream(stream);
258-
259-
items = new List<PlaylistItem>(
260-
from e in list.PlaylistEntries
261-
select new PlaylistItem(new AudioResource(e.Path, e.Title, ResolverFor)));
262-
break;
263-
}
264250
case ".m3u8":
265251
case "application/mpegurl":
266252
case "application/x-mpegurl":
@@ -269,7 +255,7 @@ from e in list.PlaylistEntries
269255
case "application/vnd.apple.mpegurl":
270256
case "application/vnd.apple.mpegurl.audio":
271257
{
272-
var parser = new M3u8Content();
258+
var parser = new M3uContent();
273259
var list = parser.GetFromStream(stream);
274260

275261
items = new List<PlaylistItem>(

TS3AudioBot/ResourceFactories/SoundcloudResolver.cs

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// You should have received a copy of the Open Software License along with this
88
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
99

10-
using Newtonsoft.Json;
11-
using Newtonsoft.Json.Linq;
1210
using System;
1311
using System.Globalization;
1412
using System.IO;

TS3AudioBot/ResourceFactories/TwitchResolver.cs

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// You should have received a copy of the Open Software License along with this
88
// program. If not, see <https://opensource.org/licenses/OSL-3.0>.
99

10-
using Newtonsoft.Json;
1110
using System;
1211
using System.Collections.Generic;
1312
using System.Globalization;
@@ -20,7 +19,6 @@ namespace TS3AudioBot.ResourceFactories
2019
{
2120
public sealed class TwitchResolver : IResourceResolver
2221
{
23-
private static readonly NLog.Logger Log = NLog.LogManager.GetCurrentClassLogger();
2422
private static readonly Regex TwitchMatch = new Regex(@"^(https?://)?(www\.)?twitch\.tv/(\w+)", Util.DefaultRegexConfig);
2523
private static readonly Regex M3U8ExtMatch = new Regex(@"#([\w-]+)(:(([\w-]+)=(""[^""]*""|[^,]+),?)*)?", Util.DefaultRegexConfig);
2624
//private const string TwitchClientId = "t9nlhlxnfux3gk2d6z1p093rj2c71i3";

TS3AudioBot/TS3AudioBot.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<PlatformTarget>AnyCPU</PlatformTarget>
1414
<Prefer32Bit>false</Prefer32Bit>
1515
<DebugType>portable</DebugType>
16-
<CodeAnalysisRuleSet>../TS3AudioBot.ruleset</CodeAnalysisRuleSet>
1716

1817
<ApplicationIcon>Media\favicon.ico</ApplicationIcon>
1918

@@ -47,7 +46,7 @@
4746
<ExcludeAssets>analyzers</ExcludeAssets>
4847
</PackageReference>
4948
<PackageReference Include="Nett" Version="0.15.0" />
50-
<PackageReference Include="PlaylistsNET" Version="1.0.5" />
49+
<PackageReference Include="PlaylistsNET" Version="1.0.6" />
5150
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
5251
</ItemGroup>
5352

TSLib/Audio/PassiveSplitterPipe.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void Write(Span<byte> data, Meta? meta)
9999
safeConsumerList[i].Write(bufSpan, meta);
100100
}
101101
// safe one memcopy call by passing the last one our original data
102-
safeConsumerList[safeConsumerList.Count - 1].Write(data, meta);
102+
safeConsumerList[^1].Write(data, meta);
103103
}
104104
}
105105
}

TSLib/Full/License.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public abstract class LicenseBlock
123123
block.Key = data.Slice(1, 32).ToArray();
124124

125125
var allLen = MinBlockLen + read;
126-
var hash = TsCrypt.Hash512It(data.Slice(1, allLen - 1).ToArray());
126+
var hash = TsCrypt.Hash512It(data[1..allLen].ToArray());
127127
block.Hash = hash.AsSpan(0, 32).ToArray();
128128

129129
return (block, allLen);

TSLib/Helper/Tools.cs

-14
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ public static T PickRandom<T>(IReadOnlyList<T> collection)
5757

5858
public static TimeSpan Min(this TimeSpan a, TimeSpan b) => a < b ? a : b;
5959
public static TimeSpan Max(this TimeSpan a, TimeSpan b) => a > b ? a : b;
60-
#if NETSTANDARD2_0
61-
public static TimeSpan Divide(this TimeSpan timeSpan, double divisor) => TimeSpan.FromTicks((long)(timeSpan.Ticks / divisor));
62-
#endif
6360

6461
public static int MathMod(int x, int mod) => (x % mod + mod) % mod;
6562

@@ -72,16 +69,5 @@ public static T PickRandom<T>(IReadOnlyList<T> collection)
7269
public static void SetLogId(string id) => NLog.MappedDiagnosticsLogicalContext.Set("BotId", id);
7370

7471
public static Exception UnhandledDefault<T>(T value) where T : struct { return new MissingEnumCaseException(typeof(T).Name, value.ToString() ?? string.Empty); }
75-
76-
#if NETSTANDARD2_0
77-
public static bool Remove<K, V>(this Dictionary<K, V> dict, K key, out V value)
78-
{
79-
if (dict.TryGetValue(key, out value))
80-
{
81-
return dict.Remove(key);
82-
}
83-
return false;
84-
}
85-
#endif
8672
}
8773
}

0 commit comments

Comments
 (0)