use diff mail client

This commit is contained in:
Henry Hiles 2026-02-28 19:48:50 -05:00
commit 2ccfd214e1
No known key found for this signature in database
7 changed files with 113 additions and 162 deletions

View file

@ -1,7 +1,6 @@
import "dart:io";
import "package:cli_tools/config.dart";
import "package:collection/collection.dart";
import "package:enough_mail/enough_mail.dart" as mail;
import "package:markdown/markdown.dart";
import "package:matrix/matrix.dart";
import "package:nexusbot/controllers/client_controller.dart";
@ -20,7 +19,7 @@ void main(List<String> argsRaw) async {
..addOption("homeserver", mandatory: true)
..addOption("failureUri", mandatory: true)
..addOption("successUri", mandatory: true)
..addOption("name", mandatory: true)
..addOption("username", mandatory: true)
..addOption("adminName", mandatory: true)
..addOption("adminRoom", mandatory: true)
..addOption("email", mandatory: true)
@ -28,9 +27,7 @@ void main(List<String> argsRaw) async {
..addOption("mailDomain", mandatory: true)
..addOption("smtpPasswordFile", mandatory: true)
..addOption("botPasswordFile", mandatory: true)
..addOption("emailAlias")
..addOption("userName")
..addOption("outgoingPort")
..addOption("mailUsername", mandatory: true)
..addOption("inviteTo");
final container = ProviderContainer();
@ -44,16 +41,20 @@ void main(List<String> argsRaw) async {
final settings = container.read(SettingsController.provider)!;
if (event.room.canonicalAlias != settings.adminRoom) return;
if (event.senderId.startsWith("@${settings.name}:")) return;
if (event.senderId.startsWith("@${settings.username}:")) return;
switch (event.type) {
case EventTypes.Reaction:
final reaction =
(event.content["m.relates_to"] as Map<String, dynamic>)["key"];
final parentEvent = await client.getOneRoomEvent(
event.roomId!,
event.relationshipEventId!,
);
if (!parentEvent.senderId.startsWith("@${settings.name}:")) return;
if (!parentEvent.senderId.startsWith("@${settings.username}:")) {
return;
}
if (reaction == "") {
final registration = Registration.fromJson(parentEvent.content);
container
@ -90,29 +91,17 @@ void main(List<String> argsRaw) async {
"✉️ Sending...",
);
String replace(String body) => body
.replaceAll("\${username}", registration.username)
.replaceAll("\${password}", password);
await container
.read(MailClientController.provider.notifier)
.sendMessage(
plainText:
"""Your registration for Federated Nexus has been accepted! Your credentials are:
Username: ${registration.username}
Password: $password
If you have any questions, check out our documentation: https://federated.nexus/services/matrix/.
If you have any issues, reply to this email.""",
markdown:
"""# Your registration for Federated Nexus has been accepted!
## Your credentials are:
- ### Username: ${registration.username}
- ### Password: $password
If you have any questions, check out [our documentation](https://federated.nexus/services/matrix/).
If you have any issues, reply to this email.""",
subject:
"Your registration for Federated Nexus has been accepted!",
to: mail.MailAddress(registration.username, registration.email),
.send(
plainText: replace(settings.plainText),
markdown: replace(settings.markdown),
subject: settings.subject,
to: registration.email,
);
await event.room.redactEvent(reactionEvent!);
await event.room.sendReaction(event.eventId, "✉️ Sent!");