chat commands: add duel arena chat command
This commit is contained in:
@@ -29,6 +29,7 @@ import com.google.common.cache.CacheBuilder;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import net.runelite.http.api.chat.Duels;
|
||||
import net.runelite.http.api.chat.Task;
|
||||
import net.runelite.http.service.util.exception.NotFoundException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -177,4 +178,34 @@ public class ChatController
|
||||
}
|
||||
return pb;
|
||||
}
|
||||
|
||||
@PostMapping("/duels")
|
||||
public void submitDuels(@RequestParam String name, @RequestParam int wins,
|
||||
@RequestParam int losses,
|
||||
@RequestParam int winningStreak, @RequestParam int losingStreak)
|
||||
{
|
||||
if (wins < 0 || losses < 0 || winningStreak < 0 || losingStreak < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Duels duels = new Duels();
|
||||
duels.setWins(wins);
|
||||
duels.setLosses(losses);
|
||||
duels.setWinningStreak(winningStreak);
|
||||
duels.setLosingStreak(losingStreak);
|
||||
|
||||
chatService.setDuels(name, duels);
|
||||
}
|
||||
|
||||
@GetMapping("/duels")
|
||||
public Duels getDuels(@RequestParam String name)
|
||||
{
|
||||
Duels duels = chatService.getDuels(name);
|
||||
if (duels == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
return duels;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import net.runelite.http.api.chat.Task;
|
||||
import net.runelite.http.api.chat.Duels;
|
||||
import net.runelite.http.service.util.redis.RedisPool;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -157,4 +158,44 @@ public class ChatService
|
||||
jedis.setex("gc." + name, (int) EXPIRE.getSeconds(), Integer.toString(gc));
|
||||
}
|
||||
}
|
||||
|
||||
public Duels getDuels(String name)
|
||||
{
|
||||
Map<String, String> map;
|
||||
|
||||
try (Jedis jedis = jedisPool.getResource())
|
||||
{
|
||||
map = jedis.hgetAll("duels." + name);
|
||||
}
|
||||
|
||||
if (map.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Duels duels = new Duels();
|
||||
duels.setWins(Integer.parseInt(map.get("wins")));
|
||||
duels.setLosses(Integer.parseInt(map.get("losses")));
|
||||
duels.setWinningStreak(Integer.parseInt(map.get("winningStreak")));
|
||||
duels.setLosingStreak(Integer.parseInt(map.get("losingStreak")));
|
||||
return duels;
|
||||
}
|
||||
|
||||
public void setDuels(String name, Duels duels)
|
||||
{
|
||||
Map<String, String> duelsMap = ImmutableMap.<String, String>builderWithExpectedSize(4)
|
||||
.put("wins", Integer.toString(duels.getWins()))
|
||||
.put("losses", Integer.toString(duels.getLosses()))
|
||||
.put("winningStreak", Integer.toString(duels.getWinningStreak()))
|
||||
.put("losingStreak", Integer.toString(duels.getLosingStreak()))
|
||||
.build();
|
||||
|
||||
String key = "duels." + name;
|
||||
|
||||
try (Jedis jedis = jedisPool.getResource())
|
||||
{
|
||||
jedis.hmset(key, duelsMap);
|
||||
jedis.expire(key, (int) EXPIRE.getSeconds());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user