Skip to content

Commit

Permalink
Merge pull request #375 from nyxx-discord/dev
Browse files Browse the repository at this point in the history
Release 4.1.0
  • Loading branch information
l7ssha authored Sep 25, 2022
2 parents 509a8db + d1753ca commit 4eec4a8
Show file tree
Hide file tree
Showing 25 changed files with 1,856 additions and 545 deletions.
42 changes: 41 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
## 4.1.0
__25.09.2022__

- feature: Add `invitesDisabled` feature (#370)
- feature: Add pending for member screening (#371)
- feature: member screening events (#372)
- feature: Cache guild events (#369)
- feature: Refactor internal shard system (#368)
- feature: Event to notify change of connection status (#364)
- feature: feature: auto moderation (#353)
- bug: Fixup shard disconnect event

## 4.1.0-dev.4
__15.09.2022__

- feature: Add `invitesDisabled` feature (#370)
- feature: Add pending for member screening (#371)
- feature: member screening events (#372)

## 4.1.0-dev.3
__03.09.2022__

- feature: Cache guild events (#369)

## 4.1.0-dev.2
__28.08.2022__

- bug: Fixup shard disconnect event

## 4.1.0-dev.1
__28.08.2022__

- feature: Refactor internal shard system (#368)
- feature: Event to notify change of connection status (#364)

## 4.1.0-dev.0
__20.08.2022__

- feature: feature: auto moderation (#353)

## 4.0.0
___29.07.2022__
__29.07.2022__

- breaking: Fix typo in `IHttpResponseSucess`
- breaking: Remove `threeDayThreadArchive` and `sevenDayThreadArchive` guild features
Expand Down
13 changes: 12 additions & 1 deletion lib/nyxx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export 'src/core/embed/embed_provider.dart' show IEmbedProvider;
export 'src/core/embed/embed_thumbnail.dart' show IEmbedThumbnail;
export 'src/core/embed/embed_video.dart' show IEmbedVideo;
export 'src/core/guild/ban.dart' show IBan;
export 'src/core/guild/auto_moderation.dart'
show IActionMetadata, IActionStructure, IAutoModerationRule, ITriggerMetadata, ActionTypes, EventTypes, TriggerTypes;
export 'src/core/guild/client_user.dart' show IClientUser;
export 'src/core/guild/guild.dart' show IGuild;
export 'src/core/guild/guild_feature.dart' show GuildFeature;
Expand Down Expand Up @@ -103,7 +105,15 @@ export 'src/events/guild_events.dart'
IGuildUpdateEvent,
IRoleCreateEvent,
IRoleDeleteEvent,
IRoleUpdateEvent;
IRoleUpdateEvent,
IAutoModerationRuleCreateEvent,
IAutoModerationRuleUpdateEvent,
IAutoModerationRuleDeleteEvent,
IAutoModerationActionExecutionEvent,
IGuildEventCreateEvent,
IGuildEventUpdateEvent,
IGuildEventDeleteEvent,
IWebhookUpdateEvent;
export 'src/events/http_events.dart' show IHttpResponseEvent, IHttpErrorEvent;
export 'src/events/invite_events.dart' show IInviteCreatedEvent, IInviteDeletedEvent;
export 'src/events/member_chunk_event.dart' show IMemberChunkEvent;
Expand Down Expand Up @@ -173,6 +183,7 @@ export 'src/utils/builders/sticker_builder.dart' show StickerBuilder;
export 'src/utils/builders/thread_builder.dart' show ThreadArchiveTime, ThreadBuilder;
export 'src/utils/builders/guild_event_builder.dart' show GuildEventBuilder;
export 'src/utils/builders/forum_thread_builder.dart' show ForumThreadBuilder;
export 'src/utils/builders/auto_moderation_builder.dart' show ActionMetadataBuilder, ActionStructureBuilder, AutoModerationRuleBuilder, TriggerMetadataBuilder;
export 'src/utils/extensions.dart' show IntExtensions, SnowflakeEntityListExtensions, StringExtensions;
export 'src/utils/permissions.dart' show PermissionsUtils;
export 'src/utils/utils.dart' show ListSafeFirstWhere;
Expand Down
11 changes: 10 additions & 1 deletion lib/src/client_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ClientOptions {
bool compressedGatewayPayloads;

/// Enables dispatching of guild subscription events (presence and typing events)
@Deprecated('No longer has any effect, use intents instead.')
bool guildSubscriptions;

/// Initial bot presence
Expand Down Expand Up @@ -141,6 +142,12 @@ class GatewayIntents {
/// Includes events: `GUILD_SCHEDULED_EVENT_CREATE`, `GUILD_SCHEDULED_EVENT_DELETE`, `GUILD_SCHEDULED_EVENT_UPDATE`, `GUILD_SCHEDULED_EVENT_USER_ADD`, `GUILD_SCHEDULED_EVENT_USER_REMOVE`
static const int guildScheduledEvents = 1 << 16;

/// Includes events: `AUTO_MODERATION_RULE_CREATE`, `AUTO_MODERATION_RULE_UPDATE`, `AUTO_MODERATION_RULE_DELETE`
static const int autoModerationConfiguration = 1 << 20;

/// Includes events: `AUTO_MODERATION_ACTION_EXECUTION`
static const int autoModerationExecution = 1 << 21;

/// All unprivileged intents
static const int allUnprivileged = guilds |
guildBans |
Expand All @@ -155,7 +162,9 @@ class GatewayIntents {
directMessages |
directMessageReactions |
directMessageTyping |
guildScheduledEvents;
guildScheduledEvents |
autoModerationConfiguration |
autoModerationExecution;

/// All privileged intents
static const int allPrivileged = guildMembers | guildPresences | messageContent;
Expand Down
63 changes: 51 additions & 12 deletions lib/src/core/audit_logs/audit_log.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import 'package:nyxx/src/nyxx.dart';
import 'package:nyxx/src/core/snowflake.dart';
import 'package:nyxx/src/core/audit_logs/audit_log_entry.dart';
import 'package:nyxx/src/core/channel/thread_channel.dart';
import 'package:nyxx/src/core/guild/auto_moderation.dart';
import 'package:nyxx/src/core/guild/scheduled_event.dart';
import 'package:nyxx/src/core/guild/webhook.dart';
import 'package:nyxx/src/core/snowflake.dart';
import 'package:nyxx/src/core/user/user.dart';
import 'package:nyxx/src/nyxx.dart';
import 'package:nyxx/src/typedefs.dart';

abstract class IAuditLog {
/// List of webhooks found in the audit log
/// Map of webhooks found in the audit log.
late final Map<Snowflake, IWebhook> webhooks;

/// List of users found in the audit log
/// Map of users found in the audit log.
late final Map<Snowflake, IUser> users;

/// List of audit log entries
/// Map of audit log entries.
late final Map<Snowflake, IAuditLogEntry> entries;

/// Map of auto moderation rules referenced in the audit log.
late final Map<Snowflake, IAutoModerationRule> autoModerationRules;

/// Map of guild scheduled events referenced in the audit log.
late final Map<Snowflake, IGuildEvent> events;

/// Map of threads referenced in the audit log.
late final Map<Snowflake, IThreadChannel> threads;

/// Filters audit log by [users]
Iterable<IAuditLogEntry> filter(bool Function(IAuditLogEntry) test);
}
Expand All @@ -23,38 +35,65 @@ abstract class IAuditLog {
///
/// [Look here for more](https://discordapp.com/developers/docs/resources/audit-log)
class AuditLog implements IAuditLog {
/// List of webhooks found in the audit log
/// Map of webhooks found in the audit log
@override
late final Map<Snowflake, IWebhook> webhooks;

/// List of users found in the audit log
/// Map of users found in the audit log
@override
late final Map<Snowflake, IUser> users;

/// List of audit log entries
/// Map of audit log entries
@override
late final Map<Snowflake, IAuditLogEntry> entries;

/// Map of auto moderation rules referenced in the audit log
@override
late final Map<Snowflake, IAutoModerationRule> autoModerationRules;

/// Map of guild scheduled events referenced in the audit log
@override
late final Map<Snowflake, IGuildEvent> events;

/// Map of threads referenced in the audit log.
@override
late final Map<Snowflake, IThreadChannel> threads;

/// Creates an instance of [AuditLog]
AuditLog(RawApiMap raw, INyxx client) {
webhooks = {};
users = {};
entries = {};
autoModerationRules = {};
events = {};
threads = {};

raw["webhooks"].forEach((o) {
webhooks[Snowflake(o["id"] as String)] = Webhook(o as RawApiMap, client);
webhooks[Snowflake(o["id"])] = Webhook(o as RawApiMap, client);
});

raw["users"].forEach((o) {
users[Snowflake(o["id"] as String)] = User(client, o as RawApiMap);
users[Snowflake(o["id"])] = User(client, o as RawApiMap);
});

raw["audit_log_entries"].forEach((o) {
entries[Snowflake(o["id"] as String)] = AuditLogEntry(o as RawApiMap, client);
entries[Snowflake(o["id"])] = AuditLogEntry(o as RawApiMap, client);
});

raw['auto_moderation_rules'].forEach((o) {
autoModerationRules[Snowflake(o['id'])] = AutoModerationRule(o as RawApiMap, client);
});

raw['guild_scheduled_events'].forEach((o) {
events[Snowflake(o['id'])] = GuildEvent(o as RawApiMap, client);
});

raw['threads'].forEach((o) {
threads[Snowflake(o['id'])] = ThreadChannel(client, o as RawApiMap);
});
}

/// Filters audit log by [users]
/// Filters audit log by [entries]
@override
Iterable<IAuditLogEntry> filter(bool Function(IAuditLogEntry) test) => entries.values.where(test);
}
12 changes: 9 additions & 3 deletions lib/src/core/audit_logs/audit_log_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:nyxx/src/core/audit_logs/audit_log_options.dart';

abstract class IAuditLogEntry implements SnowflakeEntity {
/// Id of the affected entity (webhook, user, role, etc.)
String get targetId;
String? get targetId;

/// Changes made to the target_id
List<IAuditLogChange> get changes;
Expand All @@ -34,7 +34,7 @@ abstract class IAuditLogEntry implements SnowflakeEntity {
class AuditLogEntry extends SnowflakeEntity implements IAuditLogEntry {
/// Id of the affected entity (webhook, user, role, etc.)
@override
late final String targetId;
late final String? targetId;

/// Changes made to the target_id
@override
Expand All @@ -58,7 +58,7 @@ class AuditLogEntry extends SnowflakeEntity implements IAuditLogEntry {

/// Creates an instance of [AuditLogEntry]
AuditLogEntry(RawApiMap raw, INyxx client) : super(Snowflake(raw["id"] as String)) {
targetId = raw["target_id"] as String;
targetId = raw["target_id"] as String?;

changes = [
if (raw["changes"] != null)
Expand All @@ -79,6 +79,7 @@ class AuditLogEntry extends SnowflakeEntity implements IAuditLogEntry {
}

class AuditLogEntryType extends IEnum<int> {
static const AuditLogEntryType unknown = AuditLogEntryType._create(0);
static const AuditLogEntryType guildUpdate = AuditLogEntryType._create(1);
static const AuditLogEntryType channelCreate = AuditLogEntryType._create(10);
static const AuditLogEntryType channelUpdate = AuditLogEntryType._create(11);
Expand Down Expand Up @@ -126,6 +127,11 @@ class AuditLogEntryType extends IEnum<int> {
static const AuditLogEntryType threadCreate = AuditLogEntryType._create(110);
static const AuditLogEntryType threadUpdate = AuditLogEntryType._create(111);
static const AuditLogEntryType threadDelete = AuditLogEntryType._create(112);
static const AuditLogEntryType applicationCommandPermissionUpdate = AuditLogEntryType._create(121);
static const AuditLogEntryType autoModerationRuleCreate = AuditLogEntryType._create(140);
static const AuditLogEntryType autoModerationRuleUpdate = AuditLogEntryType._create(141);
static const AuditLogEntryType autoModerationRuleDelete = AuditLogEntryType._create(142);
static const AuditLogEntryType autoModerationBlockMessage = AuditLogEntryType._create(143);

const AuditLogEntryType._create(int value) : super(value);

Expand Down
6 changes: 3 additions & 3 deletions lib/src/core/audit_logs/audit_log_options.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:nyxx/nyxx.dart';

/// Additionnal info for certain action types
/// Additional info for certain action types
///
/// [Look here for more](https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events)
abstract class IAuditLogOptions {
/// The channel in which the entites were targeted.
/// The channel in which the entities were targeted.
Snowflake? get channelId;

/// The number of entities targeted.
Expand Down Expand Up @@ -33,7 +33,7 @@ abstract class IAuditLogOptions {
}

class AuditLogOptions implements IAuditLogOptions {
/// The channel in which the entites were targeted.
/// The channel in which the entities were targeted.
@override
late final Snowflake? channelId;

Expand Down
Loading

0 comments on commit 4eec4a8

Please sign in to comment.