Skip to content

Commit 4e6992f

Browse files
committed
Made better move
1 parent e544704 commit 4e6992f

File tree

3 files changed

+93
-34
lines changed

3 files changed

+93
-34
lines changed

src/languages/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@
294294
"userNotInVoice": "{user} is not in a voice channel.",
295295
"userAlreadyInChannel": "{user} is already in the target voice channel.",
296296
"failedToMoveUser": "Failed to move {user}.",
297+
"commandSyntaxMoveHelp": "Usage: .move [user1 user2 ...] <channel> or .move <channel> to move yourself",
298+
"noLinkedUserFound": "No linked Discord account found. Please link your account or specify users to move.",
297299
"couldNotFindCategory": "Could not find category: {category}",
298300
"couldNotFindChannel": "Could not find channel: {channel}",
299301
"couldNotFindCraftDetails": "Could not find craft details for {name}.",

src/languages/ru.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@
294294
"userNotInVoice": "{user} не находится в голосовом канале.",
295295
"userAlreadyInChannel": "{user} уже находится в целевом голосовом канале.",
296296
"failedToMoveUser": "Не удалось переместить {user}.",
297+
"commandSyntaxMoveHelp": "Использование: .move [игрок1 игрок2 ...] <канал> или .move <канал> для перемещения себя",
298+
"noLinkedUserFound": "Не найдена привязанная учетная запись Discord. Пожалуйста, привяжите свою учетную запись или укажите пользователей для перемещения.",
297299
"couldNotFindCategory": "Не удалось найти категорию: {category}",
298300
"couldNotFindChannel": "Не удалось найти канал: {channel}",
299301
"couldNotFindCraftDetails": "Не удалось найти сведения о создании для {name}.",

