Added search commands and avatarurl
This commit is contained in:
@@ -38,7 +38,8 @@
|
||||
|
||||
// /api/users
|
||||
public static readonly string Users = $"{BaseApi}/users";
|
||||
public static string UserChannels(string id) => $"{Users}/{id}/channels";
|
||||
public static string UserChannels(string userId) => $"{Users}/{userId}/channels";
|
||||
public static string UserAvatar(string userId, string avatarId) => $"{Users}/{userId}/avatars/{avatarId}.jpg";
|
||||
|
||||
// /api/voice
|
||||
public static readonly string Voice = $"{BaseApi}/voice";
|
||||
|
||||
@@ -25,30 +25,25 @@ namespace Discord
|
||||
|
||||
public IEnumerable<User> Users { get { return _users; } }
|
||||
private AsyncCache<User, API.Models.UserReference> _users;
|
||||
public User GetUser(string id) => _users[id];
|
||||
|
||||
public IEnumerable<Server> Servers { get { return _servers; } }
|
||||
private AsyncCache<Server, API.Models.ServerReference> _servers;
|
||||
public Server GetServer(string id) => _servers[id];
|
||||
|
||||
public IEnumerable<Channel> Channels { get { return _channels; } }
|
||||
private AsyncCache<Channel, API.Models.ChannelReference> _channels;
|
||||
public Channel GetChannel(string id) => _channels[id];
|
||||
|
||||
public IEnumerable<Message> Messages { get { return _messages; } }
|
||||
private AsyncCache<Message, API.Models.MessageReference> _messages;
|
||||
public Message GetMessage(string id) => _messages[id];
|
||||
|
||||
public IEnumerable<Role> Roles { get { return _roles; } }
|
||||
private AsyncCache<Role, API.Models.Role> _roles;
|
||||
public Role GetRole(string id) => _roles[id];
|
||||
|
||||
public bool IsConnected { get { return _isReady; } }
|
||||
|
||||
public DiscordClient()
|
||||
{
|
||||
string version = typeof(DiscordClient).GetTypeInfo().Assembly.GetName().Version.ToString(2);
|
||||
_httpOptions = new HttpOptions { UserAgent = $"Discord.Net/{version} (https://github.com/RogueException/Discord.Net)" };
|
||||
_httpOptions = new HttpOptions($"Discord.Net/{version} (https://github.com/RogueException/Discord.Net)");
|
||||
|
||||
_servers = new AsyncCache<Server, API.Models.ServerReference>(
|
||||
(key, parentKey) => new Server(key, this),
|
||||
@@ -150,7 +145,7 @@ namespace Discord
|
||||
(key, parentKey) => new User(key, this),
|
||||
(user, model) =>
|
||||
{
|
||||
user.Avatar = model.Avatar;
|
||||
user.AvatarId = model.Avatar;
|
||||
user.Discriminator = model.Discriminator;
|
||||
user.Name = model.Username;
|
||||
if (model is SelfUserInfo)
|
||||
@@ -405,6 +400,62 @@ namespace Discord
|
||||
_webSocket.OnDebugMessage += (s, e) => RaiseOnDebugMessage(e.Message);
|
||||
}
|
||||
|
||||
//Collections
|
||||
public User GetUser(string id) => _users[id];
|
||||
public User FindUser(string name)
|
||||
{
|
||||
return _users
|
||||
.Where(x => string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
public User FindUser(string name, string discriminator)
|
||||
{
|
||||
return _users
|
||||
.Where(x =>
|
||||
string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase) &&
|
||||
x.Discriminator == discriminator
|
||||
)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
public User FindChannelUser(Channel channel, string name)
|
||||
=> FindChannelUser(channel, name);
|
||||
public User FindChannelUser(string channelId, string name)
|
||||
{
|
||||
return _users
|
||||
.Where(x => string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public Server GetServer(string id) => _servers[id];
|
||||
public Server FindServer(string name)
|
||||
{
|
||||
return _servers
|
||||
.Where(x => string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public Channel GetChannel(string id) => _channels[id];
|
||||
public Channel FindChannel(string name)
|
||||
{
|
||||
return _channels
|
||||
.Where(x => string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
public Channel FindChannel(Server server, string name)
|
||||
=> FindChannel(server.Id, name);
|
||||
public Channel FindChannel(string serverId, string name)
|
||||
{
|
||||
return _channels
|
||||
.Where(x =>
|
||||
string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase) &&
|
||||
x.ServerId == serverId
|
||||
)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public Message GetMessage(string id) => _messages[id];
|
||||
public Role GetRole(string id) => _roles[id];
|
||||
|
||||
//Auth
|
||||
public async Task Connect(string email, string password)
|
||||
{
|
||||
@@ -514,7 +565,6 @@ namespace Discord
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { }
|
||||
}
|
||||
|
||||
|
||||
//Invites
|
||||
public Task<Invite> CreateInvite(Server server, int maxAge, int maxUses, bool isTemporary, bool hasXkcdPass)
|
||||
{
|
||||
|
||||
@@ -11,12 +11,13 @@ namespace Discord.Helpers
|
||||
{
|
||||
internal class HttpOptions
|
||||
{
|
||||
public string UserAgent, Token;
|
||||
public readonly string UserAgent;
|
||||
public string Token;
|
||||
public CookieContainer Cookies;
|
||||
|
||||
public HttpOptions(string userAgent = null)
|
||||
public HttpOptions(string userAgent)
|
||||
{
|
||||
UserAgent = userAgent ?? "DiscordAPI";
|
||||
UserAgent = userAgent;
|
||||
Cookies = new CookieContainer(1);
|
||||
}
|
||||
}
|
||||
@@ -103,8 +104,6 @@ namespace Discord.Helpers
|
||||
|
||||
private static async Task<string> SendRequest(string method, string path, string data, HttpOptions options, bool hasResponse)
|
||||
{
|
||||
options = options ?? new HttpOptions();
|
||||
|
||||
//Create Request
|
||||
HttpWebRequest request = WebRequest.CreateHttp(path);
|
||||
request.Accept = "*/*";
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Discord.API;
|
||||
using System;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
@@ -9,7 +10,8 @@ namespace Discord
|
||||
public string Id { get; }
|
||||
public string Name { get; internal set; }
|
||||
|
||||
public string Avatar { get; internal set; }
|
||||
public string AvatarId { get; internal set; }
|
||||
public string AvatarUrl { get { return Endpoints.UserAvatar(Id, AvatarId); } }
|
||||
public string Discriminator { get; internal set; }
|
||||
public string Email { get; internal set; }
|
||||
public bool IsVerified { get; internal set; } = true;
|
||||
|
||||
Reference in New Issue
Block a user