Java Code Examples for com.github.theholywaffle.teamspeak3.TS3Api

The following are top voted examples for showing how to use com.github.theholywaffle.teamspeak3.TS3Api. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: TeamSpeak-3-Java-API   File: ReconnectExample.java   View source code 6 votes vote down vote up
private static void stuffThatOnlyEverNeedsToBeRunOnce(final TS3Api api) {
	// We only want to greet people once
	api.sendChannelMessage("PutPutBot is online!");

	// On the API side of things, you only need to register your TS3Listeners once!
	// These are not affected when the query disconnects.
	api.addTS3Listeners(new TS3EventAdapter() {

		@Override
		public void onTextMessage(TextMessageEvent e) {
			// Only react to channel messages not sent by the query itself
			if (e.getTargetMode() == TextMessageTargetMode.CHANNEL && e.getInvokerId() != clientId) {
				// Greet whoever sent a message in the default channel
				// (Yes this isn't smart or useful, this is just an example)
				// Message: "Hello <client name>!"
				api.sendChannelMessage("Hello " + e.getInvokerName() + "!");
			}
		}
	});
}
 
Example 2
Project: TeamSpeak-3-Java-API   File: CreateChannelExample.java   View source code 5 votes vote down vote up
public static void main(String[] args) {
	final TS3Config config = new TS3Config();
	config.setHost("77.77.77.77");
	config.setEnableCommunicationsLogging(true);

	final TS3Query query = new TS3Query(config);
	query.connect();

	final TS3Api api = query.getApi();
	api.login("serveradmin", "serveradminpassword");
	api.selectVirtualServerById(1);
	api.setNickname("PutPutBot");
	api.sendChannelMessage("PutPutBot is online!");

	// Let's customize our channel
	final Map<ChannelProperty, String> properties = new HashMap<>();
	// Make it a permanent channel
	properties.put(ChannelProperty.CHANNEL_FLAG_PERMANENT, "1");
	// Make it a subchannel of the default channel
	int defaultChannelId = api.whoAmI().getChannelId();
	properties.put(ChannelProperty.CPID, String.valueOf(defaultChannelId));
	// Let's also set a channel topic
	properties.put(ChannelProperty.CHANNEL_TOPIC, "PutPut discussion");

	// Done customizing, let's create the channel with our properties
	api.createChannel("PutPut Channel", properties);

	// We're done, disconnect
	query.exit();
}
 
Example 3
Project: TeamSpeak-3-Java-API   File: ReconnectExample.java   View source code 5 votes vote down vote up
private static void stuffThatNeedsToRunEveryTimeTheQueryConnects(TS3Api api) {
	// Logging in, selecting the virtual server, selecting a channel
	// and setting a nickname needs to be done every time we reconnect
	api.login("serveradmin", "serveradminpassword");
	api.selectVirtualServerById(1);
	// api.moveQuery(x);
	api.setNickname("PutPutBot");

	// What events we listen to also resets
	api.registerEvent(TS3EventType.TEXT_CHANNEL, 0);

	// Out clientID changes every time we connect and we need it
	// for our event listener, so we need to store the ID in a field
	clientId = api.whoAmI().getId();
}
 
Example 4
Project: UltimateTs   File: BotManager.java   View source code 4 votes vote down vote up
public static TS3Api getBot(){
	return api;
}
 
Example 5
Project: UltimateTs   File: BotManager.java   View source code 4 votes vote down vote up
public static TS3Api getBot(){
	return api;
}
 
