Skip to content

Commit

Permalink
Dev (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha authored Oct 24, 2023
2 parents b12a338 + 4f86da1 commit f80bb11
Show file tree
Hide file tree
Showing 41 changed files with 1,303 additions and 767 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
env:
TEST_TOKEN: ${{ secrets.TEST_TOKEN }}
steps:
- name: Setup Dart Action
uses: dart-lang/setup-dart@v1
Expand All @@ -25,6 +23,7 @@ jobs:
key: ${{ runner.os }}-pubspec-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-pubspec-
- name: Install dependencies
run: dart pub get

Expand All @@ -34,8 +33,6 @@ jobs:
format:
name: Format
runs-on: ubuntu-latest
env:
TEST_TOKEN: ${{ secrets.TEST_TOKEN }}
steps:
- name: Setup Dart Action
uses: dart-lang/setup-dart@v1
Expand All @@ -50,6 +47,7 @@ jobs:
key: ${{ runner.os }}-pubspec-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-pubspec-
- name: Install dependencies
run: dart pub get

Expand All @@ -62,6 +60,7 @@ jobs:
runs-on: ubuntu-latest
env:
TEST_TOKEN: ${{ secrets.TEST_TOKEN }}
TEST_GUILD: ${{ secrets.TEST_GUILD }}
steps:
- name: Setup Dart Action
uses: dart-lang/setup-dart@v1
Expand All @@ -81,4 +80,4 @@ jobs:
run: dart pub get

- name: Unit tests
run: dart run test --coverage="coverage" test/unit/**
run: dart run test --coverage="coverage"
39 changes: 0 additions & 39 deletions .pubignore

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 4.0.0
__20.10.2023__
- Fixed an issue with link formatting.

## 4.0.0-dev.1
__17.09.2023__
- Bump nyxx to `6.0.0`. See the changelog at https://pub.dev/packages/nyxx for more information.
- Removed helpers now in the nyxx package.
- Added pagination support.

## 3.2.0

- Bump nyxx to `4.2.0`
Expand Down
5 changes: 1 addition & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ include: package:lints/recommended.yaml

linter:
rules:
unrelated_type_equality_checks: false
implementation_imports: false

analyzer:
exclude: [build/**, example/**]
language:
strict-raw-types: true
strong-mode:
implicit-casts: false
strict-casts: false
83 changes: 63 additions & 20 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,71 @@
import "dart:io";

import "package:nyxx/nyxx.dart";
import "package:nyxx_extensions/emoji.dart" as emoji_extension;
import "package:nyxx_extensions/src/message_resolver/message_resolver.dart" as message_resolver_extension;
import "package:nyxx_extensions/nyxx_extensions.dart";

// nyxx.extensions contains several different extensions
// that could simplify making and implementing bots.
void main() async {
// Emoji extension would allow to download and fetch discord emoji definitions
// from resource shared by Emzi.
// Emoji utils can cache results to do not download json document each time
final allEmojis = emoji_extension.getAllEmojiDefinitions();

// Its also possible to filter the emojis based on predicate
final filteredEmojis = emoji_extension.filterEmojiDefinitions(
(emojiDefinition) => emojiDefinition.primaryName.startsWith("smile")
final client = await Nyxx.connectGateway(
Platform.environment['TOKEN']!,
GatewayIntents.guildMessages | GatewayIntents.messageContent,
options: GatewayClientOptions(plugins: [logging, cliIntegration, pagination]),
);

// Needed for next extension
final bot = Nyxx("token", GatewayIntents.allUnprivileged);
// Get an emoji by its unicode character...
final heartEmoji = client.getTextEmoji('❤️');

// ...or list all available emojis
final allEmojis = await client.getTextEmojis();
print('There are currently ${allEmojis.length} emojis!');

// Get information about a text emoji!
final heartEmojiInformation = await heartEmoji.getDefinition();
print('The primary name of ${heartEmojiInformation.surrogates} is ${heartEmojiInformation.primaryName}');

// Sanitizing content makes it safe to send to Discord without triggering any mentions
client.onMessageCreate.listen((event) async {
if (event.message.content.startsWith('!sanitize')) {
event.message.channel.sendMessage(MessageBuilder(
content: 'Sanitized content: ${await sanitizeContent(event.message.content, channel: event.message.channel)}',
));
}
});

// Pagination allows for long segments of text to be sent as one chunk.
const loreumIpsum = '''
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et. Et
malesuada fames ac turpis egestas maecenas pharetra convallis. Vulputate eu
scelerisque felis imperdiet proin fermentum leo. Amet risus nullam eget felis
eget nunc lobortis mattis aliquam. Id leo in vitae turpis. Adipiscing elit
pellentesque habitant morbi tristique. Adipiscing commodo elit at imperdiet
dui. Ridiculus mus mauris vitae ultricies leo. Sapien pellentesque habitant
morbi tristique senectus. Mauris pellentesque pulvinar pellentesque habitant.
Mus mauris vitae ultricies leo integer malesuada. Sit amet est placerat in
egestas erat. Id leo in vitae turpis massa sed elementum tempus egestas.
Posuere sollicitudin aliquam ultrices sagittis orci a scelerisque purus.
Sagittis orci a scelerisque purus semper eget. Nisl purus in mollis nunc.
Curabitur vitae nunc sed velit. At lectus urna duis convallis convallis tellus
id. Risus nec feugiat in fermentum posuere urna nec. At elementum eu facilisis
sed odio morbi quis. Est ante in nibh mauris. Dictumst quisque sagittis purus
sit amet volutpat consequat. Quis imperdiet massa tincidunt nunc pulvinar
sapien. Viverra tellus in hac habitasse platea dictumst vestibulum. Eu
consequat ac felis donec et. Mauris a diam maecenas sed enim ut sem. Placerat
in egestas erat imperdiet sed. Orci eu lobortis elementum nibh tellus molestie
nunc non blandit. Rutrum tellus pellentesque eu tincidunt tortor aliquam.
Imperdiet proin fermentum leo vel orci porta non. Ullamcorper velit sed
ullamcorper morbi tincidunt ornare.
''';

// Message Resolver extension allows to transform raw string message content
// to format that user is seeing
final messageResolver = message_resolver_extension.MessageResolver(bot);
client.onMessageCreate.listen((event) async {
if (event.message.content.startsWith('!pages')) {
await event.message.channel.sendMessage(await pagination.split(
loreumIpsum,
// Split into chunks 100 characters long.
maxLength: 100,
));
}
});

// resolve method will return message according to set handling settings in
// MessageResolver constructor.
final resolvedMessage = messageResolver.resolve("This is raw content. <!@123>");
// ...and more!
}
3 changes: 0 additions & 3 deletions lib/attachment_extension.dart

This file was deleted.

3 changes: 0 additions & 3 deletions lib/embed_builder_extension.dart

This file was deleted.

11 changes: 0 additions & 11 deletions lib/emoji.dart

This file was deleted.

3 changes: 0 additions & 3 deletions lib/guild_extension.dart

This file was deleted.

3 changes: 0 additions & 3 deletions lib/member_extension.dart

This file was deleted.

4 changes: 0 additions & 4 deletions lib/message_resolver.dart

This file was deleted.

18 changes: 11 additions & 7 deletions lib/nyxx_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
library nyxx_extensions;

export 'attachment_extension.dart';
export 'embed_builder_extension.dart';
export 'emoji.dart';
export 'member_extension.dart';
export 'message_resolver.dart';
export 'utils.dart';
export 'guild_extension.dart';
export 'src/channel.dart';
export 'src/date_time.dart';
export 'src/embed_builder.dart';
export 'src/emoji.dart';
export 'src/guild.dart';
export 'src/message.dart';
export 'src/pagination.dart';
export 'src/role.dart';
export 'src/sanitizer.dart';
export 'src/user.dart';
export 'src/utils/formatters.dart';
18 changes: 0 additions & 18 deletions lib/src/attachment_extension.dart

This file was deleted.

12 changes: 12 additions & 0 deletions lib/src/channel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nyxx/nyxx.dart';
import 'package:nyxx_extensions/src/utils/formatters.dart';

extension PartialChannelUtils on PartialChannel {
/// A mention of this channel.
String get mention => channelMention(id);
}

extension ChannelUtils on Channel {
/// A URL clients can visit to navigate to this channel.
Uri get url => Uri.https(manager.client.apiOptions.host, '/channels/${this is GuildChannel ? '${(this as GuildChannel).guildId}' : '@me'}/$id');
}
12 changes: 12 additions & 0 deletions lib/src/date_time.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:nyxx_extensions/src/utils/formatters.dart';

extension TimestampStyleDateTime on DateTime {
/// Formats the [DateTime] into a date string timestamp.
String format([TimestampStyle style = TimestampStyle.none]) => formatDate(this, style);
}

extension TimestampStyleDuration on Duration {
/// Formats the [Duration] into a date string timestamp.
/// The style will always be relative to represent as a duration on Discord.
String format() => formatDate(DateTime.now().add(this), TimestampStyle.relativeTime);
}
38 changes: 38 additions & 0 deletions lib/src/embed_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:nyxx/nyxx.dart';

extension EmbedExtension on Embed {
EmbedBuilder toEmbedBuilder() {
return EmbedBuilder(
author: author?._toEmbedAuthorBuilder(),
color: color,
description: description,
fields: fields?.map((field) => field._toEmbedFieldBuilder()).toList(),
footer: footer?._toEmbedFooterBuilder(),
image: image?._toEmbedImageBuilder(),
thumbnail: thumbnail?._toEmbedThumbnailBuilder(),
timestamp: timestamp,
title: title,
url: url,
);
}
}

extension on EmbedAuthor {
EmbedAuthorBuilder _toEmbedAuthorBuilder() => EmbedAuthorBuilder(name: name, iconUrl: iconUrl, url: url);
}

extension on EmbedField {
EmbedFieldBuilder _toEmbedFieldBuilder() => EmbedFieldBuilder(name: name, value: value, isInline: inline);
}

extension on EmbedFooter {
EmbedFooterBuilder _toEmbedFooterBuilder() => EmbedFooterBuilder(text: text, iconUrl: iconUrl);
}

extension on EmbedImage {
EmbedImageBuilder _toEmbedImageBuilder() => EmbedImageBuilder(url: url);
}

extension on EmbedThumbnail {
EmbedThumbnailBuilder _toEmbedThumbnailBuilder() => EmbedThumbnailBuilder(url: url);
}
Loading

0 comments on commit f80bb11

Please sign in to comment.