Beispiel #1
0
        public override Task <IScriptValue> InvokeAsync(
            Context context,
            IScriptValue thisValue,
            IScriptValue[] args,
            CancellationToken token = default)
        {
            if (args.Length == 0)
            {
                return(Task.FromResult <IScriptValue>(Null));
            }

            var obj = args[0].ToObject(context);

            if (obj is ScriptEmbedBuilder embedBuilder)
            {
                EmbedBuilder = embedBuilder;
            }
            else
            {
                var value = args.ToCombinedString();

                if (!string.IsNullOrEmpty(value))
                {
                    Output.AppendLine(value);
                }
            }

            return(Task.FromResult <IScriptValue>(Null));
        }
Beispiel #2
0
        public override async Task <IScriptValue> GetAsync(Context context, IScriptValue key, CancellationToken token = new CancellationToken())
        {
            var value = await base.GetAsync(context, key, token);

            if (value.IsNull)
            {
                throw new MiScriptException("Cannot get from storage through indexes, use storage.get instead");
            }

            return(value);
        }
Beispiel #3
0
        public override Task <IScriptValue> InvokeAsync(
            Context context,
            IScriptValue thisValue,
            IScriptValue[] args,
            CancellationToken token = default)
        {
            var embedBuilder = new EmbedBuilder();

            if (args.Length > 0)
            {
                embedBuilder.SetDescription(args[0].ToString());
            }

            return(Task.FromResult(FromObject(new ScriptEmbedBuilder(embedBuilder))));
        }
Beispiel #4
0
        public void Set(string key, IScriptValue value)
        {
            if (keys != null)
            {
                var keyStr = key;

                if (value.IsNull && keys.Contains(keyStr))
                {
                    keys.Remove(keyStr);
                }
                else if (!value.IsNull && !keys.Contains(keyStr))
                {
                    keys.Add(keyStr);
                }
            }

            if (!updatedKeys.Contains(key))
            {
                updatedKeys.Add(key);
            }

            values.AddOrUpdate(key, value, (a1, a2) => value);
        }
        /// <summary>
        /// Create the global context for the runtime.
        /// </summary>
        internal static async ValueTask <ScriptGlobal> CreateGlobalAsync(
            IContext e,
            IScriptValue say     = null,
            IScriptValue storage = null)
        {
            var context = new ScriptGlobal
            {
                ["author"]  = ScriptValue.FromObject(new ScriptUser(e.GetAuthor())),
                ["channel"] = ScriptValue.FromObject(new ScriptChannel(e.GetChannel())),
                ["message"] = ScriptValue.FromObject(new ScriptMessage(e.GetMessage())),
                ["args"]    = await CreateArgumentsAsync(e),
                ["say"]     = say ?? new ScriptSayFunction(),
                ["embed"]   = new CreateEmbedFunction(),
                ["storage"] = storage ?? await CreateStorageAsync(e)
            };

            if (e.GetGuild() != null)
            {
                context["guild"] = ScriptValue.FromObject(new ScriptGuild(e.GetGuild()));
            }

            return(context);
        }
Beispiel #6
0
 public override void SetRaw(IScriptValue key, IScriptValue value)
 {
     throw new MiScriptException("Cannot set in storage through indexes, use storage.set instead");
 }
Beispiel #7
0
 public override bool Equals(IScriptValue other)
 {
     return(other is ScriptStorage);
 }