This commit is contained in:
Madpeter 2020-04-29 16:48:18 +01:00
parent 78014adaaf
commit 6dd56a2295
20 changed files with 73 additions and 38 deletions

View file

@ -124,7 +124,7 @@ namespace BetterSecondBotShared.Json
return 1; return 1;
} }
public string GetProp(JsonConfig reply, string arg) public static string GetProp(JsonConfig reply, string arg)
{ {
return reply.GetType().GetProperty(arg, BindingFlags.Public | BindingFlags.Instance).GetValue(reply).ToString(); return reply.GetType().GetProperty(arg, BindingFlags.Public | BindingFlags.Instance).GetValue(reply).ToString();
} }

View file

@ -71,7 +71,7 @@ namespace BetterSecondBotShared.Static
bool default_value_found = false; bool default_value_found = false;
foreach (string a in testingfor) foreach (string a in testingfor)
{ {
if (Testing.GetCommandArgTypes(a).First() == Testing.GetProp(test, a)) if (Testing.GetCommandArgTypes(a).First() == MakeJsonConfig.GetProp(test, a))
{ {
ConsoleLog.Warn("" + a + " is currently set to the default"); ConsoleLog.Warn("" + a + " is currently set to the default");
default_value_found = true; default_value_found = true;

View file

@ -6,7 +6,7 @@ using BetterSecondBotShared.Static;
using BetterSecondBotShared.logs; using BetterSecondBotShared.logs;
namespace BetterSecondBot namespace BetterSecondBot
{ {
class Program static class Program
{ {
static void Main(string[] args) static void Main(string[] args)
{ {

View file

@ -70,7 +70,10 @@ namespace BetterSecondBot
io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file); 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!"); else
{
ConsoleLog.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) if(ok_to_try_start == true)
{ {
Config = MakeJsonConfig.http_config_check(Config); Config = MakeJsonConfig.http_config_check(Config);

View file

@ -15,12 +15,12 @@ namespace BetterSecondBot.HttpServer.Control.Actions
if (httpserver.HTTPCnCmode == true) if (httpserver.HTTPCnCmode == true)
{ {
httpserver.KillBot(); httpserver.KillBot();
return new string[] { "OK", "Bot Shutting down" }; return new [] { "OK", "Bot Shutting down" };
} }
else else
{ {
bot.KillMePlease(); bot.KillMePlease();
return new string[] { "OK", "I dont want to go" }; return new [] { "OK", "I dont want to go" };
} }
} }
else else

View file

@ -20,7 +20,7 @@ namespace BetterSecondBot.HttpServer.Control.Interface
{ {
if (bot.GetCommandsInterface.Call(args[0], args[1], UUID.Zero) == true) if (bot.GetCommandsInterface.Call(args[0], args[1], UUID.Zero) == true)
{ {
return new string[] { "OK" }; return new [] { "OK" };
} }
else else
{ {

View file

@ -91,7 +91,7 @@ namespace BetterSecondBot.HttpServer
protected string[] Failed(string why_failed) protected string[] Failed(string why_failed)
{ {
ConsoleLog.Warn("HTTP: " + CommandName + " [Failed]: " + why_failed); ConsoleLog.Warn("HTTP: " + CommandName + " [Failed]: " + why_failed);
return new string[] {"Failed",why_failed}; return new [] {"Failed",why_failed};
} }
} }

View file

@ -183,7 +183,7 @@ namespace BetterSecondBot.HttpServer
{ {
get_controler = new HTTPCommandsInterfaceGet(Bot,this); get_controler = new HTTPCommandsInterfaceGet(Bot,this);
post_controler = new HTTPCommandsInterfacePost(Bot,this); post_controler = new HTTPCommandsInterfacePost(Bot,this);
Thread t = new Thread(delegate (object unused) Thread t = new Thread(delegate (object _)
{ {
listener = new HttpListener(); listener = new HttpListener();
listener.Prefixes.Add(url); listener.Prefixes.Add(url);

View file

@ -29,7 +29,10 @@ namespace BSB.Commands.Dialogs
{ {
bot.SetRelayDialogsChannel(channel); bot.SetRelayDialogsChannel(channel);
} }
else return Failed("Not a vaild option"); else
{
return Failed("Not a vaild option");
}
return true; return true;
} }
else else

View file

@ -21,8 +21,14 @@ namespace BSB.Commands.Group
UUID.TryParse(args[2], out target_role); UUID.TryParse(args[2], out target_role);
} }
List<UUID> invite_roles = new List<UUID>(); List<UUID> invite_roles = new List<UUID>();
if (target_role != UUID.Zero) invite_roles.Add(target_role); if (target_role != UUID.Zero)
else invite_roles.Add(UUID.Zero); {
invite_roles.Add(target_role);
}
else
{
invite_roles.Add(UUID.Zero);
}
bot.GetClient.Groups.Invite(group, invite_roles, avatar); bot.GetClient.Groups.Invite(group, invite_roles, avatar);
} }
public override void Callback(string[] args, EventArgs e) public override void Callback(string[] args, EventArgs e)

View file

@ -68,10 +68,7 @@ namespace BSB.Commands.CMD_Parcel
reply.Append(cfg); reply.Append(cfg);
reply.Append("="); reply.Append("=");
reply.Append(p.Flags.HasFlag(flags[cfg]).ToString()); reply.Append(p.Flags.HasFlag(flags[cfg]).ToString());
if (addon != ",") addon = ",";
{
addon = ",";
}
} }
} }
return bot.GetCommandsInterface.SmartCommandReply(target, reply.ToString(), CommandName); return bot.GetCommandsInterface.SmartCommandReply(target, reply.ToString(), CommandName);

View file

@ -20,7 +20,10 @@ namespace BSB.Commands.CMD_Parcel
bool banuser = false; bool banuser = false;
if (args.Length == 2) if (args.Length == 2)
{ {
if (args[1] == "True") banuser = true; if (args[1] == "True")
{
banuser = true;
}
} }
bot.GetClient.Parcels.EjectUser(target, banuser); bot.GetClient.Parcels.EjectUser(target, banuser);
return true; return true;

View file

@ -47,7 +47,10 @@ namespace BSB.Commands.StreamAdmin
{ {
return bot.SendNotecard(server_reply.NotecardTitle, server_reply.NotecardContent, (UUID)server_reply.AvatarUUID); return bot.SendNotecard(server_reply.NotecardTitle, server_reply.NotecardContent, (UUID)server_reply.AvatarUUID);
} }
else Failed("Notecard title is to short"); else
{
Failed("Notecard title is to short");
}
} }
return Failed(server_reply.message); return Failed(server_reply.message);
} }

View file

@ -173,7 +173,10 @@ namespace BSB.Commands
{ "unixtime", helpers.UnixTimeNow().ToString() } { "unixtime", helpers.UnixTimeNow().ToString() }
}; };
if (command != "") values.Add("command", command); if (command != "")
{
values.Add("command", command);
}
var content = new FormUrlEncodedContent(values); var content = new FormUrlEncodedContent(values);
try try
{ {
@ -216,7 +219,7 @@ namespace BSB.Commands
string[] args = new string[] { }; string[] args = new string[] { };
if (helpers.notempty(arg) == true) if (helpers.notempty(arg) == true)
{ {
args = arg.Split(new string[] { "~#~" }, StringSplitOptions.None); args = arg.Split(new [] { "~#~" }, StringSplitOptions.None);
} }
if ((cmd.ArgTypes.Contains("Avatar") == true) || (cmd.ArgTypes.Contains("Smart") == true)) if ((cmd.ArgTypes.Contains("Avatar") == true) || (cmd.ArgTypes.Contains("Smart") == true))
{ {

View file

@ -38,7 +38,10 @@ namespace BSB.bottypes
} }
if (AvatarStorageLastUsed.Count > 0) if (AvatarStorageLastUsed.Count > 0)
{ {
if (reply != "") reply += " , "; if (reply != "")
{
reply += " , ";
}
reply += AvatarStorageLastUsed.Count.ToString() + " loaded"; reply += AvatarStorageLastUsed.Count.ToString() + " loaded";
} }
if (reply != "") if (reply != "")

View file

@ -15,7 +15,7 @@ namespace BSB.bottypes
{ {
CommandsInterface = new Commands.CoreCommandsInterface(this); CommandsInterface = new Commands.CoreCommandsInterface(this);
} }
List<string> CommandHistory = new List<string>(); protected List<string> CommandHistory = new List<string>();
protected int commandid = 1; protected int commandid = 1;
public virtual string CommandHistoryAdd(string command, string arg, bool status,string infomessage) public virtual string CommandHistoryAdd(string command, string arg, bool status,string infomessage)
{ {
@ -51,7 +51,10 @@ namespace BSB.bottypes
ConsoleLog.Info(sb.ToString()); ConsoleLog.Info(sb.ToString());
} }
commandid++; commandid++;
if (commandid >= myconfig.MaxCommandHistory) commandid = 1; if (commandid >= myconfig.MaxCommandHistory)
{
commandid = 1;
}
} }
return message; return message;
} }

