Skip to content

Commit

Permalink
Release 4.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Feb 15, 2025
1 parent f2aafcb commit 98190e0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 4.10.1
- Fix /avatar command

## 4.10.0
- Implement frontend
- Fix member left annotations
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.9'
services:
running_on_dart:
image: ghcr.io/nyxx-discord/running_on_dart:4.10.0
image: ghcr.io/nyxx-discord/running_on_dart:4.10.1
container_name: running_on_dart
env_file:
- .env
Expand Down
20 changes: 7 additions & 13 deletions lib/src/commands/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ final avatar = ChatCommand(
"Get a user's avatar",
id('avatar', (
ChatContext context, [
@Description('The user to fetch the avatar for') Member? target,
@Description("Whether to show the user's guild profile, if they have one") bool showGuildProfile = true,
@Description('The user to fetch the avatar for') User? target,
@Description("Whether to show the user's guild profile, if they have one") bool showGuildProfile = false,
]) async {
// Default to the user who invoked the command
target ??= context.member;
final targetUser = target ?? context.user;

Uri? avatarUrl;
if (showGuildProfile && context.guild != null) {
final targetMember = await context.guild?.members.get(targetUser.id);

// Try to fetch the guild profile
if (showGuildProfile) {
avatarUrl = target?.avatar?.url;
return context.respond(MessageBuilder(content: targetMember?.avatar?.url.toString() ?? 'Cannot get member avatar.'));
}

// Default to the user avatar
avatarUrl ??= target?.user?.avatar.url;

final content = avatarUrl?.toString() ?? "Cannot obtain avatar Url";
await context.respond(MessageBuilder(content: content));
return context.respond(MessageBuilder(content: targetUser.avatar.url.toString()));
}),
);
2 changes: 1 addition & 1 deletion lib/src/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:io';

import 'package:nyxx/nyxx.dart';

String get version => '4.10.0';
String get version => '4.10.1';

/// Get a [String] from an environment variable, throwing an exception if it is not set.
///
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: running_on_dart
version: 4.10.0
version: 4.10.1
description: Discord Bot for nyxx development
homepage: https://github.com/nyxx-discord/running_on_dart
repository: https://github.com/nyxx-discord/running_on_dart
Expand Down
64 changes: 60 additions & 4 deletions test/utils_test.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'package:running_on_dart/src/util/util.dart';
import 'package:test/test.dart';
import 'package:nyxx/nyxx.dart';

void main() {
test("random color test", () {
final color = getRandomColor();
final secondColor = getRandomColor();

expect(color, isNot(secondColor));
expect(color, color);
expect(color.value, inInclusiveRange(0, 0xFFFFFFFF));
});

test("strip non ascii characters", () {
Expand All @@ -17,13 +18,11 @@ void main() {
group("FormatShortDurationExtension", () {
test("Minutes and second", () {
final duration = Duration(minutes: 2, seconds: 56);

expect(duration.formatShort(), '00:02:56');
});

test("Hours, minutes and second", () {
final duration = Duration(hours: 10, minutes: 2, seconds: 56);

expect(duration.formatShort(), '10:02:56');
});
});
Expand All @@ -34,7 +33,7 @@ void main() {
});

test("whitespace", () {
expect(valueOrNull(' '), isNull);
expect(valueOrNull('  '), isNull);
});

test("null value", () {
Expand All @@ -55,4 +54,61 @@ void main() {
expect(getDurationFromStringOrDefault(null, null), isNull);
});
});

group("Utility Functions (New Tests)", () { // Group for the new tests

test('getCurrentMemoryString returns a string with memory usage', () {
final memoryString = getCurrentMemoryString();
expect(memoryString, matches(RegExp(r'^\d+\.\d+/\d+\.\d+ MB$')));
});

test('getDartPlatform returns the Dart platform', () {
final platform = getDartPlatform();
expect(platform, isNotEmpty);
});


test('ToMapExtension converts Iterable<MapEntry> to Map', () {
final entries = [MapEntry('a', 1), MapEntry('b', 2)];
final map = entries.toMap();
expect(map, {'a': 1, 'b': 2});
});

test('generateRandomString generates a random string of given length', () {
final randomString = generateRandomString(10);
expect(randomString.length, 10);
expect(randomString, matches(RegExp(r'^[A-Za-z0-9]+$')));
});

test('spliceEmbedsForMessageBuilders splits embeds into chunks', () {
final embeds = [EmbedBuilder(), EmbedBuilder(), EmbedBuilder(), EmbedBuilder()];
final messageBuilders = spliceEmbedsForMessageBuilders(embeds, 2).toList();
expect(messageBuilders.length, 2);
expect(messageBuilders[0].embeds?.length, 2);
expect(messageBuilders[1].embeds?.length, 2);
});

test('stripNonAscii removes non-ASCII characters (extended)', () {
expect(stripNonAscii('test\u00A0test'), 'testtest');
});

test('boolValue converts values to boolean', () {
expect(boolValue(true), isTrue);
expect(boolValue(1), isTrue);
expect(boolValue('1'), isTrue);
expect(boolValue('yes'), isTrue);
expect(boolValue('true'), isTrue);
expect(boolValue(false), isFalse);
expect(boolValue(0), isFalse);
expect(boolValue('0'), isFalse);
expect(boolValue('no'), isFalse);
expect(boolValue('false'), isFalse);
expect(boolValue('test'), isFalse);
});

test('boolToString converts boolean to string', () {
expect(boolToString(true), 'true');
expect(boolToString(false), 'false');
});
});
}

0 comments on commit 98190e0

Please sign in to comment.