Skip to content

Commit d414467

Browse files
BarofiosoBarofioso
authored andcommitted
Merge branch 'master' into b-master
Conflicts: src/main/java/com/github/theholywaffle/teamspeak3/example/ChatBotExample.java src/main/java/com/github/theholywaffle/teamspeak3/example/EventListenerExample.java src/main/java/com/github/theholywaffle/teamspeak3/log/LogHandler.java
2 parents 4811ec5 + a43548c commit d414467

11 files changed

Lines changed: 752 additions & 273 deletions

File tree

example/ChatBotExample.java

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* #%L
3+
* TeamSpeak 3 Java API
4+
* %%
5+
* Copyright (C) 2014 Bert De Geyter
6+
* %%
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
* #L%
25+
*/
26+
27+
import java.util.logging.Level;
28+
29+
import com.github.theholywaffle.teamspeak3.TS3Api;
30+
import com.github.theholywaffle.teamspeak3.TS3Config;
31+
import com.github.theholywaffle.teamspeak3.TS3Query;
32+
import com.github.theholywaffle.teamspeak3.api.TextMessageTargetMode;
33+
import com.github.theholywaffle.teamspeak3.api.event.ChannelDescriptionEditedEvent;
34+
import com.github.theholywaffle.teamspeak3.api.event.ChannelEditedEvent;
35+
import com.github.theholywaffle.teamspeak3.api.event.ClientJoinEvent;
36+
import com.github.theholywaffle.teamspeak3.api.event.ClientLeaveEvent;
37+
import com.github.theholywaffle.teamspeak3.api.event.ClientMovedEvent;
38+
import com.github.theholywaffle.teamspeak3.api.event.ServerEditedEvent;
39+
import com.github.theholywaffle.teamspeak3.api.event.TS3Listener;
40+
import com.github.theholywaffle.teamspeak3.api.event.TextMessageEvent;
41+
42+
public class ChatBotExample {
43+
44+
public static void main(String[] args) {
45+
new ChatBotExample();
46+
}
47+
48+
public ChatBotExample() {
49+
final TS3Config config = new TS3Config();
50+
config.setHost("77.77.77.77");
51+
config.setDebugLevel(Level.ALL);
52+
config.setLoginCredentials("serveradmin", "serveradminpassword");
53+
54+
final TS3Query query = new TS3Query(config);
55+
query.connect();
56+
57+
final TS3Api api = query.getApi();
58+
api.selectVirtualServerById(1);
59+
api.setNickname("PutPutBot");
60+
api.sendChannelMessage("PutPutBot is online!");
61+
62+
api.registerAllEvents();
63+
api.addTS3Listeners(new TS3Listener() {
64+
65+
public void onTextMessage(TextMessageEvent e) {
66+
if (e.getTargetMode() == TextMessageTargetMode.CHANNEL) {// Only
67+
// react
68+
// to
69+
// channel
70+
// messages
71+
if (e.getMessage().equals("!ping")) {
72+
api.sendChannelMessage("pong");
73+
}
74+
if (e.getMessage().toLowerCase().contains("hello")) {
75+
api.sendChannelMessage("Hello " + e.getInvokerName());
76+
}
77+
}
78+
}
79+
80+
public void onServerEdit(ServerEditedEvent e) {
81+
82+
}
83+
84+
public void onClientMoved(ClientMovedEvent e) {
85+
86+
}
87+
88+
public void onClientLeave(ClientLeaveEvent e) {
89+
90+
}
91+
92+
public void onClientJoin(ClientJoinEvent e) {
93+
94+
}
95+
96+
public void onChannelEdit(ChannelEditedEvent e) {
97+
98+
}
99+
100+
public void onChannelDescriptionChanged(
101+
ChannelDescriptionEditedEvent e) {
102+
103+
}
104+
});
105+
}
106+
107+
}

example/ClientInfoExample.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* #%L
3+
* TeamSpeak 3 Java API
4+
* %%
5+
* Copyright (C) 2014 Bert De Geyter
6+
* %%
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
* #L%
25+
*/
26+
27+
import java.util.logging.Level;
28+
29+
import com.github.theholywaffle.teamspeak3.TS3Api;
30+
import com.github.theholywaffle.teamspeak3.TS3Config;
31+
import com.github.theholywaffle.teamspeak3.TS3Query;
32+
import com.github.theholywaffle.teamspeak3.api.wrapper.Client;
33+
34+
public class ClientInfoExample {
35+
36+
public static void main(String[] args) {
37+
new ClientInfoExample();
38+
}
39+
40+
public ClientInfoExample() {
41+
final TS3Config config = new TS3Config();
42+
config.setHost("77.77.77.77");
43+
config.setDebugLevel(Level.ALL);
44+
config.setLoginCredentials("serveradmin", "serveradminpassword");
45+
46+
final TS3Query query = new TS3Query(config);
47+
query.connect();
48+
49+
final TS3Api api = query.getApi();
50+
api.selectVirtualServerById(1);
51+
api.setNickname("PutPutBot");
52+
api.sendChannelMessage("PutPutBot is online!");
53+
54+
for (final Client c : api.getClients()) {
55+
System.out.println(c.getNickname() + " in channel: "
56+
+ api.getChannelInfo(c.getChannelId()).getName());
57+
}
58+
}
59+
60+
}

