Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement thumbnail into embeds #29

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export 'src/api/channels/text_channel.dart' show TextChannel;
export 'src/api/channels/category_channel.dart' show CategoryChannel;

export 'src/api/message.dart' show Message;
export 'src/api/message_embed.dart' show MessageEmbed, Footer, Image, Author, Field;
export 'src/api/message_embed.dart' show MessageEmbed, Footer, Image, Thumbnail, Author, Field;
export 'src/api/color.dart' show Color;

export 'src/api/emoji.dart' show Emoji;
Expand Down
25 changes: 24 additions & 1 deletion lib/src/api/message_embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ class Image {
};
}

class Thumbnail {
String url;
String? proxyUrl;
int? height;
int? width;

Thumbnail({ required this.url, this.proxyUrl, this.height, this.width });

Object toJson () => {
'url': url,
'proxy_url': proxyUrl,
'width': width,
'height': height,
};
}

class Author {
String name;
String? url;
Expand Down Expand Up @@ -67,7 +83,7 @@ class MessageEmbed {
DateTime? timestamp;
Footer? footer;
Image? image;
// Thumbnail thumbnail;
Thumbnail? thumbnail;
Author? author;
List<Field>? fields;
Color? color;
Expand All @@ -79,6 +95,7 @@ class MessageEmbed {
this.timestamp,
this.footer,
this.image,
this.thumbnail,
this.author,
this.fields,
this.color,
Expand All @@ -104,6 +121,11 @@ class MessageEmbed {
return this;
}

MessageEmbed setThumbnail ({ required String url, String? proxyUrl, int? width, int? height }) {
thumbnail = Thumbnail(url: url, proxyUrl: proxyUrl, width: width, height: height);
return this;
}

MessageEmbed setAuthor ({ required String name, String? url, String? iconUrl, String? proxyIconUrl }) {
author = Author(name: name, url: url, iconUrl: iconUrl, proxyIconUrl: proxyIconUrl);
return this;
Expand Down Expand Up @@ -146,6 +168,7 @@ class MessageEmbed {
'fields': fields,
'color': color != null ? int.parse(color.toString().replaceAll('#', ''), radix: 16) : null,
'image': image?.toJson(),
'thumbnail': thumbnail?.toJson(),
};
}
}