Esempio n. 1
0
        internal static async Task <RestInteraction> CreateAsync(DiscordRestClient client, Model model)
        {
            if (model.Type == InteractionType.Ping)
            {
                return(await RestPingInteraction.CreateAsync(client, model));
            }

            if (model.Type == InteractionType.ApplicationCommand)
            {
                var dataModel = model.Data.IsSpecified
                    ? (DataModel)model.Data.Value
                    : null;

                if (dataModel == null)
                {
                    return(null);
                }

                return(dataModel.Type switch
                {
                    ApplicationCommandType.Slash => await RestSlashCommand.CreateAsync(client, model).ConfigureAwait(false),
                    ApplicationCommandType.Message => await RestMessageCommand.CreateAsync(client, model).ConfigureAwait(false),
                    ApplicationCommandType.User => await RestUserCommand.CreateAsync(client, model).ConfigureAwait(false),
                    _ => null
                });
Esempio n. 2
0
        internal static new async Task <RestPingInteraction> CreateAsync(DiscordRestClient client, Model model)
        {
            var entity = new RestPingInteraction(client, model.Id);
            await entity.UpdateAsync(client, model);

            return(entity);
        }
Esempio n. 3
0
        internal new static async Task <RestAutocompleteInteraction> CreateAsync(DiscordRestClient client, Model model)
        {
            var entity = new RestAutocompleteInteraction(client, model);
            await entity.UpdateAsync(client, model).ConfigureAwait(false);

            return(entity);
        }
Esempio n. 4
0
        internal static new async Task <RestSlashCommandData> CreateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel)
        {
            var entity = new RestSlashCommandData(client, model);
            await entity.UpdateAsync(client, model, guild, channel).ConfigureAwait(false);

            return(entity);
        }
Esempio n. 5
0
        public Guild(DiscordRestClient discord, Model model)
            : base(model.Id)
        {
            Discord = discord;

            Update(model, UpdateSource.Creation);
        }
Esempio n. 6
0
        internal new static async Task <RestModal> CreateAsync(DiscordRestClient client, ModelBase model, bool doApiCall)
        {
            var entity = new RestModal(client, model);
            await entity.UpdateAsync(client, model, doApiCall);

            return(entity);
        }
Esempio n. 7
0
        public Invite(DiscordRestClient discord, Model model)
            : base(model.Code)
        {
            Discord = discord;

            Update(model, UpdateSource.Creation);
        }
        internal new static async Task <RestMessageCommand> CreateAsync(DiscordRestClient client, Model model)
        {
            var entity = new RestMessageCommand(client, model);
            await entity.UpdateAsync(client, model).ConfigureAwait(false);

            return(entity);
        }
Esempio n. 9
0
        internal new static async Task <RestCommandBase> CreateAsync(DiscordRestClient client, Model model, bool doApiCall)
        {
            var entity = new RestCommandBase(client, model);
            await entity.UpdateAsync(client, model, doApiCall).ConfigureAwait(false);

            return(entity);
        }
Esempio n. 10
0
 /// <summary>
 ///     Initializes a new <see cref="RestInteractionContext{TInteraction}"/>.
 /// </summary>
 /// <param name="client">The underlying client.</param>
 /// <param name="interaction">The underlying interaction.</param>
 public RestInteractionContext(DiscordRestClient client, TInteraction interaction)
 {
     Client      = client;
     Guild       = interaction.Guild;
     Channel     = interaction.Channel;
     User        = interaction.User;
     Interaction = interaction;
 }
Esempio n. 11
0
 private async Task StartLoginProcess()
 {
     // TODO: Discordへログインした後の初期化処理
     DiscordRestClient            = new Discord.Rest.DiscordRestClient();
     DiscordRestClient.LoggedIn  += DiscordRestClient_LoggedIn;
     DiscordRestClient.LoggedOut += DiscordRestClient_LoggedOut;
     await DiscordRestClient.LoginAsync(Discord.TokenType.User, DiscordAccessToken);
 }
Esempio n. 12
0
        internal override async Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel)
        {
            await base.UpdateAsync(client, model, guild, channel).ConfigureAwait(false);

            Options = model.Options.IsSpecified
                ? model.Options.Value.Select(x => new RestSlashCommandDataOption(this, x)).ToImmutableArray()
                : ImmutableArray.Create <RestSlashCommandDataOption>();
        }
