/// <summary>
 /// Default constructor with no padding, no prefix and values are literally interpreted as string
 /// </summary>
 public ISOAmountFieldEncoder()
     : base()
 {
     _padder     = PaddingNone.Instance;
     _prefix     = PrefixNone.Instance;
     _translator = TranslatorASCII.Instance;
 }
 public GarlicBreadCommandContext(DiscordBotBase bot, IPrefix prefix, CachedUserMessage message,
                                  IServiceScope scope, RuntimeFlags flags) : base(bot, prefix, message, scope.ServiceProvider)
 {
     ServiceScope = scope;
     Flags        = flags;
     Member       = base.Member;
 }
 public ISOAmountFieldEncoder(IPadder padder, IPrefix prefix, ITranslator translator)
     : base()
 {
     _padder     = padder;
     _prefix     = prefix;
     _translator = translator;
 }
 /// <summary>
 /// Default constructor with no padding, no prefix and values are literally interpreted as string
 /// </summary>
 public ISOStringFieldEncoder()
     : base()
 {
     _padder = PaddingNone.Instance;
     _prefix = PrefixNone.Instance;
     _translator = TranslatorASCII.Instance;
 }
 public ISOStringFieldEncoder(IPadder padder, IPrefix prefix, ITranslator translator)
     : base()
 {
     _padder = padder;
     _prefix = prefix;
     _translator = translator;
 }
