@@ -70,7 +70,7 @@ namespace Discord | |||||
{ | { | ||||
var args = new CreateMessageParams { Content = text, IsTTS = isTTS }; | var args = new CreateMessageParams { Content = text, IsTTS = isTTS }; | ||||
var model = await Discord.ApiClient.CreateDMMessageAsync(Id, args).ConfigureAwait(false); | var model = await Discord.ApiClient.CreateDMMessageAsync(Id, args).ConfigureAwait(false); | ||||
return new Message(this, new User(Discord, model.Author.Value), model); | |||||
return new Message(this, new User(model.Author.Value), model); | |||||
} | } | ||||
public async Task<IMessage> SendFileAsync(string filePath, string text, bool isTTS) | public async Task<IMessage> SendFileAsync(string filePath, string text, bool isTTS) | ||||
{ | { | ||||
@@ -79,33 +79,33 @@ namespace Discord | |||||
{ | { | ||||
var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | ||||
var model = await Discord.ApiClient.UploadDMFileAsync(Id, file, args).ConfigureAwait(false); | var model = await Discord.ApiClient.UploadDMFileAsync(Id, file, args).ConfigureAwait(false); | ||||
return new Message(this, new User(Discord, model.Author.Value), model); | |||||
return new Message(this, new User(model.Author.Value), model); | |||||
} | } | ||||
} | } | ||||
public async Task<IMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS) | public async Task<IMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS) | ||||
{ | { | ||||
var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | ||||
var model = await Discord.ApiClient.UploadDMFileAsync(Id, stream, args).ConfigureAwait(false); | var model = await Discord.ApiClient.UploadDMFileAsync(Id, stream, args).ConfigureAwait(false); | ||||
return new Message(this, new User(Discord, model.Author.Value), model); | |||||
return new Message(this, new User(model.Author.Value), model); | |||||
} | } | ||||
public virtual async Task<IMessage> GetMessageAsync(ulong id) | public virtual async Task<IMessage> GetMessageAsync(ulong id) | ||||
{ | { | ||||
var model = await Discord.ApiClient.GetChannelMessageAsync(Id, id).ConfigureAwait(false); | var model = await Discord.ApiClient.GetChannelMessageAsync(Id, id).ConfigureAwait(false); | ||||
if (model != null) | if (model != null) | ||||
return new Message(this, new User(Discord, model.Author.Value), model); | |||||
return new Message(this, new User(model.Author.Value), model); | |||||
return null; | return null; | ||||
} | } | ||||
public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit) | public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit) | ||||
{ | { | ||||
var args = new GetChannelMessagesParams { Limit = limit }; | var args = new GetChannelMessagesParams { Limit = limit }; | ||||
var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | ||||
return models.Select(x => new Message(this, new User(Discord, x.Author.Value), x)).ToImmutableArray(); | |||||
return models.Select(x => new Message(this, new User(x.Author.Value), x)).ToImmutableArray(); | |||||
} | } | ||||
public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) | public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) | ||||
{ | { | ||||
var args = new GetChannelMessagesParams { Limit = limit }; | var args = new GetChannelMessagesParams { Limit = limit }; | ||||
var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | ||||
return models.Select(x => new Message(this, new User(Discord, x.Author.Value), x)).ToImmutableArray(); | |||||
return models.Select(x => new Message(this, new User(x.Author.Value), x)).ToImmutableArray(); | |||||
} | } | ||||
public async Task DeleteMessagesAsync(IEnumerable<IMessage> messages) | public async Task DeleteMessagesAsync(IEnumerable<IMessage> messages) | ||||
{ | { | ||||
@@ -62,7 +62,7 @@ namespace Discord | |||||
{ | { | ||||
var args = new CreateMessageParams { Content = text, IsTTS = isTTS }; | var args = new CreateMessageParams { Content = text, IsTTS = isTTS }; | ||||
var model = await Discord.ApiClient.CreateMessageAsync(Guild.Id, Id, args).ConfigureAwait(false); | var model = await Discord.ApiClient.CreateMessageAsync(Guild.Id, Id, args).ConfigureAwait(false); | ||||
return new Message(this, new User(Discord, model.Author.Value), model); | |||||
return new Message(this, new User(model.Author.Value), model); | |||||
} | } | ||||
public async Task<IMessage> SendFileAsync(string filePath, string text, bool isTTS) | public async Task<IMessage> SendFileAsync(string filePath, string text, bool isTTS) | ||||
{ | { | ||||
@@ -71,33 +71,33 @@ namespace Discord | |||||
{ | { | ||||
var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | ||||
var model = await Discord.ApiClient.UploadFileAsync(Guild.Id, Id, file, args).ConfigureAwait(false); | var model = await Discord.ApiClient.UploadFileAsync(Guild.Id, Id, file, args).ConfigureAwait(false); | ||||
return new Message(this, new User(Discord, model.Author.Value), model); | |||||
return new Message(this, new User(model.Author.Value), model); | |||||
} | } | ||||
} | } | ||||
public async Task<IMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS) | public async Task<IMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS) | ||||
{ | { | ||||
var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | var args = new UploadFileParams { Filename = filename, Content = text, IsTTS = isTTS }; | ||||
var model = await Discord.ApiClient.UploadFileAsync(Guild.Id, Id, stream, args).ConfigureAwait(false); | var model = await Discord.ApiClient.UploadFileAsync(Guild.Id, Id, stream, args).ConfigureAwait(false); | ||||
return new Message(this, new User(Discord, model.Author.Value), model); | |||||
return new Message(this, new User(model.Author.Value), model); | |||||
} | } | ||||
public virtual async Task<IMessage> GetMessageAsync(ulong id) | public virtual async Task<IMessage> GetMessageAsync(ulong id) | ||||
{ | { | ||||
var model = await Discord.ApiClient.GetChannelMessageAsync(Id, id).ConfigureAwait(false); | var model = await Discord.ApiClient.GetChannelMessageAsync(Id, id).ConfigureAwait(false); | ||||
if (model != null) | if (model != null) | ||||
return new Message(this, new User(Discord, model.Author.Value), model); | |||||
return new Message(this, new User(model.Author.Value), model); | |||||
return null; | return null; | ||||
} | } | ||||
public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit) | public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit) | ||||
{ | { | ||||
var args = new GetChannelMessagesParams { Limit = limit }; | var args = new GetChannelMessagesParams { Limit = limit }; | ||||
var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | ||||
return models.Select(x => new Message(this, new User(Discord, x.Author.Value), x)).ToImmutableArray(); | |||||
return models.Select(x => new Message(this, new User(x.Author.Value), x)).ToImmutableArray(); | |||||
} | } | ||||
public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) | public virtual async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit) | ||||
{ | { | ||||
var args = new GetChannelMessagesParams { Limit = limit }; | var args = new GetChannelMessagesParams { Limit = limit }; | ||||
var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | var models = await Discord.ApiClient.GetChannelMessagesAsync(Id, args).ConfigureAwait(false); | ||||
return models.Select(x => new Message(this, new User(Discord, x.Author.Value), x)).ToImmutableArray(); | |||||
return models.Select(x => new Message(this, new User(x.Author.Value), x)).ToImmutableArray(); | |||||
} | } | ||||
public async Task DeleteMessagesAsync(IEnumerable<IMessage> messages) | public async Task DeleteMessagesAsync(IEnumerable<IMessage> messages) | ||||
{ | { | ||||
@@ -149,7 +149,7 @@ namespace Discord | |||||
public async Task<IReadOnlyCollection<IUser>> GetBansAsync() | public async Task<IReadOnlyCollection<IUser>> GetBansAsync() | ||||
{ | { | ||||
var models = await Discord.ApiClient.GetGuildBansAsync(Id).ConfigureAwait(false); | var models = await Discord.ApiClient.GetGuildBansAsync(Id).ConfigureAwait(false); | ||||
return models.Select(x => new User(Discord, x)).ToImmutableArray(); | |||||
return models.Select(x => new User(x)).ToImmutableArray(); | |||||
} | } | ||||
public Task AddBanAsync(IUser user, int pruneDays = 0) => AddBanAsync(user, pruneDays); | public Task AddBanAsync(IUser user, int pruneDays = 0) => AddBanAsync(user, pruneDays); | ||||
public async Task AddBanAsync(ulong userId, int pruneDays = 0) | public async Task AddBanAsync(ulong userId, int pruneDays = 0) | ||||
@@ -254,7 +254,7 @@ namespace Discord | |||||
{ | { | ||||
var model = await Discord.ApiClient.GetGuildMemberAsync(Id, id).ConfigureAwait(false); | var model = await Discord.ApiClient.GetGuildMemberAsync(Id, id).ConfigureAwait(false); | ||||
if (model != null) | if (model != null) | ||||
return new GuildUser(this, new User(Discord, model.User), model); | |||||
return new GuildUser(this, new User(model.User), model); | |||||
return null; | return null; | ||||
} | } | ||||
public virtual async Task<IGuildUser> GetCurrentUserAsync() | public virtual async Task<IGuildUser> GetCurrentUserAsync() | ||||
@@ -266,13 +266,13 @@ namespace Discord | |||||
{ | { | ||||
var args = new GetGuildMembersParams(); | var args = new GetGuildMembersParams(); | ||||
var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false); | var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false); | ||||
return models.Select(x => new GuildUser(this, new User(Discord, x.User), x)).ToImmutableArray(); | |||||
return models.Select(x => new GuildUser(this, new User(x.User), x)).ToImmutableArray(); | |||||
} | } | ||||
public virtual async Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset) | public virtual async Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset) | ||||
{ | { | ||||
var args = new GetGuildMembersParams { Limit = limit, Offset = offset }; | var args = new GetGuildMembersParams { Limit = limit, Offset = offset }; | ||||
var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false); | var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false); | ||||
return models.Select(x => new GuildUser(this, new User(Discord, x.User), x)).ToImmutableArray(); | |||||
return models.Select(x => new GuildUser(this, new User(x.User), x)).ToImmutableArray(); | |||||
} | } | ||||
public async Task<int> PruneUsersAsync(int days = 30, bool simulate = false) | public async Task<int> PruneUsersAsync(int days = 30, bool simulate = false) | ||||
{ | { | ||||
@@ -46,7 +46,7 @@ namespace Discord | |||||
_syncedAtTicks = model.SyncedAt.UtcTicks; | _syncedAtTicks = model.SyncedAt.UtcTicks; | ||||
Role = Guild.GetRole(model.RoleId); | Role = Guild.GetRole(model.RoleId); | ||||
User = new User(Discord, model.User); | |||||
User = new User(model.User); | |||||
} | } | ||||
public async Task DeleteAsync() | public async Task DeleteAsync() | ||||
@@ -25,7 +25,7 @@ namespace Discord | |||||
{ | { | ||||
if (source == UpdateSource.Rest && IsAttached) return; | if (source == UpdateSource.Rest && IsAttached) return; | ||||
Inviter = new User(Discord, model.Inviter); | |||||
Inviter = new User(model.Inviter); | |||||
IsRevoked = model.Revoked; | IsRevoked = model.Revoked; | ||||
IsTemporary = model.Temporary; | IsTemporary = model.Temporary; | ||||
MaxAge = model.MaxAge != 0 ? model.MaxAge : (int?)null; | MaxAge = model.MaxAge != 0 ? model.MaxAge : (int?)null; | ||||
@@ -99,7 +99,7 @@ namespace Discord | |||||
{ | { | ||||
var mentions = new User[value.Length]; | var mentions = new User[value.Length]; | ||||
for (int i = 0; i < value.Length; i++) | for (int i = 0; i < value.Length; i++) | ||||
mentions[i] = new User(discord, value[i]); | |||||
mentions[i] = new User(value[i]); | |||||
MentionedUsers = ImmutableArray.Create(mentions); | MentionedUsers = ImmutableArray.Create(mentions); | ||||
} | } | ||||
else | else | ||||
@@ -4,7 +4,7 @@ using Model = Discord.API.Game; | |||||
namespace Discord | namespace Discord | ||||
{ | { | ||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | ||||
public struct Game | |||||
public class Game | |||||
{ | { | ||||
public string Name { get; } | public string Name { get; } | ||||
public string StreamUrl { get; } | public string StreamUrl { get; } | ||||
@@ -34,7 +34,7 @@ namespace Discord | |||||
public string Mention => User.Mention; | public string Mention => User.Mention; | ||||
public string Username => User.Username; | public string Username => User.Username; | ||||
public virtual UserStatus Status => User.Status; | public virtual UserStatus Status => User.Status; | ||||
public virtual Game? Game => User.Game; | |||||
public virtual Game Game => User.Game; | |||||
public DiscordClient Discord => Guild.Discord; | public DiscordClient Discord => Guild.Discord; | ||||
public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks); | public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks); | ||||
@@ -149,8 +149,14 @@ namespace Discord | |||||
if (channel == null) throw new ArgumentNullException(nameof(channel)); | if (channel == null) throw new ArgumentNullException(nameof(channel)); | ||||
return new ChannelPermissions(Permissions.ResolveChannel(this, channel, GuildPermissions.RawValue)); | return new ChannelPermissions(Permissions.ResolveChannel(this, channel, GuildPermissions.RawValue)); | ||||
} | } | ||||
public async Task<IDMChannel> CreateDMChannelAsync() | |||||
{ | |||||
var args = new CreateDMChannelParams { RecipientId = Id }; | |||||
var model = await Discord.ApiClient.CreateDMChannelAsync(args).ConfigureAwait(false); | |||||
public Task<IDMChannel> CreateDMChannelAsync() => User.CreateDMChannelAsync(); | |||||
return new DMChannel(Discord, User, model); | |||||
} | |||||
IGuild IGuildUser.Guild => Guild; | IGuild IGuildUser.Guild => Guild; | ||||
IReadOnlyCollection<IRole> IGuildUser.Roles => Roles; | IReadOnlyCollection<IRole> IGuildUser.Roles => Roles; | ||||
@@ -31,5 +31,8 @@ namespace Discord | |||||
Task KickAsync(); | Task KickAsync(); | ||||
/// <summary> Modifies this user's properties in this guild. </summary> | /// <summary> Modifies this user's properties in this guild. </summary> | ||||
Task ModifyAsync(Action<ModifyGuildMemberParams> func); | Task ModifyAsync(Action<ModifyGuildMemberParams> func); | ||||
/// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary> | |||||
Task<IDMChannel> CreateDMChannelAsync(); | |||||
} | } | ||||
} | } |
@@ -3,7 +3,7 @@ | |||||
public interface IPresence | public interface IPresence | ||||
{ | { | ||||
/// <summary> Gets the game this user is currently playing, if any. </summary> | /// <summary> Gets the game this user is currently playing, if any. </summary> | ||||
Game? Game { get; } | |||||
Game Game { get; } | |||||
/// <summary> Gets the current status of this user. </summary> | /// <summary> Gets the current status of this user. </summary> | ||||
UserStatus Status { get; } | UserStatus Status { get; } | ||||
} | } |
@@ -12,8 +12,5 @@ namespace Discord | |||||
bool IsBot { get; } | bool IsBot { get; } | ||||
/// <summary> Gets the username for this user. </summary> | /// <summary> Gets the username for this user. </summary> | ||||
string Username { get; } | string Username { get; } | ||||
/// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary> | |||||
Task<IDMChannel> CreateDMChannelAsync(); | |||||
} | } | ||||
} | } |
@@ -11,7 +11,7 @@ namespace Discord | |||||
public bool IsVerified { get; private set; } | public bool IsVerified { get; private set; } | ||||
public SelfUser(DiscordClient discord, Model model) | public SelfUser(DiscordClient discord, Model model) | ||||
: base(discord, model) | |||||
: base(model) | |||||
{ | { | ||||
} | } | ||||
public override void Update(Model model, UpdateSource source) | public override void Update(Model model, UpdateSource source) | ||||
@@ -1,4 +1,5 @@ | |||||
using Discord.API.Rest; | using Discord.API.Rest; | ||||
using System; | |||||
using System.Diagnostics; | using System.Diagnostics; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Model = Discord.API.User; | using Model = Discord.API.User; | ||||
@@ -14,19 +15,18 @@ namespace Discord | |||||
public bool IsBot { get; private set; } | public bool IsBot { get; private set; } | ||||
public string Username { get; private set; } | public string Username { get; private set; } | ||||
public override DiscordClient Discord { get; } | |||||
public override DiscordClient Discord { get { throw new NotSupportedException(); } } | |||||
public string AvatarUrl => API.CDN.GetUserAvatarUrl(Id, _avatarId); | public string AvatarUrl => API.CDN.GetUserAvatarUrl(Id, _avatarId); | ||||
public string Discriminator => _discriminator.ToString("D4"); | public string Discriminator => _discriminator.ToString("D4"); | ||||
public string Mention => MentionUtils.Mention(this, false); | public string Mention => MentionUtils.Mention(this, false); | ||||
public string NicknameMention => MentionUtils.Mention(this, true); | public string NicknameMention => MentionUtils.Mention(this, true); | ||||
public virtual Game? Game => null; | |||||
public virtual Game Game => null; | |||||
public virtual UserStatus Status => UserStatus.Unknown; | public virtual UserStatus Status => UserStatus.Unknown; | ||||
public User(DiscordClient discord, Model model) | |||||
public User(Model model) | |||||
: base(model.Id) | : base(model.Id) | ||||
{ | { | ||||
Discord = discord; | |||||
Update(model, UpdateSource.Creation); | Update(model, UpdateSource.Creation); | ||||
} | } | ||||
public virtual void Update(Model model, UpdateSource source) | public virtual void Update(Model model, UpdateSource source) | ||||
@@ -39,14 +39,6 @@ namespace Discord | |||||
Username = model.Username; | Username = model.Username; | ||||
} | } | ||||
public async Task<IDMChannel> CreateDMChannelAsync() | |||||
{ | |||||
var args = new CreateDMChannelParams { RecipientId = Id }; | |||||
var model = await Discord.ApiClient.CreateDMChannelAsync(args).ConfigureAwait(false); | |||||
return new DMChannel(Discord, this, model); | |||||
} | |||||
public override string ToString() => $"{Username}#{Discriminator}"; | public override string ToString() => $"{Username}#{Discriminator}"; | ||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id})"; | private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id})"; | ||||
} | } | ||||
@@ -5,14 +5,14 @@ namespace Discord | |||||
{ | { | ||||
internal class CachedGuildUser : GuildUser, ICachedUser | internal class CachedGuildUser : GuildUser, ICachedUser | ||||
{ | { | ||||
private Game? _game; | |||||
private Game _game; | |||||
private UserStatus _status; | private UserStatus _status; | ||||
public new DiscordSocketClient Discord => base.Discord as DiscordSocketClient; | public new DiscordSocketClient Discord => base.Discord as DiscordSocketClient; | ||||
public new CachedGuild Guild => base.Guild as CachedGuild; | public new CachedGuild Guild => base.Guild as CachedGuild; | ||||
public new CachedPublicUser User => base.User as CachedPublicUser; | public new CachedPublicUser User => base.User as CachedPublicUser; | ||||
public override Game? Game => _game; | |||||
public override Game Game => _game; | |||||
public override UserStatus Status => _status; | public override UserStatus Status => _status; | ||||
public VoiceState? VoiceState => Guild.GetVoiceState(Id); | public VoiceState? VoiceState => Guild.GetVoiceState(Id); | ||||
@@ -35,7 +35,7 @@ namespace Discord | |||||
base.Update(model, source); | base.Update(model, source); | ||||
_status = model.Status; | _status = model.Status; | ||||
_game = model.Game != null ? new Game(model.Game) : (Game?)null; | |||||
_game = model.Game != null ? new Game(model.Game) : (Game)null; | |||||
} | } | ||||
public CachedGuildUser Clone() => MemberwiseClone() as CachedGuildUser; | public CachedGuildUser Clone() => MemberwiseClone() as CachedGuildUser; | ||||
@@ -1,5 +1,4 @@ | |||||
using Discord.Data; | |||||
using ChannelModel = Discord.API.Channel; | |||||
using ChannelModel = Discord.API.Channel; | |||||
using Model = Discord.API.User; | using Model = Discord.API.User; | ||||
using PresenceModel = Discord.API.Presence; | using PresenceModel = Discord.API.Presence; | ||||
@@ -8,25 +7,25 @@ namespace Discord | |||||
internal class CachedPublicUser : User, ICachedUser | internal class CachedPublicUser : User, ICachedUser | ||||
{ | { | ||||
private int _references; | private int _references; | ||||
private Game? _game; | |||||
private UserStatus _status; | |||||
//private Game? _game; | |||||
//private UserStatus _status; | |||||
public CachedDMChannel DMChannel { get; private set; } | public CachedDMChannel DMChannel { get; private set; } | ||||
public new DiscordSocketClient Discord => base.Discord as DiscordSocketClient; | public new DiscordSocketClient Discord => base.Discord as DiscordSocketClient; | ||||
public override UserStatus Status => _status; | |||||
public override Game? Game => _game; | |||||
public override UserStatus Status => UserStatus.Unknown;// _status; | |||||
public override Game Game => null; //_game; | |||||
public CachedPublicUser(DiscordSocketClient discord, Model model) | |||||
: base(discord, model) | |||||
public CachedPublicUser(Model model) | |||||
: base(model) | |||||
{ | { | ||||
} | } | ||||
public CachedDMChannel AddDMChannel(ChannelModel model) | |||||
public CachedDMChannel AddDMChannel(DiscordSocketClient discord, ChannelModel model) | |||||
{ | { | ||||
lock (this) | lock (this) | ||||
{ | { | ||||
var channel = new CachedDMChannel(Discord, this, model); | |||||
var channel = new CachedDMChannel(discord, this, model); | |||||
DMChannel = channel; | DMChannel = channel; | ||||
return channel; | return channel; | ||||
} | } | ||||
@@ -49,10 +48,10 @@ namespace Discord | |||||
{ | { | ||||
if (source == UpdateSource.Rest) return; | if (source == UpdateSource.Rest) return; | ||||
var game = model.Game != null ? new Game(model.Game) : (Game?)null; | |||||
//var game = model.Game != null ? new Game(model.Game) : (Game)null; | |||||
_status = model.Status; | |||||
_game = game; | |||||
//_status = model.Status; | |||||
//_game = game; | |||||
} | } | ||||
public void AddRef() | public void AddRef() | ||||
@@ -60,12 +59,12 @@ namespace Discord | |||||
lock (this) | lock (this) | ||||
_references++; | _references++; | ||||
} | } | ||||
public void RemoveRef() | |||||
public void RemoveRef(DiscordSocketClient discord) | |||||
{ | { | ||||
lock (this) | lock (this) | ||||
{ | { | ||||
if (--_references == 0 && DMChannel == null) | if (--_references == 0 && DMChannel == null) | ||||
Discord.RemoveUser(Id); | |||||
discord.RemoveUser(Id); | |||||
} | } | ||||
} | } | ||||
@@ -88,7 +88,7 @@ namespace Discord | |||||
return msg; | return msg; | ||||
var model = await _discord.ApiClient.GetChannelMessageAsync(_channel.Id, id).ConfigureAwait(false); | var model = await _discord.ApiClient.GetChannelMessageAsync(_channel.Id, id).ConfigureAwait(false); | ||||
if (model != null) | if (model != null) | ||||
return new CachedMessage(_channel, new User(_discord, model.Author.Value), model); | |||||
return new CachedMessage(_channel, new User(model.Author.Value), model); | |||||
return null; | return null; | ||||
} | } | ||||
public async Task<IReadOnlyCollection<CachedMessage>> DownloadAsync(ulong? fromId, Direction dir, int limit) | public async Task<IReadOnlyCollection<CachedMessage>> DownloadAsync(ulong? fromId, Direction dir, int limit) | ||||
@@ -123,7 +123,7 @@ namespace Discord | |||||
IUser user = _channel.GetUser(x.Author.Value.Id, true); | IUser user = _channel.GetUser(x.Author.Value.Id, true); | ||||
if (user == null) | if (user == null) | ||||
{ | { | ||||
var newUser = new User(_channel.Discord, x.Author.Value); | |||||
var newUser = new User(x.Author.Value); | |||||
if (guild != null) | if (guild != null) | ||||
user = new GuildUser(guild, newUser); | user = new GuildUser(guild, newUser); | ||||
else | else | ||||
@@ -0,0 +1,27 @@ | |||||
namespace Discord | |||||
{ | |||||
namespace Discord | |||||
{ | |||||
public static class Format | |||||
{ | |||||
/// <summary> Returns a markdown-formatted string with bold formatting. </summary> | |||||
public static string Bold(string text) => $"**{text}**"; | |||||
/// <summary> Returns a markdown-formatted string with italics formatting. </summary> | |||||
public static string Italics(string text) => $"*{text}*"; | |||||
/// <summary> Returns a markdown-formatted string with underline formatting. </summary> | |||||
public static string Underline(string text) => $"__{text}__"; | |||||
/// <summary> Returns a markdown-formatted string with strikethrough formatting. </summary> | |||||
public static string Strikethrough(string text) => $"~~{text}~~"; | |||||
/// <summary> Returns a markdown-formatted string with strikeout formatting. </summary> | |||||
public static string Code(string text, string language = null) | |||||
{ | |||||
if (language != null || text.Contains("\n")) | |||||
return $"```{language ?? ""}\n{text}\n```"; | |||||
else | |||||
return $"`{text}`"; | |||||
} | |||||
} | |||||
} | |||||
} |