tgbot /list
This commit is contained in:
parent
fc1bf1339e
commit
19f86511e0
2 changed files with 56 additions and 6 deletions
|
@ -39,6 +39,8 @@ public class GlobalChat {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge")) {
|
||||
TGBridge.INSTANCE.outbound(String.format("[%s] <%s> %s", senderServer == null ? "null" : senderServer.getServerInfo().getName(), event.getPlayer().getUsername(), event.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package de.strifel.VTools.listeners;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.pengrad.telegrambot.Callback;
|
||||
import com.pengrad.telegrambot.TelegramBot;
|
||||
import com.pengrad.telegrambot.UpdatesListener;
|
||||
import com.pengrad.telegrambot.model.Update;
|
||||
import com.pengrad.telegrambot.model.User;
|
||||
import com.pengrad.telegrambot.request.SendMessage;
|
||||
import com.pengrad.telegrambot.response.SendResponse;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
|
@ -12,6 +14,7 @@ import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
|||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import de.strifel.VTools.VTools;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
@ -21,7 +24,10 @@ import java.io.File;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TGBridge {
|
||||
private final VTools plugin;
|
||||
|
@ -79,11 +85,45 @@ public class TGBridge {
|
|||
update.message() != null &&
|
||||
update.message().chat() != null &&
|
||||
update.message().chat().id() == CHAT_ID &&
|
||||
update.message().text() != null &&
|
||||
!update.message().text().isEmpty() &&
|
||||
update.message().from() != null
|
||||
) {
|
||||
inbound(String.format("[tg] <%s> %s", update.message().from().lastName() == null ? update.message().from().firstName(): String.format("%s %s", update.message().from().firstName(), update.message().from().lastName()), update.message().text()));
|
||||
if (update.message().text() != null && !update.message().text().isEmpty()) {
|
||||
String msg = update.message().text();
|
||||
if (msg.equals("/list")) {
|
||||
ArrayList<String> out = new ArrayList<>();
|
||||
String fmt = server.getAllPlayers().size() > 1 ? "%d players are currently connected to the proxy." : "%d player is currently connected to the proxy.";
|
||||
out.add(String.format(fmt, server.getAllPlayers().size()));
|
||||
List<RegisteredServer> servers = new ArrayList<>(server.getAllServers());
|
||||
for (RegisteredServer server : servers) {
|
||||
List<Player> onServer = ImmutableList.copyOf(server.getPlayersConnected());
|
||||
if (!onServer.isEmpty()) {
|
||||
out.add(String.format("[%s] (%d): %s",
|
||||
server.getServerInfo().getName(),
|
||||
onServer.size(),
|
||||
onServer.stream().map(Player::getUsername).collect(Collectors.joining(", ")))
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
outbound(String.join("\n", out));
|
||||
}
|
||||
tgInbound(update.message().from(), msg);
|
||||
}
|
||||
else if (update.message().sticker() != null) {
|
||||
tgInbound(update.message().from(), "[sticker]");
|
||||
}
|
||||
else if (update.message().photo() != null) {
|
||||
tgInbound(update.message().from(), "[photo]");
|
||||
}
|
||||
else if (update.message().audio() != null) {
|
||||
tgInbound(update.message().from(), "[audio]");
|
||||
}
|
||||
else if (update.message().voice() != null) {
|
||||
tgInbound(update.message().from(), "[voice]");
|
||||
}
|
||||
else if (update.message().document() != null) {
|
||||
tgInbound(update.message().from(), "[document]");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
@ -102,6 +142,10 @@ public class TGBridge {
|
|||
});
|
||||
}
|
||||
|
||||
protected void tgInbound(User user, String content) {
|
||||
inbound(String.format("[tg] <%s> %s", user.lastName() == null ? user.firstName() : String.format("%s %s", user.firstName(), user.lastName()), content));
|
||||
}
|
||||
|
||||
protected void inbound(String content) {
|
||||
for (Player player : server.getAllPlayers()) {
|
||||
if (player.getCurrentServer().isPresent()) {
|
||||
|
@ -140,12 +184,16 @@ public class TGBridge {
|
|||
@Subscribe
|
||||
public void onServerConnected(ServerConnectedEvent event) {
|
||||
if (event.getPreviousServer().isEmpty()) {
|
||||
if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) {
|
||||
outbound(String.format("%s joined the proxy", event.getPlayer().getUsername()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onDisconnect(DisconnectEvent event) {
|
||||
if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) {
|
||||
outbound(String.format("%s left the proxy", event.getPlayer().getUsername()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue