Advertisement
Guest User

Untitled

a guest
Mar 21st, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. package de.toasterguy.ts3bot;
  2.  
  3. import com.github.theholywaffle.teamspeak3.TS3Api;
  4. import com.github.theholywaffle.teamspeak3.TS3Config;
  5. import com.github.theholywaffle.teamspeak3.TS3Query;
  6. import com.github.theholywaffle.teamspeak3.api.event.*;
  7. import com.github.theholywaffle.teamspeak3.api.wrapper.Channel;
  8. import com.github.theholywaffle.teamspeak3.api.wrapper.Client;
  9. import com.github.theholywaffle.teamspeak3.api.wrapper.ServerGroup;
  10.  
  11. import java.util.logging.Level;
  12.  
  13. public class TS3Bot implements TS3Listener{
  14.  
  15. private final int idleTime = 4 * 60000;
  16. private final int querryPort = 10011;
  17.  
  18. private final String noMoveGroupName = "NoMove";
  19. private final String afkChannelName = "Really AFK!!!";
  20.  
  21. private TS3Api bot;
  22.  
  23. private String host,
  24. username,
  25. password,
  26. nickname;
  27. private int port;
  28.  
  29. private int noMoveGroupID;
  30. private Channel afkChannel;
  31.  
  32. public TS3Bot(String host, int port, String username, String password, String nickname){
  33. this.host = host;
  34. this.port = port;
  35. this.username = username;
  36. this.password = password;
  37. this.nickname = nickname;
  38.  
  39. TS3Config config = new TS3Config();
  40. config.setHost(host);
  41. config.setDebugLevel(Level.ALL);
  42. config.setQueryPort(querryPort);
  43.  
  44. TS3Query query = new TS3Query(config);
  45. query.connect();
  46.  
  47. bot = query.getApi();
  48. bot.login(username, password);
  49. bot.selectVirtualServerByPort(port);
  50.  
  51. bot.setNickname(nickname);
  52.  
  53. bot.registerAllEvents();
  54. bot.addTS3Listeners(this);
  55.  
  56. //get NoMove group
  57. for (ServerGroup i : bot.getServerGroups()){
  58. if(i.getName().equals(noMoveGroupName)){
  59. noMoveGroupID = i.getId();
  60. break;
  61. }
  62. }
  63. //get AFK channel
  64. afkChannel = bot.getChannelByNameExact(afkChannelName, true);
  65. while(true){
  66. testAFK();
  67. }
  68. }
  69.  
  70. private boolean hasNoMoveGroup(int clientID) {
  71. for (ServerGroup i : bot.getServerGroupsByClientId(clientID)) {
  72. if (i.getId() == noMoveGroupID) {
  73. return true;
  74. }
  75. }
  76. return false;
  77. }
  78.  
  79. void testAFK(){
  80. for (Client c : bot.getClients()){
  81. if (c.getIdleTime() >= idleTime && !hasNoMoveGroup(c.getId())) {
  82. bot.moveClient(c, afkChannel);
  83. }
  84. }
  85. }
  86.  
  87. @Override
  88. public void onTextMessage(TextMessageEvent textMessageEvent) {
  89. int invokerID = textMessageEvent.getInvokerId();
  90. if (textMessageEvent.getMessage().contains("Toaster ist ein Lappen")){
  91. bot.kickClientFromServer("Ist er nicht!", invokerID);
  92. }
  93. }
  94.  
  95. @Override
  96. public void onClientJoin(ClientJoinEvent clientJoinEvent) {
  97.  
  98. }
  99.  
  100. @Override
  101. public void onClientLeave(ClientLeaveEvent clientLeaveEvent) {
  102.  
  103. }
  104.  
  105. @Override
  106. public void onServerEdit(ServerEditedEvent serverEditedEvent) {
  107.  
  108. }
  109.  
  110. @Override
  111. public void onChannelEdit(ChannelEditedEvent channelEditedEvent) {
  112.  
  113. }
  114.  
  115. @Override
  116. public void onChannelDescriptionChanged(ChannelDescriptionEditedEvent channelDescriptionEditedEvent) {
  117.  
  118. }
  119.  
  120. @Override
  121. public void onClientMoved(ClientMovedEvent clientMovedEvent) {
  122.  
  123. }
  124.  
  125. @Override
  126. public void onChannelCreate(ChannelCreateEvent channelCreateEvent) {
  127.  
  128. }
  129.  
  130. @Override
  131. public void onChannelDeleted(ChannelDeletedEvent channelDeletedEvent) {
  132.  
  133. }
  134.  
  135. @Override
  136. public void onChannelMoved(ChannelMovedEvent channelMovedEvent) {
  137.  
  138. }
  139.  
  140. @Override
  141. public void onChannelPasswordChanged(ChannelPasswordChangedEvent channelPasswordChangedEvent) {
  142.  
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement