Skip to content

Commit

Permalink
Add database upgrade, and break role sync
Browse files Browse the repository at this point in the history
wip

Fix sync user function

Fix sync and  unsync commands

wip
  • Loading branch information
Brandyn committed Feb 4, 2024
1 parent 04e03b5 commit fc02a75
Show file tree
Hide file tree
Showing 15 changed files with 435 additions and 212 deletions.
34 changes: 18 additions & 16 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.js"
}
]
}
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/index.js"
},
{
"type": "node-terminal",
"name": "Run Script: start",
"request": "launch",
"command": "npm run start",
"cwd": "${workspaceFolder}"
}
]
}
32 changes: 16 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const web = require('./src/express')
const web = require("./src/express");
const ts = require("./src/teamspeak");
const db = require("./src/database");
const discord = require("./src/discord");
const _ = require('lodash');
const teamspeakClientConnected = require('./src/actions/teamspeakClientConnected');
const synchroniseUser = require('./src/actions/synchronizeUser');

const _ = require("lodash");
const teamspeakClientConnected = require("./src/actions/teamspeakClientConnected");
const synchroniseUser = require("./src/actions/synchronizeUser");

// Initialize Connections to Servers
async function initialize() {
await ts.connect();
await discord.connect();
await db.initializeDatabase();
ts.client.on("clientconnect", async (e) => {
await teamspeakClientConnected(e)
})
await ts.connect();
await discord.connect();
await db.initializeDatabase();

ts.client.on("clientconnect", async (e) => {
await teamspeakClientConnected(e);
});

discord.client.on('guildMemberUpdate', member => {
synchroniseUser(member.guild.members.cache.get(member.id))
})
discord.client.on("guildMemberUpdate", (member) => {
console.log("Guild Member Update");
synchroniseUser(member.guild.members.cache.get(member.id));
});
}

initialize();
initialize();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion src/actions/discordComamnds/createRoleRequestMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CreateRoleRequestMessageCommand {
// } catch (ex) { console.log(ex) }

// if (client) {
// await synchroniseUser(interaction.member, tsid)
// await synchroniseUser(interaction.member)
// interaction.reply(`Roles of ${member.user.username} synchronized!`)
// } else {
// interaction.reply("Sorry I can't find that ID in teamspeak, please make sure you have connected to the server before and that you have used the ID for the correct identity. If you need help contact a member of high command.")
Expand Down
10 changes: 5 additions & 5 deletions src/actions/discordComamnds/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RegisterCommand {
}

async execute(interaction) {
const user = interaction.member;
const member = interaction.member;
const tsid = interaction.options.getString("tsid");
// TOOD: FIX INVALID CLIENT ERROR
let client;
Expand All @@ -27,10 +27,10 @@ class RegisterCommand {
} catch {}

if (client) {
await db.updateTeamspeakID(user.user.id, tsid);
await synchroniseUser(user, tsid);
await db.addTeamspeakID(member.user.id, tsid);
await synchroniseUser(member);
interaction.reply({
content: `Teamspeak ID of ${user.user.username} updated!`,
content: `Teamspeak ID of ${member.user.username} updated!`,
ephemeral: true,
});
} else {
Expand All @@ -56,7 +56,7 @@ class RegisterCommand {
// let tsID = args[1];
// let client = await ts.client.clientGetDbidFromUid(tsID)
// if (client) {
// await db.updateTeamspeakID(message.member.id, tsID)
// await db.addTeamspeakID(message.member.id, tsID)
// await synchroniseUser(message.member, tsID)
// message.channel.send("Thanks! I've updated your teamspeak identity and synchronized your roles!");
// } else {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/discordComamnds/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SyncCommand {
}

if (client) {
await synchroniseUser(interaction.member, tsid);
await synchroniseUser(member);
interaction.reply({
content: `Roles of ${member.user.username} synchronized!`,
ephemeral: true,
Expand Down
20 changes: 18 additions & 2 deletions src/actions/discordComamnds/syncRole.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const db = require("../../database");
const ts = require("../../teamspeak");
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");

class SyncRoleCommand {
Expand All @@ -13,10 +14,25 @@ class SyncRoleCommand {
.setName("role")
.setDescription("The role to be synchronized")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("ts-group")
.setDescription("The teamspeak group to be synchronized")
.setRequired(true)
);
}
async execute(interaction) {
const role = interaction.options.getMentionable("role");
const tsGroup = interaction.options.getString("ts-group");

if (!(await ts.getGroupByName(tsGroup))) {
interaction.reply({
content: "Sorry I can't find that group in teamspeak!",
ephemeral: true,
});
return;
}

let synced = await db.getSynchronizedRoles();
console.log(synced);
Expand All @@ -25,13 +41,13 @@ class SyncRoleCommand {
}

synced.push(role.name);
await db.addSynchronizedRoles(role.name);
await db.addSynchronizedRoles(role.name, tsGroup);

synced = await db.getSynchronizedRoles();
console.log(synced);
let syncedString = "Syncing: ";
synced.forEach((r, index) => {
syncedString += r;
syncedString += r.discord + " -> " + r.teamspeak;
if (index < synced.length - 1) syncedString += ", ";
});
interaction.reply({ content: syncedString, ephemeral: true });
Expand Down
10 changes: 5 additions & 5 deletions src/actions/discordComamnds/tsid.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TSIDCommand {
}

async execute(interaction) {
const user = interaction.options.getMentionable("user");
const member = interaction.options.getMentionable("user");

const tsid = interaction.options.getString("tsid");
// TOOD: FIX INVALID CLIENT ERROR
Expand All @@ -35,10 +35,10 @@ class TSIDCommand {
} catch {}

if (client) {
await db.updateTeamspeakID(user.user.id, tsid);
await synchroniseUser(user, tsid);
await db.addTeamspeakID(member.user.id, tsid);
await synchroniseUser(member);
interaction.reply({
content: `Teamspeak ID of ${user.user.username} updated!`,
content: `Teamspeak ID of ${member.user.username} updated!`,
ephemeral: true,
});
} else {
Expand All @@ -64,7 +64,7 @@ class TSIDCommand {
// let tsID = args[1];
// let client = await ts.client.clientGetDbidFromUid(tsID)
// if (client) {
// await db.updateTeamspeakID(message.member.id, tsID)
// await db.addTeamspeakID(message.member.id, tsID)
// await synchroniseUser(message.member, tsID)
// message.channel.send("Thanks! I've updated your teamspeak identity and synchronized your roles!");
// } else {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/discordComamnds/unsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UnSyncCommand {
synced = await db.getSynchronizedRoles();
let syncedString = "Syncing: ";
synced.forEach((r, index) => {
syncedString += r;
syncedString += r.discord + " -> " + r.teamspeak;
if (index < synced.length - 1) syncedString += ", ";
});
interaction.reply({ content: syncedString, ephemeral: true });
Expand Down
Loading

0 comments on commit fc02a75

Please sign in to comment.