Example #1
0
        internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, Model model)
        {
            var entity = new SocketDMChannel(discord, model.Id, discord.GetOrCreateTemporaryUser(state, model.Recipients.Value[0]));

            entity.Update(state, model);
            return(entity);
        }
Example #2
0
        internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, ulong channelId, API.User recipient)
        {
            var entity = new SocketDMChannel(discord, channelId, discord.GetOrCreateTemporaryUser(state, recipient));

            entity.Update(state, recipient);
            return(entity);
        }
Example #3
0
 /// <exception cref="InvalidOperationException">Unexpected channel type is created.</exception>
 internal static ISocketPrivateChannel CreatePrivate(DiscordSocketClient discord, ClientState state, Model model)
 {
     return(model.Type switch
     {
         ChannelType.DM => SocketDMChannel.Create(discord, state, model),
         ChannelType.Group => SocketGroupChannel.Create(discord, state, model),
         _ => throw new InvalidOperationException($"Unexpected channel type: {model.Type}"),
     });
 /// <exception cref="NotSupportedException">Unexpected <see cref="ISocketMessageChannel"/> type.</exception>
 public static SocketMessage RemoveMessage(ISocketMessageChannel channel, DiscordSocketClient discord,
                                           ulong id)
 {
     return(channel switch
     {
         SocketDMChannel dmChannel => dmChannel.RemoveMessage(id),
         SocketGroupChannel groupChannel => groupChannel.RemoveMessage(id),
         SocketTextChannel textChannel => textChannel.RemoveMessage(id),
         _ => throw new NotSupportedException($"Unexpected {nameof(ISocketMessageChannel)} type."),
     });
Example #5
0
        internal static ISocketPrivateChannel CreatePrivate(DiscordSocketClient discord, ClientState state, Model model)
        {
            switch (model.Type)
            {
            case ChannelType.DM:
                return(SocketDMChannel.Create(discord, state, model));

            case ChannelType.Group:
                return(SocketGroupChannel.Create(discord, state, model));

            default:
                throw new InvalidOperationException($"Unexpected channel type: {model.Type}");
            }
        }
Example #6
0
 /// <inheritdoc />
 public IAsyncEnumerable <IReadOnlyCollection <IMessage> > GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = 100, RequestOptions options = null)
 => SocketDMChannel.GetMessagesAsync(fromMessage, dir, limit, options)
 .Select(x => x
         .Select(MessageAbstractionExtensions.Abstract)
         .ToArray());
Example #7
0
 /// <inheritdoc />
 public async Task <IMessage> GetMessageAsync(ulong id, RequestOptions options = null)
 => (await SocketDMChannel.GetMessageAsync(id, options))
 ?.Abstract();
Example #8
0
 /// <inheritdoc />
 public IReadOnlyCollection <ISocketMessage> GetCachedMessages(IMessage fromMessage, Direction dir, int limit = 100)
 => SocketDMChannel.GetCachedMessages(fromMessage, dir, limit)
 .Select(SocketMessageAbstractionExtensions.Abstract)
 .ToArray();
Example #9
0
 /// <summary>
 /// Converts an existing <see cref="SocketDMChannel"/> to an abstracted <see cref="ISocketDMChannel"/> value.
 /// </summary>
 /// <param name="socketDMChannel">The existing <see cref="SocketDMChannel"/> to be abstracted.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketDMChannel"/>.</exception>
 /// <returns>An <see cref="ISocketDMChannel"/> that abstracts <paramref name="socketDMChannel"/>.</returns>
 public static ISocketDMChannel Abstract(this SocketDMChannel socketDMChannel)
 => new SocketDMChannelAbstraction(socketDMChannel);
Example #10
0
 /// <inheritdoc />
 public Task TriggerTypingAsync(RequestOptions options = null)
 => SocketDMChannel.TriggerTypingAsync(options);
Example #11
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
 => RestUserMessageAbstractionExtensions.Abstract(
     await SocketDMChannel.SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference));
Example #12
0
 /// <inheritdoc />
 public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)
 => SocketDMChannel.DeleteMessageAsync(messageId, options);
Example #13
0
 /// <inheritdoc />
 public Task CloseAsync(RequestOptions options = null)
 => SocketDMChannel.CloseAsync(options);
Example #14
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null)
 => RestUserMessageAbstractionExtensions.Abstract(
     await SocketDMChannel.SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions));
Example #15
0
 /// <inheritdoc />
 public async Task <IReadOnlyCollection <IRestMessage> > GetPinnedMessagesAsync(RequestOptions options = null)
 => (await SocketDMChannel.GetPinnedMessagesAsync(options))
 .Select(RestMessageAbstractionExtensions.Abstract)
 .ToArray();
Example #16
0
 /// <inheritdoc />
 public Task DeleteMessageAsync(IMessage message, RequestOptions options = null)
 => SocketDMChannel.DeleteMessageAsync(message, options);
Example #17
0
 /// <inheritdoc />
 public async Task <IUserMessage> ModifyMessageAsync(ulong messageId, Action <MessageProperties> func, RequestOptions options = null)
 => (await SocketDMChannel.ModifyMessageAsync(messageId, func, options))
 ?.Abstract();
Example #18
0
 /// <inheritdoc />
 public IDisposable EnterTypingState(RequestOptions options = null)
 => SocketDMChannel.EnterTypingState(options);
Example #19
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null)
 => RestUserMessageAbstractionExtensions.Abstract(
     await SocketDMChannel.SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference));
Example #20
0
 /// <inheritdoc />
 public ISocketMessage GetCachedMessage(ulong id)
 => SocketDMChannel.GetCachedMessage(id)
 ?.Abstract();
Example #21
0
 /// <inheritdoc cref="SocketDMChannel.ToString" />
 public override string ToString()
 => SocketDMChannel.ToString();
Example #22
0
 /// <inheritdoc />
 public IReadOnlyCollection <ISocketMessage> GetCachedMessages(int limit = 100)
 => SocketDMChannel.GetCachedMessages(limit)
 .Select(SocketMessageAbstractionExtensions.Abstract)
 .ToArray();
Example #23
0
 /// <summary>
 /// Constructs a new <see cref="SocketDMChannelAbstraction"/> around an existing <see cref="WebSocket.SocketDMChannel"/>.
 /// </summary>
 /// <param name="socketDMChannel">The value to use for <see cref="WebSocket.SocketDMChannel"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketDMChannel"/>.</exception>
 public SocketDMChannelAbstraction(SocketDMChannel socketDMChannel)
     : base(socketDMChannel)
 {
 }
Example #24
0
 /// <inheritdoc />
 public async Task <IRestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null)
 => RestUserMessageAbstractionExtensions.Abstract(
     await SocketDMChannel.SendFileAsync(stream, filename, text, isTTS, embed, options));