Example 6
Project: Sprummlbot   File: TS3Connection.java   View source code 4 votes vote down vote up
private void connect(TS3Query query) throws SprummlbotInitializationException, ModuleLoadException {
    final Sprummlbot sprummlbot = Sprummlbot.getSprummlbot();

    sprummlbot.setTS3Api(query.getApi());
    sprummlbot.setTS3ApiAsync(query.getAsyncApi());

    final TS3Api api = sprummlbot.getSyncAPI();

    if (!api.login(username, password))
        throw new SprummlbotInitializationException("Authentication failed! Username or password wrong.");

    System.out.println("[Core] Selecting virtual server with ID " + serverId + "...");
    if (!api.selectVirtualServerById(serverId))
        throw new SprummlbotInitializationException("Unable to select server with ID " + serverId + "!");

    api.setNickname(nickname);
    api.registerAllEvents();

    sprummlbot.setClientManager(new Clients());
    sprummlbot.setMainEventManager(new EventManager(null));

    if (Vars.VPNCHECKER_ENABLED) {
        System.out.println("[VPN Checker] Enabling VPN Checker...");
        Tasks.startVPNChecker();
    }
    Tasks.startInternalRunner();


    if (Vars.DYNBANNER_ENABLED) {
        Map<VirtualServerProperty, String> settings = new HashMap<>();
        settings.put(VirtualServerProperty.VIRTUALSERVER_HOSTBANNER_GFX_URL,
                "http://" + Vars.IP + ":9911/f/banner.png");
        settings.put(VirtualServerProperty.VIRTUALSERVER_HOSTBANNER_GFX_INTERVAL, "60");
        api.editServer(settings);
        Tasks.startDynamicBanner();
    }

    sprummlbot.getDefaultAPI().getClients().onSuccess(result -> {
        for (Client c : result) {
            if (PermissionGroup.getPermissionGroupForField("notify").isPermitted(c.getUniqueIdentifier()) == PermissionGroup.Permission.PERMITTED)
                sprummlbot.getDefaultAPI().sendPrivateMessage(c.getId(), "Sprummlbot connected!" + (Vars.UPDATE_AVAILABLE ? " An update is available! Please update!" : ""));
        }
    });

    sprummlbot.getModuleManager().startAllModules();

    sprummlbot.setSprummlbotState(State.RUNNING);
}
 
Example 7
Project: Sprummlbot   File: Sprummlbot.java   View source code 4 votes vote down vote up
public TS3Api getSyncAPI() {
    return ts3Api;
}
 
Example 8
Project: Sprummlbot   File: Sprummlbot.java   View source code 4 votes vote down vote up
public void setTS3Api(TS3Api ts3Api) {
    this.ts3Api = ts3Api;
}
 
Example 9
Project: Sprummlbot   File: ServerGroupProtector.java   View source code 4 votes vote down vote up
Hook(int groupId, List<String> uids, TS3Api api) {
    this.groupId = groupId;
    this.uids = uids;
    this.api = api;
}
 
Example 10
Project: Geffy   File: Geffy.java   View source code 4 votes vote down vote up
public static void main(String[] args) throws Exception {	
	Logger.getLogger("").setLevel(Level.OFF);
	Configuration config = new Configuration.Builder().setVersion(VERSION).setName("Geffy").setRealName("Geforce's assistant, at your service!").setServerHostname("irc.esper.net").addAutoJoinChannel("#Geforce").setNickservPassword(SuperSecretSecrets.nickservPassword).addListener(new EventListener()).buildConfiguration();
	bot = new Bot(config);
	
	MessageHandler.messagesToRespondTo.put("new commit to", MessageHandler.newCommitToMessages);
	
	//Get the newest SecurityCraft version from GitHub.
	Gson gson = new GsonBuilder().create();
	URL updateURL = new URL("https://www.github.com/Geforce132/SecurityCraft/raw/master/Updates/Geffy.json");
	BufferedReader in = new BufferedReader(new InputStreamReader(updateURL.openStream()));

	SecurityCraftUpdate update = gson.fromJson(in, SecurityCraftUpdate.class);

	Reference.scVersion = update.getVersion();
	Reference.scBetaVersion = update.getBetaVersion();
	Reference.scBetaVersionOf = update.getBetaVersionOf();
	Reference.scBetaDownloadLink = update.getBetaDownloadLink();

	//-----

	//Start the TS3 functionality of Geffy.
	TS3Config tsConfig = new TS3Config();
	tsConfig.setHost("geforcemods.net");

	Reference.ts3Query = new TS3Query(tsConfig);
	Reference.ts3Query.connect();

	TS3Api api = Reference.ts3Query.getApi();
	api.selectVirtualServerById(1);
	api.setNickname("GeffyBot");

	api.registerAllEvents();

	Reference.ts3EventListener = new TS3ActionListener();
	api.addTS3Listeners(Reference.ts3EventListener);

	//-----
	
	bot.startBot();
}
 
Example 11
Project: Sergius   File: QueryConnection.java   View source code 4 votes vote down vote up
protected TS3Api getApi() {
    return this.api;
}
 
Example 12
Project: Sergius   File: QueryConnection.java   View source code 4 votes vote down vote up
protected TS3Api getApi() {
    return this.api;
}
 
