@@ 4,7 4,7 @@ import dotenv from "dotenv";
dotenv.config();
-TeamSpeak.connect({
+const teamspeak = new TeamSpeak({
host: process.env.HOST,
protocol: QueryProtocol.RAW, //optional
queryport: 10011, //optional
@@ 12,29 12,34 @@ TeamSpeak.connect({
username: process.env.USERNAME,
password: process.env.PASSWORD,
nickname: "10Man",
-})
- .then(async (teamspeak) => {
- const whoami = await teamspeak.whoami();
- const channel = await teamspeak.channelFind("10 Man");
- teamspeak.clientMove(whoami.clientId, channel[0].cid);
-
- teamspeak.on("textmessage", (ev) => {
- const argv = ev.msg.split(" ");
- switch (argv[0]) {
- case "!hello":
- teamspeak.sendTextMessage(
- ev.invoker.clid,
- 1,
- "Hello " + ev.invoker.nickname
- );
- break;
- }
- });
- })
- .catch((e) => {
- console.log("Catched an error!");
- console.error(e);
- });
+});
+
+teamspeak.on("ready", async () => {
+ const whoami = await teamspeak.whoami();
+ const channel = await teamspeak.channelFind("10 Man");
+ teamspeak.clientMove(whoami.clientId, channel[0].cid);
+});
+
+teamspeak.on("error", (e) => {
+ console.log("Caught an error!");
+ console.error(e);
+});
+
+teamspeak.on("textmessage", (ev) => {
+ const argv = ev.msg.split(" ");
+ const clid = ev.invoker.clid;
+ const teamspeakID = ev.invoker.uniqueIdentifier;
+
+ switch (argv[0]) {
+ case "!hello":
+ message(clid, "Hello " + ev.invoker.nickname);
+ break;
+ }
+});
+
+function message(clid: string, msg: string) {
+ teamspeak.sendTextMessage(clid, 1, msg);
+}
async function request(query: string): Promise<string> {
const endpoint = process.env.ENDPOINT!;