Skip to content

Commit

Permalink
Adds TTS discord support, plus the first pass of Log2File
Browse files Browse the repository at this point in the history
  • Loading branch information
Madpeterz committed Oct 13, 2020
1 parent 6d69232 commit 089db10
Show file tree
Hide file tree
Showing 33 changed files with 457 additions and 163 deletions.
4 changes: 2 additions & 2 deletions BSBshared/API/API_interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected virtual void LoadCommandsList()
}
else
{
ConsoleLog.Crit("[CMD] command: " + D.CommandName + " already defined!");
LogFormater.Crit("[CMD] command: " + D.CommandName + " already defined!");
}
}
}
Expand All @@ -80,7 +80,7 @@ protected IEnumerable<Type> GetAPICommandClasses()
}
else
{
ConsoleLog.Crit(this.GetType() + " Attempted to call GetSubTypes without setting API_TYPE first!");
LogFormater.Crit(this.GetType() + " Attempted to call GetSubTypes without setting API_TYPE first!");
}
return null;
}
Expand Down
57 changes: 47 additions & 10 deletions BSBshared/BotTypes/BasicBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public bool is_avatar_master(string name)
protected bool killMe;
protected JsonConfig myconfig;
protected string version = "NotSet V1.0.0.0";

protected bool reconnect;
public string MyVersion { get { return version; } }
public string Name { get { return myconfig.Basic_BotUserName; } }
Expand Down Expand Up @@ -63,7 +64,7 @@ public virtual void Setup(JsonConfig config, string Version)
if (myconfig.Security_SignedCommandkey.Length < 8)
{
myconfig.Security_SignedCommandkey = helpers.GetSHA1("" + myconfig.Basic_BotUserName + "" + myconfig.Basic_BotPassword + "" + helpers.UnixTimeNow().ToString() + "").Substring(0, 8);
ConsoleLog.Warn("Given code is not acceptable (min length 8)");
Warn("Given code is not acceptable (min length 8)");
}
List<string> bits = myconfig.Basic_BotUserName.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList();
if (bits.Count == 1)
Expand Down Expand Up @@ -93,11 +94,11 @@ public virtual void Setup(JsonConfig config, string Version)
}
string namesubmaster = String.Join(" ", bits);
SubMasters.Add(namesubmaster);
ConsoleLog.Info("Sub-Master: " + namesubmaster);
Info("Sub-Master: " + namesubmaster);
}
}
}
ConsoleLog.Info("Build: " + version);
Info("Build: " + version);
}

public virtual void Start()
Expand All @@ -118,13 +119,13 @@ public virtual void Start()
}
else
{
ConsoleLog.Warn("loginURI invaild: using secondlife");
Warn("loginURI invaild: using secondlife");
Lp = new LoginParams(Client, bits[0], bits[1], myconfig.Basic_BotPassword, "BetterSecondBot", version);
}
}
else
{
ConsoleLog.Warn("loginURI invaild: using secondlife");
Warn("loginURI invaild: using secondlife");
Lp = new LoginParams(Client, bits[0], bits[1], myconfig.Basic_BotPassword, "BetterSecondBot", version);
}
}
Expand All @@ -140,7 +141,7 @@ public virtual void Start()
}
protected virtual void BotStartHandler()
{
ConsoleLog.Debug("BotStartHandler proc not overridden");
Debug("BotStartHandler proc not overridden");
}

protected string GetSimPositionAsString()
Expand Down Expand Up @@ -181,7 +182,7 @@ public virtual string GetStatus()

protected virtual void LoginHandler(object o, LoginProgressEventArgs e)
{
ConsoleLog.Debug("LoginHandler proc not overridden");
Debug("LoginHandler proc not overridden");
}

