8
8
using System . Text ;
9
9
using System . Text . RegularExpressions ;
10
10
using System . Threading . Tasks ;
11
-
12
11
using Discord ;
13
-
14
12
using Humanizer ;
15
13
using Humanizer . Localisation ;
16
-
17
14
using Modix . Data . Models . Moderation ;
18
- using Modix . Services . CodePaste ;
19
15
20
16
namespace Modix . Services . Utilities
21
17
{
@@ -38,18 +34,16 @@ public static string StripFormatting(string code) =>
38
34
//strip out the ` characters and code block markers
39
35
_buildContentRegex . Replace ( code . Trim ( ) , string . Empty ) ;
40
36
41
- public static async Task UploadToServiceIfBiggerThan ( this EmbedBuilder embed , string content , uint size , CodePasteService service )
37
+ public static async Task UploadToServiceIfBiggerThan ( this EmbedBuilder embed , string content , uint size ,
38
+ PasteService service )
42
39
{
43
40
if ( content . Length > size )
44
41
{
45
- try
46
- {
47
- var resultLink = await service . UploadCodeAsync ( content ) ;
48
- embed . AddField ( a => a . WithName ( "More..." ) . WithValue ( $ "[View on Hastebin]({ resultLink } )") ) ;
49
- }
50
- catch ( WebException we )
42
+ var resultLink = await service . UploadPaste ( content ) ;
43
+
44
+ if ( ! string . IsNullOrWhiteSpace ( resultLink ) )
51
45
{
52
- embed . AddField ( a => a . WithName ( "More..." ) . WithValue ( we . Message ) ) ;
46
+ embed . AddField ( a => a . WithName ( "More..." ) . WithValue ( $ "[View on paste.mod.gg]( { resultLink } )" ) ) ;
53
47
}
54
48
}
55
49
}
@@ -87,7 +81,8 @@ public static IReadOnlyCollection<string> CollapsePlurals(IReadOnlyCollection<st
87
81
Value : x
88
82
) ) ;
89
83
90
- var groupedBySingulars = withSingulars . GroupBy ( x => x . Singular , x => x . Value , new SequenceEqualityComparer < string > ( ) ) ;
84
+ var groupedBySingulars =
85
+ withSingulars . GroupBy ( x => x . Singular , x => x . Value , new SequenceEqualityComparer < string > ( ) ) ;
91
86
92
87
var withDistinctParts = new HashSet < string > [ groupedBySingulars . Count ( ) ] [ ] ;
93
88
@@ -129,7 +124,8 @@ public static IReadOnlyCollection<string> CollapsePlurals(IReadOnlyCollection<st
129
124
? word . First ( )
130
125
: word . Last ( ) ;
131
126
132
- parenthesized [ aliasIndex ] [ wordIndex ] = $ "{ longestForm [ ..indexOfDifference ] } ({ longestForm [ indexOfDifference ..] } )";
127
+ parenthesized [ aliasIndex ] [ wordIndex ] =
128
+ $ "{ longestForm [ ..indexOfDifference ] } ({ longestForm [ indexOfDifference ..] } )";
133
129
}
134
130
else
135
131
{
@@ -202,6 +198,7 @@ public static string FormatCodeForEmbed(string language, string sourceCode, int
202
198
AddRemainingLineComment ( ) ;
203
199
break ;
204
200
}
201
+
205
202
braceOnlyLinesEliminated ++ ;
206
203
}
207
204
else if ( ! TryAddLine ( line ) )
@@ -244,11 +241,13 @@ public static string FormatCodeForEmbed(string language, string sourceCode, int
244
241
bool TryAddLine ( string line )
245
242
{
246
243
var remainingCount = GetRemainingLineCount ( ) ;
247
- var possibleRemainingLineCommentLength = remainingCount > 1 // 1, because the current line is included in the count
248
- ? GetRemainingLineCountComment ( remainingCount ) . Length
249
- : 0 ;
244
+ var possibleRemainingLineCommentLength =
245
+ remainingCount > 1 // 1, because the current line is included in the count
246
+ ? GetRemainingLineCountComment ( remainingCount ) . Length
247
+ : 0 ;
250
248
251
- if ( line . Length + currentLength + possibleRemainingLineCommentLength + 1 > maxLength ) // +1 because of the newline that will be added later
249
+ if ( line . Length + currentLength + possibleRemainingLineCommentLength + 1 >
250
+ maxLength ) // +1 because of the newline that will be added later
252
251
return false ;
253
252
254
253
processedLines . Add ( line ) ;
0 commit comments