Example 13
Project: TeamSpeak-3-Java-API   File: FileTransferExample.java   View source code 4 votes vote down vote up
public static void main(String[] args) {
	final TS3Config config = new TS3Config();
	config.setHost("77.77.77.77");
	config.setEnableCommunicationsLogging(true);

	final TS3Query query = new TS3Query(config);
	query.connect();

	final TS3Api api = query.getApi();
	api.login("serveradmin", "serveradminpassword");
	api.selectVirtualServerById(1);
	api.setNickname("PutPutBot");
	api.sendChannelMessage("PutPutBot is online!");

	// Set up properties for our test channels
	final Map<ChannelProperty, String> properties = new HashMap<>();
	properties.put(ChannelProperty.CHANNEL_FLAG_SEMI_PERMANENT, "1"); // Stay until restart
	int defaultChannelId = api.whoAmI().getChannelId();
	properties.put(ChannelProperty.CPID, String.valueOf(defaultChannelId));
	properties.put(ChannelProperty.CHANNEL_TOPIC, "File transfer tests");

	// --------------------- //
	// Direct file transfers //
	// --------------------- //

	// Create a new channel
	int directChannel = api.createChannel("Direct file transfers", properties);
	// Upload and set an icon
	long blackIconId = api.uploadIconDirect(RED_EXAMPLE_ICON);
	api.editChannel(directChannel, mapOf(ChannelProperty.CHANNEL_ICON_ID, blackIconId));
	// Create a new directory on the file repository
	api.createFileDirectory(EXAMPLE_DIRECTORY, directChannel);
	// And upload a file to it
	api.uploadFileDirect(EXAMPLE_FILE_CONTENT, EXAMPLE_FILE_NAME, false, directChannel);
	// Download it again and print it to System.out
	byte[] directDownload = api.downloadFileDirect(EXAMPLE_FILE_NAME, directChannel);
	System.out.println(new String(directDownload, StandardCharsets.UTF_8));

	// --------------------- //
	// Stream file transfers //
	// --------------------- //

	// Create a new channel
	int streamChannel = api.createChannel("Stream file transfers", properties);
	// Upload and set an icon
	InputStream iconIn = new ByteArrayInputStream(BLUE_EXAMPLE_ICON); // Usually a FileInputStream
	long whiteIconId = api.uploadIcon(iconIn, BLUE_EXAMPLE_ICON.length);
	api.editChannel(streamChannel, mapOf(ChannelProperty.CHANNEL_ICON_ID, whiteIconId));
	// Create a new directory on the file repository
	api.createFileDirectory(EXAMPLE_DIRECTORY, streamChannel);
	// And upload a file to it
	InputStream dataIn = new ByteArrayInputStream(EXAMPLE_FILE_CONTENT); // Usually a FileInputStream
	api.uploadFile(dataIn, EXAMPLE_FILE_CONTENT.length, EXAMPLE_FILE_NAME, false, streamChannel);
	// Download it again and print it to System.out
	ByteArrayOutputStream dataOut = new ByteArrayOutputStream(128); // Usually a FileOutputStream
	api.downloadFile(dataOut, EXAMPLE_FILE_NAME, streamChannel);
	System.out.println(new String(dataOut.toByteArray(), StandardCharsets.UTF_8));

	// We're done, disconnect
	query.exit();
}
 
Example 14
Project: TeamSpeak-3-Java-API   File: ChatBotExample.java   View source code 4 votes vote down vote up
public static void main(String[] args) {
	final TS3Config config = new TS3Config();
	config.setHost("77.77.77.77");
	config.setEnableCommunicationsLogging(true);

	final TS3Query query = new TS3Query(config);
	query.connect();

	final TS3Api api = query.getApi();
	api.login("serveradmin", "serveradminpassword");
	api.selectVirtualServerById(1);
	api.setNickname("PutPutBot");
	api.sendChannelMessage("PutPutBot is online!");

	// Get our own client ID by running the "whoami" command
	final int clientId = api.whoAmI().getId();

	// Listen to chat in the channel the query is currently in
	// As we never changed the channel, this will be the default channel of the server
	api.registerEvent(TS3EventType.TEXT_CHANNEL, 0);

	// Register the event listener
	api.addTS3Listeners(new TS3EventAdapter() {

		@Override
		public void onTextMessage(TextMessageEvent e) {
			// Only react to channel messages not sent by the query itself
			if (e.getTargetMode() == TextMessageTargetMode.CHANNEL && e.getInvokerId() != clientId) {
				String message = e.getMessage().toLowerCase();

				if (message.equals("!ping")) {
					// Answer "!ping" with "pong"
					api.sendChannelMessage("pong");
				} else if (message.startsWith("hello")) {
					// Greet whoever said hello
					// Message: "Hello <client name>!"
					api.sendChannelMessage("Hello " + e.getInvokerName() + "!");
				}
			}
		}
	});
}