Skip to content

Commit

Permalink
Merge pull request #314 from nyxx-discord/dev
Browse files Browse the repository at this point in the history
Release 3.3.0
  • Loading branch information
l7ssha authored Mar 15, 2022
2 parents 0578eff + 3440f29 commit 3f83b51
Show file tree
Hide file tree
Showing 35 changed files with 469 additions and 163 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
## 3.3.0
__15.03.2022__

- feature: Guild emoji improvements (#305)
- Added missing properties on `IBaseGuildEmoji`.
- Partial emoji can be now resolved to it's full instance with `resolve()` method
- Author of emoji can be now resolved with `fetchCreator()`
- feature: Allow editing messages to remove content (#313)
- feature: Add previous state to *UpdateEvents (#311)
- bug: fix: initialize name and format values for PartialSticker (#308)
- bug: Make IHttpResponseError subclass Exception (#303)
- bug: Update documentation (#302)

## 3.3.0-dev.1
__05.03.2022__

- feature: Guild emoji improvements (#305)
- Added missing properties on `IBaseGuildEmoji`.
- Partial emoji can be now resolved to it's full instance with `resolve()` method
- Author of emoji can be now resolved with `fetchCreator()`
- bug: Make IHttpResponseError subclass Exception (#303)
- bug: Update documentation (#302)

## 3.3.0-dev.0
__08.02.2022__

- feature: Implement TextInput component type

## 3.2.7
__08.02.2022__

Expand Down
43 changes: 43 additions & 0 deletions example/emojis.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:nyxx/nyxx.dart';

void main(List<String> args) {
// Create new bot instance. Replace string with your token
final bot = NyxxFactory.createNyxxWebsocket("<TOKEN>", GatewayIntents.allUnprivileged)
..registerPlugin(Logging()) // Default logging plugin
..registerPlugin(CliIntegration()) // Cli integration for nyxx allows stopping application via SIGTERM and SIGKILl
..registerPlugin(IgnoreExceptions()) // Plugin that handles uncaught exceptions that may occur
..connect();
bot.eventsWs.onReady.listen((_) {
print('Ready!');
});
// This event is called when a message is received
bot.eventsWs.onMessageReceived.listen((event) async {
if(event.message.content == '!emoji') {
final emoji = event.message.guild?.getFromCache()?.emojis.values.firstWhere((emo) => emo.name == 'nyxx');
final msg = await event.message.channel.sendMessage(MessageBuilder.content('Look at this emoji: $emoji'));
msg.createReaction(emoji!);
// For unicode emoji use `UnicodeEmoji` class
msg.createReaction(UnicodeEmoji('🤔'));
}
});

// This event is called when a reaction has been added to a message
bot.eventsWs.onMessageReactionAdded.listen((event) {
if (event.emoji is UnicodeEmoji) {
event.message?.channel.sendMessage(
MessageBuilder.content(
'Woah! This is a unicode emoji: ${event.emoji}',
),
);
} else if (event.emoji is IGuildEmojiPartial) {
if(event.emoji is IResolvableGuildEmojiPartial) {
final emoji = (event.emoji as IResolvableGuildEmojiPartial).resolve();
event.message?.channel.sendMessage(
MessageBuilder.content(
'Woah! This is a custom emoji: ${emoji.name}',
),
);
}
}
});
}
7 changes: 4 additions & 3 deletions lib/nyxx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export 'src/core/guild/status.dart' show IClientStatus, UserStatus;
export 'src/core/guild/webhook.dart' show IWebhook, WebhookType;
export 'src/core/message/attachment.dart' show IAttachment;
export 'src/core/message/emoji.dart' show IEmoji;
export 'src/core/message/guild_emoji.dart' show IBaseGuildEmoji, IGuildEmoji, IGuildEmojiPartial;
export 'src/core/message/guild_emoji.dart' show IBaseGuildEmoji, IGuildEmoji, IGuildEmojiPartial, IResolvableGuildEmojiPartial;
export 'src/core/message/message.dart' show IMessage;
export 'src/core/message/message_flags.dart' show MessageFlags;
export 'src/core/message/message_reference.dart' show IMessageReference;
Expand All @@ -58,7 +58,7 @@ export 'src/core/message/reaction.dart' show IReaction;
export 'src/core/message/referenced_message.dart' show IReferencedMessage;
export 'src/core/message/sticker.dart' show IStandardSticker, IStickerPack, ISticker, IGuildSticker, IPartialSticker;
export 'src/core/message/unicode_emoji.dart' show IUnicodeEmoji, UnicodeEmoji;
export 'src/core/message/components/component_style.dart' show ComponentStyle;
export 'src/core/message/components/component_style.dart' show ButtonStyle;
export 'src/core/message/components/message_component.dart'
show
IMessageButton,
Expand All @@ -69,7 +69,8 @@ export 'src/core/message/components/message_component.dart'
IMessageMultiselect,
IMessageMultiselectOption,
MessageComponentEmoji,
ComponentType;
ComponentType,
IMessageTextInput;
export 'src/core/permissions/permission_overrides.dart' show IPermissionsOverrides;
export 'src/core/permissions/permissions.dart' show IPermissions;
export 'src/core/permissions/permissions_constants.dart' show PermissionsConstants;
Expand Down
7 changes: 1 addition & 6 deletions lib/src/client_options.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import 'package:nyxx/nyxx.dart';
import 'package:nyxx/src/nyxx.dart';
import 'package:nyxx/src/core/allowed_mentions.dart';
import 'package:nyxx/src/core/channel/channel.dart';
import 'package:nyxx/src/core/message/message.dart';
import 'package:nyxx/src/core/user/member.dart';
import 'package:nyxx/src/internal/cache/cache_policy.dart';
import 'package:nyxx/src/internal/shard/shard.dart';
import 'package:nyxx/src/utils/builders/presence_builder.dart';

/// Options for configuring cache. Allows to specify where and which entities should be cached and preserved in cache
class CacheOptions {
Expand Down
1 change: 1 addition & 0 deletions lib/src/core/allowed_mentions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AllowedMentions extends Builder {
/// Allow @everyone and @here if [everyone] is true
/// Allow @user if [users] is true
/// Allow @role if [roles] is true
/// Mention the user on reply if [reply] is true
void allow({bool? reply, bool? everyone, bool? users, bool? roles}) {
if (everyone != null) {
_allowEveryone = everyone;
Expand Down
6 changes: 2 additions & 4 deletions lib/src/core/audit_logs/audit_log_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ class AuditLogEntry extends SnowflakeEntity implements IAuditLogEntry {
user = UserCacheable(client, Snowflake(raw["user_id"]));
type = AuditLogEntryType._create(raw["action_type"] as int);

if (raw["options"] != null) {
options = raw["options"] as String;
}
options = raw["options"] as String?;

reason = raw["reason"] as String;
reason = raw["reason"] as String?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/core/channel/guild/guild_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class IGuildChannel implements IMinimalGuildChannel {
/// Fetches and returns all channel"s [Invite]s
///
/// ```
/// var invites = await chan.getChannelInvites();
/// var invites = await chan.fetchChannelInvites();
/// ```
Stream<IInviteWithMeta> fetchChannelInvites();

Expand Down
46 changes: 32 additions & 14 deletions lib/src/core/channel/text_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,70 @@ abstract class ITextChannel implements IChannel, ISend {
/// Returns [IMessage] downloaded from API
Future<IMessage> fetchMessage(Snowflake id);

/// Sends message to channel. Performs `toString()` on thing passed to [content]. Allows to send embeds with [embed] field.
/// Sends message to channel. Allows to send embeds with [MessageBuilder.embed()] method.
///
/// ```
/// await channel.sendMessage(content: "Very nice message!");
/// await channel.sendMessage(MessageBuilder.content("Very nice message!"));
/// ```
///
/// Can be used in combination with Emoji. Just run `toString()` on Emoji instance:
/// ```
/// final emoji = guild.emojis.findOne((e) => e.name.startsWith("dart"));
/// await channel.send(content: "Dart is superb! ${emoji.toString()}");
/// await channel.sendMessage(MessageBuilder.content("Dart is superb! ${emoji.toString()}"));
/// ```
/// Embeds can be sent very easily:
/// ```
/// var embed = EmbedBuilder()
/// ..title = "Example Title"
/// ..addField(name: "Memory usage", value: "${ProcessInfo.currentRss / 1024 / 1024}MB");
///
/// await channel.sendMessage(embed: embed);
/// await channel.sendMessage(MessageBuilder.embed(embed));
/// ```
///
/// Method also allows to send file and optional [content] with [embed].
/// Use `expandAttachment(String file)` method to expand file names in embed
/// Method also allows to send multiple files and optional [content] with [embed].
///
/// ```
/// await channel.sendMessage(files: [new File("kitten.png"), new File("kitten.jpg")], content: "Kittens ^-^"]);
/// await event.message.channel.sendMessage(
/// MessageBuilder.files(
/// [
/// AttachmentBuilder.file(
/// File("kitten.png"),
/// name: "kitten.png",
/// ),
/// ],
/// )..content = "Kittens ^-^",
/// );
/// ```
/// You can refer the sent attachments in embeds by prefixing them with `attachment://`:
/// ```
/// var embed = new nyxx.EmbedBuilder()
/// var embed = EmbedBuilder()
/// ..title = "Example Title"
/// ..thumbnailUrl = "${attach("kitten.jpg")}";
/// ..thumbnailUrl = "attachment://kitten.jpg";
///
/// channel.sendMessage(files: [new File("kitten.jpg")], embed: embed, content: "HEJKA!");
/// await event.message.channel.sendMessage(
/// MessageBuilder.files(
/// [
/// AttachmentBuilder.file(
/// File("kitten.jpg"),
/// ),
/// ],
/// )
/// ..embeds = [embed]
/// ..content = "HEJKA!",
/// );
/// ```
@override
Future<IMessage> sendMessage(MessageBuilder builder);

/// Bulk removes many messages by its ids. [messages] is list of messages ids to delete.
/// Bulk removes many referenced messages. Where [messages] is list of messages to delete.
///
/// ```
/// var toDelete = channel.messages.take(5);
/// var toDelete = channel.messageCache.take(5);
/// await channel.bulkRemoveMessages(toDelete);
/// ```
Future<void> bulkRemoveMessages(Iterable<IMessage> messages);

/// Gets several [IMessage] objects from API. Only one of [after], [before], [around] can be specified,
/// otherwise, it will throw.
/// Gets several [IMessage] objects from API.
///
/// ```
/// var messages = await channel.downloadMessages(limit: 100, after: Snowflake("222078108977594368"));
Expand Down
1 change: 1 addition & 0 deletions lib/src/core/channel/thread_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ abstract class IThreadChannel implements MinimalGuildChannel, ITextChannel {
/// Adds [user] to [ThreadChannel]
Future<void> addThreadMember(SnowflakeEntity user);

/// Edits this [ThreadChannel] and returns the edited [ThreadChannel]
Future<ThreadChannel> edit(ThreadBuilder builder);
}

Expand Down
32 changes: 20 additions & 12 deletions lib/src/core/embed/embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,52 +107,60 @@ class Embed implements IEmbed {

/// Creates an instance [Embed]
Embed(RawApiMap raw) {
if (raw["title"] != null) {
title = raw["title"] as String;
}
title = raw["title"] as String?;

if (raw["url"] != null) {
url = raw["url"] as String;
}
url = raw["url"] as String?;

if (raw["type"] != null) {
type = raw["type"] as String;
}
type = raw["type"] as String?;

if (raw["description"] != null) {
description = raw["description"] as String;
}
description = raw["description"] as String?;

if (raw["timestamp"] != null) {
timestamp = DateTime.parse(raw["timestamp"] as String);
} else {
timestamp = null;
}

if (raw["color"] != null) {
color = DiscordColor.fromInt(raw["color"] as int);
} else {
color = null;
}

if (raw["author"] != null) {
author = EmbedAuthor(raw["author"] as RawApiMap);
} else {
author = null;
}

if (raw["video"] != null) {
video = EmbedVideo(raw["video"] as RawApiMap);
} else {
video = null;
}

if (raw["image"] != null) {
image = EmbedThumbnail(raw["image"] as RawApiMap);
} else {
image = null;
}

if (raw["footer"] != null) {
footer = EmbedFooter(raw["footer"] as RawApiMap);
} else {
footer = null;
}

if (raw["thumbnail"] != null) {
thumbnail = EmbedThumbnail(raw["thumbnail"] as RawApiMap);
} else {
thumbnail = null;
}

if (raw["provider"] != null) {
provider = EmbedProvider(raw["provider"] as RawApiMap);
} else {
provider = null;
}

fields = [
Expand Down
8 changes: 2 additions & 6 deletions lib/src/core/embed/embed_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ class EmbedProvider implements IEmbedProvider {

/// Creates an instance of [EmbedProvider]
EmbedProvider(RawApiMap raw) {
if (raw["name"] != null) {
name = raw["name"] as String?;
}
name = raw["name"] as String?;

if (raw["url"] != null) {
url = raw["url"] as String?;
}
url = raw["url"] as String?;
}
}
Loading

0 comments on commit 3f83b51

Please sign in to comment.