/// <summary> /// Verify user corp role. /// </summary> /// <param name="user"></param> /// <param name="corpRole"></param> /// <param name="eveId"></param> /// <returns></returns> async Task VerifyCorp(IGuildUser user, IRole corpRole, IRole legacyRole, int eveId) { IApiResponse corpusersReponse = await ApiModule.Esi.Path("/corporations/{corporation_id}/members/").Get(("corporation_id", Config.CorporationID)); List <int> corpUsers = corpusersReponse.ToType <List <int> >().FirstPage; bool inCorp = corpUsers.Contains(eveId); bool hasCorpRole = await RoleModule.HasRoleAsync(user, corpRole.Name); bool hasLegacyRole = await RoleModule.HasRoleAsync(user, legacyRole.Name); await UpdateRole(user, corpRole, inCorp, hasCorpRole); // Give char legacy role if he has been in corp for six months if (!inCorp && hasCorpRole) { int days = await GetDaysInCorp(eveId); if (days >= 30 * 6) // Min of six months in corp. { await LogModule.LogMessage($"{user.Nickname} has been in corp for {days} days and has been moved to #Legacy.", Config.LogChannel); await UpdateRole(user, legacyRole, true, hasLegacyRole); } } if (inCorp && !hasCorpRole) { string name = (Message.Author as IGuildUser).Nickname ?? Message.Author.Username; if (!await JobModule.JobExistsAsync <CheckupJob>(x => x.Character == name)) { await JobModule.AddJobAsync(new CheckupJob("RecruitmentModule", name)); } } }
/// <summary> /// Update a role to its appropriate status. Only modify the role if it needs a change. /// </summary> /// <param name="user"></param> /// <param name="role"></param> /// <param name="shouldHave"></param> /// <param name="have"></param> /// <returns></returns> Task UpdateRole(IGuildUser user, IRole role, bool shouldHave, bool have) { if (shouldHave && !have) { return(RoleModule.ModifyRoleAsync(user, RoleAction.Add, role.Name)); } else if (!shouldHave && have) { return(RoleModule.ModifyRoleAsync(user, RoleAction.Remove, role.Name)); } return(Task.CompletedTask); }
/// <summary> /// Verify user alliance role. /// </summary> /// <param name="user"></param> /// <param name="allianceRole"></param> /// <param name="eveId"></param> /// <returns></returns> async Task VerifyAlliance(IGuildUser user, IRole allianceRole, int eveId) { IApiResponse characterInfo = await ApiModule.Esi.Path("/characters/{character_id}/").Get(("character_id", eveId)); int corpID = JsonConvert.DeserializeObject <dynamic>(characterInfo.FirstPage)["corporation_id"]; IApiResponse allianceCorpsResponse = await ApiModule.Esi.Path("/alliances/{alliance_id}/corporations/").Get(("alliance_id", Config.AllianceID)); List <int> allianceCorps = allianceCorpsResponse.ToType <List <int> >().FirstPage; bool inAlliance = allianceCorps.Contains(corpID); bool hasRole = await RoleModule.HasRoleAsync(user, allianceRole.Name); await UpdateRole(user, allianceRole, inAlliance, hasRole); }
/// <summary> /// Verify a specific user. /// </summary> /// <param name="guild"></param> /// <param name="user"></param> /// <returns></returns> async Task VerifyUser(IGuild guild, IGuildUser user) { IRole authedRole = guild.GetRole(Config.AuthedRole); Dictionary <ulong, int> dbUsers = await GetAuthedUsers(); bool userAuthed = dbUsers.TryGetValue(user.Id, out int eveId); bool hasRole = await RoleModule.HasRoleAsync(user, authedRole.Name); await UpdateRole(user, authedRole, userAuthed, hasRole); if (userAuthed) { await VerifyName(user, eveId); await VerifyAlliance(user, guild.GetRole(Config.AllianceRole), eveId); await VerifyCorp(user, guild.GetRole(Config.CorpRole), guild.GetRole(Config.LegacyRole), eveId); } }