protected virtual void AfterBotLoginHandler()
Expand Down Expand Up @@ -255,7 +256,7 @@ protected virtual void RequestTeleport(UUID IMSessionID, string FromAgentName, U

protected virtual void ChatInputHandler(object sender, ChatEventArgs e)
{
ConsoleLog.Debug("ChatInputHandler proc not overridden");
Debug("ChatInputHandler proc not overridden");
}

protected virtual void CoreCommandLib(UUID fromUUID, bool from_master, string command, string arg)
Expand All @@ -270,12 +271,48 @@ protected virtual void CoreCommandLib(UUID fromUUID, bool from_master, string co

protected virtual void CoreCommandLib(UUID fromUUID,bool from_master,string command,string arg,string signing_code,string signed_with)
{
ConsoleLog.Debug("CoreCommandLib proc not overridden");
Debug("CoreCommandLib proc not overridden");
}

public virtual void ResetAnimations()
{
ConsoleLog.Debug("reset_animations not enabled at this level");
Debug("reset_animations not enabled at this level");
}

public virtual void Warn(string message)
{
Log2File(LogFormater.Warn(message), ConsoleLogLogLevel.Warn);
}
public virtual void Crit(string message)
{
Log2File(LogFormater.Crit(message), ConsoleLogLogLevel.Crit);
}
public virtual void Info(string message)
{
Log2File(LogFormater.Info(message), ConsoleLogLogLevel.Info);
}
public virtual void Status(string message)
{
Log2File(LogFormater.Status(message), ConsoleLogLogLevel.Status);
}
public virtual void Debug(string message)
{
Log2File(LogFormater.Debug(message), ConsoleLogLogLevel.Debug);
}

public virtual void Log2File(string message, ConsoleLogLogLevel Level)
{
if (myconfig == null)
{
Console.WriteLine(message);
}
else
{
if (myconfig.Log2File_Level >= (int)Level)
{
Console.WriteLine(message);
}
}
}
}
}
13 changes: 12 additions & 1 deletion BSBshared/Json/JsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class JsonConfig
// Settings
public bool Setting_AllowRLV { get; set; }
public bool Setting_AllowFunds { get; set; }
public bool Setting_LogCommands { get; set; }
public string Setting_RelayImToAvatarUUID { get; set; }
public string Setting_DefaultSit_UUID { get; set; }
public string Setting_loginURI { get; set; }
Expand All @@ -46,6 +45,18 @@ public class JsonConfig
public string Name2Key_Url { get; set; }
public string Name2Key_Key { get; set; }


// TTS
public bool DiscordTTS_Enable { get; set; }
public ulong DiscordTTS_server_id { get; set; }
public string DiscordTTS_channel_name { get; set; }
public string DiscordTTS_avatar_uuid { get; set; }
public string DiscordTTS_Nickname { get; set; }

// Logs
public bool Log2File_Enable { get; set; }
public int Log2File_Level { get; set; }
public bool Setting_LogCommands { get; set; }
}

}
59 changes: 42 additions & 17 deletions BSBshared/Json/JsonConfigApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ public override string GetCommandHelp(string cmd)
// Security
else if (cmd == "Security_MasterUsername") return "The username of the bots owner *you can leave out Resident if you so wish*";
else if (cmd == "Security_SubMasters") return "A CSV of avatar names who can issue commands to the bot";