Esempio n. 13
0
        public DMChannel(DiscordRestClient discord, IUser recipient, Model model)
            : base(model.Id)
        {
            Discord   = discord;
            Recipient = recipient;

            Update(model, UpdateSource.Creation);
        }
Esempio n. 14
0
        internal RestModal(DiscordRestClient client, ModelBase model)
            : base(client, model.Id)
        {
            var dataModel = model.Data.IsSpecified
                ? (DataModel)model.Data.Value
                : null;

            Data = new RestModalData(dataModel);
        }
Esempio n. 15
0
 internal virtual async Task UpdateAsync(DiscordRestClient client, Model model, RestGuild guild, IRestMessageChannel channel, bool doApiCall)
 {
     Name = model.Name;
     if (model.Resolved.IsSpecified && ResolvableData == null)
     {
         ResolvableData = new RestResolvableData <Model>();
         await ResolvableData.PopulateAsync(client, guild, channel, model, doApiCall).ConfigureAwait(false);
     }
 }
        internal override async Task UpdateAsync(DiscordRestClient client, Model model)
        {
            await base.UpdateAsync(client, model).ConfigureAwait(false);

            var dataModel = model.Data.IsSpecified
                ? (DataModel)model.Data.Value
                : null;

            Data = await RestMessageCommandData.CreateAsync(client, dataModel, Guild, Channel).ConfigureAwait(false);
        }
Esempio n. 17
0
        internal RestAutocompleteInteraction(DiscordRestClient client, Model model)
            : base(client, model.Id)
        {
            var dataModel = model.Data.IsSpecified
                ? (DataModel)model.Data.Value
                : null;

            if (dataModel != null)
            {
                Data = new RestAutocompleteInteractionData(dataModel);
            }
        }
        internal override async Task UpdateAsync(DiscordRestClient discord, Model model, bool doApiCall)
        {
            await base.UpdateAsync(discord, model, doApiCall).ConfigureAwait(false);

            if (model.Message.IsSpecified && model.ChannelId.IsSpecified)
            {
                if (Message == null)
                {
                    Message = RestUserMessage.Create(Discord, Channel, User, model.Message.Value);
                }
            }
        }
Esempio n. 19
0
 internal RestCommandBase(DiscordRestClient client, Model model)
     : base(client, model.Id)
 {
 }
Esempio n. 20
0
 /// <summary>
 /// Constructs a new <see cref="DiscordRestClientAbstraction"/> around an existing <see cref="Rest.DiscordRestClient"/>.
 /// </summary>
 /// <param name="discordRestClient">The value to use for <see cref="Rest.DiscordRestClient"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="discordRestClient"/>.</exception>
 public DiscordRestClientAbstraction(DiscordRestClient discordRestClient)
     : base(discordRestClient)
 {
 }
 internal RestMessageCommand(DiscordRestClient client, Model model)
     : base(client, model)
 {
 }
Esempio n. 22
0
 /// <inheritdoc />
 new public async Task <IRestGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options)
 => (await DiscordRestClient.CreateGuildAsync(name, region, jpegIcon, options))
 .Abstract();
Esempio n. 23
0
 internal RestUserCommand(DiscordRestClient client, Model model)
     : base(client, model)
 {
 }
Esempio n. 24
0
 public InviteMetadata(DiscordRestClient client, Model model)
     : base(client, model)
 {
     Update(model, UpdateSource.Creation);
 }
