2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-21 20:06:18 +00:00

50_SSChatBot: contrib 1.0.0

git-svn-id: https://svn.fhem.de/fhem/trunk@20648 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
nasseeder1 2019-12-02 22:58:28 +00:00
parent b4fcfa430b
commit 88e747c870

View File

@ -88,6 +88,9 @@ sub SSChatBot_Initialize($) {
$hash->{AttrList} = "disable:1,0 ". $hash->{AttrList} = "disable:1,0 ".
"defaultPeer:--wait#for#userlist-- ". "defaultPeer:--wait#for#userlist-- ".
"allowedUserForSet:--wait#for#userlist-- ".
"allowedUserForGet:--wait#for#userlist-- ".
"allowedUserForCode:--wait#for#userlist-- ".
"showTokenInLog:1,0 ". "showTokenInLog:1,0 ".
"httptimeout ". "httptimeout ".
$readingFnAttributes; $readingFnAttributes;
@ -1044,9 +1047,13 @@ sub SSChatBot_chatop_parse ($) {
my $list = $modules{$hash->{TYPE}}{AttrList}; my $list = $modules{$hash->{TYPE}}{AttrList};
my @deva = split(" ", $list); my @deva = split(" ", $list);
foreach (@deva) { foreach (@deva) {
push @newa, $_ if($_ !~ /defaultPeer:/); push @newa, $_ if($_ !~ /defaultPeer:|allowedUserFor(Set|Get|Code):|/);
} }
push @newa, ($uids?"defaultPeer:multiple-strict,$uids ":"defaultPeer:--no#userlist#selectable--"); push @newa, ($uids?"defaultPeer:multiple-strict,$uids ":"defaultPeer:--no#userlist#selectable--");
push @newa, ($uids?"allowedUserForSet:multiple-strict,$uids ":"allowedUserForSet:--no#userlist#selectable--");
push @newa, ($uids?"allowedUserForGet:multiple-strict,$uids ":"allowedUserForGet:--no#userlist#selectable--");
push @newa, ($uids?"allowedUserForCode:multiple-strict,$uids ":"allowedUserForCode:--no#userlist#selectable--");
$hash->{".AttrList"} = join(" ", @newa); # Device spezifische AttrList, überschreibt Modul AttrList ! $hash->{".AttrList"} = join(" ", @newa); # Device spezifische AttrList, überschreibt Modul AttrList !
$out .= "</table>"; $out .= "</table>";
@ -1104,8 +1111,8 @@ sub SSChatBot_chatop_parse ($) {
} }
readingsBeginUpdate ($hash); readingsBeginUpdate ($hash);
readingsBulkUpdateIfChanged ($hash, "sendPostId", $postid); readingsBulkUpdate ($hash, "sendPostId", $postid);
readingsBulkUpdateIfChanged ($hash, "sendUserId", $uid); readingsBulkUpdate ($hash, "sendUserId", $uid);
readingsEndUpdate ($hash,1); readingsEndUpdate ($hash,1);
} }
@ -1375,6 +1382,7 @@ sub SSChatBot_formText ($) {
'"' => "´", # doppelte Hochkomma sind im Text nicht erlaubt '"' => "´", # doppelte Hochkomma sind im Text nicht erlaubt
" H" => " h", # Bug im Chat wenn vor großem H ein Zeichen + Leerzeichen vorangeht " H" => " h", # Bug im Chat wenn vor großem H ein Zeichen + Leerzeichen vorangeht
"#" => "", # Hashtags sind im Text nicht erlaubt "#" => "", # Hashtags sind im Text nicht erlaubt
"&" => "", # & ist im Text nicht erlaubt
); );
$txt =~ s/\n/ESC_newline_ESC/g; $txt =~ s/\n/ESC_newline_ESC/g;
@ -1488,7 +1496,9 @@ sub SSChatBot_CGI() {
my ($request) = @_; my ($request) = @_;
my ($hash,$name,$link,$args); my ($hash,$name,$link,$args);
my ($text,$timestamp,$channelid,$channelname,$userid,$username,$postid,$triggerword) = ("","","","","","","",""); my ($text,$timestamp,$channelid,$channelname,$userid,$username,$postid,$triggerword) = ("","","","","","","","");
my ($command,$cr) = ("",""); my ($command,$cr,$au) = ("","","");
my @aul;
my $state = "active";
my $ret = "success"; my $ret = "success";
@ -1578,21 +1588,46 @@ sub SSChatBot_CGI() {
my $p2 = $2; my $p2 = $2;
if($p1 =~ /set.*/i) { if($p1 =~ /set.*/i) {
Log3($name, 4, "$name - execute FHEM command: set ".$p2); $au = AttrVal($name,"allowedUserForSet", "all");
@aul = split(",",$au);
if($au eq "all" || $username ~~ @aul) {
Log3($name, 4, "$name - Synology Chat user \"$username\" execute FHEM command: set ".$p2);
$cr = CommandSet(undef, $p2); # set-Befehl in FHEM ausführen $cr = CommandSet(undef, $p2); # set-Befehl in FHEM ausführen
} else {
$cr = "User \"$username\" is not allowed execute \"$command\" command";
$state = "command execution denied";
Log3($name, 2, "$name - WARNING - Chat user \"$username\" is not authorized for \"$command\" command. Execution denied !");
}
} elsif ($p1 =~ /get.*/i) { } elsif ($p1 =~ /get.*/i) {
Log3($name, 4, "$name - execute FHEM command: get ".$p2); $au = AttrVal($name,"allowedUserForGet", "all");
@aul = split(",",$au);
if($au eq "all" || $username ~~ @aul) {
Log3($name, 4, "$name - Synology Chat user \"$username\" execute FHEM command: get ".$p2);
$cr = CommandGet(undef, $p2); # get-Befehl in FHEM ausführen $cr = CommandGet(undef, $p2); # get-Befehl in FHEM ausführen
} else {
$cr = "User \"$username\" is not allowed execute \"$command\" command";
$state = "command execution denied";
Log3($name, 2, "$name - WARNING - Chat user \"$username\" is not authorized for \"$command\" command. Execution denied !");
}
} elsif ($p1 =~ /code.*/i) { } elsif ($p1 =~ /code.*/i) {
$au = AttrVal($name,"allowedUserForCode", "all");
@aul = split(",",$au);
if($au eq "all" || $username ~~ @aul) {
my $code = $p2; my $code = $p2;
if($p2 =~ m/^\s*(\{.*\})\s*$/s) { if($p2 =~ m/^\s*(\{.*\})\s*$/s) {
$p2 = $1; $p2 = $1;
} else { } else {
$p2 = ''; $p2 = '';
} }
Log3($name, 4, "$name - Synology Chat user \"$username\" execute FHEM command: ".$p2);
Log3($name, 4, "$name - execute FHEM command: ".$p2); $cr = AnalyzeCommand(undef, $p2) if($p2); # Perl Code in FHEM ausführen
$cr = AnalyzeCommandChain(undef, $p2) if($p2); } else {
$cr = "User \"$username\" is not allowed execute \"$command\" command";
$state = "command execution denied";
Log3($name, 2, "$name - WARNING - Chat user \"$username\" is not authorized for \"$command\" command. Execution denied !");
}
} }
$cr = $cr ne ""?$cr:"command '$command' executed"; $cr = $cr ne ""?$cr:"command '$command' executed";
@ -1613,19 +1648,19 @@ sub SSChatBot_CGI() {
} }
readingsBeginUpdate ($hash); readingsBeginUpdate ($hash);
readingsBulkUpdateIfChanged ($hash, "recChannelId", $channelid); readingsBulkUpdate ($hash, "recChannelId", $channelid);
readingsBulkUpdateIfChanged ($hash, "recChannelname", $channelname); readingsBulkUpdate ($hash, "recChannelname", $channelname);
readingsBulkUpdateIfChanged ($hash, "recUserId", $userid); readingsBulkUpdate ($hash, "recUserId", $userid);
readingsBulkUpdateIfChanged ($hash, "recUsername", $username); readingsBulkUpdate ($hash, "recUsername", $username);
readingsBulkUpdateIfChanged ($hash, "recPostId", $postid); readingsBulkUpdate ($hash, "recPostId", $postid);
readingsBulkUpdateIfChanged ($hash, "recTimestamp", $timestamp); readingsBulkUpdate ($hash, "recTimestamp", $timestamp);
readingsBulkUpdateIfChanged ($hash, "recText", $text); readingsBulkUpdate ($hash, "recText", $text);
readingsBulkUpdateIfChanged ($hash, "recTriggerword", $triggerword); readingsBulkUpdate ($hash, "recTriggerword", $triggerword);
readingsBulkUpdateIfChanged ($hash, "recCommand", $command); readingsBulkUpdate ($hash, "recCommand", $command);
readingsBulkUpdateIfChanged ($hash, "sendCommandReturn", $cr); readingsBulkUpdate ($hash, "sendCommandReturn", $cr);
readingsBulkUpdateIfChanged ($hash, "Errorcode", "none"); readingsBulkUpdate ($hash, "Errorcode", "none");
readingsBulkUpdateIfChanged ($hash, "Error", "none"); readingsBulkUpdate ($hash, "Error", "none");
readingsBulkUpdate ($hash, "state", "active"); readingsBulkUpdate ($hash, "state", $state);
readingsEndUpdate ($hash,1); readingsEndUpdate ($hash,1);
return ("text/plain; charset=utf-8", $ret); return ("text/plain; charset=utf-8", $ret);