Add !pb chat command
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user