Example #1
0
 /// <summary>
 ///     Saves the current partner info
 /// </summary>
 public void Save()
 {
     using (var session = Store.OpenSession())
     {
         session.Store(this, $"{GuildId}-Partner");
         PartnerStatuses.TryRemove(GuildId, out _);
         PartnerStatuses.TryAdd(GuildId, Settings.Enabled && !Settings.Banned);
         session.SaveChanges();
     }
 }
Example #2
0
        /// <summary>
        /// Gets a partner info config via guild ID
        /// </summary>
        /// <param name="guildId">
        /// The guild id.
        /// </param>
        /// <param name="forced">
        /// The forced.
        /// </param>
        /// <returns>
        /// The <see cref="PartnerInfo"/>.
        /// </returns>
        public PartnerInfo GetPartnerInfo(ulong guildId, bool forced = false)
        {
            if (!forced)
            {
                if (PartnerStatuses.ContainsKey(guildId))
                {
                    PartnerStatuses.TryGetValue(guildId, out var status);
                    if (status == false)
                    {
                        return(null);
                    }
                }
            }

            using (var session = Store.OpenSession())
            {
                var res = session.Load <PartnerInfo>($"{guildId}-Partner") ?? new PartnerInfo(guildId);
                PartnerStatuses.TryRemove(guildId, out _);
                PartnerStatuses.TryAdd(guildId, res.Settings.Enabled && !res.Settings.Banned);

                return(res);
            }
        }