Browse Source

Cleanup, added SendMessage aliases

tags/docs-0.9
Brandon Smith 9 years ago
parent
commit
f7f73a9d1a
7 changed files with 39 additions and 41 deletions
  1. +2
    -0
      Discord.Net/API/DiscordAPI.cs
  2. +0
    -1
      Discord.Net/API/Models/APIResponses.cs
  3. +3
    -3
      Discord.Net/API/Models/WebSocketCommands.cs
  4. +25
    -25
      Discord.Net/API/Models/WebSocketEvents.cs
  5. +8
    -8
      Discord.Net/DiscordClient.cs
  6. +0
    -1
      Discord.Net/Helpers/Http.cs
  7. +1
    -3
      Discord.Net/Server.cs

+ 2
- 0
Discord.Net/API/DiscordAPI.cs View File

@@ -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)
{ {


+ 0
- 1
Discord.Net/API/Models/APIResponses.cs View File

@@ -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


+ 3
- 3
Discord.Net/API/Models/WebSocketCommands.cs View File

@@ -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


+ 25
- 25
Discord.Net/API/Models/WebSocketEvents.cs View File

@@ -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 { }
internal sealed class GuildDelete : ExtendedServerInfo { }
public sealed class GuildCreate : ExtendedServerInfo { }
public sealed class GuildDelete : ExtendedServerInfo { }


//Channels //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 //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 { }
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")] [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 { }
internal sealed class MessageUpdate : MessageReference
public sealed class MessageCreate : Message { }
public sealed class MessageUpdate : MessageReference
{ {
[JsonProperty(PropertyName = "embeds")] [JsonProperty(PropertyName = "embeds")]
public object[] 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")] [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;


+ 8
- 8
Discord.Net/DiscordClient.cs View File

@@ -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,11 +511,13 @@ 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)
{
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(); CheckReady();
if (text.Length <= 2000) if (text.Length <= 2000)
@@ -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);


+ 0
- 1
Discord.Net/Helpers/Http.cs View File

@@ -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
- 3
Discord.Net/Server.cs View File

@@ -1,6 +1,4 @@
using Discord.Helpers;
using Newtonsoft.Json;
using System;
using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;


Loading…
Cancel
Save