public override void Use(CommandArgs command) { var isOperator = Client.Validate(command.Sender); if (!commandBuilders.ContainsKey(command.Sender.Nickname)) { commandBuilders.Add(command.Sender.Nickname, new StringBuilder()); } if (command.FullArgument == null) { command.Reply("Usage: -cs <C# code>"); return; } if (command.FullArgument.Contains("Console.Write")) { command.ReturnMessage("Console.Write calls are not supported yet."); return; } if (!(isOperator || RestrictionsCheck(command))) { return; } if (command.FullArgument.StartsWith("--")) { ProcessControlCommand(CommandArgs.FromPrevious(command.Command, command.FullArgument.Substring(2), command)); return; } try { var fullInput = commandBuilders[command.Sender.Nickname] + " " + command.FullArgument; fullInput = fullInput.TrimStart(); bool resultSet; object result; var input = evaluator.Evaluate(fullInput, out result, out resultSet); if (resultSet) { var output = CodeFormatter.PrettyPrint(result); command.ReturnMessage("--> " + output); commandBuilders[command.Sender.Nickname].Clear(); } else if (input == null) { if (reportPrinter.HasMessage) { while (reportPrinter.HasMessage) { var message = reportPrinter.GetNextMessage(); command.ReturnMessage($"{message.MessageType} at column {message.Location.Column}: {message.Text}"); } } else { command.ReturnMessage("Done (No result)"); } commandBuilders[command.Sender.Nickname].Clear(); } else { commandBuilders[command.Sender.Nickname].Append(input); command.ReturnMessage(">>>"); } } catch (InternalErrorException e) { command.ReturnMessage("Exception: " + e); } }
public override void Use(CommandArgs command) { ThreadId++; var isOperator = Client.Validate(command.Sender); if (!(isOperator || RestrictionsCheck(command))) { return; } if (command.FullArgument != null) { if (command.FullArgument.StartsWith("--")) { ProcessControlCommand(CommandArgs.FromPrevious(command.Command, command.FullArgument.Substring(2), command)); return; } if (command.FullArgument.EndsWith(":") || command.FullArgument.StartsWith(" ")) { commandBuilder.AppendLine(command.FullArgument); command.ReturnMessage(">>>"); return; } /*if (command.FullArgument == "import antigravity") { * command.ReturnMessage("--> https://xkcd.com/353/"); * return; * }*/ } string code; if (command.FullArgument == null && commandBuilder.ToString() != string.Empty) { code = commandBuilder.ToString(); commandBuilder.Clear(); } else if (command.FullArgument != null) { code = command.FullArgument; } else { command.Reply("Usage: -py [python code] - Leave the [python code] parameter out if you want to close the last indented block of a multi-line script."); return; } var source = engine.CreateScriptSourceFromString(code, SourceCodeKind.SingleStatement); threads.Add(Thread.CurrentThread); try { source.Execute(scope); var line = outputStreamReader.ReadLine(); if (line == null) { command.ReturnMessage("Done (No result)"); } else { for (var i = 0; line != null; i++) { if (i > 3 && !isOperator) { // i starts at 0, so when i=4, that would be the 5th line command.ReturnMessage("Spam prevention triggered. Sending more than 4 lines is not allowed."); outputStreamReader.ReadToEnd(); break; } command.ReturnMessage("--> " + line); line = outputStreamReader.ReadLine(); if (line != null && line.Contains("connection_string")) { line = outputStreamReader.ReadLine(); } Thread.Sleep(250); // make sure we don't spam the receiving end too much } } } catch (UnboundNameException e) { command.ReturnMessage("Error: " + e.Message); } catch (SyntaxErrorException e) { command.ReturnMessage("Syntax Error: " + e.Message); } catch (ImportException e) { command.ReturnMessage("Import Error: " + e.Message); } catch (MissingMemberException e) { command.ReturnMessage("Missing member: " + e.Message); } catch (DivideByZeroException) { command.ReturnMessage("A DivideByZeroException occurred"); } catch (Exception e) { command.ReturnMessage("Unhandled exception: " + e.GetType() + ": " + e.Message); } threads.Remove(Thread.CurrentThread); }