예제 #1
0
        public static UserKeyValueEntry GetStorageOrCreate(this BotContext context, User user, string key)
        {
            UserKeyValueEntry entry = context.UserKeyValueEntries.FirstOrDefault(x => x.User.Id == user.Id && x.Key == key);

            if (entry == null)
            {
                entry = new UserKeyValueEntry {
                    Key = key, User = user
                };
                context.UserKeyValueEntries.Add(entry);
            }
            return(entry);
        }
예제 #2
0
 public static User GetUser(this BotContext context, string nickname)
 {
     return(context.Nicknames.Include(x => x.User.LastUsedName).FirstOrDefault(x => x.Name == nickname)?.User);
 }
예제 #3
0
 public static UserKeyValueEntry GetStorage(this BotContext context, string nickname, string key)
 {
     return(context.UserKeyValueEntries.FirstOrDefault(x => x.User.Id == context.Nicknames.FirstOrDefault(n => n.Name == nickname).User.Id&& x.Key == key));
 }
예제 #4
0
 public static UserKeyValueEntry GetStorage(this BotContext context, User user, string key)
 {
     return(context.UserKeyValueEntries.FirstOrDefault(x => x.User.Id == user.Id && x.Key == key));
 }
예제 #5
0
 public static User GetUser(this BotContext context, string nickname)
 {
     return(context.TryGetUser(nickname) ?? throw new InvalidOperationException("User does not exist"));
 }