mirror of
https://github.com/ZaidElkurdi/AssistantPlus.git
synced 2025-01-22 11:28:31 +00:00
- Passthrough for Activator listeners
- Wildcards for custom replies
This commit is contained in:
parent
a836b59617
commit
c4f0c1f295
@ -23,7 +23,7 @@
|
||||
|
||||
BOOL passthrough = false;
|
||||
if (dict[@"passthrough"]) {
|
||||
enabled = [dict[@"passthrough"] boolValue];
|
||||
passthrough = [dict[@"passthrough"] boolValue];
|
||||
}
|
||||
|
||||
self.name = name;
|
||||
|
@ -663,6 +663,7 @@
|
||||
B86E670C1ACE7A77007C6014 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
B86E670D1ACE7A77007C6014 /* Build configuration list for PBXNativeTarget "assistantappTests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
@ -671,6 +672,7 @@
|
||||
B86E670F1ACE7A77007C6014 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
B88C0A591ABF794E00D4D107 /* Build configuration list for PBXProject "AssistantPlusApp" */ = {
|
||||
isa = XCConfigurationList;
|
||||
|
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14A329f" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6250" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
|
@ -35,23 +35,29 @@
|
||||
UIView *switchBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 90, self.view.frame.size.width, 50)];
|
||||
switchBackground.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
UILabel *enabledSwitchLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 50)];
|
||||
enabledSwitchLabel.text = @"Enabled:";
|
||||
|
||||
UILabel *passthroughSwitchLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 0, 80, 50)];
|
||||
passthroughSwitchLabel.text = @"Pass-Through:";
|
||||
|
||||
self.enabledSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 9.5, 51, 31)];
|
||||
self.enabledSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(85, 9.5, 51, 31)];
|
||||
[self.enabledSwitch addTarget:self action:@selector(didToggleSwitch:) forControlEvents:UIControlEventValueChanged];
|
||||
self.enabledSwitch.on = self.currListener.enabled;
|
||||
|
||||
self.passthroughSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 9.5, 51, 31)];
|
||||
|
||||
UILabel *enabledSwitchLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 50)];
|
||||
enabledSwitchLabel.text = @"Enabled:";
|
||||
|
||||
CGFloat viewWidth = self.view.frame.size.width;
|
||||
|
||||
self.passthroughSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(viewWidth-61, 9.5, 51, 31)];
|
||||
[self.passthroughSwitch addTarget:self action:@selector(didToggleSwitch:) forControlEvents:UIControlEventValueChanged];
|
||||
self.passthroughSwitch.on = self.currListener.willPassthrough;
|
||||
|
||||
CGFloat passthroughSwitchXOrigin = self.passthroughSwitch.frame.origin.x;
|
||||
|
||||
UILabel *passthroughSwitchLabel = [[UILabel alloc] initWithFrame:CGRectMake(passthroughSwitchXOrigin-110, 0, 110, 50)];
|
||||
passthroughSwitchLabel.text = @"Passthrough:";
|
||||
|
||||
[switchBackground addSubview:enabledSwitchLabel];
|
||||
[switchBackground addSubview:passthroughSwitchLabel];
|
||||
[switchBackground addSubview:self.enabledSwitch];
|
||||
[switchBackground addSubview:self.passthroughSwitch];
|
||||
[self.view addSubview:switchBackground];
|
||||
|
||||
UIView *nameBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 170, self.view.frame.size.width, 50)];
|
||||
@ -77,18 +83,26 @@
|
||||
[triggerBackground addSubview:triggerLabel];
|
||||
[triggerBackground addSubview:self.triggerField];
|
||||
[self.view addSubview:triggerBackground];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(saveChangesIfNecessary)
|
||||
name:UIApplicationWillResignActiveNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
[self saveChangesIfNecessary];
|
||||
}
|
||||
|
||||
- (void)saveChangesIfNecessary {
|
||||
if (self.didChange) {
|
||||
self.currListener.trigger = self.triggerField.text;
|
||||
self.currListener.name = self.nameField.text;
|
||||
[self.delegate listenerDidChange:self.currListener];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UI Delegates
|
||||
|
||||
- (void)didToggleSwitch:(UISwitch*)theSwitch {
|
||||
|
@ -10,26 +10,27 @@
|
||||
#define kPreferencesPath "/var/mobile/Library/Preferences/com.assistantplus.app.plist"
|
||||
|
||||
@implementation customReplyCommands {
|
||||
NSDictionary *phrases;
|
||||
NSMutableArray *phrases;
|
||||
}
|
||||
|
||||
|
||||
// @{ trigger : NSRegularExpression
|
||||
// response : NSString }
|
||||
|
||||
- (void)createPhraseDictionary:(NSDictionary*)repliesDict {
|
||||
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
||||
phrases = [[NSMutableArray alloc] init];
|
||||
NSArray *customReplies = repliesDict[@"customReplies"];
|
||||
if (customReplies) {
|
||||
for (NSDictionary *currReply in customReplies) {
|
||||
NSString *currTrigger = currReply[@"trigger"];
|
||||
NSString *currResponse = currReply[@"response"];
|
||||
if ([dict objectForKey:[currTrigger lowercaseString]]) {
|
||||
NSMutableArray *mutableCmds = [[dict objectForKey:[currTrigger lowercaseString]] mutableCopy];
|
||||
[mutableCmds addObject:currResponse];
|
||||
[dict setObject:mutableCmds forKey:[currTrigger lowercaseString]];
|
||||
} else {
|
||||
[dict setObject:@[currResponse] forKey:[currTrigger lowercaseString]];
|
||||
NSRegularExpression *regExpression = [NSRegularExpression regularExpressionWithPattern:currTrigger options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
if (currTrigger && regExpression) {
|
||||
[phrases addObject:@{@"trigger" : regExpression,
|
||||
@"response" : currResponse}];
|
||||
}
|
||||
}
|
||||
}
|
||||
phrases = dict;
|
||||
}
|
||||
|
||||
-(BOOL)handleSpeech:(NSString *)text withTokens:(NSSet *)tokens withSession:(id<APSiriSession>)session {
|
||||
@ -40,11 +41,21 @@
|
||||
|
||||
text = [[text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] lowercaseString];
|
||||
|
||||
if ([phrases objectForKey:text]) {
|
||||
NSArray *customReplies = [phrases objectForKey:text];
|
||||
for (NSString *currReply in customReplies) {
|
||||
[session sendTextSnippet:currReply temporary:NO scrollToTop:YES dialogPhase:@"Completion"];
|
||||
BOOL didHandle = NO;
|
||||
for (NSDictionary *currDict in phrases) {
|
||||
NSRegularExpression *regExpression = currDict[@"trigger"];
|
||||
if (regExpression) {
|
||||
NSArray *arrayOfAllMatches = [regExpression matchesInString:text options:0 range:NSMakeRange(0, [text length])];
|
||||
for (NSTextCheckingResult *match in arrayOfAllMatches) {
|
||||
if (match.numberOfRanges > 0) {
|
||||
[session sendTextSnippet:currDict[@"response"] temporary:NO scrollToTop:YES dialogPhase:@"Completion"];
|
||||
didHandle = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (didHandle) {
|
||||
[session sendRequestCompleted];
|
||||
return YES;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user