@@ -115,7 +115,7 @@ public static JsonObject CommandBotId(BotManager bots)
115
115
public static void CommandBotMove ( TeamspeakControl queryConnection , CallerInfo caller , ulong ? channel , string password = null )
116
116
{
117
117
if ( ! channel . HasValue )
118
- channel = ( CommandGetChannel ( caller ) as JsonSingleValue < ulong > ) ? . Value ;
118
+ channel = caller . InvokerData . ChannelId ;
119
119
if ( ! channel . HasValue )
120
120
throw new CommandException ( "No target channel found" , CommandExceptionReason . CommandError ) ;
121
121
queryConnection . MoveTo ( channel . Value , password ) . UnwrapThrow ( ) ;
@@ -159,7 +159,7 @@ public static JsonObject CommandConnect(BotManager bots)
159
159
{
160
160
var botInfo = bots . CreateBot ( ) ;
161
161
if ( botInfo == null )
162
- throw new CommandException ( "Could not create new instance" ) ;
162
+ throw new CommandException ( "Could not create new instance" , CommandExceptionReason . CommandError ) ;
163
163
return new JsonSingleValue < BotInfo > ( botInfo ) ;
164
164
}
165
165
@@ -260,7 +260,7 @@ public static JsonObject CommandHelp(CommandManager commandManager, params strin
260
260
strb . Append ( "\n ========= Welcome to the TS3AudioBot ========="
261
261
+ "\n If you need any help with a special command use !help <commandName>."
262
262
+ "\n Here are all possible commands:\n " ) ;
263
- var botComList = commandManager . AllCommands . Select ( c => c . InvokeName ) . GroupBy ( n => n . Split ( ' ' ) [ 0 ] ) . Select ( x => x . Key ) . ToArray ( ) ;
263
+ var botComList = commandManager . AllCommands . Select ( c => c . InvokeName ) . OrderBy ( x => x ) . GroupBy ( n => n . Split ( ' ' ) [ 0 ] ) . Select ( x => x . Key ) . ToArray ( ) ;
264
264
foreach ( var botCom in botComList )
265
265
strb . Append ( botCom ) . Append ( ", " ) ;
266
266
strb . Length -= 2 ;
@@ -418,27 +418,24 @@ public static JsonObject CommandHistoryId(HistoryManager historyManager, string
418
418
throw new CommandException ( "Unrecognized name descriptor" , CommandExceptionReason . CommandError ) ;
419
419
}
420
420
421
+ [ Command ( "history last" , "<count> Gets the last <count> played songs." ) ]
422
+ public static JsonObject CommandHistoryLast ( HistoryManager historyManager , int amount )
423
+ {
424
+ var query = new SeachQuery { MaxResults = amount } ;
425
+ var results = historyManager . Search ( query ) . ToArray ( ) ;
426
+ return new JsonArray < AudioLogEntry > ( historyManager . Format ( results ) , results ) ;
427
+ }
428
+
421
429
[ Command ( "history last" , "Plays the last song again" ) ]
422
- [ Usage ( "<count>" , "Gets the last <count> played songs." ) ]
423
- [ RequiredParameters ( 0 ) ]
424
- public static JsonObject CommandHistoryLast ( PlayManager playManager , HistoryManager historyManager , CallerInfo caller , int ? amount )
430
+ public static JsonObject CommandHistoryLast ( PlayManager playManager , HistoryManager historyManager , CallerInfo caller )
425
431
{
426
- if ( amount . HasValue )
432
+ var ale = historyManager . Search ( new SeachQuery { MaxResults = 1 } ) . FirstOrDefault ( ) ;
433
+ if ( ale != null )
427
434
{
428
- var query = new SeachQuery { MaxResults = amount . Value } ;
429
- var results = historyManager . Search ( query ) . ToArray ( ) ;
430
- return new JsonArray < AudioLogEntry > ( historyManager . Format ( results ) , results ) ;
431
- }
432
- else
433
- {
434
- var ale = historyManager . Search ( new SeachQuery { MaxResults = 1 } ) . FirstOrDefault ( ) ;
435
- if ( ale != null )
436
- {
437
- playManager . Play ( caller . InvokerData , ale . AudioResource ) . UnwrapThrow ( ) ;
438
- return null ;
439
- }
440
- else return new JsonEmpty ( "There is no song in the history" ) ;
435
+ playManager . Play ( caller . InvokerData , ale . AudioResource ) . UnwrapThrow ( ) ;
436
+ return null ;
441
437
}
438
+ else return new JsonEmpty ( "There is no song in the history" ) ;
442
439
}
443
440
444
441
[ Command ( "history play" , "<id> Playes the song with <id>" ) ]
@@ -880,24 +877,36 @@ public static void CommandPlay(IPlayerConnection playerConnection, PlayManager p
880
877
}
881
878
882
879
[ Command ( "plugin list" , "Lists all found plugins." ) ]
883
- public static JsonArray < PluginStatusInfo > CommandPluginList ( PluginManager pluginManager )
880
+ public static JsonArray < PluginStatusInfo > CommandPluginList ( ExecutionInformation info , PluginManager pluginManager )
884
881
{
885
- var overview = pluginManager . GetPluginOverview ( ) ;
882
+ // Get bot instance dynamically since it might be optional
883
+ // Requesting it via parameter injection would prevent some plugin types to be loaded from a higher context like 'Core'
884
+ if ( ! info . TryGet < Bot > ( out var bot ) )
885
+ bot = null ;
886
+ var overview = pluginManager . GetPluginOverview ( bot ) ;
886
887
return new JsonArray < PluginStatusInfo > ( PluginManager . FormatOverview ( overview ) , overview ) ;
887
888
}
888
889
889
890
[ Command ( "plugin unload" , "Unloads a plugin." ) ]
890
- public static void CommandPluginUnload ( PluginManager pluginManager , string identifier )
891
+ public static void CommandPluginUnload ( ExecutionInformation info , PluginManager pluginManager , string identifier )
891
892
{
892
- var result = pluginManager . StopPlugin ( identifier ) ;
893
+ // Get bot instance dynamically since it might be optional
894
+ // Requesting it via parameter injection would prevent some plugin types to be loaded from a higher context like 'Core'
895
+ if ( ! info . TryGet < Bot > ( out var bot ) )
896
+ bot = null ;
897
+ var result = pluginManager . StopPlugin ( identifier , bot ) ;
893
898
if ( result != PluginResponse . Ok )
894
899
throw new CommandException ( "Plugin error: " + result , CommandExceptionReason . CommandError ) ;
895
900
}
896
901
897
902
[ Command ( "plugin load" , "Unloads a plugin." ) ]
898
- public static void CommandPluginLoad ( PluginManager pluginManager , string identifier )
903
+ public static void CommandPluginLoad ( ExecutionInformation info , PluginManager pluginManager , string identifier )
899
904
{
900
- var result = pluginManager . StartPlugin ( identifier ) ;
905
+ // Get bot instance dynamically since it might be optional
906
+ // Requesting it via parameter injection would prevent some plugin types to be loaded from a higher context like 'Core'
907
+ if ( ! info . TryGet < Bot > ( out var bot ) )
908
+ bot = null ;
909
+ var result = pluginManager . StartPlugin ( identifier , bot ) ;
901
910
if ( result != PluginResponse . Ok )
902
911
throw new CommandException ( "Plugin error: " + result , CommandExceptionReason . CommandError ) ;
903
912
}
0 commit comments