Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nyxx-discord/nyxx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.21.5
Choose a base ref
...
head repository: nyxx-discord/nyxx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.22.0
Choose a head ref
  • 7 commits
  • 20 files changed
  • 1 contributor

Commits on Jul 8, 2018

  1. Added audit logs

    l7ssha committed Jul 8, 2018
    Copy the full SHA
    c13cd04 View commit details
  2. Copy the full SHA
    0330256 View commit details
  3. Fix formatting [ci skip]

    l7ssha committed Jul 8, 2018
    Copy the full SHA
    bd5b31f View commit details

Commits on Jul 11, 2018

  1. Copy the full SHA
    bfe9b8f View commit details
  2. Copy the full SHA
    6518d51 View commit details
  3. Bump version to 0.22.0

    l7ssha committed Jul 11, 2018
    Copy the full SHA
    6ebe228 View commit details
  4. Fix link

    l7ssha authored Jul 11, 2018
    Copy the full SHA
    dd3ac04 View commit details
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [0.22.0](https://github.com/l7ssha/nyxx/compare/0.21.5...0.22.0)
_Wed 11.07.2018_

- **Bug fixes**
* Next serialization bug fixes
- **New features**
* Added support for [audit logs](https://discordapp.com/developers/docs/resources/audit-log)
* Searching in `EmojisUnicode` based on shortcode

## [0.21.5](https://github.com/l7ssha/nyxx/compare/0.21.4...0.21.5)
_Fri 09.07.2018_

16 changes: 10 additions & 6 deletions lib/nyxx.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/// Nyxx DISCORD API wrapper for Dart
///
/// Library consists of 2 modules [nyxx] and [nyxx.commands].
///
/// This module (aka library) contains all main nyxx logic:
/// `/internal` - contains internal things like Http and Websocket stack needed for library to work
/// `/` - root path has generic models/objects/stuff which is used everywhere
/// `/builders` - contains classes used to build [Embed]s
/// `/objects` - directory which groups all data classes
/// `/events` - classes used in event dispatching
/// `/errors` - Few errors to report weird behavior
///
/// - `/internal` - contains internal things like Http and Websocket stack needed for library to work
/// - `/` - root path has generic models/objects/stuff which is used everywhere
/// - `/builders` - contains classes used to build [Embed]s
/// - `/objects` - directory which groups all data classes
/// - `/events` - classes used in event dispatching
/// - `/errors` - Few errors to report weird behavior
library nyxx;

import 'dart:async';
@@ -25,6 +27,8 @@ part 'src/internal/_WS.dart';
part 'src/internal/Http.dart';
part 'src/internal/Util.dart';

part 'src/objects/auditlogs/AuditLog.dart';

part 'src/Client.dart';
part 'src/objects/Snowflake.dart';

23 changes: 18 additions & 5 deletions lib/src/internal/Http.dart
Original file line number Diff line number Diff line change
@@ -275,12 +275,20 @@ class Http {
{dynamic body,
Map<String, String> queryParams,
bool beforeReady: false,
Map<String, String> headers: const {}}) async {
Map<String, String> headers: const {},
String reason}) async {
if (_client is Client && !this._client.ready && !beforeReady)
throw new ClientNotReadyError();

HttpRequest request = new HttpRequest._new(this, method, path, queryParams,
new Map.from(this.headers)..addAll(headers), body);
HttpRequest request = new HttpRequest._new(
this,
method,
path,
queryParams,
new Map.from(this.headers)
..addAll(headers)
..addAll(addAuditReason(reason)),
body);

await for (HttpResponse r in request.stream) {
if (!r.aborted && r.status >= 200 && r.status < 300) {
@@ -301,9 +309,12 @@ class Http {
});
}

Map<String, dynamic> addAuditReason(String reason) =>
<String, dynamic>{"X-Audit-Log-Reason": "$reason"};

Future<HttpResponse> sendMultipart(
String method, String path, List<String> filenames,
{String data, bool beforeReady: false}) async {
{String data, bool beforeReady: false, String reason}) async {
if (_client is Client && !this._client.ready && !beforeReady)
throw new ClientNotReadyError();

@@ -319,7 +330,9 @@ class Http {
filenames,
filepaths,
<String, String>{"payload_json": expandAttachments(data)},
new Map.from(this.headers)..addAll(headers));
new Map.from(this.headers)
..addAll(headers)
..addAll(addAuditReason(reason)));

await for (HttpResponse r in request.stream) {
if (!r.aborted && r.status >= 200 && r.status < 300) {
106 changes: 68 additions & 38 deletions lib/src/objects/Guild.dart
Original file line number Diff line number Diff line change
@@ -191,11 +191,9 @@ class Guild {
}

/// Prunes the guild, returns the amount of members pruned.
Future<int> prune(int days) async {
HttpResponse r = await this
.client
.http
.send('POST', "/guilds/$id/prune", body: {"days": days});
Future<int> prune(int days, {String auditReason = ""}) async {
HttpResponse r = await this.client.http.send('POST', "/guilds/$id/prune",
body: {"days": days}, reason: auditReason);
return r.body.asJson() as int;
}

@@ -212,11 +210,9 @@ class Guild {
}

/// Change guild owner
Future<Guild> changeOwner(String id) async {
HttpResponse r = await this
.client
.http
.send('PATCH', "/guilds/$id", body: {"owner_id": id});
Future<Guild> changeOwner(String id, {String auditReason = ""}) async {
HttpResponse r = await this.client.http.send('PATCH', "/guilds/$id",
body: {"owner_id": id}, reason: auditReason);

return new Guild._new(client, r.body.asJson() as Map<String, dynamic>);
}
@@ -239,24 +235,53 @@ class Guild {
return tmp;
}

Future<AuditLog> getAuditLogs(
{Snowflake userId,
String actionType,
Snowflake before,
int limit}) async {
var query = new Map<String, String>();

if (userId != null) query['user_id'] = userId.toString();

if (actionType != null) query['action_type'] = actionType;

if (before != null) query['before'] = before.toString();

if (limit != null) query['limit'] = limit.toString();

HttpResponse r = await this
.client
.http
.send('GET', '/guilds/${this.id}/audit-logs', queryParams: query);

return new AuditLog._new(
this.client, r.body.asJson() as Map<String, dynamic>);
}

/// Get Guil's embed object
Future<Embed> getGuildEmbed() async {
HttpResponse r = await this.client.http.send('GET', "/guilds/$id/embed");
return new Embed._new(this.client, r.body.asJson() as Map<String, dynamic>);
}

/// Modify guild embed object
Future<Embed> editGuildEmbed(EmbedBuilder embed) async {
HttpResponse r = await this
.client
.http
.send('PATCH', "/guilds/$id/embed", body: embed.build());
return new Embed._new(this.client, r.body.asJson() as Map<String, dynamic>);
Future<Embed> editGuildEmbed(EmbedBuilder embed,
{String auditReason = ""}) async {
HttpResponse r = await this.client.http.send('PATCH', "/guilds/$id/embed",
body: embed.build(), reason: auditReason);
return new Embed._new(
this.client,
r.body.asJson() as Map<String, dynamic>,
);
}

/// Creates an empty role.
Future<Role> createRole() async {
HttpResponse r = await this.client.http.send('POST', "/guilds/$id/roles");
Future<Role> createRole({String auditReason = ""}) async {
HttpResponse r = await this
.client
.http
.send('POST', "/guilds/$id/roles", reason: auditReason);
return new Role._new(client, r.body.asJson() as Map<String, dynamic>, this);
}

@@ -284,14 +309,15 @@ class Guild {

/// Creates a channel.
Future<dynamic> createChannel(String name, String type,
{int bitrate: 64000, int userLimit: 0}) async {
{int bitrate: 64000, int userLimit: 0, String auditReason = ""}) async {
HttpResponse r = await this.client.http.send('POST', "/guilds/$id/channels",
body: {
"name": name,
"type": type,
"bitrate": bitrate,
"user_limit": userLimit
});
},
reason: auditReason);

if (r.body.asJson()['type'] == 0) {
return new TextChannel._new(
@@ -303,16 +329,18 @@ class Guild {
}

/// Moves channel
Future<Null> moveGuildChannel(String channelId, int newPosition) async {
Future<Null> moveGuildChannel(String channelId, int newPosition,
{String auditReason = ""}) async {
await this.client.http.send('PATCH', "/guilds/${this.id}/channels",
body: {"id": id, "position": newPosition});
body: {"id": id, "position": newPosition}, reason: auditReason);
return null;
}

/// Bans a user by ID.
Future<Null> ban(String id, [int deleteMessageDays = 0]) async {
Future<Null> ban(String id,
{int deleteMessageDays = 0, String auditReason}) async {
await this.client.http.send('PUT', "/guilds/${this.id}/bans/$id",
body: {"delete-message-days": deleteMessageDays});
body: {"delete-message-days": deleteMessageDays}, reason: auditReason);
return null;
}

@@ -329,20 +357,22 @@ class Guild {
int notificationLevel: null,
VoiceChannel afkChannel: null,
int afkTimeout: null,
String icon: null}) async {
HttpResponse r =
await this.client.http.send('PATCH', "/guilds/${this.id}", body: {
"name": name != null ? name : this.name,
"verification_level": verificationLevel != null
? verificationLevel
: this.verificationLevel,
"default_message_notifications": notificationLevel != null
? notificationLevel
: this.notificationLevel,
"afk_channel_id": afkChannel != null ? afkChannel : this.afkChannel,
"afk_timeout": afkTimeout != null ? afkTimeout : this.afkTimeout,
"icon": icon != null ? icon : this.icon
});
String icon: null,
String auditReason}) async {
HttpResponse r = await this.client.http.send('PATCH', "/guilds/${this.id}",
body: {
"name": name != null ? name : this.name,
"verification_level": verificationLevel != null
? verificationLevel
: this.verificationLevel,
"default_message_notifications": notificationLevel != null
? notificationLevel
: this.notificationLevel,
"afk_channel_id": afkChannel != null ? afkChannel : this.afkChannel,
"afk_timeout": afkTimeout != null ? afkTimeout : this.afkTimeout,
"icon": icon != null ? icon : this.icon
},
reason: auditReason);
return new Guild._new(this.client, r.body.asJson() as Map<String, dynamic>);
}

7 changes: 5 additions & 2 deletions lib/src/objects/Invite.dart
Original file line number Diff line number Diff line change
@@ -26,8 +26,11 @@ class Invite {
}

/// Deletes this Invite.
Future<Null> delete() async {
await this.client.http.send('DELETE', '/invites/$code');
Future<Null> delete({String auditReason = ""}) async {
await this
.client
.http
.send('DELETE', '/invites/$code', reason: auditReason);
return null;
}
}
13 changes: 6 additions & 7 deletions lib/src/objects/Member.dart
Original file line number Diff line number Diff line change
@@ -62,19 +62,18 @@ class Member extends User {
}

/// Bans the member and optionally deletes [deleteMessageDays] days worth of messages.
Future<Null> ban([int deleteMessageDays = 0]) async {
Future<Null> ban({int deleteMessageDays = 0, String auditReason: ""}) async {
await this.client.http.send(
'PUT', "/guilds/${this.guild.id}/bans/${this.id}",
body: {"delete-message-days": deleteMessageDays});
body: {"delete-message-days": deleteMessageDays}, reason: auditReason);
return null;
}

/// Kicks the member
Future<Null> kick() async {
await this
.client
.http
.send('DELETE', "/guilds/${this.guild.id}/members/${this.id}");
Future<Null> kick({String auditReason: ""}) async {
await this.client.http.send(
'DELETE', "/guilds/${this.guild.id}/members/${this.id}",
reason: auditReason);
return null;
}
}
40 changes: 21 additions & 19 deletions lib/src/objects/Role.dart
Original file line number Diff line number Diff line change
@@ -64,33 +64,35 @@ class Role {
int position: null,
int color: null,
bool mentionable: null,
bool hoist: null}) async {
HttpResponse r = await this
.client
.http
.send('PATCH', "/guilds/${this.guild.id}/roles/$id", body: {
"name": name != null ? name : this.name,
"permissions": permissions != null ? permissions : this.permissions.raw,
"position": position != null ? position : this.position,
"color": color != null ? color : this.color,
"hoist": hoist != null ? hoist : this.hoist,
"mentionable": mentionable != null ? mentionable : this.mentionable
});
bool hoist: null,
String auditReason: ""}) async {
HttpResponse r = await this.client.http.send(
'PATCH', "/guilds/${this.guild.id}/roles/$id",
body: {
"name": name != null ? name : this.name,
"permissions":
permissions != null ? permissions : this.permissions.raw,
"position": position != null ? position : this.position,
"color": color != null ? color : this.color,
"hoist": hoist != null ? hoist : this.hoist,
"mentionable": mentionable != null ? mentionable : this.mentionable
},
reason: auditReason);
return new Role._new(
this.client, r.body.asJson() as Map<String, dynamic>, this.guild);
}

/// Deletes the role.
Future<Null> delete() async {
await this.client.http.send('DELETE', "/guilds/${this.guild.id}/roles/$id");
Future<Null> delete({String auditReason: ""}) async {
await this.client.http.send('DELETE', "/guilds/${this.guild.id}/roles/$id",
reason: auditReason);
return null;
}

Future<Null> addToUser(User user) async {
await this
.client
.http
.send('PUT', '/guilds/${guild.id}/members/${user.id}/roles/$id');
Future<Null> addToUser(User user, {String auditReason: ""}) async {
await this.client.http.send(
'PUT', '/guilds/${guild.id}/members/${user.id}/roles/$id',
reason: auditReason);
return null;
}

20 changes: 0 additions & 20 deletions lib/src/objects/User.dart
Original file line number Diff line number Diff line change
@@ -104,26 +104,6 @@ class User {
this.client, r.body.asJson() as Map<String, dynamic>);
}

@deprecated

/// Sends a message.
///
/// Throws an [Exception] if the HTTP request errored.
/// Channel.sendMessage(content: "My content!");
Future<Message> sendMessage(
{String content,
Map<dynamic, dynamic> embed,
bool tts: false,
String nonce,
bool disableEveryone}) async {
return this.send(
content: content,
embed: embed,
tts: tts,
nonce: nonce,
disableEveryone: disableEveryone);
}

/// Gets a [Message] object. Only usable by bot accounts.
///
/// Throws an [Exception] if the HTTP request errored or if the client user
Loading