public EQDKPService(ulong guildId) : base(guildId) { //dont fetch for default guild id if (guildId == ulong.MaxValue) { return; } var json = File.ReadAllText(EQDKP_PATH); var eqdkp = JsonConvert.DeserializeObject <JObject>(json); if (eqdkp.TryGetValue(GuildId.ToString(), out var guildSettings)) { var apiKey = guildSettings.Value <string>("ApiKey"); var baseUrl = guildSettings.Value <string>("BaseUrl"); HttpClient = new HttpClient { BaseAddress = new Uri(baseUrl) }; HttpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", apiKey); CharacterCache = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); var unused = PrefetchCharacterIds(); } else { Log.Error("EQDKP Service created without required guild settings."); } }
protected virtual void NetFuncSelectNpcDialogGuildStorageMenu(int menuIndex) { if (currentNpcDialog == null || currentNpcDialog.type != NpcDialogType.GuildStorage) { currentNpcDialog = null; RequestShowNpcDialog(0); return; } switch (menuIndex) { case NpcDialog.STORAGE_CONFIRM_MENU_INDEX: OpenStorage(StorageType.Guild, GuildId.ToString()); currentNpcDialog = null; break; case NpcDialog.STORAGE_CANCEL_MENU_INDEX: currentNpcDialog = currentNpcDialog.storageCancelDialog; break; } if (currentNpcDialog == null) { RequestShowNpcDialog(0); } else { RequestShowNpcDialog(currentNpcDialog.DataId); } }
public async Task <Guild?> GetGuildAsync() { if (GuildId == null) { return(null); } return(Guild ??= await Client.Cache.Guilds.GetAsync(GuildId.ToString() !)); }
public async Task CacheAsync() { var channelTask = GuildId == null ? Client.Cache.Channels.SetNullableAsync(Channel) : Client.Cache.GuildChannels.SetNullableAsync(Channel as CoreGuildChannel, GuildId.ToString()); var authorTask = Client.Cache.Users.SetNullableAsync(Author); var memberTask = Client.Cache.GuildMembers.SetNullableAsync(Member, GuildId.ToString()); var messageTask = Client.Cache.Messages.SetAsync(this, ChannelId.ToString()); await Task.WhenAll(channelTask, authorTask, memberTask, messageTask); }
// Methods public void Save() { RavenGuild old = RavenDb.GetGuild(GuildId); if (old != null) { RavenDb.UpdateGuild(old, this); } using (var session = RavenStore.Store.OpenSession()) { session.Store(this, GuildId.ToString()); session.SaveChanges(); } }
public override string ToString() { return(GuildId.ToString()); }
public async Task <CoreGuild?> GetGuildAsync() { return(await Client.Cache.Guilds.GetAsync(GuildId.ToString())); }
public override string ToString() { return($"Guild: {GuildId.ToString()}, id: {Id.ToString()}, name: \"{Name}\""); }
public async Task <Channel?> GetChannelAsync() { return(Channel ??= GuildId == null ? await Client.Cache.Channels.GetAsync(ChannelId.ToString()) : await Client.Cache.GuildChannels.GetAsync(ChannelId.ToString(), GuildId.ToString())); }
public async Task <GuildMember?> GetMemberAsync() { return(Member ??= await Client.Cache.GuildMembers.GetAsync(AuthorId.ToString(), GuildId.ToString())); }
public async Task <GuildChannel?> GetChannelAsync() { return(await Client.Cache.GuildChannels.GetAsync(GuildId.ToString())); }
public async Task <Guild?> GetGuildAsync(IClient client) { return(Guild ??= await client.Cache.Guilds.GetAsync(GuildId.ToString())); }
public async Task <IActionResult> CreateExisting(ulong roleId, ulong channelId, string courseName) { DiscordUserInfo currentUser = null; try { currentUser = await GetAuthenticatedUserInfoAsync(); } catch (HttpException httpEx) when(httpEx.HttpCode == HttpStatusCode.Unauthorized) { logger.LogError(httpEx, "Unhandled Discord HTTP Exception"); return(Unauthorized("Something broke, your login may be unauthorized.")); } catch (HttpException httpEx) when(httpEx.HttpCode == HttpStatusCode.NotFound) { logger.LogError(httpEx, "Unhandled Discord HTTP Exception"); return(NotFound("Something wasn't found.")); } catch (HttpException httpEx) { logger.LogError(httpEx, "Unhandled Discord HTTP Exception"); throw; } if (currentUser == null) { logger.LogError("Current User is null, this indicates some issue with logging in."); return(Unauthorized("Unable to log in.")); } if (!currentUser.InGuild) { return(Unauthorized("You are not a member of this server.")); } if (!currentUser.IsAdmin) { return(Unauthorized("You must be an admin to view this page.")); } var exists = await CheckExistsAndValidAsync(roleId, channelId); if (!exists) { return(BadRequest("Either the role or channel Id did not exist in this guild, or the role had permissions that could not be granted.")); } courseName = NormalizeCourseChannelName(courseName); var courseEntity = new CourseEntity() { GuildId = GuildId.ToString(), CourseId = courseName, ChannelId = channelId.ToString(), RoleId = roleId.ToString(), }; var storage = GetStorageUtil(); var table = await storage.GetCourseTableAsync(); var operation = TableOperation.InsertOrMerge(courseEntity); await table.ExecuteAsync(operation); // show the list return(await Index()); }
public async Task<CoreGuild?> GetGuildAsync() { if (GuildId == null) return null; return Guild ??= await Client.Cache.Guilds.GetAsync(GuildId.ToString()!); }