mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
50_SSChatBot: contrib 1.0.0
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@20601 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
d8972ccdfc
commit
311860d86a
@ -250,6 +250,8 @@ sub SSChatBot_Set($@) {
|
|||||||
|
|
||||||
return if(IsDisabled($name));
|
return if(IsDisabled($name));
|
||||||
|
|
||||||
|
my $idxlist = join(",",(sort keys %{$data{SSChatBot}{$name}{sendqueue}{entries}}));
|
||||||
|
|
||||||
if(!$hash->{TOKEN}) {
|
if(!$hash->{TOKEN}) {
|
||||||
# initiale setlist für neue Devices
|
# initiale setlist für neue Devices
|
||||||
$setlist = "Unknown argument $opt, choose one of ".
|
$setlist = "Unknown argument $opt, choose one of ".
|
||||||
@ -259,6 +261,7 @@ sub SSChatBot_Set($@) {
|
|||||||
$setlist = "Unknown argument $opt, choose one of ".
|
$setlist = "Unknown argument $opt, choose one of ".
|
||||||
"botToken ".
|
"botToken ".
|
||||||
"listSendqueue:noArg ".
|
"listSendqueue:noArg ".
|
||||||
|
($idxlist?"purgeSendqueue:-all-,$idxlist ":"purgeSendqueue:-all- ").
|
||||||
"sendItem:textField-long "
|
"sendItem:textField-long "
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -277,55 +280,66 @@ sub SSChatBot_Set($@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} elsif ($opt eq "listSendqueue") {
|
} elsif ($opt eq "listSendqueue") {
|
||||||
my $sub = sub ($) {
|
my $sub = sub ($) {
|
||||||
my ($idx) = @_;
|
my ($idx) = @_;
|
||||||
my $ret;
|
my $ret;
|
||||||
foreach my $key (reverse sort keys %{$data{SSChatBot}{$name}{sendqueue}{entries}{$idx}}) {
|
foreach my $key (reverse sort keys %{$data{SSChatBot}{$name}{sendqueue}{entries}{$idx}}) {
|
||||||
$ret .= ", " if($ret);
|
$ret .= ", " if($ret);
|
||||||
$ret .= $key."=>".$data{SSChatBot}{$name}{sendqueue}{entries}{$idx}{$key};
|
$ret .= $key."=>".$data{SSChatBot}{$name}{sendqueue}{entries}{$idx}{$key};
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
my $sq;
|
my $sq;
|
||||||
foreach my $idx (sort{$a<=>$b}keys %{$data{SSChatBot}{$name}{sendqueue}{entries}}) {
|
foreach my $idx (sort{$a<=>$b}keys %{$data{SSChatBot}{$name}{sendqueue}{entries}}) {
|
||||||
$sq .= $idx." => ".$sub->($idx)."\n";
|
$sq .= $idx." => ".$sub->($idx)."\n";
|
||||||
}
|
}
|
||||||
return $sq;
|
return $sq;
|
||||||
|
|
||||||
|
} elsif ($opt eq "purgeSendqueue") {
|
||||||
|
if($prop eq "-all-") {
|
||||||
|
delete $hash->{OPIDX};
|
||||||
|
delete $data{SSChatBot}{$name}{sendqueue}{entries};
|
||||||
|
$data{SSChatBot}{$name}{sendqueue}{index} = 0;
|
||||||
|
return "All entries of SendQueue deleted";
|
||||||
|
} else {
|
||||||
|
delete $data{SSChatBot}{$name}{sendqueue}{entries}{$prop};
|
||||||
|
return "SendQueue entry with index \"$prop\" deleted";
|
||||||
|
}
|
||||||
|
|
||||||
} elsif ($opt eq "sendItem") {
|
} elsif ($opt eq "sendItem") {
|
||||||
# text="First line of message to post.\nAlso you can have a second line of message." users="user1"
|
# text="First line of message to post.\nAlso you can have a second line of message." users="user1"
|
||||||
# text="<https://www.synology.com>" users="user1"
|
# text="<https://www.synology.com>" users="user1"
|
||||||
# text="Check this!! <https://www.synology.com|Click here> for details!" users="user1,user2"
|
# text="Check this!! <https://www.synology.com|Click here> for details!" users="user1,user2"
|
||||||
# text="a fun image" fileUrl="http://imgur.com/xxxxx" users="user1,user2"
|
# text="a fun image" fileUrl="http://imgur.com/xxxxx" users="user1,user2"
|
||||||
my $cmd = join(" ", @a);
|
my $cmd = join(" ", @a);
|
||||||
my ($text,$users,$fileUrl);
|
my ($text,$users,$fileUrl);
|
||||||
my($a, $h) = parseParams($cmd);
|
my($a, $h) = parseParams($cmd);
|
||||||
if($h) {
|
if($h) {
|
||||||
$text = $h->{text} if(defined $h->{text});
|
$text = $h->{text} if(defined $h->{text});
|
||||||
$users = $h->{users} if(defined $h->{users});
|
$users = $h->{users} if(defined $h->{users});
|
||||||
$fileUrl = $h->{fileUrl} if(defined $h->{fileUrl});
|
$fileUrl = $h->{fileUrl} if(defined $h->{fileUrl});
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Your sendstring is incorrect. It must contain at least the \"text\" tag like 'text=\"...\" '." if(!$text);
|
return "Your sendstring is incorrect. It must contain at least the \"text\" tag like 'text=\"...\" '." if(!$text);
|
||||||
|
|
||||||
$users = AttrVal($name,"defaultPeer", "") if(!$users);
|
$users = AttrVal($name,"defaultPeer", "") if(!$users);
|
||||||
return "You haven't defined any receptor for send the message to. ".
|
return "You haven't defined any receptor for send the message to. ".
|
||||||
"You have to use the \"users\" tag or define default receptors with attribute \"defaultPeer\"." if(!$users);
|
"You have to use the \"users\" tag or define default receptors with attribute \"defaultPeer\"." if(!$users);
|
||||||
|
|
||||||
# User aufsplitten und zu jedem die ID ermitteln
|
# User aufsplitten und zu jedem die ID ermitteln
|
||||||
my @ua = split(/,/, $users);
|
my @ua = split(/,/, $users);
|
||||||
foreach (@ua) {
|
foreach (@ua) {
|
||||||
next if(!$_);
|
next if(!$_);
|
||||||
my $uid = $hash->{HELPER}{USERS}{$_}{id};
|
my $uid = $hash->{HELPER}{USERS}{$_}{id};
|
||||||
return "The receptor \"$_\" seems to be unknown because its ID coulnd't be found." if(!$uid);
|
return "The receptor \"$_\" seems to be unknown because its ID coulnd't be found." if(!$uid);
|
||||||
|
|
||||||
# Eintrag zur SendQueue hinzufügen
|
# Eintrag zur SendQueue hinzufügen
|
||||||
# Werte: (name,opmode,method,userid,text,fileUrl,channel,attachment)
|
# Werte: (name,opmode,method,userid,text,fileUrl,channel,attachment)
|
||||||
SSChatBot_addQueue($name, "sendItem", "chatbot", $uid, $text, $fileUrl, "", "");
|
SSChatBot_addQueue($name, "sendItem", "chatbot", $uid, $text, $fileUrl, "", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
SSChatBot_getapisites($name);
|
SSChatBot_getapisites($name);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return "$setlist";
|
return "$setlist";
|
||||||
@ -484,12 +498,12 @@ return $ret; # not genera
|
|||||||
######################################################################################
|
######################################################################################
|
||||||
sub SSChatBot_initonboot ($) {
|
sub SSChatBot_initonboot ($) {
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
RemoveInternalTimer($hash, "SSChatBot_initonboot");
|
RemoveInternalTimer($hash, "SSChatBot_initonboot");
|
||||||
|
|
||||||
if ($init_done == 1) {
|
if ($init_done == 1) {
|
||||||
RemoveInternalTimer($hash); # alle Timer löschen
|
RemoveInternalTimer($hash); # alle Timer löschen
|
||||||
|
|
||||||
CommandGet(undef, "$name chatUserlist");
|
CommandGet(undef, "$name chatUserlist");
|
||||||
|
|
||||||
@ -565,7 +579,7 @@ sub SSChatBot_checkretry ($$) {
|
|||||||
$rs = 86400;
|
$rs = 86400;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log3($name, 2, "$name - ERROR - \"$hash->{OPMODE}\" index \"$idx\" finished faulty. Restart SendQueue in $rs seconds (retryCount $rc).");
|
Log3($name, 2, "$name - ERROR - \"$hash->{OPMODE}\" SendQueue index \"$idx\" not executed. Restart SendQueue in $rs seconds (retryCount $rc).");
|
||||||
|
|
||||||
RemoveInternalTimer($hash, "SSChatBot_chatop");
|
RemoveInternalTimer($hash, "SSChatBot_chatop");
|
||||||
InternalTimer(gettimeofday()+$rs, "SSChatBot_chatop", "$name", 0);
|
InternalTimer(gettimeofday()+$rs, "SSChatBot_chatop", "$name", 0);
|
||||||
@ -1332,7 +1346,8 @@ return;
|
|||||||
"synology",
|
"synology",
|
||||||
"synologychat",
|
"synologychat",
|
||||||
"chatbot",
|
"chatbot",
|
||||||
"chat"
|
"chat",
|
||||||
|
"messenger"
|
||||||
],
|
],
|
||||||
"version": "v1.1.1",
|
"version": "v1.1.1",
|
||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user