Esempio n. 1
0
        public async Task <RuntimeResult> SetLocaleAsync(string locale)
        {
            ulong id    = Context.Guild.Id;
            Guild?guild = await DbContext.Guilds.FindAsync(id);

            string?oldLocale = guild?.Locale;

            if (!LocaleService.TryParseLocale(locale, out Locale? loc))
            {
                return(WumpusRuntimeResult.FromError($"`{locale}` isn't a valid locale name. These are the recognized locales:\n\n{GetLocaleList()}"));
            }

            Locale?oldLoc = null;

            if (oldLocale != null && LocaleService.TryParseLocale(oldLocale, out oldLoc) && loc ! == oldLoc !)
            {
                return(WumpusRuntimeResult.FromError($"Locale is already `{oldLoc}`"));
            }

            if (!LocaleService.LocaleIsRecognized(loc !))
            {
                return(WumpusRuntimeResult.FromError($"`{loc}` isn't a recognized LoR locale. These are the recognized locales:\n\n{GetLocaleList()}"));
            }

            if (guild is null)
            {
                guild = new Guild
                {
                    Id     = id,
                    Locale = locale,
                };
                _ = DbContext.Add(guild);
            }
            else
            {
                guild.Locale = locale;
                _            = DbContext.Update(guild);
            }

            _ = await DbContext.SaveChangesAsync();

            if (oldLoc is null)
            {
                await GenericReplyAsync($"Set locale to `{loc}`");
            }
            else
            {
                await GenericReplyAsync($"Changed locale from `{oldLoc}` to `{loc}`");
            }

            return(WumpusRuntimeResult.FromSuccess());
        }
Esempio n. 2
0
        public async Task <RuntimeResult> SetPrefixAsync(string prefix)
        {
            ulong id    = Context.Guild.Id;
            Guild?guild = await DbContext.Guilds.FindAsync(id);

            string?oldPrefix = guild?.CommandPrefix;

            if (oldPrefix == prefix)
            {
                return(WumpusRuntimeResult.FromError($"Command prefix is already `{prefix}`"));
            }

            if (guild is null)
            {
                guild = new Guild
                {
                    Id            = id,
                    CommandPrefix = prefix,
                };
                _ = DbContext.Add(guild);
            }
            else
            {
                guild.CommandPrefix = prefix;
                _ = DbContext.Update(guild);
            }

            _ = await DbContext.SaveChangesAsync();

            if (oldPrefix is null)
            {
                await GenericReplyAsync($"Set command prefix to `{prefix}`");
            }
            else
            {
                await GenericReplyAsync($"Changed command prefix from `{oldPrefix}` to `{prefix}`");
            }

            return(WumpusRuntimeResult.FromSuccess());
        }