public static async Task <T> SelectItem <T>(this InteractiveBase <ShardedCommandContext> interactive, IList <T> items, EmbedBuilder embed) { if (items.Count <= 1) { return(items.FirstOrDefault()); } var msg = await interactive.Context.Channel.SendMessageAsync(embed : embed.Build()); var response = await interactive.NextMessageAsync( new Criteria <IMessage>() .AddCriterion(new EnsureSourceUserCriterion()) .AddCriterion(new EnsureSourceChannelCriterion()) .AddCriterion(new EnsureRangeCriterion(items.Count, Program.GetPrefix(interactive.Context))), new TimeSpan(0, 0, 23)); _ = msg.DeleteAsync(); int i; try { i = int.Parse(response.Content); } catch { _ = interactive.Context.Message.DeleteAsync(); return(default);
internal static void PickedUp(InteractiveBase interactiveBase) { foreach (var collectionInit in _instance._collectionInits.Collections.Where(a => a.InteractiveBase == interactiveBase)) { collectionInit.PickedUp = true; } }
public async Task Run(InteractiveBase context) { // Subscribe to edit/delete events for the duration of the run context.Interactive.Discord.MessageUpdated += OnMessageUpdated; context.Interactive.Discord.MessageDeleted += OnMessageDeleted; while (true) { // Wait for a new input from the user, or for some other event to interrupt var command = await context.NextMessageAsync(true, true, null, _cts.Token); _cts = new CancellationTokenSource(); // Apply changes to inputs (edits/deletions) ApplyEdits(); await ApplyDeletions(); // Add new inputs and exit if necessary if (await ApplyNew(context, command)) { await context.Context.Channel.SendMessageAsync("Ended session."); break; } // Re-Evaluate all of the messages from the top again and edit the responses into place await Evaluate(); // Wait a short while to ratelimit jupyter session evaluation load await Task.Delay(1500); } }
public async Task DisplayAsync() { var guid = BlackJackService.CreateImage(Context.User.Id); var embedBuilder = new EmbedBuilder() .WithSuccessColor() .WithImageUrl($"attachment://board{guid}.png") .WithDescription(BlackJackService.GetScoreFromMatch(Context.User.Id)) .WithFooter("React with the action you want to perform. (timeout = 30 seconds)"); var message = await InteractiveBase.SendFileAsync($"BlackJack/board{guid}.png", embed : embedBuilder); Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them await Task.Run(async() => { await message.AddReactionAsync(_options.HitEmote); await message.AddReactionAsync(_options.StandEmote); }); if (Timeout != null) { await Task.Delay(Timeout.Value).ContinueWith(async _ => { //BlackJackService.RemovePlayerFromMatch(Context.User.Id); Interactive.RemoveReactionCallback(message); if (!_userClicked) { await Message.DeleteAsync(); } }); } }
public override void Interact(PlayerController pc, InteractiveBase interactive) { wall.SetActive(true); foreach (var surface in NavMeshSurface.activeSurfaces) { surface.BuildNavMesh(); } }
public override void Interact(PlayerController pc, InteractiveBase interactive) { for (var i = 0; i < spawnamount; i += 1) { var position = itemspawn.position + Random.insideUnitSphere * radius; position.y = itemspawn.position.y; Instantiate(Item, position, Quaternion.identity); } }
public static async Task <IUserMessage> TypingReplyAsync(this InteractiveBase module, string message, bool isTTS = false, Embed embed = null, RequestOptions options = null) { using (module.Context.Channel.EnterTypingState()) { await Task.Delay(Delay(message)); return(await module.Context.Channel.SendMessageAsync(message, isTTS, embed, options).ConfigureAwait(false)); } }
public override void Interact(PlayerController pc, InteractiveBase interactive) { var comp = Instantiate(LaserPrefab, interactive.transform.position, Quaternion.identity, null).GetComponent <Laser>(); comp.initial = interactive.CenterPosition; comp.destination = destination.transform.position; comp.traveltime = time; comp.height = height; comp.SetColor(pc.manager.IconColor); StartCoroutine(TeleportCoroutine(pc, comp.transform, destination.transform.position, interactive)); }
public ReactionResponseCallback(InteractiveService interactive, InteractiveBase interactiveBase, CustomCommandContext sourceContext, ICriterion <SocketReaction> criterion = null, BlackJackService blackJackService = null) { InteractiveBase = interactiveBase; Timeout = TimeSpan.FromSeconds(30); Interactive = interactive; Context = sourceContext; Criterion = criterion ?? new EmptyCriterion <SocketReaction>(); BlackJackService = blackJackService; }
private async Task <bool> ApplyNew(InteractiveBase context, SocketMessage?command) { if (command != null) { if (command.Content == "exit") { return(true); } _inputMessagesSet.TryAdd(command.Id, true); var r = await context.Context.Channel.SendMessageAsync("Evaluating..."); _messages.Add(new MessageResponse(command, r)); } return(false); }
public override void Interact(PlayerController pc, InteractiveBase interactive) { var state = collider.activeSelf; collider.SetActive(!state); foreach (var surface in NavMeshSurface.activeSurfaces) { surface.BuildNavMesh(); } if (wallCoroutine != null) { StopCoroutine(wallCoroutine); } // wall was up, now going down if (state) { wallCoroutine = StartCoroutine(WallAnimation(height)); gem.Play(); } // wall was down, now going up else { wallCoroutine = StartCoroutine(WallAnimation(0f)); gem.Stop(); } /* * foreach(var wall in Walls){ * var collider = wall.GetComponent<BoxCollider>(); * var boxes = Physics.OverlapBox(collider.bounds.center, collider.bounds.extents, Quaternion.identity, 1 << LayerMask.NameToLayer("Item")); * * var navmeshsize = Mathf.Max(collider.size.x, collider.size.z); * * foreach (var box in boxes) { * box.GetComponent<Item>().Bounce(navmeshsize); * } * } */ }
public static void LoadAssembly(string assembly) { InteractiveBase.LoadAssembly(assembly); }
public override void Interact(PlayerController pc, InteractiveBase interactive) { base.Interact(pc, interactive); interactive.DisableEvents(); }
protected static void InternalPP(StringBuilder output, object result, bool expandTypes = false) { if (result == null) { output.Append("null"); } else { if (result is REPLMessage) { // Raw, no escaping or quoting. output.Append(((REPLMessage)result).msg); } else if (result is Component) { string n; try { n = ((Component)result).name; } catch (MissingReferenceException) { n = "<destroyed>"; } output.Append(n); } else if (result is GameObject) { string n; try { n = ((GameObject)result).name; } catch (MissingReferenceException) { n = "<destroyed>"; } output.Append(n); } else if (result is Array) { Array a = (Array)result; int top = a.GetUpperBound(0), bottom = a.GetLowerBound(0); OpenInline(output, top - bottom); for (int i = bottom; i <= top; i++) { InternalPP(output, a.GetValue(i)); if (i != top) { NextItem(output, top - bottom); } } CloseInline(output, top - bottom); } else if (result is bool) { output.Append(((bool)result) ? "true" : "false"); } else if (result is string) { output.Append('"').Append(EscapeString((string)result)).Append('"'); } else if (result is IDictionary) { IDictionary dict = (IDictionary)result; int top = dict.Count, count = 0; Open(output); foreach (DictionaryEntry entry in dict) { count++; InternalPP(output, entry.Key); output.Append(": "); InternalPP(output, entry.Value); if (count != top) { NextItem(output, 0); } } Close(output); } else if (result is IEnumerable) { int i = 0; ArrayList tmp = new ArrayList(); foreach (object item in (IEnumerable)result) { tmp.Add(item); } OpenInline(output, tmp.Count); foreach (object item in tmp) { if (i++ != 0) { NextItem(output, tmp.Count); } InternalPP(output, item); } CloseInline(output, tmp.Count); } else if (result is char) { EscapeChar(output, (char)result); } else if (result is Type || result.GetType().Name == "MonoType") { if (_depth > 0 || !expandTypes) { output.Append("typeof(" + ((Type)result).Namespace + "." + ((Type)result).Name + ")"); } else { output.Append(InteractiveBase.Describe(result)); } } else { output.Append(result.ToString()); } } }
public override void Interact(PlayerController pc, InteractiveBase interactive) { Instantiate(Item, Random.insideUnitSphere * 5 + new Vector3(0, 5, 0), Quaternion.identity); }
public void GiveModuleControl(InteractiveBase <SocketCommandContext> module) { _module = module; }
public async static Task <Marriage> SelectMarriage(List <Marriage> marriages, InteractiveBase <ShardedCommandContext> interactive) { if (interactive != null) { if (marriages.Count > 0) { var msg = await interactive.Context.Channel.SendMessageAsync(embed : ListMarriageEmbed(marriages, interactive.Context.User) .WithDescription("Enter the number of the user you wish to select.") .WithFooter("Times out in 23 seconds.") .Build()); var response = await interactive.NextMessageAsync( new Criteria <IMessage>() .AddCriterion(new EnsureSourceUserCriterion()) .AddCriterion(new EnsureSourceChannelCriterion()) .AddCriterion(new EnsureRangeCriterion(marriages.Count, Program.GetPrefix(interactive.Context))), new TimeSpan(0, 0, 23)); _ = msg.DeleteAsync(); int i; try { i = int.Parse(response.Content); } catch { _ = interactive.Context.Message.DeleteAsync(); return(null); } _ = response.DeleteAsync(); return(marriages[i - 1]); } } return(null); }
public static TimeSpan Time(Action a) { return(InteractiveBase.Time(a)); }
public string ProcessCommand(string command) { string result = ""; string dataText = ""; command = command.Remove(0, 1); int indexOfOpenAngleBracket = 0; int indexOfOpenParentheses = 0; if (!command.EndsWith("();")) { if (command.Contains("<")) { command = command.Replace(">();", ""); command = command.Replace("> ();", ""); indexOfOpenAngleBracket = command.IndexOf('<'); dataText = command.Substring(indexOfOpenAngleBracket + 1); } if (command.Contains("(")) { command = command.Replace(");", ""); indexOfOpenParentheses = command.IndexOf('('); dataText = command.Substring(indexOfOpenParentheses + 1); } } else { command = command.Replace("();", ""); } if (RuntimeUnityEditorCore._enableDebug) { File.WriteAllText(DebugHelpers.debugPath + "TELNET_CommandProcessDebug.txt", "command: " + command + "\r\ndata: " + dataText); } switch (command) { case "help": result = REPL.REPL.help; break; case "Describe": result = InteractiveBase.Describe((object)dataText); break; case "Print": if (!dataText.Contains(",")) { InteractiveBase.print((object)dataText); } else { object[] dataParams = InitializeArray <object>(20); InteractiveBase.print(dataText, dataParams); } break; case "LoadAssembly": InteractiveBase.LoadAssembly(dataText); break; case "LoadPackage": InteractiveBase.LoadPackage(dataText); break; case "ShowUsing": InteractiveBase.ShowUsing(); break; case "ShowVars": InteractiveBase.ShowVars(); break; case "Time": //TimeSpan resTime = InteractiveBase.Time(dataText); //result = resTime.ToString(); break; // TESTING --------------------------------------------------------------------------------------------------------------------------------------- case "find<": try { Object obj = UnityEngine.Object.FindObjectOfType(Type.GetType("\"" + dataText + "\"")); File.WriteAllText(DebugHelpers.debugPath + "TELNET_CommandProcessDebug.txt", "command: " + command + "\r\ndata: " + dataText); if (obj != null) { File.WriteAllText(DebugHelpers.debugPath + "TMP.txt", "object is not null"); } result = obj.QuickDump(); } catch (Exception e) { result = e.Message; } break; // END TESTING ------------------------------------------------------------------------------------------------------------------------------------ default: break; } return(result); }
private IEnumerator TeleportCoroutine(PlayerController pc, Transform laser, Vector3 destination, InteractiveBase interactive) { PlayerInput.instance.disableInput++; pc.disableNavMesh++; pc.disableRenderer++; while (Vector3.SqrMagnitude(pc.transform.position - destination) > 0.25f) { //Debug.LogFormat("{0} <= {1}", Vector3.SqrMagnitude(pc.transform.position - destination), 0.025f); pc.transform.position = laser.position; yield return(null); } PlayerInput.instance.disableInput--; pc.disableNavMesh--; pc.disableRenderer--; pc.nva.Warp(destination); interactive.DisableEvents(); }
public override void Interact(PlayerController pc, InteractiveBase interactive) { }
public abstract void Interact(PlayerController pc, InteractiveBase interactive);
public static void LoadPackage(string pkg) { InteractiveBase.LoadPackage(pkg); }