Browse Source

SendMessage now returns an array of all created messages

tags/docs-0.9
Brandon Smith 10 years ago
parent
commit
f9f31c3c04
1 changed files with 13 additions and 7 deletions
  1. +13
    -7
      Discord.Net/DiscordClient.cs

+ 13
- 7
Discord.Net/DiscordClient.cs View File

@@ -665,30 +665,33 @@ namespace Discord
} }


//Chat //Chat
public Task SendMessage(Channel channel, string text)
public Task<Message[]> SendMessage(Channel channel, string text)
=> SendMessage(channel.Id, text, new string[0]); => SendMessage(channel.Id, text, new string[0]);
public Task SendMessage(string channelId, string text)
public Task<Message[]> SendMessage(string channelId, string text)
=> SendMessage(channelId, text, new string[0]); => SendMessage(channelId, text, new string[0]);
public Task SendMessage(Channel channel, string text, string[] mentions)
public Task<Message[]> SendMessage(Channel channel, string text, string[] mentions)
=> SendMessage(channel, text, mentions); => SendMessage(channel, text, mentions);
public async Task SendMessage(string channelId, string text, string[] mentions)
public async Task<Message[]> SendMessage(string channelId, string text, string[] mentions)
{ {
CheckReady(); CheckReady();
if (text.Length <= 2000) if (text.Length <= 2000)
{ {
var msg = await DiscordAPI.SendMessage(channelId, text, mentions, _httpOptions); var msg = await DiscordAPI.SendMessage(channelId, text, mentions, _httpOptions);
_messages.Update(msg.Id, channelId, msg);
return new Message[] { _messages.Update(msg.Id, channelId, msg) };
} }
else else
{ {
int blockCount = (int)Math.Ceiling(text.Length / (double)DiscordAPI.MaxMessageSize); int blockCount = (int)Math.Ceiling(text.Length / (double)DiscordAPI.MaxMessageSize);
Message[] result = new Message[blockCount];
for (int i = 0; i < blockCount; i++) for (int i = 0; i < blockCount; i++)
{ {
int index = i * DiscordAPI.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, channelId, msg);
result[i] = _messages.Update(msg.Id, channelId, msg);
await Task.Delay(1000); await Task.Delay(1000);
} }
return result;
} }
} }


@@ -714,13 +717,16 @@ namespace Discord


public Task DeleteMessage(Message msg) public Task DeleteMessage(Message msg)
=> DeleteMessage(msg.ChannelId, msg.Id); => DeleteMessage(msg.ChannelId, msg.Id);
public async Task DeleteMessage(string channelId, string msgId)
public async Task<Message> DeleteMessage(string channelId, string msgId)
{ {
try try
{ {
await DiscordAPI.DeleteMessage(channelId, msgId, _httpOptions); await DiscordAPI.DeleteMessage(channelId, msgId, _httpOptions);
return _messages.Remove(msgId);
} }
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { } catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { }
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.InternalServerError) { } //TODO: Remove me - temporary fix for deleting nonexisting messages
return null;
} }


//Voice //Voice


Loading…
Cancel
Save