Skip to content

Commit 715dfe1

Browse files
INCOBOT-53 Add comehere command (#56)
1 parent f7b4369 commit 715dfe1

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ idle-ignore-groups:
5757
5858
## Active Administration
5959
### Idle Checker
60-
**Minimum Permission Level:** Admin
60+
**Minimum Permission Level:** Admin
6161
Dual-side support for controlling whether or not the bot will check for (and move) idle users.
6262
For configuration information, see [Idle Checker Configuration](#idle-checker-configuration).
6363
@@ -78,12 +78,18 @@ Dual-side support for forced disconnects of connected clients.
7878
**Use:** Kicks the client matching the clientId from the server with the provided reason.
7979

8080
### User Information
81-
Dual-side support for forced disconnect of connected clients.
82-
**Minimum Permission Level:** Moderator
83-
**Syntax:** `!userinfo (query)`
81+
Dual-side support for forced disconnect of connected clients.
82+
**Minimum Permission Level:** Moderator
83+
**Syntax:** `!userinfo (query)`
8484
**Use:** Retrieves information about users whose names the query partially matches. Special query `@me` retrieves information about the user who called the command. Failing to provide a query results in all online users being returned.
8585

8686
## Communication Abilities
87+
### Come Here
88+
Server-side support for moving the bot to the caller's channel.
89+
**Minimum Permission Level:** Default
90+
**Syntax:** `!comehere`
91+
**Use:** Moves the query bot to the channel of the user who issued the command. Upon success, the bot will announce itself within channel chat.
92+
8793
### Dad Mode
8894
Dual-side support for "Dad Mode" controls.
8995
**Minimum Permission Level:** Moderator

src/main/core/commands/Commands.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.github.theholywaffle.teamspeak3.api.event.TextMessageEvent;
66
import main.core.Executor;
7+
import main.core.commands.commands.ComeHereCommand;
78
import main.core.commands.commands.DadModeCommand;
89
import main.core.commands.commands.IdleCheckerCommand;
910
import main.core.commands.commands.KickCommand;
@@ -79,6 +80,10 @@ public static void handle(TextMessageEvent event)
7980
final String action = command[0].substring(1);
8081

8182
switch (action.toLowerCase()) {
83+
case "come":
84+
case "comehere":
85+
new ComeHereCommand(event);
86+
return;
8287
case "dadmode":
8388
new DadModeCommand(event);
8489
return;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package main.core.commands.commands;
2+
3+
import com.github.theholywaffle.teamspeak3.TS3ApiAsync;
4+
import com.github.theholywaffle.teamspeak3.api.event.TextMessageEvent;
5+
import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo;
6+
import java.util.concurrent.TimeUnit;
7+
import java.util.concurrent.TimeoutException;
8+
import main.conf.ConfigHandler;
9+
import main.core.Executor;
10+
import main.core.commands.AccessManager;
11+
import main.server.ServerConnectionManager;
12+
import main.util.MessageHandler;
13+
import main.util.Messages;
14+
import main.util.enums.AccessLevel;
15+
import main.util.exception.AuthorizationException;
16+
17+
/**
18+
* Command used to move the bot to the caller's channel.
19+
*/
20+
public class ComeHereCommand {
21+
22+
private TextMessageEvent event;
23+
private TS3ApiAsync api;
24+
25+
/**
26+
* Create a ComeHereCommand instance to handle client executions.
27+
*
28+
* @param event the {@link TextMessageEvent} that triggered the ComeHereCommand
29+
* @throws AuthorizationException is the invoker of this command does not have authorization
30+
* to execute it.
31+
*/
32+
public ComeHereCommand(TextMessageEvent event) throws AuthorizationException {
33+
this.event = event;
34+
ServerConnectionManager instance = Executor.getServer("testInstance");
35+
api = instance.getApiAsync();
36+
37+
AccessManager accessManager = new AccessManager(new ConfigHandler(), AccessLevel.DEFAULT);
38+
AccessLevel invokerAccessLevel = accessManager.getAccessLevel(api.getClientInfo(event
39+
.getInvokerId()).getUninterruptibly().getServerGroups());
40+
41+
try {
42+
accessManager.checkAccess(invokerAccessLevel);
43+
this.handle();
44+
} catch (AuthorizationException e) {
45+
throw new AuthorizationException(invokerAccessLevel, "!comehere");
46+
}
47+
}
48+
49+
private void handle() {
50+
final String RETURN_TEXT = "You rang?";
51+
52+
try {
53+
ClientInfo invoker = api.getClientInfo(event.getInvokerId()).get(2500, TimeUnit
54+
.MILLISECONDS);
55+
Integer channelId = invoker.getChannelId();
56+
57+
api.moveQuery(channelId);
58+
new MessageHandler(RETURN_TEXT).sendToChannel();
59+
} catch (InterruptedException | TimeoutException e) {
60+
new MessageHandler(String.format(Messages.ERROR_COMMAND_TIMEOUT, "ComeHere"))
61+
.returnToSender(event);
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)