Skip to content

Commit

Permalink
fixed setting locale
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Jan 26, 2024
1 parent 4b6902d commit 58b37ac
Showing 1 changed file with 42 additions and 20 deletions.
62 changes: 42 additions & 20 deletions src/main/java/org/myrobotlab/service/ProgramAB.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class ProgramAB extends Service<ProgramABConfig>
boolean peerSearch = true;

transient SimpleLogPublisher logPublisher = null;

final transient private OobProcessor oobProcessor;

/**
Expand Down Expand Up @@ -762,7 +762,7 @@ public void addCategory(String pattern, String template, String that) {
public void addCategory(String pattern, String template) {
addCategory(pattern, template, "*");
}

/**
* Verifies and adds a new path to the search directories for bots
*
Expand Down Expand Up @@ -1103,7 +1103,7 @@ public ProgramABConfig apply(ProgramABConfig c) {
addBotPath(botPath);
}
}

if (c.botDir == null) {
c.botDir = getResourceDir();
}
Expand All @@ -1116,19 +1116,40 @@ public ProgramABConfig apply(ProgramABConfig c) {
if (c.currentUserName != null) {
setCurrentUserName(c.currentUserName);
}

if (c.currentBotName != null) {
setCurrentBotName(c.currentBotName);
}
}

if (c.startTopic != null) {
setTopic(c.startTopic);
setTopic(c.startTopic);
}


return c;
}

/**
* Set the current locale for this service. In ProgramAB's case if a bot
* matches the local then set the bot
*
*/
@Override
public void setLocale(String code) {
if (code == null) {
error("locale cannot be null");
return;
}
locale = new Locale(code);
log.info("{} new locale is {}", getName(), code);

for (String bot : bots.keySet()) {
if (code.equals(bot)) {
setCurrentBotName(bot);
}
}
broadcastState();
}

public static void main(String args[]) {
try {
LoggingFactory.init("INFO");
Expand Down Expand Up @@ -1306,7 +1327,7 @@ public void sleep() {

@Override
public void onUtterance(Utterance utterance) throws Exception {

log.info("Utterance Received " + utterance);

boolean talkToBots = false;
Expand Down Expand Up @@ -1371,25 +1392,26 @@ public void onUtterance(Utterance utterance) throws Exception {
}
}
}

/**
* This receiver can take a config published by another service and sync
* predicates from it
*
* @param cfg
*/
public void onConfig(ServiceConfig cfg) {
Yaml yaml = new Yaml();
Yaml yaml = new Yaml();
String yml = yaml.dumpAsMap(cfg);
Map<String, Object> cfgMap = yaml.load(yml);

for (Map.Entry<String, Object> entry : cfgMap.entrySet()) {
if (entry.getValue() == null) {
setPredicate("cfg_" + entry.getKey(), null);
} else {
setPredicate("cfg_" + entry.getKey(), entry.getValue().toString());
}
}

invoke("getPredicates");
}

Expand All @@ -1402,19 +1424,19 @@ public TopicChange publishTopic(TopicChange topicChange) {
return topicChange;
}

public String getTopic() {
public String getTopic() {
return getPredicate(getCurrentUserName(), "topic");
}
public String getTopic(String username) {

public String getTopic(String username) {
return getPredicate(username, "topic");
}
public void setTopic(String username, String topic) {

public void setTopic(String username, String topic) {
setPredicate(username, "topic", topic);
}
public void setTopic(String topic) {

public void setTopic(String topic) {
setPredicate(getCurrentUserName(), "topic", topic);
}

Expand Down

0 comments on commit 58b37ac

Please sign in to comment.