From dd5355b0f2ace76accc8da2bc6d48495ed50c0f2 Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Tue, 30 Mar 2021 23:21:33 +0200 Subject: [PATCH] Fix examples --- nyxx/analysis_options.yaml | 2 -- nyxx/example/channel.dart | 6 +++--- nyxx/example/kick-ban.dart | 4 ++-- nyxx/example/permissions.dart | 4 ++-- nyxx/example/sending-file.dart | 2 +- nyxx/lib/src/core/Snowflake.dart | 3 +++ 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/nyxx/analysis_options.yaml b/nyxx/analysis_options.yaml index a7cdb3aa..7cfb55e8 100644 --- a/nyxx/analysis_options.yaml +++ b/nyxx/analysis_options.yaml @@ -3,8 +3,6 @@ analyzer: - non-nullable strong-mode: implicit-casts: false - exclude: - - example/** linter: rules: - avoid_empty_else diff --git a/nyxx/example/channel.dart b/nyxx/example/channel.dart index 2055494e..900e353a 100644 --- a/nyxx/example/channel.dart +++ b/nyxx/example/channel.dart @@ -23,16 +23,16 @@ void main() { final guild = (e.message as GuildMessage).guild.getFromCache()!; // Created text channel. Remember discord will lower the case of name and replace spaces with - and do other sanitization - final channel = (await guild.createChannel("TEST CHANNEL", ChannelType.text)) as GuildTextChannel; + final channel = await guild.createChannel(ChannelBuilder("Test channel", ChannelType.text)) as TextGuildChannel; // Send feedback - await e.message.channel.getFromCache().sendMessage(content: "Crated ${channel.mention}"); + await e.message.channel.getFromCache()?.sendMessage(content: "Crated ${channel.mention}"); // Delete channel that we just created await channel.delete(); // Send feedback - await e.message.channel.send(content: "Deleted ${channel.mention}"); + await e.message.channel.getFromCache()?.sendMessage(content: "Deleted ${channel.mention}"); } }); } diff --git a/nyxx/example/kick-ban.dart b/nyxx/example/kick-ban.dart index d7a5b71b..305a1de2 100644 --- a/nyxx/example/kick-ban.dart +++ b/nyxx/example/kick-ban.dart @@ -4,7 +4,7 @@ import "package:nyxx/nyxx.dart"; SnowflakeEntity getUserToBan(GuildMessage message) { // If mentions are not empty return first mention if(message.mentions.isNotEmpty) { - return message.mentions.first; + return message.mentions.first.id.toSnowflakeEntity(); } // Otherwise split message by spaces then take lst part and parse it to snowflake and return as Snowflake entity @@ -38,7 +38,7 @@ void main() { await (e.message as GuildMessage).guild.getFromCache()!.ban(userToBan); // Send feedback - await e.message.channel.getFromCache()?.send(content: "👍"); + await e.message.channel.getFromCache()?.sendMessage(content: "👍"); } // Check if message content equals "!embed" diff --git a/nyxx/example/permissions.dart b/nyxx/example/permissions.dart index b9192ffa..0df739df 100644 --- a/nyxx/example/permissions.dart +++ b/nyxx/example/permissions.dart @@ -21,10 +21,10 @@ void main() { } // Get current channel - final messageChannel = (e.message.channel.getFromCache()) as GuildChannel; + final messageChannel = e.message.channel.getFromCache() as GuildChannel; // Get member from id - final member = await (e.message as GuildMessage).guild.getFromCache()!.members[302359032612651009.toSnowflake()]!; + final member = (e.message as GuildMessage).guild.getFromCache()!.members[302359032612651009.toSnowflake()]!; // Get current member permissions in context of channel final permissions = await messageChannel.effectivePermissions(member); diff --git a/nyxx/example/sending-file.dart b/nyxx/example/sending-file.dart index 71a6100e..667592d2 100644 --- a/nyxx/example/sending-file.dart +++ b/nyxx/example/sending-file.dart @@ -19,7 +19,7 @@ void main() { // Files argument needs to be list of AttachmentBuilder object with // path to file that you want to send. You can also use other // AttachmentBuilder constructors to send File object or raw bytes - e.message.channel.getFromCache().sendMessage(files: [AttachmentBuilder.path("kitten.jpeg")]); + e.message.channel.getFromCache()?.sendMessage(files: [AttachmentBuilder.path("kitten.jpeg")]); } // Check if message content equals "!givemeembed" diff --git a/nyxx/lib/src/core/Snowflake.dart b/nyxx/lib/src/core/Snowflake.dart index 78326c84..d1d89efc 100644 --- a/nyxx/lib/src/core/Snowflake.dart +++ b/nyxx/lib/src/core/Snowflake.dart @@ -40,6 +40,9 @@ class Snowflake implements Comparable { /// Creates synthetic snowflake based on given [date]. Snowflake.fromDateTime(DateTime date) : _id = _parseId(date); + /// Returns [SnowflakeEntity] from current [Snowflake] + SnowflakeEntity toSnowflakeEntity() => SnowflakeEntity(this); + /// Checks if given [Snowflake] [s] is created before this instance bool isBefore(Snowflake s) => this.timestamp.isBefore(s.timestamp);