Fix: Handle server names with subtitles for Discord channel matching
- 'Homestead - A Cozy Survival Experience' now matches 'homestead-chat' - 'All The Mons (Private) - TX' now matches 'all-the-mons-chat' - Strips subtitles after ' - ' and removes parentheticals
This commit is contained in:
@@ -42,19 +42,30 @@ async function getDiscordChannels(client) {
|
||||
* Returns object with missing channels array
|
||||
*/
|
||||
function checkServerChannels(serverName, allChannels) {
|
||||
// Normalize server name to expected channel format
|
||||
const baseName = serverName
|
||||
// Extract the base name (before any " - " subtitle or parenthetical)
|
||||
// "Homestead - A Cozy Survival Experience" -> "homestead"
|
||||
// "All The Mons (Private) - TX" -> "all-the-mons"
|
||||
// "Stoneblock 4" -> "stoneblock-4"
|
||||
let baseName = serverName
|
||||
.split(' - ')[0] // Take part before " - " subtitle
|
||||
.replace(/\s*\([^)]*\)\s*/g, '') // Remove parentheticals like (Private)
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s-]/g, '') // Remove special chars except spaces/hyphens
|
||||
.replace(/\s+/g, '-') // Spaces to hyphens
|
||||
.replace(/-+/g, '-') // Multiple hyphens to single
|
||||
.replace(/[^a-z0-9\s]/g, '') // Remove special chars except spaces
|
||||
.replace(/\s+/g, '-') // Spaces to hyphens
|
||||
.replace(/-+/g, '-') // Multiple hyphens to single
|
||||
.trim();
|
||||
|
||||
// Also create a display name for voice channel matching
|
||||
const voiceDisplayName = serverName
|
||||
.split(' - ')[0]
|
||||
.replace(/\s*\([^)]*\)\s*/g, '')
|
||||
.trim();
|
||||
|
||||
const expectedChannels = [
|
||||
{ name: `${baseName}-chat`, type: 'text', label: 'Chat' },
|
||||
{ name: `${baseName}-in-game`, type: 'text', label: 'In-Game' },
|
||||
{ name: `${baseName}-forum`, type: 'forum', label: 'Forum' },
|
||||
{ name: serverName, type: 'voice', label: 'Voice' } // Voice uses display name
|
||||
{ name: voiceDisplayName, type: 'voice', label: 'Voice' }
|
||||
];
|
||||
|
||||
const missing = [];
|
||||
|
||||
Reference in New Issue
Block a user