else if (cmd == "Security_SignedCommandkey") return "Used when sending the bot a HTTP or IM command that has a hash validation";
else if (cmd == "Security_WebUIKey") return "Used with the webUI to login, note: 2FA support is planned soon for this system that will replace this UIkey";
// Settings
else if (cmd == "Setting_AllowRLV") return "Enable the RLV api interface";
else if (cmd == "Setting_AllowFunds") return "Allow the bot to transfer L$ and get a non zero balance";
else if (cmd == "Setting_LogCommands") return "Allow the bot to send command to console and discord full if enabled";
else if (cmd == "Setting_RelayImToAvatarUUID") return "UUID of who the bot should relay IMs to in secondlife";
else if (cmd == "Setting_DefaultSit_UUID") return "UUID of a object the bot should attempt to sit on after logging in";
else if (cmd == "Setting_loginURI") return "the URI to login to (leave as \"secondlife\" unless you know what your doing!)";
Expand All @@ -48,6 +47,23 @@ public override string GetCommandHelp(string cmd)
else if (cmd == "Http_Port") return "The port the HTTP interface should be running on";
else if (cmd == "Http_Host") return "The URL the interface is on example use \"docker\" for auto or \"http://localhost:portnum\"";
else if (cmd == "Http_PublicUrl") return "The public url used to access the web ui";
// Discord TTS
else if (cmd == "DiscordTTS_Enable") return "Enable discord TTS helper (Requires DiscordFull_Enable set to true) ";
else if (cmd == "DiscordTTS_server_id") return "The server ID to use for TTS";
else if (cmd == "DiscordTTS_channel_name") return "The channel name to use (found on the server set by DiscordTTS_server_id)";
else if (cmd == "DiscordTTS_avatar_uuid") return "The avatar UUID whos IMs will be turned into TTS";
else if (cmd == "DiscordTTS_Nickname") return "The nickname to use on the TTS server";
// Logs
else if (cmd == "Log2File_Enable") return "Enable writing to logs to files [Logs are sent to the Logs folder]"
+ "\n If you dont attach a volume called logs to the bot it will not be kept when the docker instance is restarted";
else if (cmd == "Log2File_Level") return "Enabled logging levels\n"
+ "- 1: Nothing\n"
+ "0: Status only\n"
+ "1: +Info\n"
+ "2: +Crititcal\n"
+ "3: +Warnings\n"
+ "4: +Debug\n";
else if (cmd == "Setting_LogCommands") return "Allow the bot to send command to console and discord full if enabled";
// Give up
return "Unknown value:" + cmd;
}
Expand Down Expand Up @@ -90,7 +106,6 @@ public string JsonGetCommandArgHints(string cmd)
// Settings
else if (cmd == "Setting_AllowRLV") return "False";
else if (cmd == "Setting_AllowFunds") return "True";
else if (cmd == "Setting_LogCommands") return "True";
else if (cmd == "Setting_RelayImToAvatarUUID") return "";
else if (cmd == "Setting_DefaultSit_UUID") return "";
else if (cmd == "Setting_loginURI") return "secondlife";
Expand All @@ -105,6 +120,16 @@ public string JsonGetCommandArgHints(string cmd)
else if (cmd == "Http_Port") return "80";
else if (cmd == "Http_Host") return "http://localhost:80";
else if (cmd == "Http_PublicUrl") return "http://localhost/";
// Discord TTS
else if (cmd == "DiscordTTS_Enable") return "False";
else if (cmd == "DiscordTTS_server_id") return "";
else if (cmd == "DiscordTTS_channel_name") return "";
else if (cmd == "DiscordTTS_avatar_uuid") return "";
else if (cmd == "DiscordTTS_Nickname") return "";
// Logs
else if (cmd == "Log2File_Enable") return "False";
else if (cmd == "Log2File_Level") return "1";
else if (cmd == "Setting_LogCommands") return "True";
// Give up
return "Unknown value:" + cmd;
}
Expand Down Expand Up @@ -169,23 +194,23 @@ protected JsonConfig process_prop(JsonConfig reply,string arg,string arg_value_d
}
else
{
ConsoleLog.Debug("unsupported arg_type: " + arg_type + " for " + arg + "");
LogFormater.Debug("unsupported arg_type: " + arg_type + " for " + arg + "");
}
}
else
{
ConsoleLog.Warn("Unable to write to " + arg + "");
LogFormater.Warn("Unable to write to " + arg + "");
}
}
else
{
ConsoleLog.Crit("unknown prop " + arg + "");
LogFormater.Crit("unknown prop " + arg + "");
}
}
}
else
{
ConsoleLog.Debug("unknown arg_type for " + arg + "");
LogFormater.Debug("unknown arg_type for " + arg + "");
}
return reply;
}
Expand All @@ -201,15 +226,15 @@ public static JsonConfig http_config_check(JsonConfig jsonConfig)
jsonConfig.Http_Enable = false;
if (jsonConfig.Security_WebUIKey.Length < 12)
{
ConsoleLog.Warn("Http disabled: Security_WebUIKey length must be 12 or more");
LogFormater.Warn("Http disabled: Security_WebUIKey length must be 12 or more");
}
else if (jsonConfig.Http_Port < 80)
{
ConsoleLog.Warn("Http disabled: Httpport range below protected range - Given: (" + jsonConfig.Http_Port + ")");
LogFormater.Warn("Http disabled: Httpport range below protected range - Given: (" + jsonConfig.Http_Port + ")");
}
else if ((jsonConfig.Http_Host != "docker") && (jsonConfig.Http_Host.StartsWith("http") == false))
{
ConsoleLog.Warn("Http disabled: Http_Host must be vaild: http://XXXXXX or \"docker\" - Given: (" + jsonConfig.Http_Host + ")");
LogFormater.Warn("Http disabled: Http_Host must be vaild: http://XXXXXX or \"docker\" - Given: (" + jsonConfig.Http_Host + ")");
}
else
{
Expand All @@ -218,18 +243,18 @@ public static JsonConfig http_config_check(JsonConfig jsonConfig)
}
else
{
ConsoleLog.Info("Http interface disabled by config");
LogFormater.Info("Http interface disabled by config");
}
}
else
{
ConsoleLog.Warn("Http disabled: Http_Host is null");
LogFormater.Warn("Http disabled: Http_Host is null");
jsonConfig.Http_Enable = false;
}
}
else
{
ConsoleLog.Warn("Http disabled: Security_WebUIKey is null");
LogFormater.Warn("Http disabled: Security_WebUIKey is null");
jsonConfig.Http_Enable = false;
}
return jsonConfig;
Expand Down Expand Up @@ -279,7 +304,7 @@ protected JsonConfig MakeDefault()
}
else
{
ConsoleLog.Debug("[Notice] No args hint found for " + arg + "");
LogFormater.Debug("[Notice] No args hint found for " + arg + "");
}
}
if (arg_value_default != null)
Expand Down Expand Up @@ -329,17 +354,17 @@ protected JsonConfig MakeDefault()
}
else
{
ConsoleLog.Debug("unknown arg_type: " + arg_type + " for " + arg + "");
LogFormater.Debug("unknown arg_type: " + arg_type + " for " + arg + "");
}
}
else
{
ConsoleLog.Warn("Unable to write to " + arg + "");
LogFormater.Warn("Unable to write to " + arg + "");
}
}
else
{
ConsoleLog.Crit("unknown prop " + arg + "");
LogFormater.Crit("unknown prop " + arg + "");
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions BSBshared/Staic/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,35 +152,35 @@ public static bool botRequired(JsonConfig test)
{
if (Testing.GetCommandArgTypes(a).First() == MakeJsonConfig.GetProp(test, a))
{
ConsoleLog.Warn("" + a + " is currently set to the default");
LogFormater.Warn("" + a + " is currently set to the default");
default_value_found = true;
break;
}
}
if (default_value_found == false)
{
ConsoleLog.Status("User => " + test.Basic_BotUserName);
ConsoleLog.Status("Master => " + test.Security_MasterUsername);
LogFormater.Status("User => " + test.Basic_BotUserName);
LogFormater.Status("Master => " + test.Security_MasterUsername);
}
return !default_value_found;
}
else
{
if (helpers.notempty(test.Basic_BotUserName) == false)
{
ConsoleLog.Warn("Basic_BotUserName is null or empty");
LogFormater.Warn("Basic_BotUserName is null or empty");
}
if (helpers.notempty(test.Basic_BotPassword) == false)
{
ConsoleLog.Warn("Basic_BotPassword is null or empty");
LogFormater.Warn("Basic_BotPassword is null or empty");
}
if (helpers.notempty(test.Security_MasterUsername) == false)
{
ConsoleLog.Warn("Security_MasterUsername is null or empty");
LogFormater.Warn("Security_MasterUsername is null or empty");
}
if (helpers.notempty(test.Security_SignedCommandkey) == false)
{
ConsoleLog.Warn("Security_SignedCommandkey is null or empty");
LogFormater.Warn("Security_SignedCommandkey is null or empty");
}
return false;
}
Expand Down
Loading

0 comments on commit 089db10

Please sign in to comment.