From 56a08b6cca63fe77e09bdce0f70b7a59e63a8e21 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Thu, 28 Nov 2024 19:04:05 +0100 Subject: [PATCH] Refactpr whosniffer a lil --- FreshShit/WhoSniffer/init.lua | 39 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/FreshShit/WhoSniffer/init.lua b/FreshShit/WhoSniffer/init.lua index 229e2b5..9143287 100644 --- a/FreshShit/WhoSniffer/init.lua +++ b/FreshShit/WhoSniffer/init.lua @@ -309,31 +309,34 @@ aura_env.NotifyGone = function(player) end -- CHANNEL fuckery -local channel = aura_env.config.channelName or "foobar" +local channel = aura_env.config.channel or "foobar" local password = aura_env.config.channelPassword -local function GetChannelId(channelName) - local channels = {GetChannelList()} - for i = 1, #channels, 2 do - local id = channels[i] - local name = channels[i + 1] - if name == channelName then - return id +local function FindOrJoinChannel(channelName, password) + local function GetChannelId(channelName) + local channels = {GetChannelList()} + for i = 1, #channels, 2 do + local id = channels[i] + local name = channels[i + 1] + if name == channelName then + return id + end end end -end -channelId = GetChannelId(channel) -if not channelId then - print(string.format("channel %s not found, joining", channel)) - if password then - JoinPermanentChannel(channel, password) - else - JoinPermanentChannel(channel) + channelId = GetChannelId(channelName) + if not channelId then + print(string.format("channel %s not found, joining", channelName)) + if password then + JoinPermanentChannel(channelName, password) + else + JoinPermanentChannel(channelName) + end end + channelId = GetChannelId(channelName) + return channelId end -channelId = GetChannelId(channel) -aura_env.channelId = channelId +aura_env.channelId = FindOrJoinChannel(channel, password) print(string.format("channel %s resolved to id %d", channel, channelId)) ---@param player Player