Fix examples

This commit is contained in:
Szymon Uglis 2021-03-30 23:21:33 +02:00
parent 15823cb437
commit dd5355b0f2
No known key found for this signature in database
GPG key ID: 112376C5BEE91FE2
6 changed files with 11 additions and 10 deletions

View file

@ -3,8 +3,6 @@ analyzer:
- non-nullable
strong-mode:
implicit-casts: false
exclude:
- example/**
linter:
rules:
- avoid_empty_else

View file

@ -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}");
}
});
}

View file

@ -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"

View file

@ -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);

View file

@ -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"

View file

@ -40,6 +40,9 @@ class Snowflake implements Comparable<Snowflake> {
/// 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);