using Newtonsoft.Json;
using OpenMetaverse;
using SecondBotEvents.Services;
using System.Collections.Generic;
using System.Linq;
namespace SecondBotEvents.Commands
{
[ClassInfo("Control services via commands (Requires the command enable service control flag be set to true)
controlable services:
" +
"BotClientService
"+
"RLVService
" +
"HttpService
" +
"DiscordService
" +
"InteractionService
" +
"HomeboundService
" +
"EventsService
" +
"DialogService
" +
"TriggerOnEventService
" +
"RelayService")]
public class Services : CommandsAPI
{
public Services(EventsSecondBot setmaster) : base(setmaster)
{
}
protected List controlable = new List { "BotClientService","RLVService",
"HttpService",
"DiscordService",
"InteractionService",
"HomeboundService",
"EventsService",
"DialogService",
"TriggerOnEventService",
"RelayService"};
[About("Marks a service as enabled and starts it")]
[ReturnHints("ok")]
[ReturnHintsFailure("Unknown service")]
[ReturnHintsFailure("Unable to manage selected service")]
[ReturnHintsFailure("Service control is not enabled by config")]
public object EnableAndStartService(string servicename)
{
if(master.CommandsService.GetAllowServiceCommands() == false)
{
return Failure("Service control is not enabled by config");
}
if(controlable.Contains(servicename) == false)
{
return Failure("Unknown service");
}
BotServices service = master.GetService(servicename);
if (service == null)
{
return Failure("Unknown service");
}
service.enableAndStart();
return BasicReply("ok");
}
[About("stops a service if it is running")]
[ReturnHints("ok")]
[ReturnHintsFailure("Unknown service")]
[ReturnHintsFailure("Unable to manage selected service")]
[ReturnHintsFailure("Service control is not enabled by config")]
public object StopService(string servicename)
{
if (master.CommandsService.GetAllowServiceCommands() == false)
{
return Failure("Service control is not enabled by config");
}
if (controlable.Contains(servicename) == false)
{
return Failure("Unknown service");
}
BotServices service = master.GetService(servicename);
if (service == null)
{
return Failure("Unknown service");
}
service.Stop();
return BasicReply("ok");
}
[About("restarts a service if it is running")]
[ReturnHints("ok")]
[ReturnHintsFailure("Unknown service")]
[ReturnHintsFailure("Unable to manage selected service")]
[ReturnHintsFailure("Service control is not enabled by config")]
public object RestartService(string servicename)
{
if (master.CommandsService.GetAllowServiceCommands() == false)
{
return Failure("Service control is not enabled by config");
}
if (controlable.Contains(servicename) == false)
{
return Failure("Unknown service");
}
BotServices service = master.GetService(servicename);
if (service == null)
{
return Failure("Unknown service");
}
service.Restart();
return BasicReply("ok");
}
[About("Change or add a config value to a service")]
[ReturnHints("ok")]
[ReturnHintsFailure("Unknown service")]
[ReturnHintsFailure("Unable to manage selected service")]
[ReturnHintsFailure("Service control is not enabled by config")]
public object ChangeConfigValue(string servicename,string configname,string configvalue)
{
if (master.CommandsService.GetAllowServiceCommands() == false)
{
return Failure("Service control is not enabled by config");
}
if (controlable.Contains(servicename) == false)
{
return Failure("Unknown service");
}
BotServices service = master.GetService(servicename);
if (service == null)
{
return Failure("Unknown service");
}
service.changeConfig(configname, configvalue);
return BasicReply("ok");
}
}
}