Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write dart api docs member user server channels #188

Open
wants to merge 12 commits into
base: 4.0.x
Choose a base branch
from
8 changes: 8 additions & 0 deletions lib/api/server/member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ final class Member {
Future<void> setNickname(String value, String? reason) => _memberMethods.updateMember(
serverId: server.id, memberId: id, payload: {'nick': value}, reason: reason);

Future<void> setTimeout(Duration duration, {String? reason}) {
final timeout = DateTime.now().add(duration);
return _memberMethods.updateMember(
serverId: server.id,
memberId: id, payload: {'communication_disabled_until': timeout.toIso8601String()},
reason: reason);
}

Future<void> ban({Duration? deleteSince, String? reason}) =>
_memberMethods.banMember(serverId: server.id, memberId: id, deleteSince: deleteSince);

Expand Down
15 changes: 15 additions & 0 deletions lib/infrastructure/internals/datastore/parts/member_part.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,19 @@ final class MemberPart implements DataStorePart {

return Future.wait(awaitedMembers);
}

Future<void> deleteServer(Snowflake id, {String? reason}) async {
final response = await _kernel.dataStore.client.delete(
'/guilds/$id',
option: HttpRequestOptionImpl(headers: {DiscordHeader.auditLogReason(reason)})
);

if (status.isSuccess(response.statusCode)) {
final cacheKey = _kernel.marshaller.cacheKey.server(id);
await _kernel.marshaller.cache.remove(cacheKey);
} else {
throw HttpException(response.body);
}
}

}
23 changes: 23 additions & 0 deletions lib/infrastructure/internals/datastore/parts/server_part.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,27 @@ final class ServerPart implements DataStorePart {
_ => throw Exception('Unknown status code: ${response.statusCode}'),
} as Future<List<Role>>;
}

Future<void> setOwner(Snowflake guildId, Snowflake newOwnerId) async {
final server = await getServer(guildId);

final response = await _kernel.dataStore.client.patch(
'/guilds/$guildId',
body: {'owner_id': newOwnerId.toString()},
);

if (response.statusCode == 200) {
server.ownerId = newOwnerId;
await _kernel.marshaller.cache.put(guildId, server);


await Future.wait([
...server.roles.list.values.map((role) => _kernel.marshaller.cache.put(role.id, role)),
...server.members.list.values.map((member) => _kernel.marshaller.cache.put(member.id, member))
]);
} else {
throw HttpException('Failed to set new owner. Status code: ${response.statusCode}');
}
}

}
12 changes: 12 additions & 0 deletions lib/infrastructure/internals/marshaller/marshaller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import 'package:mineral/infrastructure/internals/marshaller/cache_key.dart';
import 'package:mineral/infrastructure/internals/marshaller/serializer_bucket.dart';
import 'package:mineral/infrastructure/services/logger/logger.dart';

// Définition de l'interface CacheKeyContract
Arcel-Bika marked this conversation as resolved.
Show resolved Hide resolved
abstract interface class CacheKeyContract {
String server(Snowflake id);
}

class CacheKey implements CacheKeyContract {
@override
String server(Snowflake id) {
return 'server_$id';
}
}

abstract interface class MarshallerContract {
DataStoreContract get dataStore;

Expand Down
3 changes: 3 additions & 0 deletions lib/infrastructure/kernel/kernel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ abstract interface class KernelContract {
CommandInteractionManagerContract get commands;

Future<void> init();

// Ajout de la propriété ou méthode cacheKey
String cacheKey(Snowflake serverId);
}

final class Kernel implements KernelContract {
Expand Down