Skip to content

Commit

Permalink
Use public ip instead of local host
Browse files Browse the repository at this point in the history
  • Loading branch information
FeroxFoxxo committed Dec 11, 2023
1 parent 5ab52dd commit d0f2a33
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
1 change: 0 additions & 1 deletion backend/Music/Commands/PlayPlaylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Discord.Interactions;
using Fergun.Interactive;
using Lavalink4NET.Players;
using Lavalink4NET.Rest.Entities.Tracks;
using Lavalink4NET.Tracks;
using Music.Abstractions;
using Music.Enums;
Expand Down
3 changes: 0 additions & 3 deletions backend/Music/Commands/PlayStream.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using Bot.Attributes;
using Discord.Interactions;
using Lavalink4NET.Rest.Entities.Tracks;
using Microsoft.AspNetCore.Components.Routing;
using Music.Abstractions;
using Music.Enums;
using Music.Extensions;
using System.Numerics;

namespace Music.Commands;

Expand Down
38 changes: 30 additions & 8 deletions backend/Music/MusicModule.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
using Bot.Abstractions;
using Bot.Models;
using Bot.Services;
using Discord.WebSocket;
using Fergun.Interactive;
using Lavalink4NET.Artwork;
using Lavalink4NET.Clients;
using Lavalink4NET.DiscordNet;
using Lavalink4NET.Extensions;
using Lavalink4NET.InactivityTracking;
using Lavalink4NET.InactivityTracking.Extensions;
using Lavalink4NET.InactivityTracking.Trackers.Idle;
using Lavalink4NET.Lyrics;
using Lavalink4NET.Tracking;
using Microsoft.Extensions.DependencyInjection;
using System.Net;

namespace Music;

public class MusicModule : Module
{
public const string Host = "localhost";
public const int Port = 2333;
public const string Pass = "youshallnotpass";

public override string[] Contributors { get; } = ["Swyreee", "Ferox"];

public override void AddServices(IServiceCollection services, CachedServices cachedServices,
AppSettings appSettings) =>
AppSettings appSettings)
{
var host = GetMyIp().ToString();

services
.AddSingleton(new InteractiveConfig { DefaultTimeout = TimeSpan.FromMinutes(5) })
.AddSingleton<InteractiveService>()
Expand All @@ -47,10 +46,33 @@ public override void AddServices(IServiceCollection services, CachedServices cac

.ConfigureLavalink(config =>
{
config.BaseAddress = new Uri($"http://{Host}:{Port}");
config.WebSocketUri = new Uri($"ws://{Host}:{Port}/v4/websocket");
config.BaseAddress = new Uri($"http://{host}:{Port}");
config.WebSocketUri = new Uri($"ws://{host}:{Port}/v4/websocket");
config.ReadyTimeout = TimeSpan.FromSeconds(10);
config.Passphrase = Pass;
})
.AddLavalink();
}

public static IPAddress GetMyIp()
{
var services = new List<string>()
{
"https://ipv4.icanhazip.com",
"https://api.ipify.org",
"https://ipinfo.io/ip",
"https://checkip.amazonaws.com",
"https://wtfismyip.com/text",
"http://icanhazip.com"
};

using var webclient = new HttpClient();

foreach (var service in services)
try {
return IPAddress.Parse(webclient.GetStringAsync(service).Result);
} catch { }

return null;
}
}

0 comments on commit d0f2a33

Please sign in to comment.