public async Task Execute(IJobExecutionContext context) { string[] logins = BubbleWallet.loginBubbleTicks.Distinct().ToArray(); BubbleWallet.loginBubbleTicks = new List <string>(); Dictionary <string, int> cache = new Dictionary <string, int>(); PalantirDbContext dbcontext = new PalantirDbContext(); try { foreach (string login in logins) { MemberEntity member = dbcontext.Members.FirstOrDefault(s => s.Login == login); if (JsonConvert.DeserializeObject <Member>(member.Member).Guilds.Count > 0) { member.Bubbles++; } } } catch (Exception e) { Console.WriteLine(e.ToString()); } await dbcontext.SaveChangesAsync(); foreach (MemberEntity member in dbcontext.Members) { cache.Add(member.Login.ToString(), member.Bubbles); } dbcontext.Dispose(); BubbleWallet.BubbleCache = cache; }
public int GetFlagByMember(DiscordUser user) { PalantirDbContext context = new PalantirDbContext(); MemberEntity member = context.Members.FirstOrDefault(m => m.Member.Contains(user.Id.ToString())); context.Dispose(); return(member.Flag); }
public MemberEntity GetMemberByLogin(string login) { PalantirDbContext context = new PalantirDbContext(); MemberEntity member = context.Members.FirstOrDefault(m => m.Login == login); context.Dispose(); return(member); }
public void SetFlagByID(string id, int flag) { PalantirDbContext context = new PalantirDbContext(); MemberEntity member = context.Members.FirstOrDefault(m => m.Member.Contains(id)); member.Flag = flag; context.SaveChanges(); context.Dispose(); }
public static int GetDrops(string login) { PalantirDbContext context = new PalantirDbContext(); MemberEntity entity = context.Members.FirstOrDefault(s => s.Login == login); int drops = 0; if (entity != null) { drops = entity.Drops; } context.SaveChanges(); context.Dispose(); return(drops); }
public void AddMember(Member member) { PalantirDbContext Database = new PalantirDbContext(); PalantirMembers.Add(member); // add to db MemberEntity entity = new MemberEntity(); entity.Login = member.UserLogin; entity.Member = JsonConvert.SerializeObject(member); entity.Bubbles = 0; entity.Sprites = ""; Database.Members.Add(entity); Database.SaveChanges(); Database.Dispose(); }
public async Task <int> UpdatePatrons() { List <string> patrons = new List <string>(); List <string> patronizer = new List <string>(); List <string> patronized = new List <string>(); Dictionary <string, string> emojis = new Dictionary <string, string>(); // collect ids of patron members DiscordGuild typotestground = await Program.Client.GetGuildAsync(779435254225698827); foreach (DiscordMember member in await typotestground.GetAllMembersAsync()) { if (member.Roles.Any(role => role.Id == 832744566905241610)) { patrons.Add(member.Id.ToString()); } if (member.Roles.Any(role => role.Id == 859100010184572938)) { patronizer.Add(member.Id.ToString()); } } ; PatronCount = patrons.Count(); PalantirDbContext db = new PalantirDbContext(); // iterate through palantir members and set flags await db.Members.ForEachAsync(member => { PermissionFlag flag = new PermissionFlag((byte)member.Flag); flag.Patron = patrons.Any(patron => member.Member.Contains(patron)); if (patronizer.Any(id => member.Member.Contains(id))) { flag.Patronizer = true; if (member.Patronize is not null) { patronized.Add(member.Patronize.Split("#")[0]); } } else { flag.Patronizer = false; } string emoji = String.IsNullOrEmpty(member.Emoji) ? "" : member.Emoji; if (flag.Patron || flag.BotAdmin) { emojis.Add(member.Login, emoji); } member.Flag = flag.CalculateFlag(); }); // set flags of patronized members patronized.ForEach(id => { if (db.Members.Any(member => member.Member.Contains(id))) { MemberEntity member = db.Members.FirstOrDefault(member => member.Member.Contains(id)); PermissionFlag flag = new PermissionFlag((byte)member.Flag); flag.Patron = true; string emoji = String.IsNullOrEmpty(member.Emoji) ? "" : member.Emoji; emojis.Add(member.Login, emoji); member.Flag = flag.CalculateFlag(); } }); db.SaveChanges(); db.Dispose(); PatronEmojis = emojis; return(patrons.Count); }