예제 #1
0
        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.");
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
 public async Task <Guild?> GetGuildAsync()
 {
     if (GuildId == null)
     {
         return(null);
     }
     return(Guild ??= await Client.Cache.Guilds.GetAsync(GuildId.ToString() !));
 }
예제 #4
0
		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);
		}
예제 #5
0
        // 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();
            }
        }
예제 #6
0
 public override string ToString()
 {
     return(GuildId.ToString());
 }
예제 #7
0
 public async Task <CoreGuild?> GetGuildAsync()
 {
     return(await Client.Cache.Guilds.GetAsync(GuildId.ToString()));
 }
예제 #8
0
 public override string ToString()
 {
     return($"Guild: {GuildId.ToString()}, id: {Id.ToString()}, name: \"{Name}\"");
 }
예제 #9
0
 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()));
 }
예제 #10
0
 public async Task <GuildMember?> GetMemberAsync()
 {
     return(Member ??= await Client.Cache.GuildMembers.GetAsync(AuthorId.ToString(), GuildId.ToString()));
 }
예제 #11
0
 public async Task <GuildChannel?> GetChannelAsync()
 {
     return(await Client.Cache.GuildChannels.GetAsync(GuildId.ToString()));
 }
예제 #12
0
 public async Task <Guild?> GetGuildAsync(IClient client)
 {
     return(Guild ??= await client.Cache.Guilds.GetAsync(GuildId.ToString()));
 }
예제 #13
0
        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());
        }
예제 #14
0
		public async Task<CoreGuild?> GetGuildAsync()
		{
			if (GuildId == null) return null;
			return Guild ??= await Client.Cache.Guilds.GetAsync(GuildId.ToString()!);
		}