Adds TTS discord support, plus the first pass of Log2File
This commit is contained in:
parent
6d692323dc
commit
089db10196
33 changed files with 457 additions and 163 deletions
|
|
@ -60,7 +60,7 @@ namespace BetterSecondBotShared.API
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Crit("[CMD] command: " + D.CommandName + " already defined!");
|
||||
LogFormater.Crit("[CMD] command: " + D.CommandName + " already defined!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ namespace BetterSecondBotShared.API
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ namespace BetterSecondBotShared.bottypes
|
|||
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; } }
|
||||
|
|
@ -63,7 +64,7 @@ namespace BetterSecondBotShared.bottypes
|
|||
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)
|
||||
|
|
@ -93,11 +94,11 @@ namespace BetterSecondBotShared.bottypes
|
|||
}
|
||||
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()
|
||||
|
|
@ -118,13 +119,13 @@ namespace BetterSecondBotShared.bottypes
|
|||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -140,7 +141,7 @@ namespace BetterSecondBotShared.bottypes
|
|||
}
|
||||
protected virtual void BotStartHandler()
|
||||
{
|
||||
ConsoleLog.Debug("BotStartHandler proc not overridden");
|
||||
Debug("BotStartHandler proc not overridden");
|
||||
}
|
||||
|
||||
protected string GetSimPositionAsString()
|
||||
|
|
@ -181,7 +182,7 @@ namespace BetterSecondBotShared.bottypes
|
|||
|
||||
protected virtual void LoginHandler(object o, LoginProgressEventArgs e)
|
||||
{
|
||||
ConsoleLog.Debug("LoginHandler proc not overridden");
|
||||
Debug("LoginHandler proc not overridden");
|
||||
}
|
||||
|
||||
protected virtual void AfterBotLoginHandler()
|
||||
|
|
@ -255,7 +256,7 @@ namespace BetterSecondBotShared.bottypes
|
|||
|
||||
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)
|
||||
|
|
@ -270,12 +271,48 @@ namespace BetterSecondBotShared.bottypes
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ namespace BetterSecondBotShared.Json
|
|||
// 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; }
|
||||
|
|
@ -46,6 +45,18 @@ namespace BetterSecondBotShared.Json
|
|||
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; }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,12 @@ namespace BetterSecondBotShared.Json
|
|||
// 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!)";
|
||||
|
|
@ -48,6 +47,23 @@ namespace BetterSecondBotShared.Json
|
|||
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;
|
||||
}
|
||||
|
|
@ -90,7 +106,6 @@ namespace BetterSecondBotShared.Json
|
|||
// 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";
|
||||
|
|
@ -105,6 +120,16 @@ namespace BetterSecondBotShared.Json
|
|||
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;
|
||||
}
|
||||
|
|
@ -169,23 +194,23 @@ namespace BetterSecondBotShared.Json
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
@ -201,15 +226,15 @@ namespace BetterSecondBotShared.Json
|
|||
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
|
||||
{
|
||||
|
|
@ -218,18 +243,18 @@ namespace BetterSecondBotShared.Json
|
|||
}
|
||||
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;
|
||||
|
|
@ -279,7 +304,7 @@ namespace BetterSecondBotShared.Json
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Debug("[Notice] No args hint found for " + arg + "");
|
||||
LogFormater.Debug("[Notice] No args hint found for " + arg + "");
|
||||
}
|
||||
}
|
||||
if (arg_value_default != null)
|
||||
|
|
@ -329,17 +354,17 @@ namespace BetterSecondBotShared.Json
|
|||
}
|
||||
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 + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,15 +152,15 @@ namespace BetterSecondBotShared.Static
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
|
@ -168,19 +168,19 @@ namespace BetterSecondBotShared.Static
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,35 +5,35 @@ namespace BetterSecondBotShared.logs
|
|||
{
|
||||
public enum ConsoleLogLogLevel
|
||||
{
|
||||
Debug, // [Not logged unless in debug]
|
||||
Info, // [Not logged unless in debug]
|
||||
Status,
|
||||
Info,
|
||||
Crit,
|
||||
Warn,
|
||||
Crit
|
||||
Debug,
|
||||
};
|
||||
public static class ConsoleLog
|
||||
public static class LogFormater
|
||||
{
|
||||
public static void Warn(string message)
|
||||
public static string Warn(string message)
|
||||
{
|
||||
Add(message, ConsoleLogLogLevel.Warn);
|
||||
return Add(message, ConsoleLogLogLevel.Warn);
|
||||
}
|
||||
public static void Crit(string message)
|
||||
public static string Crit(string message)
|
||||
{
|
||||
Add(message, ConsoleLogLogLevel.Crit);
|
||||
return Add(message, ConsoleLogLogLevel.Crit);
|
||||
}
|
||||
public static void Info(string message)
|
||||
public static string Info(string message)
|
||||
{
|
||||
Add(message, ConsoleLogLogLevel.Info);
|
||||
return Add(message, ConsoleLogLogLevel.Info);
|
||||
}
|
||||
public static void Status(string message)
|
||||
public static string Status(string message)
|
||||
{
|
||||
Add(message, ConsoleLogLogLevel.Status);
|
||||
return Add(message, ConsoleLogLogLevel.Status);
|
||||
}
|
||||
public static void Debug(string message)
|
||||
public static string Debug(string message)
|
||||
{
|
||||
Add(message, ConsoleLogLogLevel.Debug);
|
||||
return Add(message, ConsoleLogLogLevel.Debug);
|
||||
}
|
||||
private static void Add(string message, ConsoleLogLogLevel Level)
|
||||
private static string Add(string message, ConsoleLogLogLevel Level)
|
||||
{
|
||||
var date = DateTime.Now;
|
||||
StringBuilder n = new StringBuilder();
|
||||
|
|
@ -86,7 +86,7 @@ namespace BetterSecondBotShared.logs
|
|||
}
|
||||
}
|
||||
n.Append(message);
|
||||
Console.WriteLine(n.ToString());
|
||||
return n.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ namespace BetterSecondBot
|
|||
{
|
||||
new CliHardware(args);
|
||||
}
|
||||
ConsoleLog.Status("- Exiting in 5 secs -");
|
||||
LogFormater.Status("- Exiting in 5 secs -");
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace BetterSecondBot
|
|||
public CliDocker()
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
ConsoleLog.Status("-> Getting config from Docker");
|
||||
LogFormater.Status("-> Getting config from Docker");
|
||||
JsonConfig Config = MakeJsonConfig.FromENV();
|
||||
Config = MakeJsonConfig.http_config_check(Config);
|
||||
new CliExitOnLogout(Config);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace BetterSecondBot
|
|||
{
|
||||
public CliExitOnLogout(JsonConfig Config)
|
||||
{
|
||||
ConsoleLog.Status("Mode: Cli [Basic]");
|
||||
LogFormater.Status("Mode: Cli [Basic]");
|
||||
if (helpers.botRequired(Config) == true)
|
||||
{
|
||||
SecondBot Bot = new SecondBot();
|
||||
|
|
@ -33,7 +33,7 @@ namespace BetterSecondBot
|
|||
if (NewStatusMessage != Bot.LastStatusMessage)
|
||||
{
|
||||
Bot.LastStatusMessage = NewStatusMessage;
|
||||
ConsoleLog.Status(Bot.LastStatusMessage);
|
||||
Bot.Log2File(LogFormater.Status(Bot.LastStatusMessage),ConsoleLogLogLevel.Status);
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ namespace BetterSecondBot
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("Required settings missing");
|
||||
LogFormater.Warn("Required settings missing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ namespace BetterSecondBot
|
|||
JsonConfig Config = new JsonConfig();
|
||||
string json_file = "";
|
||||
#if DEBUG
|
||||
ConsoleLog.Status("Hardware/Debug version");
|
||||
LogFormater.Status("Hardware/Debug version");
|
||||
json_file = "debug.json";
|
||||
#else
|
||||
ConsoleLog.Status("Hardware/Live version");
|
||||
Status("Hardware/Live version");
|
||||
if(args.Length == 1)
|
||||
{
|
||||
json_file = ""+args[0]+".json";
|
||||
|
|
@ -26,15 +26,15 @@ namespace BetterSecondBot
|
|||
else
|
||||
{
|
||||
json_file = "mybot.json";
|
||||
ConsoleLog.Warn("Using: mybot.json as the config");
|
||||
Warn("Using: mybot.json as the config");
|
||||
}
|
||||
|
||||
#endif
|
||||
if (SimpleIO.dir_exists("wiki") == false)
|
||||
{
|
||||
ConsoleLog.Info("Basic Wiki [Creating]");
|
||||
LogFormater.Info("Basic Wiki [Creating]");
|
||||
new DebugModeCreateWiki(AssemblyInfo.GetGitHash(), io);
|
||||
ConsoleLog.Info("Basic Wiki [Ready]");
|
||||
LogFormater.Info("Basic Wiki [Ready]");
|
||||
io = new SimpleIO();
|
||||
}
|
||||
bool ok_to_try_start = false;
|
||||
|
|
@ -52,7 +52,7 @@ namespace BetterSecondBot
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleLog.Warn("Unable to read config file\n moving config to " + json_file + ".old and creating a empty config\nError was: " + e.Message + "");
|
||||
LogFormater.Warn("Unable to read config file\n moving config to " + json_file + ".old and creating a empty config\nError was: " + e.Message + "");
|
||||
io.makeOld(json_file);
|
||||
Config = new JsonConfig();
|
||||
io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file);
|
||||
|
|
@ -60,19 +60,19 @@ namespace BetterSecondBot
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("Json config is empty creating an empty one for you");
|
||||
LogFormater.Warn("Json config is empty creating an empty one for you");
|
||||
io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("Json config does not Exist creating it for you");
|
||||
LogFormater.Warn("Json config does not Exist creating it for you");
|
||||
io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Crit("you must select a .json file for config! example \"BetterSecondBot.exe mybot\" will use the mybot.json file!");
|
||||
LogFormater.Crit("you must select a .json file for config! example \"BetterSecondBot.exe mybot\" will use the mybot.json file!");
|
||||
}
|
||||
if(ok_to_try_start == true)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,6 +55,16 @@ ENV Http_PublicUrl='http://localhost/'
|
|||
ENV Name2Key_Enable='false'
|
||||
ENV Name2Key_Url='http://localhost:1234'
|
||||
ENV Name2Key_Key='magic'
|
||||
|
||||
ENV DiscordTTS_Enable='false'
|
||||
ENV DiscordTTS_server_id=''
|
||||
ENV DiscordTTS_channel_name=''
|
||||
ENV DiscordTTS_avatar_uuid=''
|
||||
ENV DiscordTTS_Nickname=''
|
||||
|
||||
ENV Log2File_Enable='false'
|
||||
ENV Log2File_Level=1
|
||||
|
||||
EXPOSE 80
|
||||
ENV ASPNETCORE_URLS http://+:80
|
||||
|
||||
|
|
|
|||
|
|
@ -243,25 +243,25 @@ namespace BetterSecondBot.HttpServer
|
|||
catch (Exception e)
|
||||
{
|
||||
ok = false;
|
||||
ConsoleLog.Crit("Unable to setup http service: "+e.Message+"");
|
||||
ConsoleLog.Crit("if running on windows please check: https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-http-and-https?redirectedfrom=MSDN");
|
||||
LogFormater.Crit("Unable to setup http service: "+e.Message+"");
|
||||
LogFormater.Crit("if running on windows please check: https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-http-and-https?redirectedfrom=MSDN");
|
||||
}
|
||||
if (ok == true)
|
||||
{
|
||||
bool clean_exit = false;
|
||||
ConsoleLog.Status("Listening for connections on " + url + "");
|
||||
LogFormater.Status("Listening for connections on " + url + "");
|
||||
while (clean_exit == false)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConsoleLog.Status("HTTP ready");
|
||||
LogFormater.Status("HTTP ready");
|
||||
Task listenTask = HandleIncomingConnections();
|
||||
listenTask.GetAwaiter().GetResult();
|
||||
}
|
||||
catch
|
||||
{
|
||||
ConsoleLog.Status("HTTP died");
|
||||
//ConsoleLog.Status("Http interface killed itself: " + e.ToString() + "");
|
||||
LogFormater.Status("HTTP died");
|
||||
//Status("Http interface killed itself: " + e.ToString() + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace BetterSecondBot.HttpServer
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Debug("" + command + " [Failed]: I have no fucking idea what you are talking about");
|
||||
LogFormater.Debug("" + command + " [Failed]: I have no fucking idea what you are talking about");
|
||||
return new[] { "Failed", "I have no fucking idea what you are talking about" };
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ namespace BetterSecondBot.HttpServer
|
|||
}
|
||||
protected string[] Failed(string why_failed)
|
||||
{
|
||||
ConsoleLog.Warn("HTTP: " + CommandName + " [Failed]: " + why_failed);
|
||||
LogFormater.Warn("HTTP: " + CommandName + " [Failed]: " + why_failed);
|
||||
return new [] {"Failed",why_failed};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ namespace BetterSecondBot.WikiMake
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Debug("command " + c + " from " + interface_name + " overlaps an ready loaded command from "+ seen_command_names[c]+"");
|
||||
LogFormater.Debug("command " + c + " from " + interface_name + " overlaps an ready loaded command from "+ seen_command_names[c]+"");
|
||||
}
|
||||
}
|
||||
string workspace = shared_interface.GetCommandWorkspace(c);
|
||||
|
|
@ -132,7 +132,7 @@ namespace BetterSecondBot.WikiMake
|
|||
else
|
||||
{
|
||||
ExampleCall.Append("?");
|
||||
ConsoleLog.Debug("[WikiMake] " + area + " Command " + c + " missing some required hint values");
|
||||
LogFormater.Debug("[WikiMake] " + area + " Command " + c + " missing some required hint values");
|
||||
}
|
||||
loop++;
|
||||
}
|
||||
|
|
@ -261,7 +261,7 @@ namespace BetterSecondBot.WikiMake
|
|||
}
|
||||
protected void InterfaceWiki(string area,API_supported_interface shared_interface, bool track_commands = false)
|
||||
{
|
||||
ConsoleLog.Info("[WIKI] Starting area " + area + "");
|
||||
LogFormater.Info("[WIKI] Starting area " + area + "");
|
||||
// create index
|
||||
InterfaceIndex(area, shared_interface);
|
||||
|
||||
|
|
@ -270,7 +270,7 @@ namespace BetterSecondBot.WikiMake
|
|||
|
||||
// create commands
|
||||
InterfaceCommands(area, shared_interface, track_commands);
|
||||
ConsoleLog.Info("[WIKI] Done with area");
|
||||
LogFormater.Info("[WIKI] Done with area");
|
||||
}
|
||||
|
||||
public DebugModeCreateWiki(string Version, SimpleIO shareio)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace BSB.Commands.Group
|
|||
{
|
||||
if(UUID.TryParse(args[2], out target_role) == false)
|
||||
{
|
||||
ConsoleLog.Warn("GroupInvite: Role uuid not vaild using everyone");
|
||||
LogFormater.Warn("GroupInvite: Role uuid not vaild using everyone");
|
||||
}
|
||||
}
|
||||
bot.GetClient.Groups.Invite(group, new List<UUID>() { target_role }, avatar);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace BSB.Commands.CMD_Parcel
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("Flag: " + a + " is unknown");
|
||||
LogFormater.Warn("Flag: " + a + " is unknown");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,17 +37,17 @@ namespace BSB.Commands.CMD_Parcel
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Crit("Unable to set flag " + parts[0] + " to : " + parts[1] + "");
|
||||
LogFormater.Crit("Unable to set flag " + parts[0] + " to : " + parts[1] + "");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("Flag: " + parts[0] + " is unknown");
|
||||
LogFormater.Warn("Flag: " + parts[0] + " is unknown");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("Flag: " + a + " missing = True|False");
|
||||
LogFormater.Warn("Flag: " + a + " missing = True|False");
|
||||
}
|
||||
}
|
||||
if (setflags.Count > 0)
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ namespace BSB.Commands
|
|||
else
|
||||
{
|
||||
run_status = false;
|
||||
ConsoleLog.Crit("[SmartReply] output Channel must be zero or higher");
|
||||
LogFormater.Crit("[SmartReply] output Channel must be zero or higher");
|
||||
}
|
||||
}
|
||||
else if (mode == "IM")
|
||||
|
|
@ -209,12 +209,12 @@ namespace BSB.Commands
|
|||
catch (Exception e)
|
||||
{
|
||||
run_status = false;
|
||||
ConsoleLog.Crit("[SmartReply] HTTP failed: " + e.Message + "");
|
||||
LogFormater.Crit("[SmartReply] HTTP failed: " + e.Message + "");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Crit("[SmartReply] Unsupported output target");
|
||||
LogFormater.Crit("[SmartReply] Unsupported output target");
|
||||
return false;
|
||||
}
|
||||
return run_status;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace BSB.RLV
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("[RLVapi/Failed] " + command + ": Incorrect number of args");
|
||||
LogFormater.Warn("[RLVapi/Failed] " + command + ": Incorrect number of args");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -50,7 +50,7 @@ namespace BSB.RLV
|
|||
if(suppress_warning.Contains(command) == false)
|
||||
{
|
||||
suppress_warning.Add(command);
|
||||
ConsoleLog.Warn("[RLVapi/Failed] " + command + ": I have no fucking idea what you are talking about");
|
||||
LogFormater.Warn("[RLVapi/Failed] " + command + ": I have no fucking idea what you are talking about");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -97,7 +97,7 @@ namespace BSB.RLV
|
|||
|
||||
public bool Failed(string why_failed)
|
||||
{
|
||||
ConsoleLog.Warn("[RLVapi/Failed] " + CommandName + ": " + why_failed);
|
||||
LogFormater.Warn("[RLVapi/Failed] " + CommandName + ": " + why_failed);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace BSB.bottypes
|
|||
message = sb.ToString();
|
||||
if (myconfig.Setting_LogCommands == true)
|
||||
{
|
||||
ConsoleLog.Info(message);
|
||||
Info(message);
|
||||
}
|
||||
commandid++;
|
||||
if (commandid >= 50)
|
||||
|
|
@ -236,27 +236,27 @@ namespace BSB.bottypes
|
|||
{
|
||||
if (finalSuccess)
|
||||
{
|
||||
ConsoleLog.Info("Sending notecard now");
|
||||
Info("Sending notecard now");
|
||||
Client.Inventory.GiveItem(finalItemID, name, AssetType.Notecard, sendToUUID, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnstatus = false;
|
||||
ConsoleLog.Warn("Unable to request notecard upload");
|
||||
Warn("Unable to request notecard upload");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Crit("The fuck empty success notecard create");
|
||||
Crit("The fuck empty success notecard create");
|
||||
returnstatus = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("Unable to find default notecards folder");
|
||||
Warn("Unable to find default notecards folder");
|
||||
returnstatus = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -328,7 +328,7 @@ namespace BSB.bottypes
|
|||
{
|
||||
if (finalcompileSuccess == false)
|
||||
{
|
||||
ConsoleLog.Warn("Script failed to compile, sending anyway.");
|
||||
Warn("Script failed to compile, sending anyway.");
|
||||
}
|
||||
Client.Inventory.GiveItem(finalitemID, name, AssetType.LSLText, sendToUUID, false);
|
||||
|
||||
|
|
@ -336,14 +336,14 @@ namespace BSB.bottypes
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Crit("The fuck empty success Script create");
|
||||
Crit("The fuck empty success Script create");
|
||||
returnstatus = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Warn("Unable to find default Scripts folder");
|
||||
Warn("Unable to find default Scripts folder");
|
||||
returnstatus = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using System.Threading;
|
|||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class DialogsBot : DiscordBot
|
||||
public abstract class DialogsBot : DiscordBotTTS
|
||||
{
|
||||
protected bool TrackDialogs;
|
||||
protected int RelayDialogsToChannel;
|
||||
|
|
|
|||
|
|
@ -25,16 +25,21 @@ namespace BSB.bottypes
|
|||
}
|
||||
|
||||
protected async Task<ITextChannel> FindTextChannel(string channelname, ICategoryChannel cat, UUID sender, string TopicType)
|
||||
{
|
||||
return await FindTextChannel(DiscordServer, channelname, cat, sender, TopicType);
|
||||
}
|
||||
|
||||
protected async Task<ITextChannel> FindTextChannel(IGuild onserver,string channelname, ICategoryChannel cat, UUID sender, string TopicType,bool create_channel=true)
|
||||
{
|
||||
await WaitForUnlock().ConfigureAwait(false);
|
||||
channelname = channelname.ToLowerInvariant();
|
||||
channelname = String.Concat(channelname.Where(char.IsLetterOrDigit));
|
||||
DiscordLock = true;
|
||||
IReadOnlyCollection<ITextChannel> found_chans = await DiscordServer.GetTextChannelsAsync(CacheMode.AllowDownload);
|
||||
IReadOnlyCollection<ITextChannel> found_chans = await onserver.GetTextChannelsAsync(CacheMode.AllowDownload);
|
||||
ITextChannel result = null;
|
||||
foreach (ITextChannel ITC in found_chans)
|
||||
{
|
||||
if (ITC.CategoryId == cat.Id)
|
||||
if (create_channel == false)
|
||||
{
|
||||
if (ITC.Name == channelname)
|
||||
{
|
||||
|
|
@ -42,14 +47,28 @@ namespace BSB.bottypes
|
|||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ITC.CategoryId == cat.Id)
|
||||
{
|
||||
if (ITC.Name == channelname)
|
||||
{
|
||||
result = ITC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result == null)
|
||||
if (create_channel == true)
|
||||
{
|
||||
result = await CreateChannel(channelname, TopicType, sender.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await CleanDiscordChannel(result, 24).ConfigureAwait(false);
|
||||
if (result == null)
|
||||
{
|
||||
result = await CreateChannel(onserver, channelname, TopicType, sender.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await CleanDiscordChannel(result, 24).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
DiscordLock = false;
|
||||
return result;
|
||||
|
|
@ -66,7 +85,7 @@ namespace BSB.bottypes
|
|||
|
||||
protected async static Task CleanDiscordChannel(ITextChannel chan, int HistoryHours, bool forceempty)
|
||||
{
|
||||
DateTimeOffset Now = new DateTimeOffset(new DateTime());
|
||||
long nowunix = DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||
IEnumerable<IMessage> messages;
|
||||
bool empty = false;
|
||||
while (empty == false)
|
||||
|
|
@ -74,23 +93,51 @@ namespace BSB.bottypes
|
|||
empty = true;
|
||||
messages = await chan.GetMessagesAsync(50).FlattenAsync();
|
||||
List<ulong> deleteMessages = new List<ulong>();
|
||||
List<IMessage> slowDeleteMessages = new List<IMessage>();
|
||||
|
||||
foreach (IMessage mess in messages)
|
||||
{
|
||||
var hours = ((Now.ToUnixTimeSeconds() - mess.Timestamp.ToUnixTimeSeconds()) / 60) / 60;
|
||||
long messageunix = mess.Timestamp.ToUnixTimeSeconds();
|
||||
long dif = nowunix - messageunix;
|
||||
var hours = (dif / 60)/60;
|
||||
bool slowdel = false;
|
||||
|
||||
if (hours > (24 * 13))
|
||||
{
|
||||
slowdel = true;
|
||||
}
|
||||
if ((hours > HistoryHours) || (forceempty == true))
|
||||
{
|
||||
empty = false;
|
||||
deleteMessages.Add(mess.Id);
|
||||
if (slowdel == false)
|
||||
{
|
||||
deleteMessages.Add(mess.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
slowDeleteMessages.Add(mess);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deleteMessages.Count > 0)
|
||||
if ((deleteMessages.Count > 0) || (slowDeleteMessages.Count > 0))
|
||||
{
|
||||
await chan.DeleteMessagesAsync(deleteMessages);
|
||||
if (deleteMessages.Count > 0)
|
||||
{
|
||||
await chan.DeleteMessagesAsync(deleteMessages).ConfigureAwait(true);
|
||||
}
|
||||
if (slowDeleteMessages.Count > 0)
|
||||
{
|
||||
foreach (IMessage slowdelmessage in slowDeleteMessages)
|
||||
{
|
||||
await chan.DeleteMessageAsync(slowdelmessage).ConfigureAwait(true);
|
||||
}
|
||||
}
|
||||
empty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<ITextChannel> CreateChannel(string channelname, string channeltopictype, string sender_id)
|
||||
protected async Task<ITextChannel> CreateChannel(IGuild onserver, string channelname, string channeltopictype, string sender_id)
|
||||
{
|
||||
channelname = channelname.ToLowerInvariant();
|
||||
channelname = String.Concat(channelname.Where(char.IsLetterOrDigit));
|
||||
|
|
@ -121,8 +168,8 @@ namespace BSB.bottypes
|
|||
}
|
||||
try
|
||||
{
|
||||
IGuildChannel channel = await DiscordServer.CreateTextChannelAsync(channelname, X => DiscordGetNewChannelProperies(X, channelname, display_topic, channeltopictype.ToLowerInvariant()));
|
||||
ITextChannel Txtchan = await DiscordServer.GetTextChannelAsync(channel.Id);
|
||||
IGuildChannel channel = await onserver.CreateTextChannelAsync(channelname, X => DiscordGetNewChannelProperies(X, channelname, display_topic, channeltopictype.ToLowerInvariant()));
|
||||
ITextChannel Txtchan = await onserver.GetTextChannelAsync(channel.Id);
|
||||
return Txtchan;
|
||||
}
|
||||
catch
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace BSB.bottypes
|
|||
base.AfterBotLoginHandler();
|
||||
_ = DiscordBotAfterLogin();
|
||||
}
|
||||
protected async Task DiscordBotAfterLogin()
|
||||
protected virtual async Task DiscordBotAfterLogin()
|
||||
{
|
||||
if (reconnect == false)
|
||||
{
|
||||
|
|
@ -56,14 +56,14 @@ namespace BSB.bottypes
|
|||
}
|
||||
}
|
||||
|
||||
protected Task DiscordClientReady()
|
||||
protected virtual async Task<Task> DiscordClientReady()
|
||||
{
|
||||
DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
|
||||
if (DiscordServer != null)
|
||||
{
|
||||
DiscordUnixTimeOnine = helpers.UnixTimeNow();
|
||||
DiscordClientConnected = true;
|
||||
_ = DiscordRebuildChannels();
|
||||
await DiscordRebuildChannels();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ namespace BSB.bottypes
|
|||
await SendMessageToChannelAsync("interface", "Please format help request as follows: !help commandname", "bot", UUID.Zero, "bot");
|
||||
}
|
||||
}
|
||||
else if (message.Content != "!clear")
|
||||
else
|
||||
{
|
||||
output.Append("Unknown request: ");
|
||||
output.Append(message.Content);
|
||||
|
|
@ -120,13 +120,13 @@ namespace BSB.bottypes
|
|||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
protected async Task<Task> InboundImMessage(ITextChannel Chan, SocketMessage message)
|
||||
protected virtual async Task<Task> InboundImMessage(ITextChannel Chan, SocketMessage message)
|
||||
{
|
||||
if (message.Content == "!close")
|
||||
if (message.Content.StartsWith("!close"))
|
||||
{
|
||||
await Chan.DeleteAsync();
|
||||
}
|
||||
else if (message.Content == "!clear")
|
||||
else if (message.Content.StartsWith("!clear"))
|
||||
{
|
||||
await CleanDiscordChannel(Chan, 0, true);
|
||||
}
|
||||
|
|
@ -137,11 +137,7 @@ namespace BSB.bottypes
|
|||
{
|
||||
if (bits[0] == "IM")
|
||||
{
|
||||
if (message.Content == "!clear")
|
||||
{
|
||||
await CleanDiscordChannel(Chan, 0, true);
|
||||
}
|
||||
else if (UUID.TryParse(bits[1], out UUID avatar) == true)
|
||||
if (UUID.TryParse(bits[1], out UUID avatar) == true)
|
||||
{
|
||||
IGuildUser user = (IGuildUser)message.Author;
|
||||
Client.Self.InstantMessage(avatar, "[" + user.Nickname + "]->" + message.Content);
|
||||
|
|
@ -220,13 +216,13 @@ namespace BSB.bottypes
|
|||
else
|
||||
{
|
||||
ITextChannel Chan = (ITextChannel)message.Channel;
|
||||
if (Chan.CategoryId == catmap["bot"].Id)
|
||||
if (message.Content.StartsWith("!clear") == true)
|
||||
{
|
||||
if (message.Content == "!clear")
|
||||
{
|
||||
await CleanDiscordChannel(Chan, 0, true).ConfigureAwait(false);
|
||||
}
|
||||
else if (Chan.Name == "interface")
|
||||
await CleanDiscordChannel(Chan, 0, true).ConfigureAwait(false);
|
||||
}
|
||||
else if (Chan.CategoryId == catmap["bot"].Id)
|
||||
{
|
||||
if (Chan.Name == "interface")
|
||||
{
|
||||
await InboundInterfaceMessage(message).ConfigureAwait(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace BSB.bottypes
|
|||
protected string LastSendDiscordStatus = "";
|
||||
protected long DiscordUnixTimeOnine;
|
||||
protected bool DiscordLock;
|
||||
|
||||
protected Dictionary<string, ICategoryChannel> catmap = new Dictionary<string, ICategoryChannel>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace BSB.bottypes
|
|||
}
|
||||
}
|
||||
}
|
||||
protected async Task DiscordIMMessage(UUID sender_uuid, string sender_name, string message)
|
||||
protected virtual async Task DiscordIMMessage(UUID sender_uuid, string sender_name, string message)
|
||||
{
|
||||
if ((helpers.notempty(sender_name) == true) && (helpers.notempty(message) == true))
|
||||
{
|
||||
|
|
@ -54,28 +54,25 @@ namespace BSB.bottypes
|
|||
{
|
||||
if (fromme == false)
|
||||
{
|
||||
if (myconfig.DiscordFull_Enable == false)
|
||||
if (discord_group_relay == true)
|
||||
{
|
||||
if (discord_group_relay == true)
|
||||
// GroupChat Relay only
|
||||
if (group == true)
|
||||
{
|
||||
// GroupChat Relay only
|
||||
if (group == true)
|
||||
if (myconfig.DiscordRelay_URL != "")
|
||||
{
|
||||
if (myconfig.DiscordRelay_URL != "")
|
||||
if ((myconfig.DiscordRelay_GroupUUID == group_uuid.ToString()) || (myconfig.DiscordRelay_GroupUUID == "*") || (myconfig.DiscordRelay_GroupUUID == "all"))
|
||||
{
|
||||
if ((myconfig.DiscordRelay_GroupUUID == group_uuid.ToString()) || (myconfig.DiscordRelay_GroupUUID == "*") || (myconfig.DiscordRelay_GroupUUID == "all"))
|
||||
{
|
||||
Group Gr = mygroups[group_uuid];
|
||||
using var DWHclient = new DiscordWebhookClient(myconfig.DiscordRelay_URL);
|
||||
string SendMessage = "(" + Gr.Name + ") @" + sender_name + ":" + message + "";
|
||||
await DWHclient.SendMessageAsync(text: SendMessage).ConfigureAwait(false);
|
||||
DWHclient.Dispose();
|
||||
}
|
||||
Group Gr = mygroups[group_uuid];
|
||||
using var DWHclient = new DiscordWebhookClient(myconfig.DiscordRelay_URL);
|
||||
string SendMessage = "(" + Gr.Name + ") @" + sender_name + ":" + message + "";
|
||||
await DWHclient.SendMessageAsync(text: SendMessage).ConfigureAwait(false);
|
||||
DWHclient.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (DiscordClientConnected == true)
|
||||
if (DiscordClientConnected == true)
|
||||
{
|
||||
if (avatar == true)
|
||||
{
|
||||
|
|
@ -83,18 +80,25 @@ namespace BSB.bottypes
|
|||
{
|
||||
if (group == true)
|
||||
{
|
||||
Debug("DiscordBotChatControler - GroupChat:("+ group_uuid.ToString()+" -> " + sender_name + ":" + message);
|
||||
await DiscordGroupMessage(group_uuid, sender_name, message).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug("DiscordBotChatControler - IM:" + sender_name + ":" + message);
|
||||
await DiscordIMMessage(sender_uuid, sender_name, message).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug("DiscordBotChatControler - Localchat:" + sender_name + ":" + message);
|
||||
await SendMessageToChannelAsync("localchat", "" + sender_name + ":" + message, "bot", UUID.Zero, "bot").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug("DiscordBotChatControler - Not from an avatar");
|
||||
}
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
|
|
|
|||
46
Core/bottypes/DiscordTTS/DiscordTTS.cs
Normal file
46
Core/bottypes/DiscordTTS/DiscordTTS.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenMetaverse;
|
||||
using Discord;
|
||||
using BetterSecondBotShared.Static;
|
||||
using Discord.WebSocket;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class DiscordBotTTS : DiscordBot
|
||||
{
|
||||
protected ITextChannel TTSchannel;
|
||||
protected IGuild TTSDiscordServer;
|
||||
protected override async Task<Task> DiscordClientReady()
|
||||
{
|
||||
await base.DiscordClientReady();
|
||||
TTSDiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
|
||||
if (TTSDiscordServer != null)
|
||||
{
|
||||
IGuildUser user = await TTSDiscordServer.GetCurrentUserAsync();
|
||||
await user.ModifyAsync(x => {
|
||||
x.Nickname = myconfig.DiscordTTS_Nickname;
|
||||
});
|
||||
if (myconfig.DiscordTTS_Enable == true)
|
||||
{
|
||||
TTSchannel = await FindTextChannel(TTSDiscordServer, myconfig.DiscordTTS_channel_name, null, UUID.Zero, "notUSED", false);
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected override async Task DiscordIMMessage(UUID sender_uuid, string sender_name, string message)
|
||||
{
|
||||
await base.DiscordIMMessage(sender_uuid, sender_name, message);
|
||||
if ((helpers.notempty(sender_name) == true) && (helpers.notempty(message) == true))
|
||||
{
|
||||
if(sender_uuid.ToString() == myconfig.DiscordTTS_avatar_uuid)
|
||||
{
|
||||
await TTSchannel.SendMessageAsync(message, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
102
Core/bottypes/Log2FileBot.cs
Normal file
102
Core/bottypes/Log2FileBot.cs
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenMetaverse;
|
||||
using BetterSecondBotShared.Static;
|
||||
using BetterSecondBotShared.logs;
|
||||
using BetterSecondBotShared.bottypes;
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class Log2FileBot : BasicBot
|
||||
{
|
||||
// stolen from: https://gist.github.com/Kashkovsky/eba3c91cc9d64e705f18ba9a272f7d92
|
||||
protected string LogFolderName = "logs";
|
||||
protected string LogFileName = "secondbot.log";
|
||||
private readonly int _logChunkSize = 1000000;
|
||||
private readonly int _logChunkMaxCount = 5;
|
||||
private readonly int _logArchiveMaxCount = 10;
|
||||
private readonly int _logCleanupPeriod = 7;
|
||||
|
||||
public override void Log2File(string message, ConsoleLogLogLevel Level)
|
||||
{
|
||||
if(myconfig.Log2File_Enable == true)
|
||||
{
|
||||
if(myconfig.Log2File_Level >= (int)Level)
|
||||
{
|
||||
CreateLog(message);
|
||||
}
|
||||
}
|
||||
base.Log2File(message, Level);
|
||||
}
|
||||
protected void CreateLog(string message)
|
||||
{
|
||||
var logFolderPath = LogFolderName;
|
||||
|
||||
if (!Directory.Exists(logFolderPath))
|
||||
Directory.CreateDirectory(logFolderPath);
|
||||
|
||||
var logFilePath = Path.Combine(logFolderPath, LogFileName);
|
||||
|
||||
Rotate(logFilePath);
|
||||
|
||||
using (var sw = File.AppendText(logFilePath))
|
||||
{
|
||||
sw.WriteLine(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void Rotate(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
return;
|
||||
|
||||
var fileInfo = new FileInfo(filePath);
|
||||
if (fileInfo.Length < _logChunkSize)
|
||||
return;
|
||||
|
||||
var fileTime = DateTime.Now.ToString("dd_MM_yy_h_m_s");
|
||||
var rotatedPath = filePath.Replace(".log", $".{fileTime}");
|
||||
File.Move(filePath, rotatedPath);
|
||||
|
||||
var folderPath = Path.GetDirectoryName(rotatedPath);
|
||||
var logFolderContent = new DirectoryInfo(folderPath).GetFileSystemInfos();
|
||||
|
||||
var chunks = logFolderContent.Where(x => !x.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (chunks.Count() <= _logChunkMaxCount)
|
||||
return;
|
||||
|
||||
var archiveFolderInfo = Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(rotatedPath), $"{LogFolderName}_{fileTime}"));
|
||||
|
||||
foreach (var chunk in chunks)
|
||||
{
|
||||
Directory.Move(chunk.FullName, Path.Combine(archiveFolderInfo.FullName, chunk.Name));
|
||||
}
|
||||
|
||||
ZipFile.CreateFromDirectory(archiveFolderInfo.FullName, Path.Combine(folderPath, $"{LogFolderName}_{fileTime}.zip"));
|
||||
Directory.Delete(archiveFolderInfo.FullName, true);
|
||||
|
||||
var archives = logFolderContent.Where(x => x.Extension.Equals(".zip", StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
|
||||
if (archives.Count() <= _logArchiveMaxCount)
|
||||
return;
|
||||
|
||||
var oldestArchive = archives.OrderBy(x => x.CreationTime).First();
|
||||
var cleanupDate = oldestArchive.CreationTime.AddDays(_logCleanupPeriod);
|
||||
if (DateTime.Compare(cleanupDate, DateTime.Now) <= 0)
|
||||
{
|
||||
foreach (var file in logFolderContent)
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
File.Delete(oldestArchive.FullName);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ namespace BSB.bottypes
|
|||
{
|
||||
if (myconfig.Setting_AllowRLV == true)
|
||||
{
|
||||
ConsoleLog.Info("RLV: Enabled");
|
||||
Info("RLV: Enabled");
|
||||
RLVinterface = new RLV.RLVcontrol(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ namespace BSB.bottypes
|
|||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Debug("RLV API -> blacklisted [" + command + "]");
|
||||
Debug("RLV API -> blacklisted [" + command + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using BetterSecondBotShared.bottypes;
|
||||
using BetterSecondBotShared.logs;
|
||||
using BetterSecondBotShared.logs;
|
||||
using OpenMetaverse;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -7,7 +6,7 @@ using System.Text;
|
|||
|
||||
namespace BSB.bottypes
|
||||
{
|
||||
public abstract class VirtualsBot : BasicBot
|
||||
public abstract class VirtualsBot : Log2FileBot
|
||||
{
|
||||
#region DiscordOutputTarget
|
||||
public virtual bool send_to_discord(string command,string message)
|
||||
|
|
@ -84,20 +83,20 @@ namespace BSB.bottypes
|
|||
#region events
|
||||
protected virtual void PermissionsHandler(object sender, ScriptQuestionEventArgs e)
|
||||
{
|
||||
ConsoleLog.Debug("PermissionsHandler proc not overridden");
|
||||
Debug("PermissionsHandler proc not overridden");
|
||||
}
|
||||
protected virtual void AvatarAnimationHandler(object sender, AvatarAnimationEventArgs e)
|
||||
{
|
||||
ConsoleLog.Debug("AvatarAnimationHandler proc not overridden");
|
||||
Debug("AvatarAnimationHandler proc not overridden");
|
||||
}
|
||||
|
||||
protected virtual void SitHandler(object sender, AvatarSitResponseEventArgs e)
|
||||
{
|
||||
ConsoleLog.Debug("SitHandler proc not overridden");
|
||||
Debug("SitHandler proc not overridden");
|
||||
}
|
||||
protected virtual void MessageHandler(object sender, InstantMessageEventArgs e)
|
||||
{
|
||||
ConsoleLog.Debug("MessageHandler proc not overridden");
|
||||
Debug("MessageHandler proc not overridden");
|
||||
}
|
||||
#endregion
|
||||
#region Dialogs
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ namespace BSB.bottypes
|
|||
{
|
||||
addon = " [" + login_status + "]";
|
||||
}
|
||||
Debug("Function/LoggedOutNextAction - "+ addon);
|
||||
return addon;
|
||||
}
|
||||
protected int last_tested_home_id = -1;
|
||||
|
|
@ -90,7 +91,7 @@ namespace BSB.bottypes
|
|||
{
|
||||
if (SimShutdownAvoid == true)
|
||||
{
|
||||
ConsoleLog.Status("Avoided sim shutdown will attempt to go home in 4 mins");
|
||||
Status("Avoided sim shutdown will attempt to go home in 4 mins");
|
||||
SimShutdownAvoid = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -100,7 +101,7 @@ namespace BSB.bottypes
|
|||
if(e.Message.Contains("restart") == true)
|
||||
{
|
||||
// oh snap region is dead run away
|
||||
ConsoleLog.Info("--- Sim Restarting ---");
|
||||
Info("--- Sim Restarting ---");
|
||||
if (avoid_sims.ContainsKey(Client.Network.CurrentSim.Name) == false)
|
||||
{
|
||||
avoid_sims.Add(Client.Network.CurrentSim.Name, helpers.UnixTimeNow() + (10 * 60));
|
||||
|
|
@ -193,12 +194,12 @@ namespace BSB.bottypes
|
|||
if (UseSLurl != "")
|
||||
{
|
||||
TeleportWithSLurl(UseSLurl);
|
||||
ConsoleLog.Status("Attempting panic evac to: "+ last_attempted_teleport_region+"");
|
||||
Status("Attempting panic evac to: "+ last_attempted_teleport_region+"");
|
||||
AvoidSim(UseSLurl); // black list that region so we dont try to go back there if we get a shutdown notice again
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleLog.Status("No vaild SLurl found, Teleporting to backup hub");
|
||||
Status("No vaild SLurl found, Teleporting to backup hub");
|
||||
string[] Hubs = new[] { "https://maps.secondlife.com/secondlife/Morris/28/228/40/", "https://maps.secondlife.com/secondlife/Ahern/28/28/40/",
|
||||
"https://maps.secondlife.com/secondlife/Bonifacio/228/228/40/","https://maps.secondlife.com/secondlife/Dore/228/28/40/" };
|
||||
TeleportWithSLurl(Hubs[new Random().Next(0, Hubs.Length - 1)]);
|
||||
|
|
|
|||
6
Core/bottypes/loadorder.txt
Normal file
6
Core/bottypes/loadorder.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
SecondBot -> DialogsBot -> DiscordBotTTS -> DiscordBot -> DiscordBotInbound ->
|
||||
DiscordBotRelay -> DiscordBotStatus -> DiscordBotChannelControl ->
|
||||
DiscordBotFunctions -> Values -> ChatRelay -> RLVbot -> RLVbotHelper ->
|
||||
AwaitReplyEventBot -> CommandsBot -> AVstorageBot -> AtHome ->
|
||||
MessageSwitcherBot -> EventsBot -> VoidEventBot -> AnimationsBot ->
|
||||
VirtualsBot -> Log2FileBot -> BasicBot
|
||||
13
Dockerfile
13
Dockerfile
|
|
@ -36,14 +36,14 @@ ENV Security_WebUIKey=''
|
|||
|
||||
ENV Setting_AllowRLV='false'
|
||||
ENV Setting_AllowFunds='false'
|
||||
ENV Setting_LogCommands='true'
|
||||
ENV Setting_LogCommands='false'
|
||||
ENV Setting_RelayImToAvatarUUID=''
|
||||
ENV Setting_DefaultSit_UUID=''
|
||||
ENV Setting_loginURI='secondlife'
|
||||
|
||||
ENV DiscordRelay_URL=''
|
||||
ENV DiscordRelay_GroupUUID=''
|
||||
ENV DiscordFull_Enable='true'
|
||||
ENV DiscordFull_Enable='false'
|
||||
ENV DiscordFull_Token=''
|
||||
ENV DiscordFull_ServerID=''
|
||||
|
||||
|
|
@ -56,6 +56,15 @@ ENV Name2Key_Enable='false'
|
|||
ENV Name2Key_Url='http://localhost:1234'
|
||||
ENV Name2Key_Key='magic'
|
||||
|
||||
ENV DiscordTTS_Enable='false'
|
||||
ENV DiscordTTS_server_id=''
|
||||
ENV DiscordTTS_channel_name=''
|
||||
ENV DiscordTTS_avatar_uuid=''
|
||||
ENV DiscordTTS_Nickname=''
|
||||
|
||||
ENV Log2File_Enable='false'
|
||||
ENV Log2File_Level=1
|
||||
|
||||
EXPOSE 80
|
||||
ENV ASPNETCORE_URLS http://+:80
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue