001package com.github.theholywaffle.teamspeak3.commands; 002 003/* 004 * #%L 005 * TeamSpeak 3 Java API 006 * %% 007 * Copyright (C) 2017 Bert De Geyter, Roger Baumgartner 008 * %% 009 * Permission is hereby granted, free of charge, to any person obtaining a copy 010 * of this software and associated documentation files (the "Software"), to deal 011 * in the Software without restriction, including without limitation the rights 012 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 013 * copies of the Software, and to permit persons to whom the Software is 014 * furnished to do so, subject to the following conditions: 015 * 016 * The above copyright notice and this permission notice shall be included in 017 * all copies or substantial portions of the Software. 018 * 019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 021 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 022 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 023 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 025 * THE SOFTWARE. 026 * #L% 027 */ 028 029import com.github.theholywaffle.teamspeak3.api.ClientProperty; 030import com.github.theholywaffle.teamspeak3.api.ReasonIdentifier; 031import com.github.theholywaffle.teamspeak3.commands.parameter.ArrayParameter; 032import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam; 033import com.github.theholywaffle.teamspeak3.commands.parameter.OptionParam; 034 035import java.util.Map; 036 037public final class ClientCommands { 038 039 private ClientCommands() { 040 throw new Error("No instances"); 041 } 042 043 public static Command clientEdit(int clientId, Map<ClientProperty, String> options) { 044 CommandBuilder builder = new CommandBuilder("clientedit", 2); 045 builder.add(new KeyValueParam("clid", clientId)); 046 builder.addProperties(options); 047 return builder.build(); 048 } 049 050 public static Command clientFind(String pattern) { 051 if (pattern == null || pattern.isEmpty()) { 052 throw new IllegalArgumentException("Client name pattern must be a non-empty string"); 053 } 054 055 return new CommandBuilder("clientfind", 1).add(new KeyValueParam("pattern", pattern)).build(); 056 } 057 058 public static Command clientGetDBIdFromUId(String clientUId) { 059 if (clientUId == null || clientUId.isEmpty()) { 060 throw new IllegalArgumentException("Client UId must be a non-empty string"); 061 } 062 063 return new CommandBuilder("clientgetdbidfromuid", 1).add(new KeyValueParam("cluid", clientUId)).build(); 064 } 065 066 public static Command clientGetIds(String clientUId) { 067 if (clientUId == null || clientUId.isEmpty()) { 068 throw new IllegalArgumentException("Client UId must be a non-empty string"); 069 } 070 071 return new CommandBuilder("clientgetids", 1).add(new KeyValueParam("cluid", clientUId)).build(); 072 } 073 074 public static Command clientInfo(int clientId) { 075 return new CommandBuilder("clientinfo", 1).add(new KeyValueParam("clid", clientId)).build(); 076 } 077 078 public static Command clientKick(ReasonIdentifier reason, String reasonMessage, int... clientIds) { 079 if (clientIds == null || clientIds.length == 0) { 080 throw new IllegalArgumentException("Client ID array cannot be null or empty"); 081 } 082 083 CommandBuilder builder = new CommandBuilder("clientkick", 3); 084 builder.add(new KeyValueParam("reasonid", reason.getIndex())); 085 builder.addIf(reasonMessage != null, new KeyValueParam("reasonmsg", reasonMessage)); 086 087 ArrayParameter clients = new ArrayParameter(clientIds.length); 088 for (final int id : clientIds) { 089 clients.add(new KeyValueParam("clid", id)); 090 } 091 builder.add(clients); 092 093 return builder.build(); 094 } 095 096 public static Command clientList() { 097 CommandBuilder builder = new CommandBuilder("clientlist", 10); 098 builder.add(new OptionParam("uid")); 099 builder.add(new OptionParam("away")); 100 builder.add(new OptionParam("voice")); 101 builder.add(new OptionParam("times")); 102 builder.add(new OptionParam("groups")); 103 builder.add(new OptionParam("info")); 104 builder.add(new OptionParam("icon")); 105 builder.add(new OptionParam("country")); 106 builder.add(new OptionParam("ip")); 107 builder.add(new OptionParam("badges")); 108 return builder.build(); 109 } 110 111 public static Command clientMove(int clientId, int channelId, String channelPassword) { 112 CommandBuilder builder = new CommandBuilder("clientmove", 3); 113 builder.add(new KeyValueParam("clid", clientId)); 114 builder.add(new KeyValueParam("cid", channelId)); 115 builder.addIf(channelPassword != null, new KeyValueParam("cpw", channelPassword)); 116 return builder.build(); 117 } 118 119 public static Command clientMove(int[] clientIds, int channelId, String channelPassword) { 120 if (clientIds == null || clientIds.length == 0) { 121 throw new IllegalArgumentException("Client ID array cannot be null or empty"); 122 } 123 124 CommandBuilder builder = new CommandBuilder("clientmove", 3); 125 builder.add(new KeyValueParam("cid", channelId)); 126 builder.addIf(channelPassword != null, new KeyValueParam("cpw", channelPassword)); 127 128 ArrayParameter clients = new ArrayParameter(clientIds.length); 129 for (final int clientId : clientIds) { 130 clients.add(new KeyValueParam("clid", clientId)); 131 } 132 builder.add(clients); 133 134 return builder.build(); 135 } 136 137 public static Command clientPoke(int clientId, String message) { 138 CommandBuilder builder = new CommandBuilder("clientpoke", 2); 139 builder.add(new KeyValueParam("clid", clientId)); 140 builder.add(new KeyValueParam("msg", message)); 141 return builder.build(); 142 } 143 144 public static Command clientSetServerQueryLogin(String username) { 145 CommandBuilder builder = new CommandBuilder("clientsetserverquerylogin", 1); 146 builder.add(new KeyValueParam("client_login_name", username)); 147 return builder.build(); 148 } 149 150 public static Command clientUpdate(Map<ClientProperty, String> options) { 151 return new CommandBuilder("clientupdate", 1).addProperties(options).build(); 152 } 153 154 public static Command sendTextMessage(int targetMode, int targetId, String message) { 155 CommandBuilder builder = new CommandBuilder("sendtextmessage", 3); 156 builder.add(new KeyValueParam("targetmode", targetMode)); 157 builder.add(new KeyValueParam("target", targetId)); 158 builder.add(new KeyValueParam("msg", message)); 159 return builder.build(); 160 } 161}