/// <summary> /// Initializes a new instance of the <see cref="LavalinkSocket"/> class. /// </summary> /// <param name="options">the node options</param> /// <param name="client">the discord client</param> /// <param name="logger">the logger</param> /// <param name="cache">an optional cache that caches track requests</param> public LavalinkSocket(LavalinkNodeOptions options, IDiscordClientWrapper client, ILogger logger, ILavalinkCache cache = null) : base(options, logger, cache) { Logger = logger; if (options.BufferSize <= 0) { if (Logger is null) { throw new InvalidOperationException("The specified buffer size is zero or negative."); } Logger.Log(this, "The specified buffer size is zero or negative .. using 1048576 (1MiB).", LogLevel.Warning); options.BufferSize = 1024 * 1024; // 1 MiB buffer size } if (options.ReconnectStrategy is null) { throw new InvalidOperationException("No reconnection strategy specified in options."); } _client = client; _password = options.Password; _webSocketUri = new Uri(options.WebSocketUri); _receiveBuffer = new byte[options.BufferSize]; _overflowBuffer = new StringBuilder(); _resume = options.AllowResuming; _ioDebug = options.DebugPayloads; _resumeKey = Guid.NewGuid(); _queue = new Queue <IPayload>(); _reconnectionStrategy = options.ReconnectStrategy; _cancellationTokenSource = new CancellationTokenSource(); }
public Worker(ILogger <Worker> logger, IConfigurationProvider configuration, IServiceProvider serviceProvider, IDiscordClientWrapper clientWrapper) { this.configuration = configuration; this.commandService = new CommandService(); this.serviceProvider = serviceProvider; this.clientWrapper = clientWrapper; this.client = clientWrapper.Client; }
/// <summary> /// Initializes a new instance of the <see cref="LavalinkPlayer"/> class. /// </summary> /// <param name="lavalinkSocket">the lavalink socket</param> /// <param name="client">the discord client</param> /// <param name="guildId">the identifier of the guild that is controlled by the player</param> /// <param name="disconnectOnStop"> /// a value indicating whether the player should stop after the track finished playing /// </param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="lavalinkSocket"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="client"/> is <see langword="null"/>. /// </exception> public LavalinkPlayer(LavalinkSocket lavalinkSocket, IDiscordClientWrapper client, ulong guildId, bool disconnectOnStop) { GuildId = guildId; LavalinkSocket = lavalinkSocket ?? throw new ArgumentNullException(nameof(lavalinkSocket)); Client = client ?? throw new ArgumentNullException(nameof(client)); _disconnectOnStop = disconnectOnStop; _lastPositionUpdate = DateTimeOffset.UtcNow; _position = TimeSpan.Zero; }
/// <summary> /// Initializes a new instance of the <see cref="LavalinkNode"/> class. /// </summary> /// <param name="options">the node options for connecting</param> /// <param name="client">the discord client</param> /// <param name="logger">the logger</param> /// <param name="cache">an optional cache that caches track requests</param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="options"/> parameter is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="client"/> is <see langword="null"/>. /// </exception> public LavalinkNode(LavalinkNodeOptions options, IDiscordClientWrapper client, ILogger logger = null, ILavalinkCache cache = null) : base(options, client, logger, cache) { if (options is null) { throw new ArgumentNullException(nameof(options)); } _discordClient = client ?? throw new ArgumentNullException(nameof(client)); Players = new ConcurrentDictionary <ulong, LavalinkPlayer>(); _disconnectOnStop = options.DisconnectOnStop; _discordClient.VoiceServerUpdated += VoiceServerUpdated; _discordClient.VoiceStateUpdated += VoiceStateUpdated; }
/// <summary> /// Initializes a new instance of the <see cref="LavalinkCluster"/> class. /// </summary> /// <param name="options">the cluster options</param> /// <param name="client">the discord client</param> /// <param name="logger">the logger</param> /// <param name="cache"> /// a cache that is shared between the different lavalink rest clients. If the cache is /// <see langword="null"/>, no cache will be used. /// </param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="options"/> parameter is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="client"/> is <see langword="null"/>. /// </exception> public LavalinkCluster(LavalinkClusterOptions options, IDiscordClientWrapper client, ILogger logger = null, ILavalinkCache cache = null) { if (options is null) { throw new ArgumentNullException(nameof(options)); } _client = client ?? throw new ArgumentNullException(nameof(client)); _loadBalacingStrategy = options.LoadBalacingStrategy; _logger = logger; _cache = cache; _nodesLock = new object(); StayOnline = options.StayOnline; _nodes = options.Nodes.Select(CreateNode).ToList(); }
/// <summary> /// Initializes a new instance of a player. /// </summary> /// <param name="playerFactory">the player factory</param> /// <param name="socket">the lavalink socket</param> /// <param name="client">the discord client</param> /// <param name="guildId">the identifier of the guild that is controlled by the player</param> /// <param name="disconnectOnStop"> /// a value indicating whether the player should stop after the track finished playing /// </param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="playerFactory"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="socket"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="client"/> is <see langword="null"/>. /// </exception> internal static T CreatePlayer <T>( PlayerFactory <T> playerFactory, LavalinkSocket socket, IDiscordClientWrapper client, ulong guildId, bool disconnectOnStop) where T : LavalinkPlayer { if (playerFactory is null) { throw new ArgumentNullException(nameof(playerFactory)); } var player = playerFactory(); player.LavalinkSocket = socket ?? throw new ArgumentNullException(nameof(socket)); player.Client = client ?? throw new ArgumentNullException(nameof(client)); player.GuildId = guildId; player.DisconnectOnStop = disconnectOnStop; return(player); }
public NewMusicChecker(ILogger <NewMusicChecker> logger, INewMusicBotService newMusicBotService, IDiscordClientWrapper clientWrapper, IConfigurationProvider configurationProvider) { this.logger = logger; this.configuration = configurationProvider; this.clientWrapper = clientWrapper; this.client = clientWrapper.Client; client.Log += Log; this.newMusicBotService = newMusicBotService; schedule = CrontabSchedule.Parse(configuration.CheckSchedule, new CrontabSchedule.ParseOptions { IncludingSeconds = true }); nextRun = schedule.GetNextOccurrence(DateTime.Now); }
/// <summary> /// Initializes a new instance of the <see cref="InactivityTrackingService"/> class. /// </summary> /// <param name="audioService">the audio service where the players should be tracked</param> /// <param name="clientWrapper">the discord client wrapper</param> /// <param name="options">the tracking options</param> /// <param name="logger">the optional logger</param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="audioService"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="clientWrapper"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="options"/> is <see langword="null"/>. /// </exception> public InactivityTrackingService(IAudioService audioService, IDiscordClientWrapper clientWrapper, InactivityTrackingOptions options, ILogger logger = null) { _audioService = audioService ?? throw new ArgumentNullException(nameof(audioService)); _clientWrapper = clientWrapper ?? throw new ArgumentNullException(nameof(clientWrapper)); _options = options ?? throw new ArgumentNullException(nameof(options)); _logger = logger; _players = new Dictionary <ulong, DateTimeOffset>(); _trackers = new List <InactivityTracker>(); _trackersLock = new object(); // add default trackers _trackers.Add(DefaultInactivityTrackers.UsersInactivityTracker); _trackers.Add(DefaultInactivityTrackers.ChannelInactivityTracker); if (options.TrackInactivity) { BeginTracking(); } }
/// <summary> /// Initializes a new instance of the <see cref="LavalinkNode"/> class. /// </summary> /// <param name="cluster">the cluster</param> /// <param name="options">the node options for connecting</param> /// <param name="client">the discord client</param> /// <param name="logger">the logger</param> /// <param name="cache">an optional cache that caches track requests</param> /// <param name="id">the node number</param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="cluster"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="options"/> parameter is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="client"/> is <see langword="null"/>. /// </exception> public LavalinkClusterNode( LavalinkCluster cluster, LavalinkNodeOptions options, IDiscordClientWrapper client, int id, ILogger?logger = null, ILavalinkCache?cache = null) : base(options, client, logger, cache) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (client is null) { throw new ArgumentNullException(nameof(client)); } if (Label is null) { Label = "Cluster Node-" + id; } Id = id; Cluster = cluster ?? throw new ArgumentNullException(nameof(cluster)); LastUsage = DateTimeOffset.MinValue; }
public LavalinkPlayerEx(LavalinkSocket lavalinkSocket, IDiscordClientWrapper client, ulong guildId, bool disconnectOnStop) : base(lavalinkSocket, client, guildId, false) { }
/// <summary> /// Initializes a new instance of the <see cref="LavalinkPlayer"/> class. /// </summary> /// <param name="lavalinkSocket">the lavalink socket</param> /// <param name="client">the discord client</param> /// <param name="guildId">the identifier of the guild that is controlled by the player</param> public MyCustomPlayer(LavalinkSocket lavalinkSocket, IDiscordClientWrapper client, ulong guildId) : base(lavalinkSocket, client, guildId) { // This constructor pattern must be always used for a custom player. You can not add nor // remove any constructor parameters. The player class will be instantiated using System.Activator. }
/// <summary> /// Initializes a new instance of the <see cref="QueuedLavalinkPlayer"/> class. /// </summary> /// <param name="lavalinkSocket">the lavalink socket</param> /// <param name="client">the discord client</param> /// <param name="guildId">the identifier of the guild that is controlled by the player</param> /// <param name="disconnectOnStop"> /// a value indicating whether the player should stop after the track finished playing /// </param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="lavalinkSocket"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="client"/> is <see langword="null"/>. /// </exception> public QueuedLavalinkPlayer(LavalinkSocket lavalinkSocket, IDiscordClientWrapper client, ulong guildId, bool disconnectOnStop) : base(lavalinkSocket, client, guildId, false /* this player handles this on itself */) { Queue = new LavalinkQueue(); _disconnectOnStop = disconnectOnStop; }
/// <summary> /// Initializes a new instance of the <see cref="VoteLavalinkPlayer"/> class. /// </summary> /// <param name="lavalinkSocket">the lavalink socket</param> /// <param name="client">the discord client</param> /// <param name="guildId">the identifier of the guild that is controlled by the player</param> /// <param name="disconnectOnStop"> /// a value indicating whether the player should stop after the track finished playing /// </param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="lavalinkSocket"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="client"/> is <see langword="null"/>. /// </exception> public VoteLavalinkPlayer(LavalinkSocket lavalinkSocket, IDiscordClientWrapper client, ulong guildId, bool disconnectOnStop) : base(lavalinkSocket, client, guildId, disconnectOnStop) => _skipVotes = new List <ulong>();
/// <summary> /// Initializes a new instance of the <see cref="LavalinkNode"/> class. /// </summary> /// <param name="cluster">the cluster</param> /// <param name="options">the node options for connecting</param> /// <param name="client">the discord client</param> /// <param name="logger">the logger</param> /// <param name="cache">an optional cache that caches track requests</param> /// <param name="id">the node number</param> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="cluster"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="options"/> parameter is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentNullException"> /// thrown if the specified <paramref name="client"/> is <see langword="null"/>. /// </exception> public LavalinkClusterNode(LavalinkCluster cluster, LavalinkNodeOptions options, IDiscordClientWrapper client, ILogger logger, ILavalinkCache cache, int id) : base(options, client, logger, cache) { if (options is null) { throw new ArgumentNullException(nameof(options)); } if (client is null) { throw new ArgumentNullException(nameof(client)); } Cluster = cluster ?? throw new ArgumentNullException(nameof(cluster)); Identifier = "Cluster Node-" + id; LastUsage = DateTimeOffset.MinValue; }