Esempio n. 25
0
 /// <inheritdoc />
 new public async Task <IRestApplication> GetApplicationInfoAsync(RequestOptions options)
 => (await DiscordRestClient.GetApplicationInfoAsync(options))
 .Abstract();
Esempio n. 26
0
 /// <summary>
 ///     Initializes a new <see cref="RestInteractionContext{TInteraction}"/>.
 /// </summary>
 /// <param name="client">The underlying client.</param>
 /// <param name="interaction">The underlying interaction.</param>
 /// <param name="interactionResponseCallback">The callback for outgoing json.</param>
 public RestInteractionContext(DiscordRestClient client, TInteraction interaction, Func <string, Task> interactionResponseCallback)
     : this(client, interaction)
 {
     InteractionResponseCallback = interactionResponseCallback;
 }
Esempio n. 27
0
 internal RestSlashCommandData(DiscordRestClient client, Model model)
     : base(client, model)
 {
 }
Esempio n. 28
0
 public SelfUser(DiscordRestClient discord, Model model)
     : base(model)
 {
     Discord = discord;
 }
        internal async Task PopulateAsync(DiscordRestClient discord, RestGuild guild, IRestMessageChannel channel, T model)
        {
            var resolved = model.Resolved.Value;

            if (resolved.Users.IsSpecified)
            {
                foreach (var user in resolved.Users.Value)
                {
                    var restUser = RestUser.Create(discord, user.Value);

                    Users.Add(ulong.Parse(user.Key), restUser);
                }
            }

            if (resolved.Channels.IsSpecified)
            {
                var channels = await guild.GetChannelsAsync().ConfigureAwait(false);

                foreach (var channelModel in resolved.Channels.Value)
                {
                    var restChannel = channels.FirstOrDefault(x => x.Id == channelModel.Value.Id);

                    restChannel.Update(channelModel.Value);

                    Channels.Add(ulong.Parse(channelModel.Key), restChannel);
                }
            }

            if (resolved.Members.IsSpecified)
            {
                foreach (var member in resolved.Members.Value)
                {
                    // pull the adjacent user model
                    member.Value.User = resolved.Users.Value.FirstOrDefault(x => x.Key == member.Key).Value;
                    var restMember = RestGuildUser.Create(discord, guild, member.Value);

                    GuildMembers.Add(ulong.Parse(member.Key), restMember);
                }
            }

            if (resolved.Roles.IsSpecified)
            {
                foreach (var role in resolved.Roles.Value)
                {
                    var restRole = RestRole.Create(discord, guild, role.Value);

                    Roles.Add(ulong.Parse(role.Key), restRole);
                }
            }

            if (resolved.Messages.IsSpecified)
            {
                foreach (var msg in resolved.Messages.Value)
                {
                    channel ??= (IRestMessageChannel)(Channels.FirstOrDefault(x => x.Key == msg.Value.ChannelId).Value ?? await discord.GetChannelAsync(msg.Value.ChannelId).ConfigureAwait(false));

                    RestUser author;

                    if (msg.Value.Author.IsSpecified)
                    {
                        author = RestUser.Create(discord, msg.Value.Author.Value);
                    }
                    else
                    {
                        author = RestGuildUser.Create(discord, guild, msg.Value.Member.Value);
                    }

                    var message = RestMessage.Create(discord, channel, author, msg.Value);

                    Messages.Add(message.Id, message);
                }
            }

            if (resolved.Attachments.IsSpecified)
            {
                foreach (var attachment in resolved.Attachments.Value)
                {
                    var discordAttachment = Attachment.Create(attachment.Value);

                    Attachments.Add(ulong.Parse(attachment.Key), discordAttachment);
                }
            }
        }
Esempio n. 30
0
 internal override async Task UpdateAsync(DiscordRestClient client, Model model)
 {
     await base.UpdateAsync(client, model).ConfigureAwait(false);
 }