Add !pb chat command

This commit is contained in:
Adam
2019-01-25 17:03:30 -05:00
parent 9c4df28f2b
commit 9d5dad5cad
6 changed files with 269 additions and 1 deletions

View File

@@ -133,4 +133,26 @@ public class ChatController
{
return chatService.getTask(name);
}
@PostMapping("/pb")
public void submitPb(@RequestParam String name, @RequestParam int pb)
{
if (pb < 0)
{
return;
}
chatService.setPb(name, pb);
}
@GetMapping("/pb")
public int getPb(@RequestParam String name)
{
Integer pb = chatService.getPb(name);
if (pb == null)
{
throw new NotFoundException();
}
return pb;
}
}

View File

@@ -121,4 +121,22 @@ public class ChatService
jedis.expire(key, (int) EXPIRE.getSeconds());
}
}
public Integer getPb(String name)
{
String value;
try (Jedis jedis = jedisPool.getResource())
{
value = jedis.get("pb." + name);
}
return value == null ? null : Integer.parseInt(value);
}
public void setPb(String name, int pb)
{
try (Jedis jedis = jedisPool.getResource())
{
jedis.setex("pb." + name, (int) EXPIRE.getSeconds(), Integer.toString(pb));
}
}
}