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);
|
||||
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.senderId.startsWith("@${settings.name}:")) return;
|
||||
switch (event.type) {
|
||||
case EventTypes.Reaction:
|
||||
if ((event.content["m.relates_to"] as Map<String, dynamic>)["key"] !=
|
||||
"✅") {
|
||||
return;
|
||||
}
|
||||
final parentEvent = await client.getOneRoomEvent(
|
||||
event.roomId!,
|
||||
event.relationshipEventId!,
|
||||
);
|
||||
if (!parentEvent.senderId.startsWith("@${settings.name}:")) return;
|
||||
final registration = Registration.fromJson(parentEvent.content);
|
||||
container
|
||||
.read(RegistrationController.provider.notifier)
|
||||
.add(registration);
|
||||
if (event.room.canonicalAlias != settings.adminRoom) return;
|
||||
if (event.senderId.startsWith("@${settings.name}:")) return;
|
||||
switch (event.type) {
|
||||
case EventTypes.Reaction:
|
||||
if ((event.content["m.relates_to"] as Map<String, dynamic>)["key"] !=
|
||||
"✅") {
|
||||
return;
|
||||
}
|
||||
final parentEvent = await client.getOneRoomEvent(
|
||||
event.roomId!,
|
||||
event.relationshipEventId!,
|
||||
);
|
||||
if (!parentEvent.senderId.startsWith("@${settings.name}:")) return;
|
||||
final registration = Registration.fromJson(parentEvent.content);
|
||||
container
|
||||
.read(RegistrationController.provider.notifier)
|
||||
.add(registration);
|
||||
|
||||
await event.room.sendTextEvent(
|
||||
"!admin users create ${registration.username}",
|
||||
);
|
||||
break;
|
||||
case EventTypes.Message:
|
||||
if (!event.senderId.startsWith("@${settings.adminName}:")) break;
|
||||
final results = RegExp(
|
||||
r"@(?<username>[a-zA-Z0-9._-]+):[^\s]+.*?password:\s+`(?<password>[^`]+)`",
|
||||
).firstMatch(event.body);
|
||||
if (results == null) return;
|
||||
await event.room.sendTextEvent(
|
||||
"!admin users create ${registration.username}",
|
||||
);
|
||||
break;
|
||||
case EventTypes.Message:
|
||||
if (!event.senderId.startsWith("@${settings.adminName}:")) break;
|
||||
final results = RegExp(
|
||||
r"@(?<username>[a-zA-Z0-9._-]+):[^\s]+.*?password:\s+`(?<password>[^`]+)`",
|
||||
).firstMatch(event.body);
|
||||
if (results == null) return;
|
||||
|
||||
final registration = container
|
||||
.read(RegistrationController.provider)
|
||||
.firstWhere(
|
||||
(account) => account.username == results.namedGroup("username"),
|
||||
);
|
||||
final password = results.namedGroup("password")!;
|
||||
final reactionEvent = await event.room.sendReaction(
|
||||
event.eventId,
|
||||
"✉️ Sending...",
|
||||
);
|
||||
final registration = container
|
||||
.read(RegistrationController.provider)
|
||||
.firstWhere(
|
||||
(account) => account.username == results.namedGroup("username"),
|
||||
);
|
||||
final password = results.namedGroup("password")!;
|
||||
final reactionEvent = await event.room.sendReaction(
|
||||
event.eventId,
|
||||
"✉️ Sending...",
|
||||
);
|
||||
|
||||
await container
|
||||
.read(MailClientController.provider.notifier)
|
||||
.sendMessage(
|
||||
plainText:
|
||||
"""Your registration for Federated Nexus has been accepted! Your credentials are:
|
||||
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!
|
||||
markdown:
|
||||
"""# Your registration for Federated Nexus has been accepted!
|
||||
## Your credentials are:
|
||||
- ### Username: ${registration.username}.
|
||||
- ### 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 issues, reply to this email.""",
|
||||
subject:
|
||||
"Your registration for Federated Nexus has been accepted!",
|
||||
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")!,
|
||||
subject:
|
||||
"Your registration for Federated Nexus has been accepted!",
|
||||
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")!,
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error, stackTrace) {
|
||||
print("$error\n$stackTrace");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue