Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Jun 28, 2018
1 parent 29c37eb commit a6160e6
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 66 deletions.
69 changes: 24 additions & 45 deletions lib/src/main/builders/EmbedBuilder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,44 +58,32 @@ class EmbedBuilder {
Map<String, dynamic> build() {
Map<String, dynamic> tmp = new Map();

if(title != null)
tmp["title"] = title;
if (title != null) tmp["title"] = title;

if(type != null)
tmp["type"] = type;
if (type != null) tmp["type"] = type;

if(description != null)
tmp["description"] = description;
if (description != null) tmp["description"] = description;

if(url != null)
tmp["url"] = url;
if (url != null) tmp["url"] = url;

if(timestamp != null)
tmp["timestamp"] = timestamp.toIso8601String();
if (timestamp != null) tmp["timestamp"] = timestamp.toIso8601String();

if(color != null)
tmp["color"] = color;
if (color != null) tmp["color"] = color;

if(footer != null)
tmp["footer"] = footer.build();
if (footer != null) tmp["footer"] = footer.build();

if(imageUrl != null)
tmp["image"] = <String, dynamic> { "url": imageUrl };
if (imageUrl != null) tmp["image"] = <String, dynamic>{"url": imageUrl};

if(thumbnailUrl != null)
tmp["thumbnail"] = <String, dynamic> { "url": thumbnailUrl };
if (thumbnailUrl != null)
tmp["thumbnail"] = <String, dynamic>{"url": thumbnailUrl};

if(videoUrl != null)
tmp["video"] = <String, dynamic> { "url": videoUrl };
if (videoUrl != null) tmp["video"] = <String, dynamic>{"url": videoUrl};

if(provider != null)
tmp["provider"] = provider.build();
if (provider != null) tmp["provider"] = provider.build();

if(author != null)
tmp["author"] = author.build();
if (author != null) tmp["author"] = author.build();

if(_fields.length > 0)
tmp["fields"] = _fields;
if (_fields.length > 0) tmp["fields"] = _fields;

return tmp;
}
Expand All @@ -118,13 +106,11 @@ class EmbedFieldBuilder {
Map<String, dynamic> build() {
Map<String, dynamic> tmp = new Map();

if(name != null)
tmp["name"] = name;
if (name != null) tmp["name"] = name;

if(content != null)
tmp["value"] = content;
if (content != null) tmp["value"] = content;

if(inline != null)
if (inline != null)
tmp["inline"] = inline;
else
tmp["inline"] = false;
Expand All @@ -144,11 +130,9 @@ class EmbedFooterBuilder {
Map<String, dynamic> build() {
Map<String, dynamic> tmp = new Map();

if (text != null)
tmp["text"] = text;
if (text != null) tmp["text"] = text;

if (iconUrl != null)
tmp["icon_url"] = iconUrl;
if (iconUrl != null) tmp["icon_url"] = iconUrl;

return tmp;
}
Expand All @@ -165,11 +149,9 @@ class EmbedProviderBuilder {
Map<String, dynamic> build() {
Map<String, dynamic> tmp = new Map();

if (name != null)
tmp["name"] = name;
if (name != null) tmp["name"] = name;

if (url != null)
tmp["url"] = url;
if (url != null) tmp["url"] = url;

return tmp;
}
Expand All @@ -189,14 +171,11 @@ class EmbedAuthorBuilder {
Map<String, dynamic> build() {
Map<String, dynamic> tmp = new Map();

if (name != null)
tmp["name"] = name;
if (name != null) tmp["name"] = name;

if (url != null)
tmp["url"] = url;
if (url != null) tmp["url"] = url;

if (iconUrl != null)
tmp["icon_url"] = iconUrl;
if (iconUrl != null) tmp["icon_url"] = iconUrl;

return tmp;
}
Expand Down
15 changes: 9 additions & 6 deletions lib/src/main/objects/Embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Embed {
/// The embed's URL
String url;

/// Timestamp of embed content
/// Timestamp of embed content
DateTime timestamp;

/// Color of embed
Expand Down Expand Up @@ -54,7 +54,7 @@ class Embed {
this.type = raw['type'];
this.description = raw['description'];

if(raw['timestamp'] != null)
if (raw['timestamp'] != null)
this.timestamp = DateTime.parse(raw['timestamp']);

this.color = raw['color'];
Expand All @@ -66,16 +66,19 @@ class Embed {
this.video = new EmbedVideo._new(raw['video'] as Map<String, dynamic>);

if (raw.containsKey('image'))
this.image = new EmbedThumbnail._new(raw['image'] as Map<String, dynamic>);
this.image =
new EmbedThumbnail._new(raw['image'] as Map<String, dynamic>);

if(raw.containsKey('footer'))
if (raw.containsKey('footer'))
this.footer = new EmbedFooter._new(raw['footer'] as Map<String, dynamic>);

if (raw.containsKey('thumbnail'))
this.thumbnail = new EmbedThumbnail._new(raw['thumbnail'] as Map<String, dynamic>);
this.thumbnail =
new EmbedThumbnail._new(raw['thumbnail'] as Map<String, dynamic>);

if (raw.containsKey('provider'))
this.provider = new EmbedProvider._new(raw['provider'] as Map<String, dynamic>);
this.provider =
new EmbedProvider._new(raw['provider'] as Map<String, dynamic>);

fields = new Map();
raw['fields'].forEach((Map<String, dynamic> o) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/objects/EmbedAuthor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ class EmbedAuthor {
this.icon_url = raw['icon_url'];
this.iconProxyUrl = raw['iconProxyUrl'];
}
}
}
3 changes: 1 addition & 2 deletions lib/src/main/objects/EmbedField.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ part of discord;

/// Single instance of Embed's field. Can contain null elements.
class EmbedField {

/// Field name
String name;

Expand All @@ -25,4 +24,4 @@ class EmbedField {

this.embed.fields[name] = this;
}
}
}
2 changes: 1 addition & 1 deletion lib/src/main/objects/EmbedFooter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class EmbedFooter {
iconUrl = raw['icon_url'];
iconProxyUrl = raw['icon_proxy_url'];
}
}
}
4 changes: 2 additions & 2 deletions lib/src/main/objects/EmbedVideo.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of discord;

/// Video attached to embed. Can contain null elements.
class EmbedVideo {
class EmbedVideo {
/// The embed video's URL.
String url;

Expand All @@ -19,4 +19,4 @@ class EmbedVideo {
this.height = raw['height'];
this.width = raw['width'];
}
}
}
7 changes: 5 additions & 2 deletions lib/src/main/objects/TextChannel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ class TextChannel extends GuildChannel {
newContent = content;
}

final HttpResponse r = await this.client.http.send(
'POST', '/channels/${this.id}/messages', body: <String, dynamic>{
final HttpResponse r = await this
.client
.http
.send('POST', '/channels/${this.id}/messages', body: <String, dynamic>{
"content": newContent,
"tts": tts,
"nonce": nonce,
Expand All @@ -69,6 +71,7 @@ class TextChannel extends GuildChannel {
}

@deprecated

/// Sends a message.
///
/// Throws an [Exception] if the HTTP request errored.
Expand Down
16 changes: 9 additions & 7 deletions test/discord.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ void main() {
m.channel.send(content: "Command '${m.content}' not found!");
})
..cooldownEvent.listen((m) {
m.channel
.send(content: "Command is on cooldown!. Wait a few seconds!");
m.channel.send(content: "Command is on cooldown!. Wait a few seconds!");
})
..ignoreBots = false;

Expand All @@ -48,7 +47,7 @@ void main() {

discord.EmbedBuilder createTestEmbed() {
return new discord.EmbedBuilder("Test title")
..addField(name: "Test field", value: "Test value");
..addField(name: "Test field", value: "Test value");
}

bot.onReady.listen((e) async {
Expand Down Expand Up @@ -78,7 +77,8 @@ void main() {
await cc.delete();

print("TESTING EMBEDS");
var e = await channel.send(content: "Testing embed!", embed: createTestEmbed());
var e =
await channel.send(content: "Testing embed!", embed: createTestEmbed());
await e.delete();
});

Expand Down Expand Up @@ -112,12 +112,14 @@ void main() {
if (m.channel.id == "422285619952222208" &&
m.author.id == bot.user.id &&
m.content == "Testing embed!") {
if(m.embeds.length > 0) {
if (m.embeds.length > 0) {
var embed = m.embeds.values.toList()[0];
if(embed.title == "Test title" && embed.fields.length > 0) {
if (embed.title == "Test title" && embed.fields.length > 0) {
var field = embed.fields.values.toList()[0];

if(field.name == "Test field" && field.content == "Test value" && !field.inline) {
if (field.name == "Test field" &&
field.content == "Test value" &&
!field.inline) {
await m.channel.send(content: "Tests completed successfully!");
print("Nyxx tests completed successfully!");
await bot.destroy();
Expand Down

0 comments on commit a6160e6

Please sign in to comment.