mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 01:09:47 +00:00
50_SSChatBot: contrib 1.0.0
git-svn-id: https://svn.fhem.de/fhem/trunk@20668 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
1a33610b46
commit
a802338991
@ -93,7 +93,7 @@ sub SSChatBot_Initialize($) {
|
||||
"allowedUserForGet:--wait#for#userlist-- ".
|
||||
"allowedUserForCode:--wait#for#userlist-- ".
|
||||
"allowedUserForOwn:--wait#for#userlist-- ".
|
||||
"ownCommand ".
|
||||
"ownCommand1 ".
|
||||
"showTokenInLog:1,0 ".
|
||||
"httptimeout ".
|
||||
$readingFnAttributes;
|
||||
@ -246,6 +246,11 @@ sub SSChatBot_Attr($$$$) {
|
||||
if ($aName =~ m/httptimeout/) {
|
||||
unless ($aVal =~ /^\d+$/) { return " The Value for $aName is not valid. Use only figures 1-9 !";}
|
||||
}
|
||||
|
||||
if ($aName =~ m/ownCommand([1-9][0-9]*)$/) {
|
||||
# add neue ownCommand dynamisch
|
||||
addToDevAttrList($name, "ownCommand".($1+1));
|
||||
}
|
||||
}
|
||||
|
||||
return undef;
|
||||
@ -1504,7 +1509,7 @@ sub SSChatBot_CGI() {
|
||||
my ($command,$cr,$au,$arg) = ("","","","");
|
||||
my @aul;
|
||||
my $state = "active";
|
||||
|
||||
my $do = 0;
|
||||
my $ret = "success";
|
||||
|
||||
return ( "text/plain; charset=utf-8", "Booting up" ) unless ($init_done);
|
||||
@ -1593,6 +1598,7 @@ sub SSChatBot_CGI() {
|
||||
|
||||
if($p1 =~ /set.*/i) {
|
||||
$command = "set ".$p2;
|
||||
$do = 1;
|
||||
$au = AttrVal($name,"allowedUserForSet", "all");
|
||||
@aul = split(",",$au);
|
||||
if($au eq "all" || $username ~~ @aul) {
|
||||
@ -1606,6 +1612,7 @@ sub SSChatBot_CGI() {
|
||||
|
||||
} elsif ($p1 =~ /get.*/i) {
|
||||
$command = "get ".$p2;
|
||||
$do = 1;
|
||||
$au = AttrVal($name,"allowedUserForGet", "all");
|
||||
@aul = split(",",$au);
|
||||
if($au eq "all" || $username ~~ @aul) {
|
||||
@ -1619,6 +1626,7 @@ sub SSChatBot_CGI() {
|
||||
|
||||
} elsif ($p1 =~ /code.*/i) {
|
||||
$command = $p2;
|
||||
$do = 1;
|
||||
$au = AttrVal($name,"allowedUserForCode", "all");
|
||||
@aul = split(",",$au);
|
||||
if($au eq "all" || $username ~~ @aul) {
|
||||
@ -1643,20 +1651,21 @@ sub SSChatBot_CGI() {
|
||||
$cr = SSChatBot_formText($cr);
|
||||
|
||||
SSChatBot_addQueue($name, "sendItem", "chatbot", $userid, $cr, "", "", "");
|
||||
|
||||
RemoveInternalTimer($hash, "SSChatBot_getapisites");
|
||||
InternalTimer(gettimeofday()+1, "SSChatBot_getapisites", "$name", 0);
|
||||
}
|
||||
|
||||
my $uc = AttrVal($name,"ownCommand", ""); # User Commands zusammenstellen
|
||||
if ($uc) {
|
||||
my @cmda = split(",", $uc);
|
||||
foreach my $cmd (@cmda) {
|
||||
$cmd = SSChatBot_trim($cmd);
|
||||
($uc,$arg) = split(":", $cmd, 2);
|
||||
my $ua = $attr{$name}{userattr}; # Liste aller ownCommand.. zusammenstellen
|
||||
$ua = "" if(!$ua);
|
||||
my %hc = map { ($_ => 1) } grep { "$_" =~ m/ownCommand(\d+)/ } split(" ","ownCommand1 $ua");
|
||||
|
||||
if($uc && $text =~ /^$uc\s?$/) { # User eigene Slash-Befehle, z.B.: /Wetter
|
||||
$au = AttrVal($name,"allowedUserForOwn", "all");
|
||||
foreach my $ca (sort keys %hc) {
|
||||
my $uc = AttrVal($name, $ca, "");
|
||||
next if (!$uc);
|
||||
($uc,$arg) = split(/\s+/, $uc, 2);
|
||||
|
||||
if($uc && $text =~ /^$uc\s?$/) { # User eigener Slash-Befehl, z.B.: /Wetter
|
||||
$command = $arg;
|
||||
$do = 1;
|
||||
$au = AttrVal($name,"allowedUserForOwn", "all"); # Berechtgung des Chat-Users checken
|
||||
@aul = split(",",$au);
|
||||
if($au eq "all" || $username ~~ @aul) {
|
||||
Log3($name, 4, "$name - Synology Chat user \"$username\" execute FHEM command: ".$arg);
|
||||
@ -1676,10 +1685,11 @@ sub SSChatBot_CGI() {
|
||||
}
|
||||
}
|
||||
|
||||
# Wenn Kommando ausgeführt wurde Ergebnisse aus Queue übertragen
|
||||
if($do) {
|
||||
RemoveInternalTimer($hash, "SSChatBot_getapisites");
|
||||
InternalTimer(gettimeofday()+1, "SSChatBot_getapisites", "$name", 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($h->{trigger_word}) {
|
||||
|
Loading…
Reference in New Issue
Block a user