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