Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.toasterguy.ts3bot;
- import com.github.theholywaffle.teamspeak3.TS3Api;
- import com.github.theholywaffle.teamspeak3.TS3Config;
- import com.github.theholywaffle.teamspeak3.TS3Query;
- import com.github.theholywaffle.teamspeak3.api.event.*;
- import com.github.theholywaffle.teamspeak3.api.wrapper.Channel;
- import com.github.theholywaffle.teamspeak3.api.wrapper.Client;
- import com.github.theholywaffle.teamspeak3.api.wrapper.ServerGroup;
- import java.util.logging.Level;
- public class TS3Bot implements TS3Listener{
- private final int idleTime = 4 * 60000;
- private final int querryPort = 10011;
- private final String noMoveGroupName = "NoMove";
- private final String afkChannelName = "Really AFK!!!";
- private TS3Api bot;
- private String host,
- username,
- password,
- nickname;
- private int port;
- private int noMoveGroupID;
- private Channel afkChannel;
- public TS3Bot(String host, int port, String username, String password, String nickname){
- this.host = host;
- this.port = port;
- this.username = username;
- this.password = password;
- this.nickname = nickname;
- TS3Config config = new TS3Config();
- config.setHost(host);
- config.setDebugLevel(Level.ALL);
- config.setQueryPort(querryPort);
- TS3Query query = new TS3Query(config);
- query.connect();
- bot = query.getApi();
- bot.login(username, password);
- bot.selectVirtualServerByPort(port);
- bot.setNickname(nickname);
- bot.registerAllEvents();
- bot.addTS3Listeners(this);
- //get NoMove group
- for (ServerGroup i : bot.getServerGroups()){
- if(i.getName().equals(noMoveGroupName)){
- noMoveGroupID = i.getId();
- break;
- }
- }
- //get AFK channel
- afkChannel = bot.getChannelByNameExact(afkChannelName, true);
- while(true){
- testAFK();
- }
- }
- private boolean hasNoMoveGroup(int clientID) {
- for (ServerGroup i : bot.getServerGroupsByClientId(clientID)) {
- if (i.getId() == noMoveGroupID) {
- return true;
- }
- }
- return false;
- }
- void testAFK(){
- for (Client c : bot.getClients()){
- if (c.getIdleTime() >= idleTime && !hasNoMoveGroup(c.getId())) {
- bot.moveClient(c, afkChannel);
- }
- }
- }
- @Override
- public void onTextMessage(TextMessageEvent textMessageEvent) {
- int invokerID = textMessageEvent.getInvokerId();
- if (textMessageEvent.getMessage().contains("Toaster ist ein Lappen")){
- bot.kickClientFromServer("Ist er nicht!", invokerID);
- }
- }
- @Override
- public void onClientJoin(ClientJoinEvent clientJoinEvent) {
- }
- @Override
- public void onClientLeave(ClientLeaveEvent clientLeaveEvent) {
- }
- @Override
- public void onServerEdit(ServerEditedEvent serverEditedEvent) {
- }
- @Override
- public void onChannelEdit(ChannelEditedEvent channelEditedEvent) {
- }
- @Override
- public void onChannelDescriptionChanged(ChannelDescriptionEditedEvent channelDescriptionEditedEvent) {
- }
- @Override
- public void onClientMoved(ClientMovedEvent clientMovedEvent) {
- }
- @Override
- public void onChannelCreate(ChannelCreateEvent channelCreateEvent) {
- }
- @Override
- public void onChannelDeleted(ChannelDeletedEvent channelDeletedEvent) {
- }
- @Override
- public void onChannelMoved(ChannelMovedEvent channelMovedEvent) {
- }
- @Override
- public void onChannelPasswordChanged(ChannelPasswordChangedEvent channelPasswordChangedEvent) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement