Skip to content

Commit

Permalink
dev-0.1
Browse files Browse the repository at this point in the history
removed a small bug (temp)
added StackedEvents & Admin greeting ion Join
prepared the next step ahead
  • Loading branch information
crackscout123 committed Mar 30, 2023
1 parent 9b56bc8 commit 249a27f
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ AdminBot/auth.app
AdminBot/auth.app
*.log
*.lck
AdminBot/auth.app
11 changes: 9 additions & 2 deletions src/de/crackscout/AdminBot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import de.crackscout.Collectors.AfkCollector;
import de.crackscout.Collectors.KickCollector;
import de.crackscout.Commands.Clear;
import de.crackscout.Commands.KickMe;
import de.crackscout.Commands.Ping;
import de.crackscout.Commands.Stay;
import de.crackscout.Events.StackedEvents;
import de.crackscout.Events.Disconnect;
import de.crackscout.Logging.Logging;
import de.crackscout.Managers.AuthManager;
Expand Down Expand Up @@ -63,7 +65,7 @@ public static void main(String[] args) {
api = query.getApi();
api.login(username, password);
api.selectVirtualServerById(serverID);
api.setNickname("AdminBot");
api.setNickname("AdminBot dev");

registerCollectors();

Expand All @@ -90,9 +92,14 @@ private static void registerCommands() {
KickMe.load();
Ping.load();
Stay.load();
Clear.load();

//events
Disconnect.load();
StackedEvents.load();


Debug.info("Commands loaded.");
Debug.info("Commands & Events loaded.");
}


Expand Down
3 changes: 2 additions & 1 deletion src/de/crackscout/Collectors/KickCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void run() {
}

public void kickClients(Client client) {
if(kickMeList.contains(client.getId())) {
if(kickMeList.contains(client.getId())) {
Utils.kickMeList.remove(client.getId());
api.kickClientFromServer(client);
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/de/crackscout/Commands/Clear.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package de.crackscout.Commands;

import com.github.theholywaffle.teamspeak3.TS3Api;
import com.github.theholywaffle.teamspeak3.api.TextMessageTargetMode;
import com.github.theholywaffle.teamspeak3.api.event.TS3EventAdapter;
import com.github.theholywaffle.teamspeak3.api.event.TS3EventType;
import com.github.theholywaffle.teamspeak3.api.event.TextMessageEvent;

import de.crackscout.AdminBot.Main;
import de.crackscout.Managers.Utils;

public class Clear {

static TS3Api api = Main.api;

public static void load(){
// Get our own client ID by running the "whoami" command
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_PRIVATE, 0);

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

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

if (message.equals("!clear")) {
int kickSize = Utils.kickMeList.size();
int whitelistSize = Utils.whitelistedUsers.size();

api.sendPrivateMessage(e.getInvokerId(), "\nArray<> kickMe has a total size of: " +kickSize +"."
+ "\nArray<> whitelist has a total size of: " +whitelistSize+"."
+ "\n Both are going to be cleared.");
Utils.kickMeList.clear();
Utils.whitelistedUsers.clear();
api.sendPrivateMessage(e.getInvokerId(), "done.");

}
}
}
});
}
}




/**
*
* @author Joel Rzepka - crackscout.de
*
* @date 30.03.2023 - 03:11:54
*
*/
8 changes: 5 additions & 3 deletions src/de/crackscout/Events/Disconnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.github.theholywaffle.teamspeak3.api.event.TS3EventType;

import de.crackscout.AdminBot.Main;
import de.crackscout.Managers.Utils;

public class Disconnect {

Expand All @@ -21,8 +20,11 @@ public static void load(){

@Override
public void onClientLeave(ClientLeaveEvent e) {
Utils.kickMeList.remove(e.getClientId());
Utils.whitelistedUsers.remove(e.getClientId());
// Utils.whitelistedUsers.remove(client.getId());
/*
* TODO:
* fix: everytime collecting afk users also check for dead-id's in the Array and remove!
*/


}
Expand Down
116 changes: 116 additions & 0 deletions src/de/crackscout/Events/StackedEvents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package de.crackscout.Events;

import com.github.theholywaffle.teamspeak3.TS3Api;
import com.github.theholywaffle.teamspeak3.api.event.ChannelCreateEvent;
import com.github.theholywaffle.teamspeak3.api.event.ChannelDeletedEvent;
import com.github.theholywaffle.teamspeak3.api.event.ChannelDescriptionEditedEvent;
import com.github.theholywaffle.teamspeak3.api.event.ChannelEditedEvent;
import com.github.theholywaffle.teamspeak3.api.event.ChannelMovedEvent;
import com.github.theholywaffle.teamspeak3.api.event.ChannelPasswordChangedEvent;
import com.github.theholywaffle.teamspeak3.api.event.ClientJoinEvent;
import com.github.theholywaffle.teamspeak3.api.event.ClientLeaveEvent;
import com.github.theholywaffle.teamspeak3.api.event.ClientMovedEvent;
import com.github.theholywaffle.teamspeak3.api.event.PrivilegeKeyUsedEvent;
import com.github.theholywaffle.teamspeak3.api.event.ServerEditedEvent;
import com.github.theholywaffle.teamspeak3.api.event.TS3Listener;
import com.github.theholywaffle.teamspeak3.api.event.TextMessageEvent;
import com.github.theholywaffle.teamspeak3.api.wrapper.Client;

import de.crackscout.AdminBot.Main;
import de.crackscout.Managers.AuthManager;
import de.crackscout.Managers.Debug;

public class StackedEvents {

static TS3Api api = Main.api;

public static void load(){

api.registerAllEvents();
api.addTS3Listeners(new TS3Listener() {


@Override
public void onClientJoin(ClientJoinEvent e) {

Client client = api.getClientByUId(e.getUniqueClientIdentifier());

if(AuthManager.auth(client)) {
api.sendPrivateMessage(client.getId(), "\nWelcome Admin"
+ "\n!stay - Ignore AFK"
+ "\n!kickme - Self kick"
+ "\n!clear - Clear the Array cache"
+ "\n!ping - Ping");
}else {

Debug.err("no auth");
}
}

@Override
public void onTextMessage(TextMessageEvent e) {
// ...
}

@Override
public void onServerEdit(ServerEditedEvent e) {
// ...
}

@Override
public void onClientMoved(ClientMovedEvent e) {
// ...
}

@Override
public void onClientLeave(ClientLeaveEvent e) {
// ...
}

@Override
public void onChannelEdit(ChannelEditedEvent e) {
// ...
}

@Override
public void onChannelDescriptionChanged(ChannelDescriptionEditedEvent e) {
// ...
}

@Override
public void onChannelCreate(ChannelCreateEvent e) {
// ...
}

@Override
public void onChannelDeleted(ChannelDeletedEvent e) {
// ...
}

@Override
public void onChannelMoved(ChannelMovedEvent e) {
// ...
}

@Override
public void onChannelPasswordChanged(ChannelPasswordChangedEvent e) {
// ...
}

@Override
public void onPrivilegeKeyUsed(PrivilegeKeyUsedEvent e) {
// ...
}
});
}
}



/**
*
* @author Joel Rzepka - crackscout.de
*
* @date 30.03.2023 - 02:38:34
*
*/

0 comments on commit 249a27f

Please sign in to comment.