View file

@ -151,7 +151,7 @@ namespace BSB.bottypes
protected async Task<ITextChannel> FindTextChannel(string channelname, ICategoryChannel cat, UUID sender, string sendername, string TopicType) protected async Task<ITextChannel> FindTextChannel(string channelname, ICategoryChannel cat, UUID sender, string sendername, string TopicType)
{ {
await WaitForUnlock(); await WaitForUnlock().ConfigureAwait(false);
channelname = channelname.ToLowerInvariant(); channelname = channelname.ToLowerInvariant();
channelname = String.Concat(channelname.Where(char.IsLetterOrDigit)); channelname = String.Concat(channelname.Where(char.IsLetterOrDigit));
DiscordLock = true; DiscordLock = true;
@ -170,7 +170,7 @@ namespace BSB.bottypes
} }
if(result == null) if(result == null)
{ {
result = await CreateChannel(channelname, TopicType, sender.ToString()); result = await CreateChannel(channelname, TopicType, sender.ToString()).ConfigureAwait(false);
} }
else else
{ {
@ -552,7 +552,7 @@ namespace BSB.bottypes
protected async override void BotChatControler(string message, string sender_name, UUID sender_uuid, bool avatar, bool group, UUID group_uuid, bool localchat, bool fromme) protected async override void BotChatControler(string message, string sender_name, UUID sender_uuid, bool avatar, bool group, UUID group_uuid, bool localchat, bool fromme)
{ {
base.BotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, fromme); base.BotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, fromme);
await DiscordBotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, fromme); await DiscordBotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, fromme).ConfigureAwait(false);
} }
public override string CommandHistoryAdd(string command, string arg, bool status,string WhyFailed) public override string CommandHistoryAdd(string command, string arg, bool status,string WhyFailed)

