From 12674b6d36d060be43312f6cce36a95e46376f4b Mon Sep 17 00:00:00 2001 From: Zachary Vacura Date: Wed, 21 Sep 2016 15:28:19 -0500 Subject: [PATCH 1/9] Attempted travis integration --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e04ca4d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: dart +install: pub global activate linter +script: pub global run linter . From 674a7f6820ac2afc19e8099097f01ba15a260a20 Mon Sep 17 00:00:00 2001 From: Zachary Vacura Date: Wed, 21 Sep 2016 15:32:51 -0500 Subject: [PATCH 2/9] Updated readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f9c888..68fda49 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Discord Dart -A Dart library for Discord +[![Build Status](https://travis-ci.org/Hackzzila/Discord-Dart.svg)](https://travis-ci.org/Hackzzila/Discord-Dart) +
+A Dart library for Discord
[Join Our Discord Server](https://discord.gg/6JwnkNk) From 260f64a23912e5beb70b7cd4d0b2436864610d4d Mon Sep 17 00:00:00 2001 From: Zachary Vacura Date: Wed, 21 Sep 2016 15:36:54 -0500 Subject: [PATCH 3/9] readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 68fda49..03fee00 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Discord Dart [![Build Status](https://travis-ci.org/Hackzzila/Discord-Dart.svg)](https://travis-ci.org/Hackzzila/Discord-Dart) +[![Our Discord Server](https://img.shields.io/badge/discord-Discord%20Dart-7289DA.svg)](https://discord.gg/6JwnkNk)
-A Dart library for Discord
-[Join Our Discord Server](https://discord.gg/6JwnkNk) +A Dart library for Discord From 818ba2f7e06c65459eee71ecce5d151547807f6e Mon Sep 17 00:00:00 2001 From: Zachary Vacura Date: Wed, 21 Sep 2016 15:47:07 -0500 Subject: [PATCH 4/9] Updated readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 03fee00..ef65f5e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Discord Dart [![Build Status](https://travis-ci.org/Hackzzila/Discord-Dart.svg)](https://travis-ci.org/Hackzzila/Discord-Dart) [![Our Discord Server](https://img.shields.io/badge/discord-Discord%20Dart-7289DA.svg)](https://discord.gg/6JwnkNk) +[![Pub](https://img.shields.io/pub/v/box2d.svg?maxAge=2592000)](https://pub.dartlang.org/packages/discord_dart) +
A Dart library for Discord From 09815fdaceb407030f8dae114f788a8dfc85c13d Mon Sep 17 00:00:00 2001 From: Zachary Vacura Date: Wed, 21 Sep 2016 15:48:13 -0500 Subject: [PATCH 5/9] Updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ef65f5e..121d720 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Discord Dart [![Build Status](https://travis-ci.org/Hackzzila/Discord-Dart.svg)](https://travis-ci.org/Hackzzila/Discord-Dart) [![Our Discord Server](https://img.shields.io/badge/discord-Discord%20Dart-7289DA.svg)](https://discord.gg/6JwnkNk) -[![Pub](https://img.shields.io/pub/v/box2d.svg?maxAge=2592000)](https://pub.dartlang.org/packages/discord_dart) +[![Pub](https://img.shields.io/pub/v/discord_dart.svg)](https://pub.dartlang.org/packages/discord_dart)
A Dart library for Discord From 39201e26d216c185345e325d554c75e9dd76c661 Mon Sep 17 00:00:00 2001 From: Zachary Vacura Date: Wed, 21 Sep 2016 15:59:38 -0500 Subject: [PATCH 6/9] Fixed travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e04ca4d..b6a7a91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: dart install: pub global activate linter -script: pub global run linter . +script: pub global run linter lib/ From 2d9b09c6ba1725014acb3522773921d6f9bc38a8 Mon Sep 17 00:00:00 2001 From: Zachary Vacura Date: Wed, 21 Sep 2016 16:01:08 -0500 Subject: [PATCH 7/9] Fixed again --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b6a7a91..4405552 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: dart -install: pub global activate linter +install: pub get && pub global activate linter script: pub global run linter lib/ From 3730016c1edbdc568fc5b24b1ba62d4240c397ce Mon Sep 17 00:00:00 2001 From: Zachary Vacura Date: Wed, 21 Sep 2016 17:19:35 -0500 Subject: [PATCH 8/9] Made linter happy --- lib/src/client.dart | 120 +++++++++---------- lib/src/events/ChannelCreateEvent.dart | 7 +- lib/src/events/ChannelDeleteEvent.dart | 7 +- lib/src/events/ChannelUpdateEvent.dart | 3 +- lib/src/events/GuildBanAddEvent.dart | 3 +- lib/src/events/GuildBanRemoveEvent.dart | 3 +- lib/src/events/GuildCreateEvent.dart | 9 +- lib/src/events/GuildDeleteEvent.dart | 5 +- lib/src/events/GuildMemberAddEvent.dart | 3 +- lib/src/events/GuildMemberRemoveEvent.dart | 3 +- lib/src/events/GuildMemberUpdateEvent.dart | 3 +- lib/src/events/GuildUpdateEvent.dart | 3 +- lib/src/events/MessageDeleteEvent.dart | 3 +- lib/src/events/MessageEvent.dart | 3 +- lib/src/events/MessageUpdateEvent.dart | 3 +- lib/src/events/TypingEvent.dart | 3 +- lib/src/http.dart | 28 +++-- lib/src/objects/Attachment.dart | 3 +- lib/src/objects/ClientOAuth2Application.dart | 5 +- lib/src/objects/ClientOptions.dart | 2 +- lib/src/objects/ClientUser.dart | 3 +- lib/src/objects/Embed.dart | 3 +- lib/src/objects/EmbedProvider.dart | 3 +- lib/src/objects/EmbedThumbnail.dart | 3 +- lib/src/objects/Guild.dart | 11 +- lib/src/objects/GuildChannel.dart | 3 +- lib/src/objects/Invite.dart | 3 +- lib/src/objects/InviteChannel.dart | 3 +- lib/src/objects/InviteGuild.dart | 3 +- lib/src/objects/Member.dart | 3 +- lib/src/objects/Message.dart | 17 +-- lib/src/objects/MessageOptions.dart | 1 + lib/src/objects/OAuth2Application.dart | 5 +- lib/src/objects/OAuth2Guild.dart | 3 +- lib/src/objects/OAuth2Info.dart | 7 +- lib/src/objects/PrivateChannel.dart | 7 +- lib/src/objects/User.dart | 3 +- 37 files changed, 171 insertions(+), 129 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 65dfc16..da88f91 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -4,14 +4,15 @@ import 'dart:async'; import '../objects.dart'; import '../events.dart'; import 'http.dart'; -import 'package:events/events.dart'; +import 'package:events/events.dart' as events; +import 'package:http/http.dart' as http; /// The base class. /// It contains all of the methods. -class Client extends Events { - var _socket; - int _lastS = null; +class Client extends events.Events { + WebSocket _socket; + int _lastS; String _sessionID; API _api = new API(); @@ -28,25 +29,37 @@ class Client extends Events { ClientOAuth2Application app; /// A map of all the guilds the bot is in, by id. - Map guilds = {}; + Map guilds = {}; /// A map of all the channels the bot is in, by id. Either a [GuildChannel] or /// [PrivateChannel]. - Map channels = {}; + Map channels = {}; /// A map of all of the users the bot can see, by id. Does not always have /// offline users without forceFetchUsers enabled. - Map users = {}; + Map users = {}; /// Whether or not the client is ready. bool ready = false; + /// Creates and logs in a new client. + Client(this.token, [this.options]) { + if (this.options == null) { + this.options = new ClientOptions(); + } + + WebSocket.connect('wss://gateway.discord.gg?v=6&encoding=json').then((WebSocket socket) { + this._socket = socket; + this._socket.listen(this._handleMsg); + }); + } + void _heartbeat() { - this._socket.add(JSON.encode({"op": 1,"d": this._lastS})); + this._socket.add(JSON.encode({"op": 1,"d": this._lastS})); } - Future _handleMsg(msg) async { - var json = JSON.decode(msg); + Future _handleMsg(String msg) async { + Map json = JSON.decode(msg); if (json['s'] != null) { this._lastS = json['s']; @@ -55,14 +68,14 @@ class Client extends Events { //const ms = const JSON.decode(msg)["d"]["heartbeat_interval"]; if (json["op"] == 10) { - const heartbeat_interval = const Duration(milliseconds: 41250); - new Timer.periodic(heartbeat_interval, (Timer t) => this._heartbeat()); + const Duration heartbeatInterval = const Duration(milliseconds: 41250); + new Timer.periodic(heartbeatInterval, (Timer t) => this._heartbeat()); - this._socket.add(JSON.encode({ + this._socket.add(JSON.encode({ "op": 2, - "d": { + "d": { "token": this.token, - "properties": { + "properties": { "\$browser": "Discord Dart" }, "large_threshold": 100, @@ -84,11 +97,11 @@ class Client extends Events { this._sessionID = json['d']['session_id']; this.user = new ClientUser(json['d']['user']); - json['d']['guilds'].forEach((o) { + json['d']['guilds'].forEach((Map o) { this.guilds[o['id']] = null; }); - json['d']['private_channels'].forEach((o) { + json['d']['private_channels'].forEach((Map o) { PrivateChannel channel = new PrivateChannel(o); this.channels[channel.id] = channel; }); @@ -96,8 +109,8 @@ class Client extends Events { if (this.user.bot) { this._api.headers['Authorization'] = "Bot ${this.token}"; - var r = await this._api.get('oauth2/applications/@me'); - Map res = JSON.decode(r.body); + http.Response r = await this._api.get('oauth2/applications/@me'); + Map res = JSON.decode(r.body); if (r.statusCode == 200) { this.app = new ClientOAuth2Application(res); } @@ -168,9 +181,11 @@ class Client extends Events { break; } } + + return null; } - String _resolve(String to, Object object) { + String _resolve(String to, dynamic object) { if (to == "channel") { if (object is Message) { return object.channel.id; @@ -244,26 +259,11 @@ class Client extends Events { } } - Client(String token, [ClientOptions options]) { - if (options == null) { - this.options = new ClientOptions(); - } else { - this.options = options; - } - - this.token = token; - - WebSocket.connect('wss://gateway.discord.gg?v=6&encoding=json').then((socket) { - this._socket = socket; - this._socket.listen(this._handleMsg); - }); - } - /// Sends a message. /// /// Throws an [Exception] if the HTTP request errored. /// Client.sendMessage("channel id", "My content!"); - Future sendMessage(Object channel, String content, [MessageOptions options]) async { + Future sendMessage(dynamic channel, String content, [MessageOptions options]) async { if (this.ready) { if (options == null) { options = new MessageOptions(); @@ -275,8 +275,8 @@ class Client extends Events { String id = this._resolve("channel", channel); - var r = await this._api.post('channels/$id/messages', {"content": content, "tts": options.tts, "nonce": options.nonce}); - Map res = JSON.decode(r.body); + http.Response r = await this._api.post('channels/$id/messages', {"content": content, "tts": options.tts, "nonce": options.nonce}); + Map res = JSON.decode(r.body); if (r.statusCode == 200) { return new Message(this, res); @@ -292,12 +292,12 @@ class Client extends Events { /// /// Throws an [Exception] if the HTTP request errored. /// Client.sendMessage("channel id", "message id"); - Future deleteMessage(Object channel, Object message) async { + Future deleteMessage(dynamic channel, dynamic message) async { if (this.ready) { channel = this._resolve('channel', channel); message = this._resolve('message', message); - var r = await this._api.delete('channels/$channel/messages/$message'); + http.Response r = await this._api.delete('channels/$channel/messages/$message'); if (r.statusCode == 204) { return true; @@ -313,7 +313,7 @@ class Client extends Events { /// /// Throws an [Exception] if the HTTP request errored. /// Client.sendMessage("channel id", "message id", "My edited content!"); - Future editMessage(Object channel, Object message, String content, [MessageOptions options]) async { + Future editMessage(dynamic channel, dynamic message, String content, [MessageOptions options]) async { if (this.ready) { if (options == null) { options = new MessageOptions(); @@ -326,8 +326,8 @@ class Client extends Events { channel = this._resolve('channel', channel); message = this._resolve('message', message); - var r = await this._api.patch('channels/$channel/messages/$message', {"content": content}); - Map res = JSON.decode(r.body); + http.Response r = await this._api.patch('channels/$channel/messages/$message', {"content": content}); + Map res = JSON.decode(r.body); if (r.statusCode == 200) { return new Message(this, res); @@ -344,7 +344,7 @@ class Client extends Events { /// /// Throws an [Exception] if the HTTP request errored. /// Client.getMember("guild id", "user id"); - Future getMember(Object guild, Object member) async { + Future getMember(dynamic guild, dynamic member) async { if (this.ready) { guild = this._resolve('guild', guild); @@ -353,8 +353,8 @@ class Client extends Events { if (this.guilds[guild].members[member] != null) { return this.guilds[guild].members[member]; } else { - var r = await this._api.get('guilds/$guild/members/$member'); - Map res = JSON.decode(r.body); + http.Response r = await this._api.get('guilds/$guild/members/$member'); + Map res = JSON.decode(r.body); if (r.statusCode == 200) { Member m = new Member(res, this.guilds[guild]); this.guilds[guild].members[m.user.id] = m; @@ -372,12 +372,12 @@ class Client extends Events { /// /// Throws an [Exception] if the HTTP request errored. /// Client.getUser("user id"); - Future getUser(Object user) async { + Future getUser(dynamic user) async { if (this.ready) { user = this._resolve('user', user); - var r = await this._api.get('users/$user'); - Map res = JSON.decode(r.body); + http.Response r = await this._api.get('users/$user'); + Map res = JSON.decode(r.body); if (r.statusCode == 200) { return new User(res); } else { @@ -394,8 +394,8 @@ class Client extends Events { /// Client.getInvite("invite code"); Future getInvite(String code) async { if (this.ready) { - var r = await this._api.get('invites/$code'); - Map res = JSON.decode(r.body); + http.Response r = await this._api.get('invites/$code'); + Map res = JSON.decode(r.body); if (r.statusCode == 200) { return new Invite(res); } else { @@ -411,14 +411,14 @@ class Client extends Events { /// Throws an [Exception] if the HTTP request errored or if the client user /// is not a bot. /// Client.getMessage("channel id", "message id"); - Future getMessage(Object channel, String message) async { + Future getMessage(dynamic channel, String message) async { if (this.ready) { if (this.user.bot) { channel = this._resolve('channel', channel); message = this._resolve('message', message); - var r = await this._api.get('channels/$channel/messages/$message'); - Map res = JSON.decode(r.body); + http.Response r = await this._api.get('channels/$channel/messages/$message'); + Map res = JSON.decode(r.body); if (r.statusCode == 200) { return new Message(this, res); } else { @@ -436,12 +436,12 @@ class Client extends Events { /// /// Throws an [Exception] if the HTTP request errored /// Client.getOAuth2Info("app id"); - Future getOAuth2Info(Object app) async { + Future getOAuth2Info(dynamic app) async { if (this.ready) { app = this._resolve('app', app); - var r = await this._api.get('oauth2/authorize?client_id=$app&scope=bot'); - Map res = JSON.decode(r.body); + http.Response r = await this._api.get('oauth2/authorize?client_id=$app&scope=bot'); + Map res = JSON.decode(r.body); if (r.statusCode == 200) { return new OAuth2Info(res); } else { @@ -457,14 +457,14 @@ class Client extends Events { /// Throws an [Exception] if the HTTP request errored or if the client user /// is a bot. /// Client.oauth2Authorize("app id", "guild id"); - Future oauth2Authorize(Object app, Object guild, [int permissions = 0]) async { + Future oauth2Authorize(dynamic app, dynamic guild, [int permissions = 0]) async { if (this.ready) { if (!this.user.bot) { app = this._resolve('app', app); guild = this._resolve('guild', guild); - var r = await this._api.post('oauth2/authorize?client_id=$app&scope=bot', {"guild_id": guild, "permissions": permissions, "authorize": true}); - Map res = JSON.decode(r.body); + http.Response r = await this._api.post('oauth2/authorize?client_id=$app&scope=bot', {"guild_id": guild, "permissions": permissions, "authorize": true}); + Map res = JSON.decode(r.body); if (r.statusCode == 200) { return true; } else { diff --git a/lib/src/events/ChannelCreateEvent.dart b/lib/src/events/ChannelCreateEvent.dart index e1fc762..6089c5a 100644 --- a/lib/src/events/ChannelCreateEvent.dart +++ b/lib/src/events/ChannelCreateEvent.dart @@ -1,12 +1,13 @@ import '../../objects.dart'; import '../client.dart'; -/// Sent when a channel is created, can be a [PMChannel]. +/// Sent when a channel is created, can be a `PMChannel`. class ChannelCreateEvent { - /// The channel that was created, either a [GuildChannel] or [PMChannel]. + /// The channel that was created, either a `GuildChannel` or `PMChannel`. dynamic channel; - ChannelCreateEvent(Client client, Map json) { + /// Constructs a new [ChannelCreateEvent]. + ChannelCreateEvent(Client client, Map json) { if (client.ready) { if (json['d']['type'] == 1) { this.channel = new PrivateChannel(json['d']); diff --git a/lib/src/events/ChannelDeleteEvent.dart b/lib/src/events/ChannelDeleteEvent.dart index 427f063..d902acb 100644 --- a/lib/src/events/ChannelDeleteEvent.dart +++ b/lib/src/events/ChannelDeleteEvent.dart @@ -1,12 +1,13 @@ import '../../objects.dart'; import '../client.dart'; -/// Sent when a channel is deleted, can be a [PMChannel]. +/// Sent when a channel is deleted, can be a `PMChannel`. class ChannelDeleteEvent { - /// The channel that was deleted, either a [GuildChannel] or [PMChannel]. + /// The channel that was deleted, either a `GuildChannel` or `PMChannel`. dynamic channel; - ChannelDeleteEvent(Client client, Map json) { + /// Constructs a new [ChannelDeleteEvent]. + ChannelDeleteEvent(Client client, Map json) { if (client.ready) { if (json['d']['type'] == 1) { this.channel = new PrivateChannel(json['d']); diff --git a/lib/src/events/ChannelUpdateEvent.dart b/lib/src/events/ChannelUpdateEvent.dart index c3cd94b..9ae4144 100644 --- a/lib/src/events/ChannelUpdateEvent.dart +++ b/lib/src/events/ChannelUpdateEvent.dart @@ -9,7 +9,8 @@ class ChannelUpdateEvent { /// The channel after the update. GuildChannel newChannel; - ChannelUpdateEvent(Client client, Map json) { + /// Constructs a new [ChannelUpdateEvent]. + ChannelUpdateEvent(Client client, Map json) { if (client.ready) { Guild guild = client.guilds[json['d']['guild_id']]; this.oldChannel = client.channels[json['d']['id']]; diff --git a/lib/src/events/GuildBanAddEvent.dart b/lib/src/events/GuildBanAddEvent.dart index cef7a04..8f98ebe 100644 --- a/lib/src/events/GuildBanAddEvent.dart +++ b/lib/src/events/GuildBanAddEvent.dart @@ -9,7 +9,8 @@ class GuildBanAddEvent { /// The user that was banned. User user; - GuildBanAddEvent(Client client, Map json) { + /// Constructs a new [GuildBanAddEvent]. + GuildBanAddEvent(Client client, Map json) { if (client.ready) { this.guild = client.guilds[json['d']['guild_id']]; this.user = new User(json['d']['user']); diff --git a/lib/src/events/GuildBanRemoveEvent.dart b/lib/src/events/GuildBanRemoveEvent.dart index 9fd85d7..cd15eb2 100644 --- a/lib/src/events/GuildBanRemoveEvent.dart +++ b/lib/src/events/GuildBanRemoveEvent.dart @@ -9,7 +9,8 @@ class GuildBanRemoveEvent { /// The user that was unbanned. User user; - GuildBanRemoveEvent(Client client, Map json) { + /// Constructs a new [GuildBanRemoveEvent]. + GuildBanRemoveEvent(Client client, Map json) { if (client.ready) { this.guild = client.guilds[json['d']['guild_id']]; this.user = new User(json['d']['user']); diff --git a/lib/src/events/GuildCreateEvent.dart b/lib/src/events/GuildCreateEvent.dart index 327b249..6aa4f98 100644 --- a/lib/src/events/GuildCreateEvent.dart +++ b/lib/src/events/GuildCreateEvent.dart @@ -7,21 +7,22 @@ class GuildCreateEvent { /// The guild created. Guild guild; - GuildCreateEvent(Client client, Map json) { + /// Constructs a new [GuildCreateEvent]. + GuildCreateEvent(Client client, Map json) { this.guild = new Guild(client, json['d'], true, true); client.guilds[guild.id] = guild; - guild.channels.forEach((i, v) { + guild.channels.forEach((String i, GuildChannel v) { client.channels[v.id] = v; }); - guild.members.forEach((i, v) { + guild.members.forEach((String i, Member v) { client.users[v.user.id] = v.user; }); if (!client.ready) { bool match = true; - client.guilds.forEach((i, o) { + client.guilds.forEach((String i, Guild o) { if (o == null) { match = false; } diff --git a/lib/src/events/GuildDeleteEvent.dart b/lib/src/events/GuildDeleteEvent.dart index 3f2857d..dc2acab 100644 --- a/lib/src/events/GuildDeleteEvent.dart +++ b/lib/src/events/GuildDeleteEvent.dart @@ -9,11 +9,12 @@ class GuildDeleteEvent { /// The guild, will be an unavailable guild if the guild is unavailable. Guild guild; - GuildDeleteEvent(Client client, Map json) { + /// Constructs a new [GuildDeleteEvent]. + GuildDeleteEvent(Client client, Map json) { if (client.ready) { if (json['d']['unavailable']) { this.unavailable = true; - this.guild = new Guild(client, {}, false); + this.guild = new Guild(client, null, false); client.guilds[json['d']['id']] = guild; client.emit('guildDelete', this); } else { diff --git a/lib/src/events/GuildMemberAddEvent.dart b/lib/src/events/GuildMemberAddEvent.dart index 9a3d49b..093e76e 100644 --- a/lib/src/events/GuildMemberAddEvent.dart +++ b/lib/src/events/GuildMemberAddEvent.dart @@ -6,7 +6,8 @@ class GuildMemberAddEvent { /// The member that joined. Member member; - GuildMemberAddEvent(Client client, Map json) { + /// Constructs a new [GuildMemberAddEvent]. + GuildMemberAddEvent(Client client, Map json) { if (client.ready) { Guild guild = client.guilds[json['d']['guild_id']]; this.member = new Member(json['d'], guild); diff --git a/lib/src/events/GuildMemberRemoveEvent.dart b/lib/src/events/GuildMemberRemoveEvent.dart index 0bd46c5..c053973 100644 --- a/lib/src/events/GuildMemberRemoveEvent.dart +++ b/lib/src/events/GuildMemberRemoveEvent.dart @@ -9,7 +9,8 @@ class GuildMemberRemoveEvent { ///The user that left. User user; - GuildMemberRemoveEvent(Client client, Map json) { + /// Constructs a new [GuildMemberRemoveEvent]. + GuildMemberRemoveEvent(Client client, Map json) { if (client.ready) { this.guild = client.guilds[json['d']['guild_id']]; this.user = new User(json['d']['user']); diff --git a/lib/src/events/GuildMemberUpdateEvent.dart b/lib/src/events/GuildMemberUpdateEvent.dart index 0413b4d..fb7c552 100644 --- a/lib/src/events/GuildMemberUpdateEvent.dart +++ b/lib/src/events/GuildMemberUpdateEvent.dart @@ -9,7 +9,8 @@ class GuildMemberUpdateEvent { /// The member after the update. Member newMember; - GuildMemberUpdateEvent(Client client, Map json) { + /// Constructs a new [GuildMemberUpdateEvent]. + GuildMemberUpdateEvent(Client client, Map json) { if (client.ready) { Guild guild = client.guilds[json['d']['guild_id']]; this.oldMember = guild.members[json['d']['user']['id']]; diff --git a/lib/src/events/GuildUpdateEvent.dart b/lib/src/events/GuildUpdateEvent.dart index 7d5e9c1..4af6fce 100644 --- a/lib/src/events/GuildUpdateEvent.dart +++ b/lib/src/events/GuildUpdateEvent.dart @@ -9,7 +9,8 @@ class GuildUpdateEvent { /// The guild after the update. Guild newGuild; - GuildUpdateEvent(Client client, Map json) { + /// Constructs a new [GuildUpdateEvent]. + GuildUpdateEvent(Client client, Map json) { if (client.ready) { Guild newGuild = new Guild(client, json['d']); Guild oldGuild = client.guilds[newGuild.id]; diff --git a/lib/src/events/MessageDeleteEvent.dart b/lib/src/events/MessageDeleteEvent.dart index 9163b0c..a21a1cf 100644 --- a/lib/src/events/MessageDeleteEvent.dart +++ b/lib/src/events/MessageDeleteEvent.dart @@ -9,7 +9,8 @@ class MessageDeleteEvent { /// The message's channel. GuildChannel channel; - MessageDeleteEvent(Client client, Map json) { + /// Constructs a new [MessageDeleteEvent]. + MessageDeleteEvent(Client client, Map json) { if (client.ready) { this.id = json['d']['id']; this.channel = client.channels[json['d']['channel_id']]; diff --git a/lib/src/events/MessageEvent.dart b/lib/src/events/MessageEvent.dart index 84bbaa7..bd69361 100644 --- a/lib/src/events/MessageEvent.dart +++ b/lib/src/events/MessageEvent.dart @@ -6,7 +6,8 @@ class MessageEvent { /// The new message. Message message; - MessageEvent(Client client, Map json) { + /// Constucts a new [MessageEvent]. + MessageEvent(Client client, Map json) { if (client.ready) { this.message = new Message(client, json['d']); client.emit('message', this); diff --git a/lib/src/events/MessageUpdateEvent.dart b/lib/src/events/MessageUpdateEvent.dart index c510743..c1db865 100644 --- a/lib/src/events/MessageUpdateEvent.dart +++ b/lib/src/events/MessageUpdateEvent.dart @@ -6,7 +6,8 @@ class MessageUpdateEvent { /// The updated message. Message message; - MessageUpdateEvent(Client client, Map json) { + /// Constructs a new [MessageUpdateEvent]. + MessageUpdateEvent(Client client, Map json) { if (client.ready) { if (!json['d'].containsKey('embeds')) { this.message = new Message(client, json['d']); diff --git a/lib/src/events/TypingEvent.dart b/lib/src/events/TypingEvent.dart index ed54768..07e0135 100644 --- a/lib/src/events/TypingEvent.dart +++ b/lib/src/events/TypingEvent.dart @@ -9,7 +9,8 @@ class TypingEvent { /// The user that is typing. User user; - TypingEvent(Client client, Map json) { + /// Constructs a new [TypingEvent]. + TypingEvent(Client client, Map json) { if (client.ready) { this.channel = client.channels[json['d']['channel_id']]; this.user = client.users[json['d']['user_id']]; diff --git a/lib/src/http.dart b/lib/src/http.dart index e2ef6ea..b7e326a 100644 --- a/lib/src/http.dart +++ b/lib/src/http.dart @@ -1,23 +1,31 @@ import 'dart:convert'; +import 'dart:async'; import 'package:http/http.dart' as http; +/// The base class for the API manager. class API { - String host = "https://discordapp.com/api"; - Map headers = {'User-Agent': 'DiscordDart (https://github.com/Hackzzila/Discord-Dart, 0.1.0)', 'Content-Type': 'application/json'}; + String _host = "https://discordapp.com/api"; - get(String uri) async { - return await http.get("${this.host}/$uri", headers: this.headers); + /// A list of headers to be sent on each request. + Map headers = {'User-Agent': 'DiscordDart (https://github.com/Hackzzila/Discord-Dart, 0.1.0)', 'Content-Type': 'application/json'}; + + /// Sends a GET request. + Future get(String uri) async { + return await http.get("${this._host}/$uri", headers: this.headers); } - post(String uri, Object content) async { - return await http.post("${this.host}/$uri", body: JSON.encode(content), headers: this.headers); + /// Sends a POST request. + Future post(String uri, Object content) async { + return await http.post("${this._host}/$uri", body: JSON.encode(content), headers: this.headers); } - patch(String uri, Object content) async { - return await http.patch("${this.host}/$uri", body: JSON.encode(content), headers: this.headers); + /// Sends a PATCH request. + Future patch(String uri, Object content) async { + return await http.patch("${this._host}/$uri", body: JSON.encode(content), headers: this.headers); } - delete(String uri) async { - return await http.delete("${this.host}/$uri", headers: this.headers); + /// Sends a DELETE request. + Future delete(String uri) async { + return await http.delete("${this._host}/$uri", headers: this.headers); } } diff --git a/lib/src/objects/Attachment.dart b/lib/src/objects/Attachment.dart index 5535e3e..4cc41f0 100644 --- a/lib/src/objects/Attachment.dart +++ b/lib/src/objects/Attachment.dart @@ -26,7 +26,8 @@ class Attachment { /// A timestamp for when the message was created. double createdAt; - Attachment(Map data) { + /// Constructs a new [Attachment]. + Attachment(Map data) { this.id = data['id']; this.filename = data['filename']; this.url = data['url']; diff --git a/lib/src/objects/ClientOAuth2Application.dart b/lib/src/objects/ClientOAuth2Application.dart index 2a92039..a0fc093 100644 --- a/lib/src/objects/ClientOAuth2Application.dart +++ b/lib/src/objects/ClientOAuth2Application.dart @@ -15,7 +15,7 @@ class ClientOAuth2Application { String name; /// The app's RPC origins. - List rpcOrigins; + List rpcOrigins; /// The app's flags. int flags; @@ -26,7 +26,8 @@ class ClientOAuth2Application { /// A timestamp for when the app was created double createdAt; - ClientOAuth2Application(Map data) { + /// Constructs a new [ClientOAuth2Application]. + ClientOAuth2Application(Map data) { this.description = data['description']; this.icon = data['icon']; this.id = data['id']; diff --git a/lib/src/objects/ClientOptions.dart b/lib/src/objects/ClientOptions.dart index 6860752..8c9d70e 100644 --- a/lib/src/objects/ClientOptions.dart +++ b/lib/src/objects/ClientOptions.dart @@ -1,6 +1,6 @@ import '../../objects.dart'; -/// The options for [Client] +/// The options for `Client`. class ClientOptions { /// Whether or not to disable @everyone and @here mentions at a global level. bool disableEveryone = false; diff --git a/lib/src/objects/ClientUser.dart b/lib/src/objects/ClientUser.dart index 4f0c82a..7a3edca 100644 --- a/lib/src/objects/ClientUser.dart +++ b/lib/src/objects/ClientUser.dart @@ -32,7 +32,8 @@ class ClientUser { /// Weather or not the client user has MFA enabled. bool mfa; - ClientUser(Map data) { + /// Constructs a new [ClientUser]. + ClientUser(Map data) { this.username = data['username']; this.id = data['id']; this.discriminator = data['discriminator']; diff --git a/lib/src/objects/Embed.dart b/lib/src/objects/Embed.dart index ca71c28..1a3eec7 100644 --- a/lib/src/objects/Embed.dart +++ b/lib/src/objects/Embed.dart @@ -20,7 +20,8 @@ class Embed { /// The embed's provider, if any. EmbedProvider provider; - Embed(Map data) { + /// Constructs a new [Embed]. + Embed(Map data) { this.url = data['url']; this.type = data['type']; this.description = data['description']; diff --git a/lib/src/objects/EmbedProvider.dart b/lib/src/objects/EmbedProvider.dart index 2291ff1..a3acadf 100644 --- a/lib/src/objects/EmbedProvider.dart +++ b/lib/src/objects/EmbedProvider.dart @@ -8,7 +8,8 @@ class EmbedProvider { /// The embed provider's URL. String url; - EmbedProvider(Map data) { + /// Constructs a new [EmbedProvider]. + EmbedProvider(Map data) { this.name = data['name']; this.url = data['url']; } diff --git a/lib/src/objects/EmbedThumbnail.dart b/lib/src/objects/EmbedThumbnail.dart index 8a1b593..143d06c 100644 --- a/lib/src/objects/EmbedThumbnail.dart +++ b/lib/src/objects/EmbedThumbnail.dart @@ -14,7 +14,8 @@ class EmbedThumbnail { /// The embed thumbnal's width. int width; - EmbedThumbnail(Map data) { + /// Constructs a new [EmbedThumbnail]. + EmbedThumbnail(Map data) { this.url = data['url']; this.proxyUrl = data['proxy_url']; this.height = data['height']; diff --git a/lib/src/objects/Guild.dart b/lib/src/objects/Guild.dart index def2632..23772db 100644 --- a/lib/src/objects/Guild.dart +++ b/lib/src/objects/Guild.dart @@ -52,12 +52,13 @@ class Guild { String ownerID; /// The guild's members. - Map members = {}; + Map members = {}; /// The guild's channels. - Map channels = {}; + Map channels = {}; - Guild(Client client, Map data, [bool available = true, bool guildCreate = false]) { + /// Constructs a new [Guild]. + Guild(Client client, Map data, [bool available = true, bool guildCreate = false]) { if (available) { this.name = data['name']; this.id = data['id']; @@ -76,12 +77,12 @@ class Guild { if (guildCreate) { //this.roles = JSON.decode(data['roles']); - data['members'].forEach((o) { + data['members'].forEach((Map o) { Member member = new Member(o, this); this.members[member.user.id] = member; }); - data['channels'].forEach((o) { + data['channels'].forEach((Map o) { GuildChannel channel = new GuildChannel(client, o, this); this.channels[channel.id] = channel; }); diff --git a/lib/src/objects/GuildChannel.dart b/lib/src/objects/GuildChannel.dart index 6d3878c..ac60633 100644 --- a/lib/src/objects/GuildChannel.dart +++ b/lib/src/objects/GuildChannel.dart @@ -36,7 +36,8 @@ class GuildChannel { /// Always false representing that it is a GuildChannel. bool isPrivate = false; - GuildChannel(Client client, Map data, Guild guild) { + /// Constructs a new [GuildChannel]. + GuildChannel(Client client, Map data, Guild guild) { this.name = data['name']; this.id = data['id']; this.type = data['type']; diff --git a/lib/src/objects/Invite.dart b/lib/src/objects/Invite.dart index 624e73a..4d66810 100644 --- a/lib/src/objects/Invite.dart +++ b/lib/src/objects/Invite.dart @@ -11,7 +11,8 @@ class Invite { /// A mini channel object for the invite's channel. InviteChannel channel; - Invite(Map data) { + /// Constructs a new [Invite]. + Invite(Map data) { this.code = data['code']; this.guild = new InviteGuild(data['guild']); this.channel = new InviteChannel(data['channel']); diff --git a/lib/src/objects/InviteChannel.dart b/lib/src/objects/InviteChannel.dart index f25e3c1..03721d0 100644 --- a/lib/src/objects/InviteChannel.dart +++ b/lib/src/objects/InviteChannel.dart @@ -14,7 +14,8 @@ class InviteChannel { /// A timestamp for the channel was created. double createdAt; - InviteChannel(Map data) { + /// Constructs a new [InviteChannel]. + InviteChannel(Map data) { this.id = data['id']; this.name = data['name']; this.type = data['type']; diff --git a/lib/src/objects/InviteGuild.dart b/lib/src/objects/InviteGuild.dart index f8df04d..eb21e5c 100644 --- a/lib/src/objects/InviteGuild.dart +++ b/lib/src/objects/InviteGuild.dart @@ -14,7 +14,8 @@ class InviteGuild { /// A timestamp for when the guild was created. double createdAt; - InviteGuild(Map data) { + /// Constructs a new [InviteGuild]. + InviteGuild(Map data) { this.id = data['id']; this.name = data['name']; this.spash = data['splash_hash']; diff --git a/lib/src/objects/Member.dart b/lib/src/objects/Member.dart index a00b2c2..a203836 100644 --- a/lib/src/objects/Member.dart +++ b/lib/src/objects/Member.dart @@ -23,7 +23,8 @@ class Member { /// The guild that the member is a part of. Guild guild; - Member(Map data, Guild guild) { + /// Constructs a new [Member]. + Member(Map data, Guild guild) { this.nickname = data['nick']; this.joinedAt = data['joined_at']; this.deaf = data['deaf']; diff --git a/lib/src/objects/Message.dart b/lib/src/objects/Message.dart index 5f05740..42f9d28 100644 --- a/lib/src/objects/Message.dart +++ b/lib/src/objects/Message.dart @@ -31,16 +31,16 @@ class Message { Member member; /// A list of the mentions in the message. - List mentions = []; + List mentions = []; /// A list of IDs for the role mentions in the message. - List roleMentions = []; + List roleMentions = []; /// A list of the embeds in the message. - List embeds = []; + List embeds = []; /// A list of attachments in the message. - List attachments = []; + List attachments = []; /// When the message was created, redundant of `timestamp`. double createdAt; @@ -54,7 +54,8 @@ class Message { /// Whether or @everyone was mentioned in the message. bool mentionEveryone; - Message(Client client, Map data) { + /// Constructs a new [Message]. + Message(Client client, Map data) { this.content = data['content']; this.id = data['id']; this.nonce = data['nonce']; @@ -70,15 +71,15 @@ class Message { this.createdAt = (int.parse(this.id) / 4194304) + 1420070400000; this.member = guild.members[this.author.id]; - data['mentions'].forEach((user) { + data['mentions'].forEach((Map user) { this.mentions.add(new User(user)); }); - data['embeds'].forEach((embed) { + data['embeds'].forEach((Map embed) { this.embeds.add(new Embed(embed)); }); - data['attachments'].forEach((attachment) { + data['attachments'].forEach((Map attachment) { this.attachments.add(new Attachment(attachment)); }); } diff --git a/lib/src/objects/MessageOptions.dart b/lib/src/objects/MessageOptions.dart index cfc3814..66179d0 100644 --- a/lib/src/objects/MessageOptions.dart +++ b/lib/src/objects/MessageOptions.dart @@ -1,5 +1,6 @@ import '../../objects.dart'; +/// The options for message sending. class MessageOptions { /// Whether or not to send the message using TTS. bool tts = false; diff --git a/lib/src/objects/OAuth2Application.dart b/lib/src/objects/OAuth2Application.dart index 8e936c5..50c75c5 100644 --- a/lib/src/objects/OAuth2Application.dart +++ b/lib/src/objects/OAuth2Application.dart @@ -15,12 +15,13 @@ class OAuth2Application { String name; /// The app's RPC origins. - List rpcOrigins; + List rpcOrigins; /// A timestamp for when the app was created. double createdAt; - OAuth2Application(Map data) { + /// Constructs a new [OAuth2Application]. + OAuth2Application(Map data) { this.description = data['description']; this.icon = data['icon']; this.id = data['id']; diff --git a/lib/src/objects/OAuth2Guild.dart b/lib/src/objects/OAuth2Guild.dart index c13b3ee..03fabf3 100644 --- a/lib/src/objects/OAuth2Guild.dart +++ b/lib/src/objects/OAuth2Guild.dart @@ -17,7 +17,8 @@ class OAuth2Guild { /// A timestamp for when the guild was created. double createdAt; - OAuth2Guild(Map data) { + /// Constructs a new [OAuth2Guild]. + OAuth2Guild(Map data) { this.permissions = data['permissions']; this.icon = data['icon']; this.id = data['id']; diff --git a/lib/src/objects/OAuth2Info.dart b/lib/src/objects/OAuth2Info.dart index ce1964b..1b14b40 100644 --- a/lib/src/objects/OAuth2Info.dart +++ b/lib/src/objects/OAuth2Info.dart @@ -13,14 +13,15 @@ class OAuth2Info { User me; /// A list of mini guild objects with permissions for every guild you are on. - List guilds = []; + List guilds = []; - OAuth2Info(Map data) { + /// Constructs a new [OAuth2Info]. + OAuth2Info(Map data) { this.app = new OAuth2Application(data['application']); this.bot = new User(data['bot']); this.me = new User(data['user']); - data['guilds'].forEach((v) { + data['guilds'].forEach((Map v) { guilds.add(new OAuth2Guild(v)); }); } diff --git a/lib/src/objects/PrivateChannel.dart b/lib/src/objects/PrivateChannel.dart index 382062e..5b7e9d5 100644 --- a/lib/src/objects/PrivateChannel.dart +++ b/lib/src/objects/PrivateChannel.dart @@ -17,14 +17,15 @@ class PrivateChannel { double createdAt; /// The recipients. - List recipients = []; + List recipients = []; - PrivateChannel(Map data) { + /// Constructs a new [PrivateChannel]. + PrivateChannel(Map data) { this.id = data['id']; this.createdAt = (int.parse(this.id) / 4194304) + 1420070400000; this.lastMessageID = data['last_message_id']; - data['recipients'].forEach((o) { + data['recipients'].forEach((Map o) { this.recipients.add(new User(o)); }); } diff --git a/lib/src/objects/User.dart b/lib/src/objects/User.dart index 067e288..7607cff 100644 --- a/lib/src/objects/User.dart +++ b/lib/src/objects/User.dart @@ -23,7 +23,8 @@ class User { /// Whether or not the user is a bot. bool bot = false; - User(Map data) { + /// Constructs a new [User]. + User(Map data) { this.username = data['username']; this.id = data['id']; this.discriminator = data['discriminator']; From 814dcbb4f8933c167c5eac66e65f5156c2fd57ba Mon Sep 17 00:00:00 2001 From: Zachary Vacura Date: Wed, 21 Sep 2016 17:27:16 -0500 Subject: [PATCH 9/9] Bumped version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 547880b..0116c1f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: discord_dart -version: 0.7.3 +version: 0.7.4 description: A Discord library for Dart author: Hackzzila homepage: https://github.com/Hackzzila/Discord-Dart