Beispiel #6
0
 public override DiscordCommandContext CreateCommandContext(
     IPrefix prefix,
     string input,
     IGatewayUserMessage message,
     CachedTextChannel channel)
 {
     return(new MilkmanCommandContext(message, input, this, prefix));
 }
 public ISOBinaryFieldEncoder(int length, string name, IPrefix prefix, ITranslatorBinary translator)
     : base()
 {
     base._length = length;
     Name = name;
     _prefix = prefix;
     _translator = translator;
 }
 public static string Format(this IPrefix prefix)
 {
     return(prefix switch
     {
         StringPrefix => Markdown.Code(prefix),
         MentionPrefix => prefix.ToString(),
         _ => throw new ArgumentOutOfRangeException(nameof(prefix), prefix, null)
     });
Beispiel #9
0
 public ISOBinaryFieldEncoder(int length, string name, IPrefix prefix, ITranslatorBinary translator)
     : base()
 {
     base._length = length;
     Name         = name;
     _prefix      = prefix;
     _translator  = translator;
 }
Beispiel #10
0
        public static Hash256 PrefixedHalfSha512(IPrefix prefix, byte[] blob)
        {
            var messageDigest = new HalfSha512();

            messageDigest.Update(prefix);
            messageDigest.Update(blob);
            return(messageDigest.Finish());
        }
 public PrefixTypeParser(
     IPrefix prefix,
     System.Func <TInput, string> messageFunc,
     Func <TInput, string, TOutput> typeParser)
 {
     this.prefix      = prefix;
     this.messageFunc = messageFunc;
     this.typeParser  = typeParser;
 }
 public ISOAmountFieldEncoder(int length, string name, IPadder padder, IPrefix prefix, ITranslator translator)
     : base()
 {
     base._length = length;
     Name         = name;
     _padder      = padder;
     _prefix      = prefix;
     _translator  = translator;
 }
 public ISOStringFieldEncoder(int length, string name, IPadder padder, IPrefix prefix, ITranslator translator)
     : base()
 {
     base.Length = length;
     Name = name;
     _padder = padder;
     _prefix = prefix;
     _translator = translator;
 }
Beispiel #14
0
 public EspeonCommandContext(IServiceScope scope, EspeonBot bot, IPrefix prefix, CachedUserMessage message)
     : base(bot, prefix, message, scope.ServiceProvider)
 {
     if (!(message.Author is CachedMember member && message.Channel is CachedTextChannel channel))
     {
         throw new InvalidOperationException("Bot should not be used in dms");
     }
     ServiceScope = scope;
     Bot          = bot;
     Member       = member;
     Channel      = channel;
 }
Beispiel #15
0
        public bool Set(IPrefix <IStatus> t)
        {
            var statusModifierCore = new StatusModifierCore {
                type = t.modifier.type, amount = t.modifier.amount
            };

            this.Data = ZeroFormatterSerializer.Serialize(new FigereCore {
                statusModifierCore = statusModifierCore, tier = t.tier
            });
            //Debug.Log(TypeUtils.TypeToSTring(t.GetType()));
            this.DataType = TypeUtils.TypeToString(t.GetType().GenericTypeArguments.First());
            return(true);
        }
 public XmlWriter(IAliases aliases, IIdentifierFormatter formatter, IIdentityStore store,
                  ITypePartResolver parts, IPrefix prefixes,
                  System.Xml.XmlWriter writer, Delimiter separator)
 {
     _aliases   = aliases;
     _formatter = formatter;
     _store     = store;
     _parts     = parts;
     _prefixes  = prefixes;
     _writer    = writer;
     _separator = separator;
     _selector  = Get;
 }
        public static AsyncFuncBuilder <DiscordContext> WithGroup(
            this AsyncFuncBuilder <DiscordContext> asyncFuncBuilder,
            IPrefix prefix,
            List <Action <AsyncFuncBuilder <PrefixNormalizedDiscordContext> > > configuration)
        {
            // TODO: Optimize by making a new type parser for the specific use case
            asyncFuncBuilder.WithAdapter(
                new PrefixTypeParser <DiscordContext, PrefixNormalizedDiscordContext>(
                    prefix,
                    context => context.Message.Content,
                    (context, normalizedMessage) => new PrefixNormalizedDiscordContext(context, normalizedMessage)),
                group => group.Any(configuration, result => result == Result.Completed || result == Result.Aborted));

            return(asyncFuncBuilder);
        }
Beispiel #18
0
        public DiscordCommandResult RemovePrefixAsync([Remainder] IPrefix prefix)
        {
            if (!CurrentGuildSettings.Prefixes.Contains(prefix))
            {
                return(Response($"The prefix {prefix.Format()} is not enabled on this server."));
            }
            else if (CurrentGuildSettings.Prefixes.Count == 1)
            {
                return(Response("You cannot remove the last enabled prefix on this server."));
            }

            CurrentGuildSettings.Prefixes.Remove(prefix);

            return(Response($"Ok, the prefix {prefix.Format()} will no longer be recognized on this server."));
        }
        public static AsyncFuncBuilder <DiscordContext> WithPrefix(
            this AsyncFuncBuilder <DiscordContext> asyncFuncBuilder,
            IPrefix prefix,
            Action <AsyncFuncBuilder <PrefixNormalizedDiscordContext> > configuration)
        {
            asyncFuncBuilder.WithAdapter(
                new PrefixTypeParser <DiscordContext, PrefixNormalizedDiscordContext>(
                    prefix,
                    context => context.Message.Content,
                    (context, normalizedMessage) =>
                    new PrefixNormalizedDiscordContext(context, normalizedMessage)),
                configuration);

            return(asyncFuncBuilder);
        }
        public static AsyncFuncBuilder <TContext> WithPrefix <TContext, TContext2>(
            this AsyncFuncBuilder <TContext> asyncFuncBuilder,
            IPrefix prefix,
            Func <TContext, string> message,
            Func <TContext, string, TContext2> typeParser,
            Action <AsyncFuncBuilder <TContext2> > configuration)
        {
            asyncFuncBuilder.WithAdapter(
                new PrefixTypeParser <TContext, TContext2>(
                    prefix,
                    message,
                    typeParser),
                configuration);

            return(asyncFuncBuilder);
        }
Beispiel #21
0
        private ValueTask <bool> TryModifyAsync(IGuild guild, IPrefix prefix, Func <GuildPrefixes, IPrefix, bool> modifyFunc)
        {
            var modified = false;
            var prefixes = this._guildPrefixes.AddOrUpdate(
                guild.Id,
                (id, func) => throw new KeyNotFoundException($"{guild.Id.ToString()} was not found in prefix cache, this shouldn't happen"),
                (id, prefixes, func) => {
                modified = func(prefixes, prefix);
                return(prefixes);
            },
                modifyFunc);

            return(modified
                ? new ValueTask <bool>(PersistAsync(prefixes))
                : new ValueTask <bool>(false));
        }
        public static AsyncFuncBuilder <TContext> WithGroup <TContext, TContext2>(
            this AsyncFuncBuilder <TContext> asyncFuncBuilder,
            IPrefix prefix,
            Func <TContext, string> message,
            Func <TContext, string, TContext2> typeParser,
            List <Action <AsyncFuncBuilder <TContext2> > > configuration)
        {
            asyncFuncBuilder.WithAdapter(
                new PrefixTypeParser <TContext, TContext2>(
                    prefix,
                    message,
                    typeParser),
                group => group.Any(configuration, result => result == Result.Completed || result == Result.Aborted));

            return(asyncFuncBuilder);
        }
Beispiel #23
0
        public DiscordCommandResult AddPrefixAsync([Remainder] IPrefix prefix)
        {
            if (CurrentGuildSettings.Prefixes.Count >= DefaultGuildSettingsProvider.MaxNumberOfPrefixes)
            {
                return(Response($"Your server has reached the max number of prefixes ({DefaultGuildSettingsProvider.MaxNumberOfPrefixes})"));
            }
            else if (CurrentGuildSettings.Prefixes.Contains(prefix))
            {
                return(Response($"Prefix: {prefix.Format()} is already enabled on this server."));
            }
            else if (prefix is MentionPrefix mentionPrefix && mentionPrefix.UserId != Context.Bot.CurrentUser.Id)
            {
                return(Response("You cannot enable mentions for users other than myself as a prefix."));
            }

            CurrentGuildSettings.Prefixes.Add(prefix);

            return(Response($"Ok, the prefix {prefix.Format()} will now be recognized on this server."));
        }
 public override void VisitPrefix(IPrefix prefixParam, IHighlightingConsumer consumer)
 {
     DocumentRange range = prefixParam.GetDocumentRange();
     var prefix = prefixParam as Prefix;
     if (prefix != null)
     {
         ResolveResultWithInfo resolve = prefix.Resolve();
         if (resolve == null ||
             resolve.Result.DeclaredElement is UnresolvedNamespacePrefixDeclaredElement ||
             ((resolve.Result.DeclaredElement == null) && (resolve.Result.Candidates.Count == 0)))
         {
             this.AddHighLighting(
                 range,
                 prefixParam,
                 consumer,
                 new NTriplesUnresolvedReferenceHighlighting<NTriplesPrefixReference>(
                     prefix, prefix.PrefixReference, string.Format("Unresolved prefix '{0}'", prefix.GetText())));
         }
     }
 }
Beispiel #25
0
        public override void VisitPrefix(IPrefix prefixParam, IHighlightingConsumer consumer)
        {
            DocumentRange range  = prefixParam.GetDocumentRange();
            var           prefix = prefixParam as Prefix;

            if (prefix != null)
            {
                ResolveResultWithInfo resolve = prefix.Resolve();
                if (resolve == null ||
                    resolve.Result.DeclaredElement is UnresolvedNamespacePrefixDeclaredElement ||
                    ((resolve.Result.DeclaredElement == null) && (resolve.Result.Candidates.Count == 0)))
                {
                    this.AddHighLighting(
                        range,
                        prefixParam,
                        consumer,
                        new NTriplesUnresolvedReferenceHighlighting <NTriplesPrefixReference>(
                            prefix, prefix.PrefixReference, string.Format("Unresolved prefix '{0}'", prefix.GetText())));
                }
            }
        }
Beispiel #26
0
        public Startup(
            Session session,
            IIOConfiguration ioConfig,
            ICommonConfiguration commonConfig,
            IInput input,
            IOutput output,
            IDataRepository dataRepo,
            ILogger logger,
            IPrefix prefix,
            IKernel serviceProvider)
        {
            _session = session;

            _ioConfig        = ioConfig;
            _prefix          = prefix;
            _logger          = logger;
            _dataRepo        = dataRepo;
            _output          = output;
            _input           = input;
            _commonConfig    = commonConfig;
            _serviceProvider = serviceProvider;
        }
Beispiel #27
0
        internal async ValueTask <bool> ProcessCommandsAsync(IGatewayUserMessage message, CachedMessageGuildChannel channel)
        {
            // We check if the message is suitable for execution.
            // By default excludes bot messages.
            try
            {
                if (!await CheckMessageAsync(message).ConfigureAwait(false))
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "An exception occurred while executing the check message callback.");
                return(false);
            }

            // We get the prefixes from the prefix provider.
            IEnumerable <IPrefix> prefixes;

            try
            {
                prefixes = await Prefixes.GetPrefixesAsync(message).ConfigureAwait(false);

                if (prefixes == null)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "An exception occurred while getting the prefixes.");
                return(false);
            }

            // We try to find a prefix in the message.
            IPrefix foundPrefix = null;
            string  output      = null;

            try
            {
                foreach (var prefix in prefixes)
                {
                    if (prefix == null)
                    {
                        continue;
                    }

                    if (prefix.TryFind(message, out output))
                    {
                        foundPrefix = prefix;
                        break;
                    }
                }

                if (foundPrefix == null)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "An exception occurred while finding the prefixes in the message.");
                return(false);
            }

            // We create a command context for Qmmands.
            DiscordCommandContext context;

            try
            {
                context = CreateCommandContext(foundPrefix, output, message, channel);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "An exception occurred while creating the command context.");
                return(false);
            }

            // We check the before execution callback, by default returns true.
            try
            {
                if (!await BeforeExecutedAsync(context).ConfigureAwait(false))
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                await DisposeContextAsync(context).ConfigureAwait(false);

                Logger.LogError(ex, "An exception occurred while executing the before executed callback.");
                return(false);
            }

            // We post the execution to the command queue.
            // See the Post() method in the default queue for more information.
            try
            {
                Queue.Post(context, context => context.Bot.ExecuteAsync(context));
                return(true);
            }
            catch (Exception ex)
            {
                await DisposeContextAsync(context).ConfigureAwait(false);

                Logger.LogError(ex, "An exception occurred while posting the execution to the command queue.");
                return(false);
            }
        }
 /// <summary>Visit a prefix.</summary>
 /// <param name="prefix">Prefix to be visited.</param>
 protected abstract void VisitPrefix(IPrefix prefix);
Beispiel #29
0
 public override string ToString(T unit, IPrefix prefix) => $"{GetValue(unit)} {prefix?.Abbreviation ?? ""}{unit.GetAbbreviation(_dimension)}";
Beispiel #30
0
 protected internal LengthBase(double value, T unit, IPrefix prefix) : base(value, unit, prefix)
 {
 }
Beispiel #31
0
 public double GetYard(IPrefix prefix) => GetValue((T)Unit.Yard, prefix);
Beispiel #32
0
 public double GetFeet(IPrefix prefix) => GetValue((T)Unit.Feet, prefix);
Beispiel #33
0
 public double GetMile(IPrefix prefix) => GetValue((T)Unit.Mile, prefix);
Beispiel #34
0
 public double GetMeter(IPrefix prefix) => GetValue((T)Unit.Meter, prefix);
Beispiel #35
0
 public GPrefix(string name, bool suffix = false, IPrefix code = null)
     : base(name, suffix, code)
 {
     randValues = new List<float>();
     delegates = new Dictionary<string, Delegate>();
 }
 public ISOBinaryFieldEncoder(IPrefix prefix, ITranslatorBinary translator)
     : base()
 {
     _prefix = prefix;
     _translator = translator;
 }
 /// <summary>
 /// Default constructor with no padding, no prefix and values are literally interpreted as string
 /// </summary>
 public ISOBinaryFieldEncoder()
     : base()
 {
     _prefix = PrefixNone.Instance;
     _translator = TranslatorBinary.Instance;
 }
Beispiel #38
0
 public Power(double value, IPowerUnit unit, IPrefix prefix = null) : base(value, unit, prefix)
 {
 }
Beispiel #39
0
 public DPrefixGroup(string name, bool suffix = false, IPrefix code = null)
     : base(name, suffix, code)
 {
     prefixes = new List<DPrefix>();
 }