example/CreateChannelExample.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* #%L
3+
* TeamSpeak 3 Java API
4+
* %%
5+
* Copyright (C) 2014 Bert De Geyter
6+
* %%
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
* #L%
25+
*/
26+
27+
import java.util.HashMap;
28+
import java.util.logging.Level;
29+
30+
import com.github.theholywaffle.teamspeak3.TS3Api;
31+
import com.github.theholywaffle.teamspeak3.TS3Config;
32+
import com.github.theholywaffle.teamspeak3.TS3Query;
33+
import com.github.theholywaffle.teamspeak3.api.ChannelProperty;
34+
35+
public class CreateChannelExample {
36+
37+
public static void main(String[] args) {
38+
new ChatBotExample();
39+
}
40+
41+
public CreateChannelExample() {
42+
final TS3Config config = new TS3Config();
43+
config.setHost("77.77.77.77");
44+
config.setDebugLevel(Level.ALL);
45+
config.setLoginCredentials("serveradmin", "serveradminpassword");
46+
47+
final TS3Query query = new TS3Query(config);
48+
query.connect();
49+
50+
final TS3Api api = query.getApi();
51+
api.selectVirtualServerById(1);
52+
api.setNickname("PutPutBot");
53+
api.sendChannelMessage("PutPutBot is online!");
54+
55+
final HashMap<ChannelProperty, String> properties = new HashMap<>();
56+
properties.put(ChannelProperty.CHANNEL_FLAG_PERMANENT, "1"); // Make
57+
// channel
58+
// permanent
59+
properties.put(ChannelProperty.CPID, "3"); // Make it a subchannel of
60+
// channel 3
61+
62+
api.createChannel("New Channel", properties); // Create the channel with
63+
// our properties :)
64+
}
65+
66+
}

example/EventListenerExample.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* #%L
3+
* TeamSpeak 3 Java API
4+
* %%
5+
* Copyright (C) 2014 Bert De Geyter
6+
* %%
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
* #L%
25+
*/
26+
27+
import java.util.logging.Level;
28+
29+
import com.github.theholywaffle.teamspeak3.TS3Api;
30+
import com.github.theholywaffle.teamspeak3.TS3Config;
31+
import com.github.theholywaffle.teamspeak3.TS3Query;
32+
import com.github.theholywaffle.teamspeak3.api.event.ChannelDescriptionEditedEvent;
33+
import com.github.theholywaffle.teamspeak3.api.event.ChannelEditedEvent;
34+
import com.github.theholywaffle.teamspeak3.api.event.ClientJoinEvent;
35+
import com.github.theholywaffle.teamspeak3.api.event.ClientLeaveEvent;
36+
import com.github.theholywaffle.teamspeak3.api.event.ClientMovedEvent;
37+
import com.github.theholywaffle.teamspeak3.api.event.ServerEditedEvent;
38+
import com.github.theholywaffle.teamspeak3.api.event.TS3Listener;
39+
import com.github.theholywaffle.teamspeak3.api.event.TextMessageEvent;
40+
41+
public class EventListenerExample {
42+
43+
public static void main(String[] args) {
44+
new EventListenerExample();
45+
}
46+
47+
public EventListenerExample() {
48+
final TS3Config config = new TS3Config();
49+
config.setHost("77.77.77.77");
50+
config.setDebugLevel(Level.ALL);
51+
config.setLoginCredentials("serveradmin", "serveradminpassword");
52+
53+
final TS3Query query = new TS3Query(config);
54+
query.connect();
55+
56+
final TS3Api api = query.getApi();
57+
api.selectVirtualServerById(1);
58+
api.setNickname("PutPutBot");
59+
api.sendChannelMessage("PutPutBot is online!");
60+
61+
api.registerAllEvents();
62+
api.addTS3Listeners(new TS3Listener() {
63+
64+
public void onTextMessage(TextMessageEvent e) {
65+
System.out.println("Text message received in "
66+
+ e.getTargetMode());
67+
}
68+
69+
public void onServerEdit(ServerEditedEvent e) {
70+
System.out.println("Server edited by " + e.getInvokerName());
71+
}
72+
73+
public void onClientMoved(ClientMovedEvent e) {
74+
System.out.println("Client has been moved " + e.getClientId());
75+
}
76+
77+
public void onClientLeave(ClientLeaveEvent e) {
78+
// ...
79+
80+
}
81+
82+
public void onClientJoin(ClientJoinEvent e) {
83+
// ...
84+
85+
}
86+
87+
public void onChannelEdit(ChannelEditedEvent e) {
88+
// ...
89+
90+
}
91+
92+
public void onChannelDescriptionChanged(
93+
ChannelDescriptionEditedEvent e) {
94+
// ...
95+
96+
}
97+
});
98+
99+
}
100+
101+
}

0 commit comments

Comments
 (0)