Beispiel #1
0
        public static async Task SetLanguageAsync(long id, string language)
        {
            using (var context = new IAContext())
            {
                ChannelLanguage lang = await context.Languages.FindAsync(id);

                if (LocaleNames.TryGetValue(language, out string val))
                {
                    language = val;
                }

                if (lang == null)
                {
                    lang = context.Languages.Add(new ChannelLanguage()
                    {
                        EntityId = id,
                        Language = language
                    }).Entity;
                }

                lang.Language = language;

                cache.AddOrUpdate(id, lang.Language, (x, y) => lang.Language);

                await context.SaveChangesAsync();
            }
        }
Beispiel #2
0
        public async Task ChangeForGuildAsync(ulong id, string prefix)
        {
            if (Changable)
            {
                using (var context = new IAContext())
                {
                    long guildId = id.ToDbLong();

                    Identifier i = await context.Identifiers.FindAsync(guildId, DefaultValue);

                    if (i == null)
                    {
                        context.Identifiers.Add(new Identifier()
                        {
                            GuildId = guildId, DefaultValue = DefaultValue, Value = prefix
                        });
                    }
                    else
                    {
                        i.Value = prefix;
                    }
                    await context.SaveChangesAsync();
                }
            }
        }
Beispiel #3
0
        public async Task <string> GetIdentifierAsync(ulong guildId, PrefixInstance prefix)
        {
            using (var context = new IAContext())
            {
                Identifier i = await context.Identifiers.FindAsync(guildId);

                if (i == null)
                {
                    i = context.Identifiers.Add(new Identifier()
                    {
                        GuildId = guildId.ToDbLong(), Value = prefix.DefaultValue
                    });
                    await context.SaveChangesAsync();
                }
                return(i.Value);
            }
        }
Beispiel #4
0
        public async Task SetEnabled(ulong channelId, bool enabled)
        {
            using (var context = new IAContext())
            {
                CommandState state = await context.CommandStates.FindAsync(Name, channelId.ToDbLong());

                if (state == null)
                {
                    state = context.CommandStates.Add(new CommandState()
                    {
                        ChannelId = channelId.ToDbLong(), CommandName = Name, State = DefaultEnabled
                    });
                }
                state.State = enabled;
                await context.SaveChangesAsync();
            }
        }
        public async Task <string> LoadFromDatabase(ulong id)
        {
            long       guildId    = id.ToDbLong();
            Identifier identifier = null;

            using (var context = new IAContext())
            {
                identifier = await context.Identifiers.FindAsync(guildId, DefaultValue);

                if (identifier == null)
                {
                    identifier = await CreateNewAsync(context, guildId);
                }
                await context.SaveChangesAsync();
            }
            return(identifier.Value);
        }
Beispiel #6
0
        public async Task SetEnabled(ulong serverId, bool enabled)
        {
            using (var context = new IAContext())
            {
                ModuleState state = await context.ModuleStates.FindAsync(SqlName, serverId.ToDbLong());

                if (state == null)
                {
                    state = context.ModuleStates.Add(new ModuleState()
                    {
                        ChannelId = serverId.ToDbLong(), ModuleName = SqlName, State = Enabled
                    });
                }
                state.State = enabled;
                await context.SaveChangesAsync();
            }
        }
Beispiel #7
0
        public async Task SetEnabled(ICacheClient client, ulong channelId, bool enabled)
        {
            using (var context = new IAContext())
            {
                CommandState state = await context.CommandStates.FindAsync(Name, channelId.ToDbLong());

                if (state == null)
                {
                    state = context.CommandStates.Add(new CommandState()
                    {
                        ChannelId = channelId.ToDbLong(), CommandName = Name, State = DefaultEnabled
                    }).Entity;
                }
                state.State = enabled;

                await client.UpsertAsync(GetCacheKey(channelId), enabled);

                await context.SaveChangesAsync();
            }
        }
Beispiel #8
0
        public async Task SetEnabled(ICacheClient cache, ulong channelId, bool enabled)
        {
            using (var context = new IAContext())
            {
                ModuleState state = await context.ModuleStates.FindAsync(SqlName, channelId.ToDbLong());

                if (state == null)
                {
                    state = context.ModuleStates.Add(new ModuleState()
                    {
                        ChannelId  = channelId.ToDbLong(),
                        ModuleName = SqlName,
                        State      = Enabled
                    }).Entity;
                }
                state.State = enabled;

                await cache.UpsertAsync(GetCacheKey(channelId), enabled);

                await context.SaveChangesAsync();
            }
        }
Beispiel #9
0
        public async Task <string> GetForGuildAsync(ulong id)
        {
            if (Changable)
            {
                long guildId = id.ToDbLong();

                using (var context = new IAContext())
                {
                    Identifier identifier = await context.Identifiers.FindAsync(guildId, DefaultValue);

                    if (identifier == null)
                    {
                        identifier = context.Identifiers.Add(new Identifier()
                        {
                            GuildId = guildId, DefaultValue = DefaultValue, Value = DefaultValue
                        });
                        await context.SaveChangesAsync();
                    }
                    return(identifier.Value);
                }
            }
            return(DefaultValue);
        }