Cleanup, added SendMessage aliases
This commit is contained in:
@@ -6,6 +6,8 @@ namespace Discord.API
|
||||
{
|
||||
internal static class DiscordAPI
|
||||
{
|
||||
public const int MaxMessageSize = 2000;
|
||||
|
||||
//Auth
|
||||
public static async Task<APIResponses.AuthRegister> LoginAnonymous(string username, HttpOptions options)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@ using System;
|
||||
|
||||
namespace Discord.API.Models
|
||||
{
|
||||
|
||||
internal static class APIResponses
|
||||
{
|
||||
public class AuthFingerprint
|
||||
|
||||
@@ -10,12 +10,12 @@ namespace Discord.API.Models
|
||||
{
|
||||
internal static class WebSocketCommands
|
||||
{
|
||||
internal sealed class KeepAlive : WebSocketMessage<int>
|
||||
public sealed class KeepAlive : WebSocketMessage<int>
|
||||
{
|
||||
private static DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
public KeepAlive() : base(1, (int)(DateTime.UtcNow - epoch).TotalMilliseconds) { }
|
||||
}
|
||||
internal sealed class Login : WebSocketMessage<Login.Data>
|
||||
public sealed class Login : WebSocketMessage<Login.Data>
|
||||
{
|
||||
public Login() : base(2) { }
|
||||
public class Data
|
||||
@@ -26,7 +26,7 @@ namespace Discord.API.Models
|
||||
public Dictionary<string, string> Properties = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
internal sealed class UpdateStatus : WebSocketMessage<UpdateStatus.Data>
|
||||
public sealed class UpdateStatus : WebSocketMessage<UpdateStatus.Data>
|
||||
{
|
||||
public UpdateStatus() : base(3) { }
|
||||
public class Data
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Discord.API.Models
|
||||
{
|
||||
internal static class WebSocketEvents
|
||||
{
|
||||
internal sealed class Ready
|
||||
public sealed class Ready
|
||||
{
|
||||
[JsonProperty(PropertyName = "user")]
|
||||
public SelfUserInfo User;
|
||||
@@ -26,74 +26,74 @@ namespace Discord.API.Models
|
||||
}
|
||||
|
||||
//Servers
|
||||
internal sealed class GuildCreate : ExtendedServerInfo { }
|
||||
internal sealed class GuildDelete : ExtendedServerInfo { }
|
||||
public sealed class GuildCreate : ExtendedServerInfo { }
|
||||
public sealed class GuildDelete : ExtendedServerInfo { }
|
||||
|
||||
//Channels
|
||||
internal sealed class ChannelCreate : ChannelInfo { }
|
||||
internal sealed class ChannelDelete : ChannelInfo { }
|
||||
internal sealed class ChannelUpdate : ChannelInfo { }
|
||||
public sealed class ChannelCreate : ChannelInfo { }
|
||||
public sealed class ChannelDelete : ChannelInfo { }
|
||||
public sealed class ChannelUpdate : ChannelInfo { }
|
||||
|
||||
//Memberships
|
||||
internal abstract class GuildMemberEvent
|
||||
public abstract class GuildMemberEvent
|
||||
{
|
||||
[JsonProperty(PropertyName = "user")]
|
||||
public UserReference User;
|
||||
[JsonProperty(PropertyName = "guild_id")]
|
||||
public string GuildId;
|
||||
}
|
||||
internal sealed class GuildMemberAdd : GuildMemberEvent
|
||||
public sealed class GuildMemberAdd : GuildMemberEvent
|
||||
{
|
||||
[JsonProperty(PropertyName = "joined_at")]
|
||||
public DateTime JoinedAt;
|
||||
[JsonProperty(PropertyName = "roles")]
|
||||
public object[] Roles;
|
||||
}
|
||||
internal sealed class GuildMemberUpdate : GuildMemberEvent
|
||||
public sealed class GuildMemberUpdate : GuildMemberEvent
|
||||
{
|
||||
[JsonProperty(PropertyName = "roles")]
|
||||
public object[] Roles;
|
||||
}
|
||||
internal sealed class GuildMemberRemove : GuildMemberEvent { }
|
||||
public sealed class GuildMemberRemove : GuildMemberEvent { }
|
||||
|
||||
//Roles
|
||||
internal abstract class GuildRoleEvent
|
||||
public abstract class GuildRoleEvent
|
||||
{
|
||||
[JsonProperty(PropertyName = "guild_id")]
|
||||
public string GuildId;
|
||||
}
|
||||
internal sealed class GuildRoleCreateUpdate : GuildRoleEvent
|
||||
public sealed class GuildRoleCreateUpdate : GuildRoleEvent
|
||||
{
|
||||
[JsonProperty(PropertyName = "role")]
|
||||
public Role Role;
|
||||
}
|
||||
internal sealed class GuildRoleDelete : GuildRoleEvent
|
||||
public sealed class GuildRoleDelete : GuildRoleEvent
|
||||
{
|
||||
[JsonProperty(PropertyName = "role_id")]
|
||||
public string RoleId;
|
||||
}
|
||||
|
||||
//Bans
|
||||
internal abstract class GuildBanEvent
|
||||
public abstract class GuildBanEvent
|
||||
{
|
||||
[JsonProperty(PropertyName = "guild_id")]
|
||||
public string GuildId;
|
||||
}
|
||||
internal sealed class GuildBanAddRemove : GuildBanEvent
|
||||
public sealed class GuildBanAddRemove : GuildBanEvent
|
||||
{
|
||||
[JsonProperty(PropertyName = "user")]
|
||||
public UserReference User;
|
||||
}
|
||||
internal sealed class GuildBanRemove : GuildBanEvent
|
||||
public sealed class GuildBanRemove : GuildBanEvent
|
||||
{
|
||||
[JsonProperty(PropertyName = "user_id")]
|
||||
public string UserId;
|
||||
}
|
||||
|
||||
//User
|
||||
internal sealed class UserUpdate : SelfUserInfo { }
|
||||
internal sealed class PresenceUpdate : PresenceUserInfo { }
|
||||
internal sealed class VoiceStateUpdate
|
||||
public sealed class UserUpdate : SelfUserInfo { }
|
||||
public sealed class PresenceUpdate : PresenceUserInfo { }
|
||||
public sealed class VoiceStateUpdate
|
||||
{
|
||||
[JsonProperty(PropertyName = "user_id")]
|
||||
public string UserId;
|
||||
@@ -116,15 +116,15 @@ namespace Discord.API.Models
|
||||
}
|
||||
|
||||
//Chat
|
||||
internal sealed class MessageCreate : Message { }
|
||||
internal sealed class MessageUpdate : MessageReference
|
||||
public sealed class MessageCreate : Message { }
|
||||
public sealed class MessageUpdate : MessageReference
|
||||
{
|
||||
[JsonProperty(PropertyName = "embeds")]
|
||||
public object[] Embeds;
|
||||
}
|
||||
internal sealed class MessageDelete : MessageReference { }
|
||||
internal sealed class MessageAck : MessageReference { }
|
||||
internal sealed class TypingStart
|
||||
public sealed class MessageDelete : MessageReference { }
|
||||
public sealed class MessageAck : MessageReference { }
|
||||
public sealed class TypingStart
|
||||
{
|
||||
[JsonProperty(PropertyName = "user_id")]
|
||||
public string UserId;
|
||||
@@ -135,7 +135,7 @@ namespace Discord.API.Models
|
||||
}
|
||||
|
||||
//Voice
|
||||
internal sealed class VoiceServerUpdate
|
||||
public sealed class VoiceServerUpdate
|
||||
{
|
||||
[JsonProperty(PropertyName = "guild_id")]
|
||||
public string ServerId;
|
||||
|
||||
@@ -12,8 +12,6 @@ namespace Discord
|
||||
{
|
||||
public partial class DiscordClient
|
||||
{
|
||||
private const int MaxMessageSize = 2000;
|
||||
|
||||
private DiscordWebSocket _webSocket;
|
||||
private HttpOptions _httpOptions;
|
||||
private bool _isClosing, _isReady;
|
||||
@@ -513,11 +511,13 @@ namespace Discord
|
||||
}
|
||||
|
||||
//Chat
|
||||
public Task SendMessage(Channel channel, string text)
|
||||
=> SendMessage(channel.Id, text, new string[0]);
|
||||
public Task SendMessage(string channelId, string text)
|
||||
{
|
||||
return SendMessage(channelId, text, new string[0]);
|
||||
}
|
||||
public async Task SendMessage(string channelId, string text, string[] mentions)
|
||||
=> SendMessage(channelId, text, new string[0]);
|
||||
public Task SendMessage(Channel channel, string text, string[] mentions)
|
||||
=> SendMessage(channel, text, mentions);
|
||||
public async Task SendMessage(string channelId, string text, string[] mentions)
|
||||
{
|
||||
CheckReady();
|
||||
if (text.Length <= 2000)
|
||||
@@ -527,10 +527,10 @@ namespace Discord
|
||||
}
|
||||
else
|
||||
{
|
||||
int blockCount = (int)Math.Ceiling(text.Length / (double)MaxMessageSize);
|
||||
int blockCount = (int)Math.Ceiling(text.Length / (double)DiscordAPI.MaxMessageSize);
|
||||
for (int i = 0; i < blockCount; i++)
|
||||
{
|
||||
int index = i * MaxMessageSize;
|
||||
int index = i * DiscordAPI.MaxMessageSize;
|
||||
var msg = await DiscordAPI.SendMessage(channelId, text.Substring(index, Math.Min(2000, text.Length - index)), mentions, _httpOptions);
|
||||
_messages.Update(msg.Id, msg);
|
||||
await Task.Delay(1000);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Discord.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
Reference in New Issue
Block a user