View file

@ -311,15 +311,9 @@ namespace BSB.bottypes
await_event_idtolistener.Add(eventid, event_listener); await_event_idtolistener.Add(eventid, event_listener);
return true; return true;
} }
else return false;
} }
return false;
} }
else return false; return false;
} }
} }
} }

View file

@ -99,7 +99,12 @@ namespace BSB.bottypes
protected bool permissive_mode = true; protected bool permissive_mode = true;
protected UUID permissive_mode_set_by = UUID.Zero; protected UUID permissive_mode_set_by = UUID.Zero;
public UUID Getpermissive_mode_set_by { get { return permissive_mode_set_by; } } public UUID Getpermissive_mode_set_by { get { return permissive_mode_set_by; } }
public void SetPermissiveMode(UUID caller, bool status = false)
public void SetPermissiveMode(UUID caller)
{
SetPermissiveMode(caller, false);
}
public void SetPermissiveMode(UUID caller, bool status)
{ {
bool allow = true; bool allow = true;
if((permissive_mode == false) && (caller != permissive_mode_set_by)) if((permissive_mode == false) && (caller != permissive_mode_set_by))
@ -243,7 +248,13 @@ namespace BSB.bottypes
// Notify // Notify
protected Dictionary<string, List<int>> Notify = new Dictionary<string, List<int>>(); protected Dictionary<string, List<int>> Notify = new Dictionary<string, List<int>>();
public Dictionary<string, List<int>> Getnotify { get { return Notify; } } public Dictionary<string, List<int>> Getnotify { get { return Notify; } }
public void NotifyUpdate(bool Add, string word,int channel = -1)
public void NotifyUpdate(bool Add, string word)
{
NotifyUpdate(Add, word, -1);
}
public void NotifyUpdate(bool Add, string word,int channel)
{ {
lock (Notify) lock (Notify)
{ {

View file

@ -216,8 +216,14 @@ namespace BSB.bottypes
public bool IsSimHome(string simname) public bool IsSimHome(string simname)
{ {
simname = simname.ToLowerInvariant(); simname = simname.ToLowerInvariant();
if (helpers.notempty(myconfig.homeRegion) == false) return false; if (helpers.notempty(myconfig.homeRegion) == false)
else if (myconfig.homeRegion.Length == 0) return false; {
return false;
}
else if (myconfig.homeRegion.Length == 0)
{
return false;
}
else else
{ {
bool reply = false; bool reply = false;
@ -272,7 +278,7 @@ namespace BSB.bottypes
TeleportWithSLurl(myconfig.homeRegion[last_tested_home_id]); TeleportWithSLurl(myconfig.homeRegion[last_tested_home_id]);
return " [@home **** active teleport: "+ last_attempted_teleport_region+"***]"; return " [@home **** active teleport: "+ last_attempted_teleport_region+"***]";
} }
else return " [@home No home regions]"; return " [@home No home regions]";
} }
else else
{ {