-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignalCliDBus.pm
More file actions
92 lines (63 loc) · 1.57 KB
/
SignalCliDBus.pm
File metadata and controls
92 lines (63 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package SignalCliDBus;
use strict;
use warnings;
use Net::DBus;
use Net::DBus::Reactor;
use Mojo::Base -base;
use MIME::Base64;
use Data::Dumper;
has reactor => undef;
has signalBot => undef;
has groups => sub {{}};
my $bus = Net::DBus->system;
my $hal = $bus->get_service("org.asamk.Signal");
my $object = $hal->get_object(
"/org/asamk/Signal",
"org.asamk.Signal"
);
sub StartReactor {
my $self = shift;
$object->connect_to_signal('MessageReceived', sub
{
$self->signalBot->MessageReceived(@_);
});
my $reactor = Net::DBus::Reactor->main();
$self->reactor($reactor);
$self->reactor->run();
}
sub StopReactor {
my $self = shift;
$self->reactor->shutdown();
}
sub sendGroupMessage {
my $self = shift;
my $send_message = shift;
$self->signalBot->logEntry("sende: ".$send_message." an gruppe: ".Data::Dumper::Dumper($self->signalBot->groupID));
$object->sendGroupMessage($send_message,undef,$self->signalBot->groupID);
return 1;
}
sub getGroupName {
my $self = shift;
return $object->getGroupName($self->signalBot->groupID);
}
sub setGroupIDByName {
my $self = shift;
my $name = shift;
$self->signalBot->groupID($self->getGroupIdByName($name));
}
sub getGroupIdByName {
my $self = shift;
my $name = shift;
my $groups = $self->groups;
return $groups->{$name} if (defined($groups->{$name}));
# Update known groups
$groups = {};
my @groupIds = $object->getGroupIds();
foreach (@{$groupIds[0]}) {
$groups->{$object->getGroupName($_)} = $_;
}
$self->groups($groups);
return $groups->{$name} if (defined($groups->{$name}));
return [];
}
1;