Beispiel #1
0
        public ILocalisable <string> GetString()
        {
            var baseFormat = "**{0}**: {1}";

            var entries = new List <LocalisedString>
            {
                new LocalisedString(SINGLE_TITLE, ReplyType.Info, Command.Name),
                (LocalisedString)(Command.Description ?? SINGLE_NODESCRIPTION),
                new RawString(baseFormat, (LocalisedString)TBLocalisation.GROUP, Group)
            };

            if (!string.IsNullOrWhiteSpace(Aliases))
            {
                entries.Add(new RawString(baseFormat, (LocalisedString)TBLocalisation.ALIASES, Format.Sanitize(Aliases)));
            }
            entries.Add(new RawString(baseFormat, (LocalisedString)TBLocalisation.USAGE, Usage));
            if (Flags.Count != 0)
            {
                entries.Add(new RawString(baseFormat, (LocalisedString)TBLocalisation.FLAGS, Flag));
            }
            if (Notes != null && !string.IsNullOrWhiteSpace(Notes.Key))
            {
                entries.Add(new RawString(baseFormat, (LocalisedString)TBLocalisation.NOTES, Notes));
            }
            if (Usages.Count > 0)
            {
                entries.Add(NotesFooter);
            }

            return(LocalisedString.JoinEnumerable("\n", entries));
        }
Beispiel #2
0
 public ShopMenu()
 {
     items  = new List <ItemConfig>();
     unkDB0 = new LocalisedString(0);
     unk1   = "";
     path   = "";
 }
Beispiel #3
0
        public HelpCommandEmbeddable(CommandInfo subject, IEnumerable <CallInfo> permitted, string name, ICommandContext context)
        {
            Name      = name;
            Command   = subject;
            Permitted = permitted;
            Context   = context;

            foreach (var call in Permitted)
            {
                Usages.Add(new RawString("`{0}{1} {2} {3} {4}` - {5}", Context.Prefix, Name, call.SubCall, string.Join(" ", call.GetParameters()), call.GetFlags(), (LocalisedString)call.Usage));
            }
            if (Usages.Count == 0)
            {
                Usage = (LocalisedString)SINGLE_NOUSAGE;
            }
            else
            {
                Usage = new DynamicString(tr => string.Join("\n", Usages.Select(u => u.Localise(tr).RegexReplace(" +", " "))));
            }
            Notes       = (LocalisedString)Command.Note;
            NotesFooter = (LocalisedString)SINGLE_USAGE_FOOTER;
            Aliases     = Command.Alias.Length == 0 ? "" : string.Join(", ", Command.Alias.ToList());
            Group       = (RawString)Command.Group ?? (LocalisedString)SINGLE_NOGROUP;
            Flags.AddRange(Permitted.SelectMany(c => c.Flags)
                           .GroupBy(f => f.ShortKey)
                           .Select(g => g.First()));
            Flag = LocalisedString.JoinEnumerable("\n", Flags);
        }
Beispiel #4
0
                private string UpdateNewLocalisedStringRef(SerializedProperty property, string key)
                {
                    LocalisedString localisedString = key;

                    SerializedPropertyUtils.SetSerializedPropertyValue(property, localisedString);
                    return(key);
                }
 private Action <ISettingEditorBuilder <TStore[], TAccept[]> > MakeArrayEditor <TStore, TAccept>(Action <ISettingEditorBuilder <TStore, TAccept> > templateEditor = null)
 => b =>
 {
     var temp = MakeBuilder <TStore, TAccept>(null, null);
     templateEditor?.Invoke(temp);
     b.SetName(temp.Name);
     b.SetValidator((c, a) => a.Select(v => temp.Validator?.Invoke(c, v)).FirstOrDefault(v => v != null));
     b.SetViewer((c, s) => s.Length == 0 ? null : LocalisedString.JoinEnumerable(", ", s.Select(v => temp.Viewer?.Invoke(c, v))));
 };
        public virtual ILocalisable <string> GetString()
        {
            var builder = GetBaseString();

            AddFields(builder);
            AddFooter(builder);

            return(LocalisedString.Join("\n", builder.Cast <object>().ToArray()));
        }
Beispiel #7
0
 public ItemConfig()
 {
     CameraConfig = new ItemCamera();
     unkMatrix    = new float[10];
     section1     = new Item[0];
     section2     = new Item[0];
     unkDB0       = new LocalisedString(0);
     unkDB1       = new LocalisedString(0);
     unkDB2       = new LocalisedString(0);
     unkDB3       = new LocalisedString(0);
     unkDB4       = new LocalisedString(0);
     unkDB5       = new LocalisedString(0);
 }
Beispiel #8
0
        private void GetFromDB(LocalisedString loc)
        {
            string result;

            textDB.TryGetValue(loc.ID, out result);

            if (textDB.Count == 0)
            {
                loc.Text = "TextDatabase is not loaded!";
            }
            else
            {
                loc.Text = result;
            }
        }
Beispiel #9
0
        protected override void AddFields(LocalisedEmbedBuilder builder)
        {
            var grouped = GroupEquipment();

            if (grouped == null)
            {
                builder.WithDescription(EquipmentText.LIST_DESCRIPTION_NONE, LocalisedString.Join("\n", Enum.GetValues(typeof(EquipmentClass)).Cast <EquipmentClass>().Select(c => c.ToLocalisable()).ToArray()), Context.Prefix, Context.CommandText);
            }
            else
            {
                foreach (var group in GroupEquipment())
                {
                    builder.AddInlineField(f => f.WithName(group.Key).WithValues("\n", group.Value));
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Drawable Notification
        /// </summary>
        /// <param name="text"></param>
        /// <param name="colourInfo"></param>
        /// <param name="duration">Hide after X amount of MS, -1 = PositiveInfinity</param>
        /// <param name="clickAction"></param>
        public DrawableNotification(LocalisedString text, ColourInfo colourInfo, int duration = -1, Action clickAction = null)
        {
            _clock             = new StopwatchClock();
            _clickAction       = clickAction;
            _borderColour      = colourInfo;
            _textFlowContainer = new TextFlowContainer
            {
                Direction    = FillDirection.Full,
                AutoSizeAxes = Axes.Both,
                MaximumSize  = new Vector2(290, float.MaxValue),
                Padding      = new MarginPadding(10)
            };
            _duration = duration == -1 ? Math.Max(3000, (double)(text.ToString().Length * 100)) : duration;

            _textFlowContainer.AddText(text);
        }
Beispiel #11
0
        public ILocalisable <string> GetString()
        {
            var entries = new List <LocalisedString>
            {
                new LocalisedString(LIST_TITLE, ReplyType.Info),
                new LocalisedString(LIST_DESCRIPTION, Prefix, string.Join("\", \"", AcceptedPrefixes)),
                (RawString)"```prolog"
            };
            var groups = Commands.GroupBy(c => c.Group);

            foreach (var group in groups)
            {
                entries.Add(new LocalisedString(LIST_COMMAND, group.Key.ToTitleCase(), string.Join(", ", group.GroupBy(g => g.Name).Select(g => g.Key.ToLower()))));
            }
            entries.Add((RawString)"```");

            return(LocalisedString.Join("\n", entries.ToArray()));
        }
        async Task PrestigeStatsAsync(int stage,
                                      [CallFlag('b', "bos", Flag.PRESTIGE_B)] int bosLevel   = -1,
                                      [CallFlag('c', "clan", Flag.PRESTIGE_C)] int clanLevel = -1,
                                      [CallFlag('i', "ip", Flag.PRESTIGE_I)] int ipLevel     = -1)
        {
            ipLevel = Math.Min(62, ipLevel);
            var startingStage   = Math.Max(1, stage * Calculator.AdvanceStart(clanLevel.Clamp(0, int.MaxValue)) - 1);
            var totalRelics     = Calculator.RelicsEarned(stage, bosLevel.Clamp(0, int.MaxValue));
            var baseRelics      = Calculator.RelicsEarned(stage, 0);
            var enemiesToKill   = Enumerable.Range(startingStage, stage - startingStage).Sum(s => Calculator.TitansOnStage(s, ipLevel.Clamp(0, int.MaxValue)));
            var timeTaken       = Calculator.RunTime(startingStage, stage, ipLevel.Clamp(0, int.MaxValue), 1);
            var timeTakenSplash = Calculator.RunTime(startingStage, stage, ipLevel.Clamp(0, int.MaxValue), 4);

            List <LocalisedString> description = new List <LocalisedString>();

            if (bosLevel > 0)
            {
                description.Add(new LocalisedString(PrestigeText.DESCRIPTION_BOS, bosLevel));
            }
            if (clanLevel > 0)
            {
                description.Add(new LocalisedString(PrestigeText.DESCRIPTION_CLAN, clanLevel));
            }
            if (ipLevel > 0)
            {
                description.Add(new LocalisedString(PrestigeText.DESCRIPTION_IP, ipLevel));
            }

            var builder = new LocalisedEmbedBuilder
            {
                Description = LocalisedString.Join("\n", description.ToArray()),
                Color       = System.Drawing.Color.Gold.ToDiscord(),
                Footer      = new LocalisedFooterBuilder().WithText(PrestigeText.FOOTER).WithRawIconUrl(BotUser.GetAvatarUrl())
            }
            .WithTitle(PrestigeText.TITLE, stage)
            .AddInlineField(f => f.WithName(PrestigeText.FIELD_STARTINGSTAGE).WithValue(startingStage))
            .AddInlineField(f => f.WithName(PrestigeText.FIELD_RELICS).WithValue(PrestigeText.FIELD_RELICS_VALUE, baseRelics, totalRelics - baseRelics, totalRelics))
            .AddInlineField(f => f.WithName(PrestigeText.FIELD_ENEMIES).WithValue(PrestigeText.FIELD_ENEMIES_VALUE, enemiesToKill, stage - startingStage))
            .AddInlineField(f => f.WithName(PrestigeText.FIELD_TIME).WithValue(PrestigeText.FIELD_TIME_VALUE, timeTaken, timeTakenSplash));

            await ReplyAsync(builder);
        }
Beispiel #13
0
        protected virtual async Task ExecAsync([Dense, RawArguments] string code)
        {
            var assemblies = GetAssemblies();
            var namespaces = GetNamespaces(assemblies);

            var test = string.Join("\n", assemblies.SelectMany(a => a.GetTypes())
                                   .Select(t => t.Name)
                                   .Where(t => t.All(c => "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._".Contains(c)))
                                   .OrderBy(x => x));

            var    codeWithUsings = string.Join("\n", namespaces.Select(n => $"using {n};")) + "\n" + code;
            var    globals        = GetGlobals(this);
            object result         = null;

            ILocalisable <string> footerText;

            if (!TryConstruct(codeWithUsings, assemblies.ToArray(), globals.GetType(), out var constructTime, out var constructRes))
            {
                result     = constructRes;
                footerText = new LocalisedString(ExecText.FOOTER_CONSTRUCTFAILED, constructTime.TotalMilliseconds);
            }
Beispiel #14
0
 private static void GetRecommendedJobs(this Staff staff, QualificationSlot qualificationSlot, List <JobMaintenance.JobDescription> recommendedJobs)
 {
     foreach (CharacterModifier characterModifier in qualificationSlot.Definition.Modifiers)
     {
         if (characterModifier is QualificationMaintenanceModifier)
         {
             recommendedJobs.AddRange(Main.settings.MaintenanceJobs);
         }
         else
         {
             if (!(characterModifier is QualificationUpgradeItemModifier))
             {
                 LocalisedString nameLocalised = qualificationSlot.Definition.NameLocalised;
                 if (!nameLocalised.ToString().ToLowerInvariant().StartsWith("mechanics"))
                 {
                     if (characterModifier is CharacterModifierIgnoreStatusEffect)
                     {
                         recommendedJobs.AddRange(Main.settings.GhostJobs);
                     }
                     else
                     {
                         recommendedJobs.AddRange(Main.settings.MiscJobs);
                     }
                 }
             }
             else
             {
                 recommendedJobs.AddRange(Main.settings.UpgradeJobs);
             }
         }
     }
     if (qualificationSlot.Definition.Modifiers.Count <CharacterModifier>() == 0 && qualificationSlot.Definition.ToString().ToLowerInvariant().StartsWith("mechanics"))
     {
         recommendedJobs.AddRange(Main.settings.UpgradeJobs);
     }
 }
Beispiel #15
0
 public static LocalisationLocalVariable Variable(string key, LocalisedString value)
 {
     return(new LocalisationLocalVariable(key, value.GetLocalisationKey(), true));
 }
Beispiel #16
0
 public LocalisedFieldBuilder WithValues <T>(string separator, T[] values)
 => WithValue(LocalisedString.Join(separator, values.Cast <object>().ToArray()));
Beispiel #17
0
 public Shop()
 {
     unk0 = new LocalisedString(0);
     Name = "";
 }
Beispiel #18
0
        protected async Task ListSettingsAsync(string settingGroup = null)
        {
            var builder = new LocalisedEmbedBuilder
            {
                Color     = new Color(135, 206, 235), //System.Drawing.Color.SkyBlue.ToDiscord(),
                Timestamp = DateTime.Now,
                Footer    = new LocalisedFooterBuilder().WithRawIconUrl(BotUser.GetAvatarUrl())
                            .WithText(SettingText.FOOTERTEXT, BotUser.Username)
            };

            if (Settings.Count == 1)
            {
                settingGroup = Settings.First().Name;
            }

            if (settingGroup == null)
            {
                builder.WithTitle(SettingText.TITLE_NOGROUP);
                var desc = string.Join("\n", Settings.Select(g => g.Name));
                if (string.IsNullOrWhiteSpace(desc))
                {
                    builder.WithDescription(SettingText.DESCRIPTION_NOSETTINGS);
                }
                else
                {
                    builder.WithRawDescription(desc);
                }
                await ReplyAsync(builder);

                return;
            }
            var groups = Settings.Where(g => g.Name.ToLower() == settingGroup.ToLower()).ToList();

            if (groups.Count() == 0)
            {
                await ReplyAsync(SettingText.INVALIDGROUP, ReplyType.Error, settingGroup);

                return;
            }

            builder.WithTitle(SettingText.TITLE_GROUP, groups.First().Name);
            foreach (var setting in groups.SelectMany(s => s))
            {
                var value = setting.Display(Context, SettingContext);
                if (value == null)
                {
                    builder.AddInlineField(f => f.WithRawName(setting.Name).WithValue(SettingText.NOTSET));
                }
                else
                {
                    builder.AddInlineField(f => f.WithRawName(setting.Name).WithValue(value));
                }
            }
            var descriptions = LocalisedString.JoinEnumerable("\n", groups.Where(g => g.Description != null).Select(g => g.Description));
            var notes        = LocalisedString.JoinEnumerable("\n", groups.Where(g => g.Notes != null).Select(g => g.Notes));

            if (groups.Exists(g => g.Description != null))
            {
                builder.WithDescription(descriptions);
            }
            if (groups.Exists(g => g.Notes != null))
            {
                builder.AddField(f => f.WithName(TBLocalisation.NOTES).WithValue(notes));
            }
            await ReplyAsync(builder);
        }
Beispiel #19
0
 public DrawableSettingsCheckbox(bool defaultValue, LocalisedString label, LocalisedString toolTip) : base(defaultValue, label, toolTip)
 {
 }
Beispiel #20
0
 public void Deserialize(string data, Type type, out object value) => value = new LocalisedString(data);
Beispiel #21
0
        public async ValueTask <IUserMessage> SendAsync(bool stealthy = false)
        {
            if (string.IsNullOrWhiteSpace(Localised) && Embedable == null && Attachment == null)
            {
                return(null);
            }

            IUserMessage msg = null;

            try
            {
                var me = Guild?.GetUserAsync(Client.CurrentUser.Id).Result ?? (IUser)Client.CurrentUser;
                IsTTS = IsTTS && Channel.UserHasPermission(me, ChannelPermission.SendTTSMessages);
                if (Attachment == null)
                {
                    if (GeneralUserSetting.UseEmbeds && Channel.UserHasPermission(me, ChannelPermission.EmbedLinks))
                    {
                        msg = await Channel.SendMessageAsync(Localised, IsTTS, Embedable?.GetEmbed().Localise(TextResource), Options);
                    }
                    else
                    {
                        msg = await Channel.SendMessageAsync(Localised + "\n" + Embedable?.GetString(), IsTTS, null, Options);
                    }
                }
                else
                {
                    msg = await Channel.SendFileAsync(Attachment(), AttachmentName, Localised + "\n" + Embedable?.GetString().Localise(TextResource), IsTTS, Options);
                }
            }
            catch (HttpException ex) when(ex.DiscordCode == 50013 || ex.DiscordCode == 50001)
            {
                Message = new LocalisedString(UNABLE_SEND, ReplyType.Error, Channel, Localised);
                Channel = await User.GetOrCreateDMChannelAsync();

                return(await SendAsync(stealthy));
            }
            catch (ArgumentException ex) when(ex.Message.StartsWith("Message content is too long,"))
            {
                var message = (Localised + "\n" + Embedable?.GetString()).Trim();

                if (Attachment != null)
                {
                    message += "\n\n" + TextResource.Format(MESSAGE_CONTAINED_ATTACHMENT, AttachmentName);
                }
                Attachment     = () => message.ToStream();
                AttachmentName = "Output.txt";
                Message        = new LocalisedString(MESSAGE_TOO_LONG, ReplyType.Error);
                Embedable      = null;

                return(await SendAsync(stealthy));
            }
            catch (Exception ex)
            {
                if (Handler == null)
                {
                    throw;
                }
                await Handler(ex, Channel, Localised, Embedable);
            }
            if (!stealthy)
            {
                await OnSend(this, msg);
            }
            Logger.Log(Logging.LogSeverity.Verbose, LogType.Message, $"Sent Message | Channel: {Channel} | Guild: {Guild} | Content: {msg.Content}", "Replier");
            return(msg);
        }
Beispiel #22
0
 public void AddNotification(LocalisedString text, ColourInfo colourInfo, int duration = -1, Action clickAction = null)
 => AddNotification(new DrawableNotification(text, colourInfo, duration, clickAction));
Beispiel #23
0
                public static object PropertyField(object obj, GUIContent label, ref bool dataChanged, GUIStyle style, params GUILayoutOption[] options)
                {
                    LocalisedString localisedString = (LocalisedString)obj;

                    //Draw list of possible keys
                    int currentKeyIndex = 0;

                    {
                        string[] keys       = Localisation.GetStringKeys();
                        string   currentKey = localisedString.GetLocalisationKey();

                        for (int i = 0; i < keys.Length; i++)
                        {
                            if (keys[i] == currentKey)
                            {
                                currentKeyIndex = i;
                                break;
                            }
                        }

                        EditorGUI.BeginChangeCheck();
                        currentKeyIndex = EditorGUILayout.Popup("Localisation Key", currentKeyIndex, keys);

                        //If key has changed
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (currentKeyIndex == 0)
                            {
                                localisedString = new LocalisedString();
                            }
                            else
                            {
                                localisedString = keys[currentKeyIndex];
                            }

                            dataChanged = true;
                        }
                    }

                    //Draw actual localised text (can be edited to update localisation file)
                    {
                        string currentKey = localisedString.GetLocalisationKey();

                        //Only display if have a valid key
                        if (!string.IsNullOrEmpty(currentKey) && Localisation.Exists(currentKey))
                        {
                            EditorGUI.BeginChangeCheck();
                            string text;
                            if (style != null)
                            {
                                text = EditorGUILayout.TextArea(Localisation.GetRawString(currentKey, Localisation.GetCurrentLanguage()), style);
                            }
                            else
                            {
                                text = EditorGUILayout.TextArea(Localisation.GetRawString(currentKey, Localisation.GetCurrentLanguage()));
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                Localisation.Set(currentKey, Localisation.GetCurrentLanguage(), text);
                            }
                        }
                    }

                    return(localisedString);
                }
 public static LocalisedString Dynamic(LocalisedString localisedString, params LocalisationLocalVariable[] variables)
 {
     return(new LocalisedString(localisedString.GetLocalisationKey(), variables));
 }
Beispiel #25
0
 public static string Serialize(LocalisedString str) => str.Text.Original ?? str.Text.Fallback;
Beispiel #26
0
 public ButtonContent()
 {
     Text = new LocalisedString("load replies");
 }