src/structures/RustPlus.js

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ class RustPlus extends RustPlusLib {
14811481

14821482
async handleMoveCommand(command, callerSteamId, callerName) {
14831483
const args = command.split(' ').slice(1);
1484-
if (args.length < 2) {
1484+
if (args.length < 1) {
14851485
return Client.client.intlGet(this.guildId, 'commandSyntaxMoveHelp');
14861486
}
14871487

@@ -1495,9 +1495,44 @@ class RustPlus extends RustPlusLib {
14951495
return Client.client.intlGet(this.guildId, 'missingMoveMembersPermission');
14961496
}
14971497

1498-
// The last argument is the target channel
1499-
const targetChannelInput = args[args.length - 1];
1500-
const playerNames = args.slice(0, -1);
1498+
let targetChannelInput, playerNames;
1499+
1500+
// If only one argument is provided, it's the channel name and we'll try to move the command sender
1501+
if (args.length === 1) {
1502+
targetChannelInput = args[0];
1503+
1504+
// Find the caller's Discord ID from credentials
1505+
const fs = require('fs');
1506+
const path = require('path');
1507+
const credentialsPath = path.join(__dirname, '..', '..', 'credentials', `${this.guildId}.json`);
1508+
1509+
try {
1510+
if (fs.existsSync(credentialsPath)) {
1511+
const credentialsData = JSON.parse(fs.readFileSync(credentialsPath, 'utf8'));
1512+
console.log('Credentials data:', JSON.stringify(credentialsData, null, 2));
1513+
1514+
if (credentialsData[callerSteamId]?.discord_user_id) {
1515+
const discordUserId = credentialsData[callerSteamId].discord_user_id;
1516+
console.log(`Found Discord ID ${discordUserId} for SteamID ${callerSteamId}`);
1517+
playerNames = [discordUserId];
1518+
} else {
1519+
console.log(`No Discord ID linked for SteamID ${callerSteamId} in credentials`);
1520+
console.log('Available Steam IDs in credentials:', Object.keys(credentialsData).filter(k => k !== 'hoster'));
1521+
return Client.client.intlGet(this.guildId, 'noLinkedUserFound');
1522+
}
1523+
} else {
1524+
console.log(`Credentials file not found: ${credentialsPath}`);
1525+
return Client.client.intlGet(this.guildId, 'noLinkedUserFound');
1526+
}
1527+
} catch (error) {
1528+
console.error('Error reading user data:', error);
1529+
return Client.client.intlGet(this.guildId, 'noLinkedUserFound');
1530+
}
1531+
} else {
1532+
// The last argument is the target channel, the rest are player names
1533+
targetChannelInput = args[args.length - 1];
1534+
playerNames = args.slice(0, -1);
1535+
}
15011536

15021537
// First try to find the channel by ID
15031538
let targetChannel = guild.channels.cache.get(targetChannelInput);
@@ -1563,39 +1598,59 @@ class RustPlus extends RustPlusLib {
15631598
const searchName = name.toLowerCase();
15641599
let member = null;
15651600

1566-
// First, try to find an exact match in voice channels
1567-
const voiceMembers = guild.members.cache.filter(m => m.voice?.channelId);
1601+
// First, try to find by Discord user ID (since we have it from credentials)
1602+
member = guild.members.cache.get(name);
1603+
console.log(`Looking for member with ID: ${name}`);
15681604

1569-
// 1. Check for exact matches in voice channels
1570-
member = voiceMembers.find(m =>
1571-
m.displayName?.toLowerCase() === searchName ||
1572-
m.nickname?.toLowerCase() === searchName ||
1573-
m.user.username.toLowerCase() === searchName
1574-
);
1575-
1576-
// 2. If no exact match, check for partial matches in voice channels
1577-
if (!member) {
1605+
if (member) {
1606+
console.log(`Found member by ID: ${member.user.tag} (${member.id})`);
1607+
} else {
1608+
console.log(`No member found with ID: ${name}`);
1609+
1610+
// If not found by ID, try to find by name as fallback
1611+
const voiceMembers = guild.members.cache.filter(m => m.voice?.channelId);
1612+
console.log(`Searching in ${voiceMembers.size} voice members...`);
1613+
1614+
// 1. Check for exact matches in voice channels
15781615
member = voiceMembers.find(m =>
1579-
m.displayName?.toLowerCase().includes(searchName) ||
1580-
m.nickname?.toLowerCase().includes(searchName) ||
1581-
m.user.username.toLowerCase().includes(searchName)
1616+
m.user.id === name ||
1617+
m.displayName?.toLowerCase() === searchName ||
1618+
m.nickname?.toLowerCase() === searchName ||
1619+
m.user.username.toLowerCase() === searchName
15821620
);
1583-
}
1584-
1585-
// 3. If still no match, search all members (including those not in voice)
1586-
if (!member) {
1587-
member = guild.members.cache.find(m => {
1588-
const displayName = m.displayName?.toLowerCase();
1589-
const nickname = m.nickname?.toLowerCase();
1590-
const username = m.user.username.toLowerCase();
1591-
1592-
return displayName === searchName ||
1593-
nickname === searchName ||
1594-
username === searchName ||
1595-
displayName?.includes(searchName) ||
1596-
nickname?.includes(searchName) ||
1597-
username.includes(searchName);
1598-
});
1621+
1622+
// 2. If no exact match, check for partial matches in voice channels
1623+
if (!member) {
1624+
member = voiceMembers.find(m =>
1625+
m.displayName?.toLowerCase().includes(searchName) ||
1626+
m.nickname?.toLowerCase().includes(searchName) ||
1627+
m.user.username.toLowerCase().includes(searchName)
1628+
);
1629+
}
1630+
1631+
// 3. If still no match, search all members (including those not in voice)
1632+
if (!member) {
1633+
console.log('Searching in all members...');
1634+
member = guild.members.cache.find(m => {
1635+
const displayName = m.displayName?.toLowerCase();
1636+
const nickname = m.nickname?.toLowerCase();
1637+
const username = m.user.username.toLowerCase();
1638+
1639+
return m.user.id === name ||
1640+
displayName === searchName ||
1641+
nickname === searchName ||
1642+
username === searchName ||
1643+
displayName?.includes(searchName) ||
1644+
nickname?.includes(searchName) ||
1645+
username.includes(searchName);
1646+
});
1647+
}
1648+
1649+
if (member) {
1650+
console.log(`Found member by name: ${member.user.tag} (${member.id})`);
1651+
} else {
1652+
console.log('No member found with any search method');
1653+
}
15991654
}
16001655

16011656
if (!member) {

0 commit comments

Comments
 (0)