Doc fixes, message == fix,

[ci skip]
This commit is contained in:
Szymon Uglis 2020-06-24 23:26:23 +02:00
parent 7bb4f6a987
commit cc49a9e111
4 changed files with 53 additions and 19 deletions

View file

@ -4,6 +4,7 @@ part of nyxx;
abstract class ITextChannel implements Channel, MessageChannel {
/// Returns message with given [id]. Allows to force fetch message from api
/// with [ignoreCache] property. By default it checks if message is in cache and fetches from api if not.
@override
Future<Message?> getMessage(Snowflake id, {bool ignoreCache = false});
/// Sends message to channel. Performs `toString()` on thing passed to [content]. Allows to send embeds with [embed] field.
@ -49,12 +50,15 @@ abstract class ITextChannel implements Channel, MessageChannel {
MessageBuilder? builder});
/// Starts typing.
@override
Future<void> startTyping();
/// Loops `startTyping` until `stopTypingLoop` is called.
@override
void startTypingLoop();
/// Stops a typing loop if one is running.
@override
void stopTypingLoop();
/// Bulk removes many messages by its ids. [messagesIds] is list of messages ids to delete.
@ -63,6 +67,7 @@ abstract class ITextChannel implements Channel, MessageChannel {
/// var toDelete = chan.messages.keys.take(5);
/// await chan.bulkRemoveMessages(toDelete);
/// ```
@override
Future<void> bulkRemoveMessages(Iterable<Message> messagesIds);
/// Gets several [Message] objects from API. Only one of [after], [before], [around] can be specified,
@ -71,5 +76,6 @@ abstract class ITextChannel implements Channel, MessageChannel {
/// ```
/// var messages = await chan.getMessages(limit: 100, after: Snowflake("222078108977594368"));
/// ```
@override
Stream<Message> getMessages({int limit = 50, Snowflake? after, Snowflake? before, Snowflake? around});
}

View file

@ -50,6 +50,7 @@ class GuildMessage extends Message implements GuildEntity {
/// True if message is sent by a webhook
bool get isByWebhook => author is Webhook;
/// Role mentions in this message
late final List<IRole> roleMentions;
GuildMessage._new(Map<String, dynamic> raw, Nyxx client) : super._new(raw, client) {
@ -68,6 +69,7 @@ class GuildMessage extends Message implements GuildEntity {
if (member == null) {
if (raw["member"] == null) {
this.author = User._new(raw["author"] as Map<String, dynamic>, client);
this.client.users[this.author.id] = this.author as User;
} else {
final authorData = raw["author"] as Map<String, dynamic>;
final memberData = raw["member"] as Map<String, dynamic>;
@ -275,7 +277,19 @@ abstract class Message extends SnowflakeEntity implements Disposable {
@override
bool operator ==(other) {
if (other is Message) {
return other.content == this.content || other.embeds.any((e) => this.embeds.any((f) => e == f));
return this.id == other.id;
}
if(other is Snowflake) {
return this.id == other;
}
if(other is int) {
return this.id == other;
}
if(other is String) {
return this.id == other;
}
return false;

View file

@ -11,8 +11,10 @@ class DisconnectEvent {
DisconnectEvent._new(this.shard, this.reason);
}
/// Reason why shard was disconnected.
class DisconnectEventReason extends IEnum<int> {
/// When shard is disconnected due invalid shard session.
static const DisconnectEventReason invalidSession = const DisconnectEventReason._from(9);
const DisconnectEventReason._from(int value) : super(value);
}
}

View file

@ -1,24 +1,36 @@
part of nyxx;
/// Allows to build object of user presence used later when setting user presence.
class PresenceBuilder implements Builder {
final UserStatus? status;
final bool? afk;
final Activity? game;
/// Status of user.
UserStatus? status;
/// If is afk
bool? afk;
/// Type of activity.
Activity? game;
/// WHen activity was started
DateTime? since;
PresenceBuilder({this.status, this.afk, this.game, this.since});
/// Empty constructor to when setting all values manually.
PresenceBuilder();
/// Default builder constructor.
PresenceBuilder.of({this.status, this.afk, this.game, this.since});
@override
Map<String, dynamic> _build() =>
<String, dynamic> {
"status": (status != null) ? status.toString() : UserStatus.online.toString(),
"afk": (afk != null) ? afk : false,
if (game != null)
"game": <String, dynamic>{
"name": game!.name,
"type": game!.type.value,
if (game!.type == ActivityType.streaming) "url": game!.url
},
"since": (since != null) ? since!.millisecondsSinceEpoch : null
};
}
Map<String, dynamic> _build() => <String, dynamic>{
"status":
(status != null) ? status.toString() : UserStatus.online.toString(),
"afk": (afk != null) ? afk : false,
if (game != null)
"game": <String, dynamic>{
"name": game!.name,
"type": game!.type.value,
if (game!.type == ActivityType.streaming) "url": game!.url
},
"since": (since != null) ? since!.millisecondsSinceEpoch : null
};
}