1+ using Cliptok . Helpers ;
12using Microsoft . EntityFrameworkCore ;
23
34namespace Cliptok . Commands
@@ -24,10 +25,11 @@ public async Task LogPrint(TextCommandContext ctx)
2425
2526 using ( var dbContext = new CliptokDbContext ( ) )
2627 {
27- var records = ( await dbContext . Messages . Include ( m => m . User ) . Include ( m => m . Sticker ) . Include ( m => m . User . BulkMessageLogs ) . OrderByDescending ( m => m . Id ) . Take ( 100 ) . ToListAsync ( ) ) ;
28- var json = JsonConvert . SerializeObject ( records , Formatting . Indented ) ;
28+ var records = ( await dbContext . Messages . Include ( m => m . User ) . Include ( m => m . Sticker ) . OrderByDescending ( m => m . Id ) . Take ( 100 ) . ToListAsync ( ) ) ;
29+ var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( JsonConvert . SerializeObject ( records , Formatting . Indented ) ) ) ;
2930 await ctx . RespondAsync ( new DiscordMessageBuilder ( )
30- . WithContent ( $ "100 most recent message logs:\n { await StringHelpers . CodeOrHasteBinAsync ( json , "json" , plain : true ) } ") ) ;
31+ . WithContent ( $ "100 most recent message logs")
32+ . AddFile ( "messages.json" , stream ) ) ;
3133 }
3234 }
3335
@@ -65,7 +67,14 @@ public async Task MuteDebug(TextCommandContext ctx, DiscordUser targetUser = def
6567 strOut += $ "{ entry . Value } \n ";
6668 }
6769 }
68- await ctx . RespondAsync ( await StringHelpers . CodeOrHasteBinAsync ( strOut , "json" ) ) ;
70+ var hasteResult = await StringHelpers . CodeOrHasteBinAsync ( strOut , "json" ) ;
71+ if ( hasteResult . Success )
72+ await ctx . RespondAsync ( hasteResult . Text ) ;
73+ else
74+ {
75+ var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( strOut ) ) ;
76+ await ctx . RespondAsync ( new DiscordMessageBuilder ( ) . AddFile ( "mutes.json" , stream ) ) ;
77+ }
6978 }
7079 else // if (targetUser != default)
7180 {
@@ -104,7 +113,16 @@ public async Task BanDebug(TextCommandContext ctx, DiscordUser targetUser = defa
104113 strOut += $ "{ entry . Value } \n ";
105114 }
106115 }
107- await ctx . RespondAsync ( await StringHelpers . CodeOrHasteBinAsync ( strOut , "json" ) ) ;
116+ var haste = await StringHelpers . CodeOrHasteBinAsync ( strOut , "json" ) ;
117+ if ( haste . Success )
118+ await ctx . Channel . SendMessageAsync ( haste . Text ) ;
119+ else
120+ {
121+ var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( JsonConvert . SerializeObject ( strOut , Formatting . Indented ) ) ) ;
122+ await ctx . Channel . SendMessageAsync ( new DiscordMessageBuilder ( )
123+ . AddFile ( "bans.txt" , stream ) ) ;
124+ }
125+
108126 }
109127 else // if (targetUser != default)
110128 {
@@ -182,7 +200,7 @@ public async Task Shell(TextCommandContext ctx, [RemainingText] string command)
182200 ShellResult finishedShell = RunShellCommand ( command ) ;
183201 string result = Regex . Replace ( finishedShell . result , "ghp_[0-9a-zA-Z]{36}" , "ghp_REDACTED" ) . Replace ( Environment . GetEnvironmentVariable ( "CLIPTOK_TOKEN" ) , "REDACTED" ) . Replace ( Environment . GetEnvironmentVariable ( "CLIPTOK_ANTIPHISHING_ENDPOINT" ) ?? "DUMMYVALUE" , "REDACTED" ) ;
184202
185- string msgContent = await StringHelpers . CodeOrHasteBinAsync ( result , charLimit : 1947 ) ;
203+ string msgContent = ( await StringHelpers . CodeOrHasteBinAsync ( result , charLimit : 1947 ) ) . Text ;
186204
187205 msgContent += $ "\n Process exited with code `{ finishedShell . proc . ExitCode } `.";
188206
@@ -264,8 +282,15 @@ public async Task CheckPendingChannelEvents(TextCommandContext ctx)
264282 }
265283 list += "```\n " ;
266284 }
267-
268- await ctx . RespondAsync ( await StringHelpers . CodeOrHasteBinAsync ( list ) ) ;
285+ var haste = await StringHelpers . CodeOrHasteBinAsync ( list , "json" ) ;
286+ if ( haste . Success )
287+ await ctx . Channel . SendMessageAsync ( haste . Text ) ;
288+ else
289+ {
290+ var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( JsonConvert . SerializeObject ( list , Formatting . Indented ) ) ) ;
291+ await ctx . Channel . SendMessageAsync ( new DiscordMessageBuilder ( )
292+ . AddFile ( "events.txt" , stream ) ) ;
293+ }
269294 }
270295
271296 [ Command ( "dmchannel" ) ]
@@ -286,7 +311,15 @@ public async Task DumpDMChannels(TextCommandContext ctx)
286311
287312 var json = JsonConvert . SerializeObject ( dmChannels , Formatting . Indented ) ;
288313
289- await ctx . RespondAsync ( await StringHelpers . CodeOrHasteBinAsync ( json , "json" ) ) ;
314+ var haste = await StringHelpers . CodeOrHasteBinAsync ( json , "json" ) ;
315+ if ( haste . Success )
316+ await ctx . Channel . SendMessageAsync ( haste . Text ) ;
317+ else
318+ {
319+ var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( JsonConvert . SerializeObject ( json , Formatting . Indented ) ) ) ;
320+ await ctx . Channel . SendMessageAsync ( new DiscordMessageBuilder ( )
321+ . AddFile ( "members.json" , stream ) ) ;
322+ }
290323 }
291324
292325 [ Command ( "searchmembers" ) ]
@@ -305,7 +338,16 @@ public async Task SearchMembersCmd(TextCommandContext ctx, string regex)
305338 Dictionary < ulong , string > memberIdsTonames = matchedMembers . Select ( member => new KeyValuePair < ulong , string > ( member . Id , member . Username ) ) . ToDictionary ( x => x . Key , x => x . Value ) ;
306339
307340 _ = msg . DeleteAsync ( ) ;
308- await ctx . Channel . SendMessageAsync ( await StringHelpers . CodeOrHasteBinAsync ( JsonConvert . SerializeObject ( memberIdsTonames , Formatting . Indented ) , "json" ) ) ;
341+ var json = JsonConvert . SerializeObject ( memberIdsTonames , Formatting . Indented ) ;
342+ var haste = await StringHelpers . CodeOrHasteBinAsync ( json , "json" ) ;
343+ if ( haste . Success )
344+ await ctx . Channel . SendMessageAsync ( haste . Text ) ;
345+ else
346+ {
347+ var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( JsonConvert . SerializeObject ( json , Formatting . Indented ) ) ) ;
348+ await ctx . Channel . SendMessageAsync ( new DiscordMessageBuilder ( )
349+ . AddFile ( "members.json" , stream ) ) ;
350+ }
309351 }
310352
311353 [ Command ( "testnre" ) ]
@@ -340,7 +382,7 @@ public async Task WarningCacheCmd(TextCommandContext ctx)
340382 await ctx . RespondAsync ( "No cached warning found." ) ;
341383 return ;
342384 }
343- await ctx . RespondAsync ( await StringHelpers . CodeOrHasteBinAsync ( JsonConvert . SerializeObject ( WarningHelpers . mostRecentWarning , Formatting . Indented ) , "json" ) ) ;
385+ await ctx . RespondAsync ( ( await StringHelpers . CodeOrHasteBinAsync ( JsonConvert . SerializeObject ( WarningHelpers . mostRecentWarning , Formatting . Indented ) , "json" ) ) . Text ) ;
344386 }
345387
346388 [ Command ( "bancache" ) ]
@@ -352,7 +394,7 @@ public async Task BanCacheCmd(TextCommandContext ctx)
352394 await ctx . RespondAsync ( "No cached ban found." ) ;
353395 return ;
354396 }
355- await ctx . RespondAsync ( await StringHelpers . CodeOrHasteBinAsync ( JsonConvert . SerializeObject ( BanHelpers . MostRecentBan , Formatting . Indented ) , "json" ) ) ;
397+ await ctx . RespondAsync ( ( await StringHelpers . CodeOrHasteBinAsync ( JsonConvert . SerializeObject ( BanHelpers . MostRecentBan , Formatting . Indented ) , "json" ) ) . Text ) ;
356398 }
357399
358400
@@ -365,7 +407,7 @@ public async Task MuteCacheCmd(TextCommandContext ctx)
365407 await ctx . RespondAsync ( "No cached mute found." ) ;
366408 return ;
367409 }
368- await ctx . RespondAsync ( await StringHelpers . CodeOrHasteBinAsync ( JsonConvert . SerializeObject ( MuteHelpers . MostRecentMute , Formatting . Indented ) , "json" ) ) ;
410+ await ctx . RespondAsync ( ( await StringHelpers . CodeOrHasteBinAsync ( JsonConvert . SerializeObject ( MuteHelpers . MostRecentMute , Formatting . Indented ) , "json" ) ) . Text ) ;
369411 }
370412
371413 }
@@ -424,7 +466,7 @@ await ctx.RespondAsync(
424466 if ( response . Length > 2000 )
425467 {
426468 // I am abusing my own helper here. I know for a fact that it will be over the char limit so I know it won't return a code block.
427- await ctx . RespondAsync ( await StringHelpers . CodeOrHasteBinAsync ( response ) ) ;
469+ await ctx . RespondAsync ( ( await StringHelpers . CodeOrHasteBinAsync ( response ) ) . Text ) ;
428470 }
429471 else
430472 {
@@ -633,7 +675,7 @@ public async Task DumpFromDiscord(TextCommandContext ctx,
633675 output += $ "{ JsonConvert . SerializeObject ( overwrite ) } \n ";
634676 }
635677
636- await ctx . RespondAsync ( $ "Dump from Discord:\n { await StringHelpers . CodeOrHasteBinAsync ( output , "json" ) } ") ;
678+ await ctx . RespondAsync ( $ "Dump from Discord:\n { ( await StringHelpers . CodeOrHasteBinAsync ( output , "json" ) ) . Text } ") ;
637679 }
638680
639681 [ Command ( "db" ) ]
@@ -676,7 +718,7 @@ public async Task DumpFromDb(TextCommandContext ctx,
676718 output += $ "{ JsonConvert . SerializeObject ( overwrite ) } \n ";
677719 }
678720
679- await ctx . RespondAsync ( $ "Dump from db:\n { await StringHelpers . CodeOrHasteBinAsync ( output , "json" ) } ") ;
721+ await ctx . RespondAsync ( $ "Dump from db:\n { ( await StringHelpers . CodeOrHasteBinAsync ( output , "json" ) ) . Text } ") ;
680722 }
681723 }
682724
0 commit comments