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", 11); 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 builder.add(new OptionParam("location")); 109 return builder.build(); 110 } 111 112 public static Command clientMove(int clientId, int channelId, String channelPassword) { 113 CommandBuilder builder = new CommandBuilder("clientmove", 3); 114 builder.add(new KeyValueParam("clid", clientId)); 115 builder.add(new KeyValueParam("cid", channelId)); 116 builder.addIf(channelPassword != null, new KeyValueParam("cpw", channelPassword)); 117 return builder.build(); 118 } 119 120 public static Command clientMove(int[] clientIds, int channelId, String channelPassword) { 121 if (clientIds == null || clientIds.length == 0) { 122 throw new IllegalArgumentException("Client ID array cannot be null or empty"); 123 } 124 125 CommandBuilder builder = new CommandBuilder("clientmove", 3); 126 builder.add(new KeyValueParam("cid", channelId)); 127 builder.addIf(channelPassword != null, new KeyValueParam("cpw", channelPassword)); 128 129 ArrayParameter clients = new ArrayParameter(clientIds.length); 130 for (final int clientId : clientIds) { 131 clients.add(new KeyValueParam("clid", clientId)); 132 } 133 builder.add(clients); 134 135 return builder.build(); 136 } 137 138 public static Command clientPoke(int clientId, String message) { 139 CommandBuilder builder = new CommandBuilder("clientpoke", 2); 140 builder.add(new KeyValueParam("clid", clientId)); 141 builder.add(new KeyValueParam("msg", message)); 142 return builder.build(); 143 } 144 145 public static Command clientSetServerQueryLogin(String username) { 146 CommandBuilder builder = new CommandBuilder("clientsetserverquerylogin", 1); 147 builder.add(new KeyValueParam("client_login_name", username)); 148 return builder.build(); 149 } 150 151 public static Command clientUpdate(Map<ClientProperty, String> options) { 152 return new CommandBuilder("clientupdate", 1).addProperties(options).build(); 153 } 154 155 public static Command sendTextMessage(int targetMode, int targetId, String message) { 156 CommandBuilder builder = new CommandBuilder("sendtextmessage", 3); 157 builder.add(new KeyValueParam("targetmode", targetMode)); 158 builder.add(new KeyValueParam("target", targetId)); 159 builder.add(new KeyValueParam("msg", message)); 160 return builder.build(); 161 } 162}