catch errs
This commit is contained in:
parent
0bc13515e5
commit
5f45903d79
1 changed files with 63 additions and 59 deletions
|
@ -37,61 +37,62 @@ void main(List<String> argsRaw) async {
|
||||||
|
|
||||||
final client = await container.read(ClientController.provider.future);
|
final client = await container.read(ClientController.provider.future);
|
||||||
client.onTimelineEvent.stream.listen((event) async {
|
client.onTimelineEvent.stream.listen((event) async {
|
||||||
final settings = container.read(SettingsController.provider)!;
|
try {
|
||||||
|
final settings = container.read(SettingsController.provider)!;
|
||||||
|
|
||||||
if (event.room.canonicalAlias != settings.adminRoom) return;
|
if (event.room.canonicalAlias != settings.adminRoom) return;
|
||||||
if (event.senderId.startsWith("@${settings.name}:")) return;
|
if (event.senderId.startsWith("@${settings.name}:")) return;
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case EventTypes.Reaction:
|
case EventTypes.Reaction:
|
||||||
if ((event.content["m.relates_to"] as Map<String, dynamic>)["key"] !=
|
if ((event.content["m.relates_to"] as Map<String, dynamic>)["key"] !=
|
||||||
"✅") {
|
"✅") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final parentEvent = await client.getOneRoomEvent(
|
final parentEvent = await client.getOneRoomEvent(
|
||||||
event.roomId!,
|
event.roomId!,
|
||||||
event.relationshipEventId!,
|
event.relationshipEventId!,
|
||||||
);
|
);
|
||||||
if (!parentEvent.senderId.startsWith("@${settings.name}:")) return;
|
if (!parentEvent.senderId.startsWith("@${settings.name}:")) return;
|
||||||
final registration = Registration.fromJson(parentEvent.content);
|
final registration = Registration.fromJson(parentEvent.content);
|
||||||
container
|
container
|
||||||
.read(RegistrationController.provider.notifier)
|
.read(RegistrationController.provider.notifier)
|
||||||
.add(registration);
|
.add(registration);
|
||||||
|
|
||||||
await event.room.sendTextEvent(
|
await event.room.sendTextEvent(
|
||||||
"!admin users create ${registration.username}",
|
"!admin users create ${registration.username}",
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case EventTypes.Message:
|
case EventTypes.Message:
|
||||||
if (!event.senderId.startsWith("@${settings.adminName}:")) break;
|
if (!event.senderId.startsWith("@${settings.adminName}:")) break;
|
||||||
final results = RegExp(
|
final results = RegExp(
|
||||||
r"@(?<username>[a-zA-Z0-9._-]+):[^\s]+.*?password:\s+`(?<password>[^`]+)`",
|
r"@(?<username>[a-zA-Z0-9._-]+):[^\s]+.*?password:\s+`(?<password>[^`]+)`",
|
||||||
).firstMatch(event.body);
|
).firstMatch(event.body);
|
||||||
if (results == null) return;
|
if (results == null) return;
|
||||||
|
|
||||||
final registration = container
|
final registration = container
|
||||||
.read(RegistrationController.provider)
|
.read(RegistrationController.provider)
|
||||||
.firstWhere(
|
.firstWhere(
|
||||||
(account) => account.username == results.namedGroup("username"),
|
(account) => account.username == results.namedGroup("username"),
|
||||||
);
|
);
|
||||||
final password = results.namedGroup("password")!;
|
final password = results.namedGroup("password")!;
|
||||||
final reactionEvent = await event.room.sendReaction(
|
final reactionEvent = await event.room.sendReaction(
|
||||||
event.eventId,
|
event.eventId,
|
||||||
"✉️ Sending...",
|
"✉️ Sending...",
|
||||||
);
|
);
|
||||||
|
|
||||||
await container
|
await container
|
||||||
.read(MailClientController.provider.notifier)
|
.read(MailClientController.provider.notifier)
|
||||||
.sendMessage(
|
.sendMessage(
|
||||||
plainText:
|
plainText:
|
||||||
"""Your registration for Federated Nexus has been accepted! Your credentials are:
|
"""Your registration for Federated Nexus has been accepted! Your credentials are:
|
||||||
Username: ${registration.username}.
|
Username: ${registration.username}.
|
||||||
Password: $password
|
Password: $password
|
||||||
|
|
||||||
If you have any questions, check out our documentation: https://federated.nexus/services/matrix/.
|
If you have any questions, check out our documentation: https://federated.nexus/services/matrix/.
|
||||||
|
|
||||||
If you have any issues, reply to this email.""",
|
If you have any issues, reply to this email.""",
|
||||||
markdown:
|
markdown:
|
||||||
"""# Your registration for Federated Nexus has been accepted!
|
"""# Your registration for Federated Nexus has been accepted!
|
||||||
## Your credentials are:
|
## Your credentials are:
|
||||||
- ### Username: ${registration.username}.
|
- ### Username: ${registration.username}.
|
||||||
- ### Password: $password
|
- ### Password: $password
|
||||||
|
@ -99,21 +100,24 @@ If you have any issues, reply to this email.""",
|
||||||
If you have any questions, check out [our documentation](https://federated.nexus/services/matrix/).
|
If you have any questions, check out [our documentation](https://federated.nexus/services/matrix/).
|
||||||
|
|
||||||
If you have any issues, reply to this email.""",
|
If you have any issues, reply to this email.""",
|
||||||
subject:
|
subject:
|
||||||
"Your registration for Federated Nexus has been accepted!",
|
"Your registration for Federated Nexus has been accepted!",
|
||||||
to: mail.MailAddress(registration.username, registration.email),
|
to: mail.MailAddress(registration.username, registration.email),
|
||||||
);
|
|
||||||
await event.room.redactEvent(reactionEvent!);
|
|
||||||
await event.room.sendReaction(event.eventId, "✉️ Sent!");
|
|
||||||
if (settings.inviteTo != null) {
|
|
||||||
client
|
|
||||||
.getRoomByAlias(settings.inviteTo!)!
|
|
||||||
.invite(
|
|
||||||
RegExp(
|
|
||||||
r"(?<userid>@[a-zA-Z0-9._-]+:[^\s]+)",
|
|
||||||
).firstMatch(event.body)!.namedGroup("userid")!,
|
|
||||||
);
|
);
|
||||||
}
|
await event.room.redactEvent(reactionEvent!);
|
||||||
|
await event.room.sendReaction(event.eventId, "✉️ Sent!");
|
||||||
|
if (settings.inviteTo != null) {
|
||||||
|
client
|
||||||
|
.getRoomByAlias(settings.inviteTo!)!
|
||||||
|
.invite(
|
||||||
|
RegExp(
|
||||||
|
r"(?<userid>@[a-zA-Z0-9._-]+:[^\s]+)",
|
||||||
|
).firstMatch(event.body)!.namedGroup("userid")!,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error, stackTrace) {
|
||||||
|
print("$error\n$stackTrace");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue