diff --git a/lib/api/server/member.dart b/lib/api/server/member.dart index f5f258bd..83af2942 100644 --- a/lib/api/server/member.dart +++ b/lib/api/server/member.dart @@ -56,6 +56,14 @@ final class Member { Future setNickname(String value, String? reason) => _memberMethods.updateMember( serverId: server.id, memberId: id, payload: {'nick': value}, reason: reason); + Future 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 ban({Duration? deleteSince, String? reason}) => _memberMethods.banMember(serverId: server.id, memberId: id, deleteSince: deleteSince); diff --git a/lib/infrastructure/internals/datastore/parts/member_part.dart b/lib/infrastructure/internals/datastore/parts/member_part.dart index 491fd7e1..41c7f462 100644 --- a/lib/infrastructure/internals/datastore/parts/member_part.dart +++ b/lib/infrastructure/internals/datastore/parts/member_part.dart @@ -128,4 +128,19 @@ final class MemberPart implements DataStorePart { return Future.wait(awaitedMembers); } + + Future 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); + } +} + } diff --git a/lib/infrastructure/internals/datastore/parts/server_part.dart b/lib/infrastructure/internals/datastore/parts/server_part.dart index 34a20a74..e46e279e 100644 --- a/lib/infrastructure/internals/datastore/parts/server_part.dart +++ b/lib/infrastructure/internals/datastore/parts/server_part.dart @@ -102,4 +102,27 @@ final class ServerPart implements DataStorePart { _ => throw Exception('Unknown status code: ${response.statusCode}'), } as Future>; } + + Future 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}'); + } +} + } diff --git a/lib/infrastructure/internals/marshaller/marshaller.dart b/lib/infrastructure/internals/marshaller/marshaller.dart index ceb335b4..2b882de4 100644 --- a/lib/infrastructure/internals/marshaller/marshaller.dart +++ b/lib/infrastructure/internals/marshaller/marshaller.dart @@ -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 +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; diff --git a/lib/infrastructure/kernel/kernel.dart b/lib/infrastructure/kernel/kernel.dart index eb2e1445..56488c2c 100644 --- a/lib/infrastructure/kernel/kernel.dart +++ b/lib/infrastructure/kernel/kernel.dart @@ -47,6 +47,9 @@ abstract interface class KernelContract { CommandInteractionManagerContract get commands; Future init(); + + // Ajout de la propriété ou méthode cacheKey + String cacheKey(Snowflake serverId); } final class Kernel implements KernelContract {