public MusicService(LavalinkExtension lavalink, DiscordClient discord) { this._lavalinkExtension = lavalink; this._discord = discord; this._discord.Ready += this.Ready; }
public LavaPlayer() { LavalinkConfiguration lavaConfig = global.botConfig.GetLavalinkConfiguration(); LavalinkExtension lavalink = global.bot.UseLavalink(); lavalink.ConnectAsync(lavaConfig).GetAwaiter().GetResult(); }
private async Task <LavalinkNodeConnection> ConnectLavaNodeAsync() { ConnectionEndpoint endpoint = new ConnectionEndpoint { Hostname = "server.local", Port = 2333 }; LavalinkConfiguration lavalinkConfig = new LavalinkConfiguration { Password = ReadConfig.Config.LavaLinkPass, RestEndpoint = endpoint, SocketEndpoint = endpoint, SocketAutoReconnect = false }; LavalinkExtension lavalink = Client.UseLavalink(); LavalinkNodeConnection res = null; try { res = await lavalink.ConnectAsync(lavalinkConfig); } catch (WebSocketException e) { SystemService.Instance.Logger.Log("Failed to start connection with Lavalink server:\n" + e.Message); } return(res); }
/// <summary> /// Method for configuring <see cref="LavalinkExtension"/>, accessing each configuration individually. /// </summary> /// <param name="botBase"></param> /// <param name="hostname">Sets the hostname associated with the Lavalink.</param> /// <param name="port">Sets the port associated with the Lavalink.</param> /// <param name="password">Sets the password associated with the Lavalink.</param> /// <param name="secured">Sets the secured status associated with the Lavalink.</param> /// <param name="region">Sets the voice region ID for the Lavalink connection. This should be used if nodes should be filtered by region with <see cref="LavalinkExtension.GetIdealNodeConnection(DiscordVoiceRegion)"/>.</param> /// <param name="resumeKey">Sets the resume key for the Lavalink connection. This will allow existing voice sessions to continue for a certain time after the client is disconnected.</param> /// <param name="resumeTimeout">Sets the time in seconds when all voice sessions are closed after the client disconnects. Defaults to 1 minute.</param> /// <param name="webSocketCloseTimeout">Sets the time in miliseconds to wait for Lavalink's voice WebSocket to close after leaving a voice channel. This will be the delay before the guild connection is removed. Defaults to 3 minutes.</param> /// <param name="socketAutoReconnect">Sets whether the connection wrapper should attempt automatic reconnects should the connection drop.</param> public static void LavalinkSetup(this TarsBase botBase, string hostname, int port, string password, bool secured = false, DiscordVoiceRegion region = null, string resumeKey = null, TimeSpan?resumeTimeout = null, TimeSpan?webSocketCloseTimeout = null, bool socketAutoReconnect = true) { _botBase = botBase; var connectionEndpoint = new ConnectionEndpoint(hostname, port, secured); _lavalinkConfiguration = new LavalinkConfiguration { SocketEndpoint = connectionEndpoint, RestEndpoint = connectionEndpoint, Password = password, Region = region, ResumeKey = resumeKey, ResumeTimeout = (int)(resumeTimeout?.TotalSeconds ?? TimeSpan.FromMinutes(1).TotalSeconds), WebSocketCloseTimeout = (int)(webSocketCloseTimeout?.TotalMilliseconds ?? TimeSpan.FromSeconds(3).TotalMilliseconds), SocketAutoReconnect = _socketAutoReconnect = socketAutoReconnect }; _lavalink = botBase.Discord.UseLavalink(); botBase.Discord.Heartbeated += DiscordHeartbeated; RegisterExitEvent(); RegisterLavalinkAsService(botBase); HttpClientSetup(); }
public MusicService(DiscordClient client, LavalinkExtension lavalink, LogService logger) { Players = new ConcurrentDictionary <ulong, MusicPlayer>(); Lavalink = lavalink; Logger = logger; client.VoiceStateUpdated += Client_VoiceStateUpdated; }
public MusicService(PlaylistDataAccess db, DiscordHelper helper, DiscordClient client, ConfigService config) { this.db = db; this.helper = helper; this.client = client; this.config = config; lavalink = client.GetLavalink(); playlist = db.GetAllPlaylistTracks().Result; }
public static async Task <LavalinkNodeConnection> GetNodeConnection(CommandContext ctx, bool newConnection = false) { LavalinkExtension lavalink = ctx.Client.GetLavalink(); LavalinkNodeConnection lavalinkNodeConnection = lavalink.GetNodeConnection(Program.GetLavalinkConnectionEndpoint()); if (lavalinkNodeConnection == null) { lavalinkNodeConnection = await lavalink.ConnectAsync(Program.GetLavalinkConfiguration()); } return(lavalinkNodeConnection); }
private void BuildClient() { __discord = new DiscordClient(new DiscordConfiguration { Token = __config.GetValue <string>("discord:token"), TokenType = TokenType.Bot, MinimumLogLevel = Microsoft.Extensions.Logging.LogLevel.Error }); __interactivity = __discord.UseInteractivity(); __voice = __discord.UseVoiceNext(); __lavalink = __discord.UseLavalink(); }
public TutorialBot() { Instance = this; this.Discord = new DiscordClient(new DiscordConfiguration { Token = Environment.GetEnvironmentVariable("TUTORIAL_BOT_TOKEN"), TokenType = TokenType.Bot, AutoReconnect = true, LogLevel = LogLevel.Error, GatewayCompressionLevel = GatewayCompressionLevel.Stream, UseInternalLogHandler = true }); this.Lavalink = this.Discord.UseLavalink(); this.Interactivity = this.Discord.UseInteractivity(new InteractivityConfiguration { PaginationBehaviour = PaginationBehaviour.Ignore, PaginationDeletion = PaginationDeletion.DeleteMessage, PollBehaviour = PollBehaviour.KeepEmojis, Timeout = TimeSpan.FromMinutes(5d) }); this.Services = new ServiceCollection() .AddSingleton(this) .BuildServiceProvider(true); this.CommandsNext = this.Discord.UseCommandsNext(new CommandsNextConfiguration { StringPrefixes = new string[] { "!" }, EnableDms = false, Services = this.Services }); this.CommandsNext.RegisterCommands(typeof(TutorialBot).Assembly); this.CommandsNext.CommandErrored += (e) => { Console.WriteLine(e.Exception); return(Task.CompletedTask); }; }
public MusicCommands(LavalinkExtension lavaLink) { _Lavalink = lavaLink; _Playlist = new Queue <LavalinkTrack>(); }
static async Task MainAsync(string[] args) { await b118DB.Init(); DiscordConfiguration discordConfiguration = new DiscordConfiguration { MinimumLogLevel = logLevel, Token = token, TokenType = TokenType.Bot }; discord = new DiscordClient(discordConfiguration); discord.Ready += async(DiscordClient client, ReadyEventArgs e) => { await discord.UpdateStatusAsync(new DiscordActivity("The Bee Movie | b.help", ActivityType.Watching)); }; #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously discord.GuildAvailable += async(DiscordClient client, GuildCreateEventArgs e) => { GuildDetails.AddClientGuild(client, e.Guild); }; discord.MessageCreated += async(DiscordClient client, MessageCreateEventArgs e) => #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { if (e.Author.IsBot) { e.Handled = true; } }; discord.MessageCreated += BeeReaction; discord.MessageCreated += Bees; discord.MessageCreated += Beep; discord.ClientErrored += ClientErrored; CommandsNextConfiguration commandsNextConfiguration = new CommandsNextConfiguration { StringPrefixes = Prefixes, EnableDms = true, EnableDefaultHelp = false }; interactivity = discord.UseInteractivity(new InteractivityConfiguration() { Timeout = TimeSpan.FromSeconds(30) }); commands = discord.UseCommandsNext(commandsNextConfiguration); commands.CommandExecuted += CommandExecuted; commands.CommandErrored += CommandErrored; commands.RegisterCommands <BoardCommands>(); commands.RegisterCommands <BeatCommands>(); commands.RegisterCommands <CampaignCommands>(); commands.RegisterCommands <BCommands>(); lavalink = discord.UseLavalink(); await discord.ConnectAsync(); await Task.Delay(-1); }
public TestBot(TestBotConfig cfg, int shardid) { // global bot config this.Config = cfg; // discord instance config and the instance itself var dcfg = new DiscordConfiguration { AutoReconnect = true, LargeThreshold = 250, MinimumLogLevel = LogLevel.Debug, Token = this.Config.Token, TokenType = TokenType.Bot, ShardId = shardid, ShardCount = this.Config.ShardCount, MessageCacheSize = 2048, LogTimestampFormat = "dd-MM-yyyy HH:mm:ss zzz", Intents = DiscordIntents.All // if 4013 is received, change to DiscordIntents.AllUnprivileged }; this.Discord = new DiscordClient(dcfg); // events this.Discord.Ready += this.Discord_Ready; this.Discord.GuildAvailable += this.Discord_GuildAvailable; //Discord.PresenceUpdated += this.Discord_PresenceUpdated; //Discord.ClientErrored += this.Discord_ClientErrored; this.Discord.SocketErrored += this.Discord_SocketError; this.Discord.GuildCreated += this.Discord_GuildCreated; this.Discord.VoiceStateUpdated += this.Discord_VoiceStateUpdated; this.Discord.GuildDownloadCompleted += this.Discord_GuildDownloadCompleted; this.Discord.GuildUpdated += this.Discord_GuildUpdated; this.Discord.ChannelDeleted += this.Discord_ChannelDeleted; // For event timeout testing //Discord.GuildDownloadCompleted += async (s, e) => //{ // await Task.Delay(TimeSpan.FromSeconds(2)).ConfigureAwait(false); // throw new Exception("Flippin' tables"); //}; // voice config and the voice service itself var vcfg = new VoiceNextConfiguration { AudioFormat = AudioFormat.Default, EnableIncoming = true }; this.VoiceService = this.Discord.UseVoiceNext(vcfg); // build a dependency collection for commandsnext var depco = new ServiceCollection(); // commandsnext config and the commandsnext service itself var cncfg = new CommandsNextConfiguration { StringPrefixes = this.Config.CommandPrefixes, EnableDms = true, EnableMentionPrefix = true, CaseSensitive = false, Services = depco.BuildServiceProvider(true), IgnoreExtraArguments = false, UseDefaultCommandHandler = true, }; this.CommandsNextService = this.Discord.UseCommandsNext(cncfg); this.CommandsNextService.CommandErrored += this.CommandsNextService_CommandErrored; this.CommandsNextService.CommandExecuted += this.CommandsNextService_CommandExecuted; this.CommandsNextService.RegisterCommands(typeof(TestBot).GetTypeInfo().Assembly); this.CommandsNextService.SetHelpFormatter <TestBotHelpFormatter>(); // interactivity service var icfg = new InteractivityConfiguration() { Timeout = TimeSpan.FromSeconds(3) }; this.InteractivityService = this.Discord.UseInteractivity(icfg); this.LavalinkService = this.Discord.UseLavalink(); //this.Discord.MessageCreated += async e => //{ // if (e.Message.Author.IsBot) // return; // _ = Task.Run(async () => await e.Message.RespondAsync(e.Message.Content)).ConfigureAwait(false); //}; }
static async Task MainAsync(string[] args) { // Create service collection and configure our services var serviceProvider = new ServiceCollection() .AddSingleton <IKarvisConfigurationService>(new KarvisConfigurationService()) .AddSingleton <IProvideAudioState>(new AudioStateProvider()) .BuildServiceProvider(); karvisConfiguration = serviceProvider.GetService <IKarvisConfigurationService>().Configuration; discord = new DiscordClient(new DSharpPlus.DiscordConfiguration() { Token = karvisConfiguration.DiscordConfiguration.Token, TokenType = TokenType.Bot, UseInternalLogHandler = true, LogLevel = LogLevel.Debug, AutoReconnect = true }); var audioConfig = new VoiceNextConfiguration(); audioConfig.AudioFormat = new AudioFormat(48000, 2, VoiceApplication.Music); audioConfig.EnableIncoming = true; voice = discord.UseVoiceNext(audioConfig); discord.MessageCreated += async e => { if (e.Message.Content.ToLower().StartsWith("ping")) { await e.Message.RespondAsync("pong!"); } }; commands = discord.UseCommandsNext(new CommandsNextConfiguration { StringPrefixes = new List <string>() { ";;", "->" }, EnableDms = false, // required for UseVoiceNext? Services = serviceProvider }); commands.RegisterCommands <CommandsModule>(); commands.RegisterCommands <LavalinkCommandsModule>(); commands.RegisterCommands <AzureCommandsModule>(); commands.RegisterCommands <GoogleCommandsModule>(); interactivity = discord.UseInteractivity(new InteractivityConfiguration { }); lavalink = discord.UseLavalink(); discord.Ready += Client_Ready; discord.GuildAvailable += Client_GuildAvailable; discord.ClientErrored += Client_ClientError; await discord.ConnectAsync(); await Task.Delay(-1); // infinite wait to prevent exit }
public TestBot(TestBotConfig cfg, int shardid) { // global bot config this.Config = cfg; // discord instance config and the instance itself var dcfg = new DiscordConfiguration { AutoReconnect = true, LargeThreshold = 250, MinimumLogLevel = LogLevel.Trace, Token = this.Config.Token, TokenType = TokenType.Bot, ShardId = shardid, ShardCount = this.Config.ShardCount, MessageCacheSize = 2048, LogTimestampFormat = "dd-MM-yyyy HH:mm:ss zzz", Intents = DiscordIntents.All // if 4013 is received, change to DiscordIntents.AllUnprivileged }; this.Discord = new DiscordClient(dcfg); // events this.Discord.Ready += this.Discord_Ready; this.Discord.GuildStickersUpdated += this.Discord_StickersUpdated; this.Discord.GuildAvailable += this.Discord_GuildAvailable; //Discord.PresenceUpdated += this.Discord_PresenceUpdated; //Discord.ClientErrored += this.Discord_ClientErrored; this.Discord.SocketErrored += this.Discord_SocketError; this.Discord.GuildCreated += this.Discord_GuildCreated; this.Discord.VoiceStateUpdated += this.Discord_VoiceStateUpdated; this.Discord.GuildDownloadCompleted += this.Discord_GuildDownloadCompleted; this.Discord.GuildUpdated += this.Discord_GuildUpdated; this.Discord.ChannelDeleted += this.Discord_ChannelDeleted; //this.Discord.ComponentInteractionCreated += this.RoleMenu; //this.Discord.ComponentInteractionCreated += this.DiscordComponentInteractionCreated; //this.Discord.InteractionCreated += this.SendButton; // For event timeout testing //Discord.GuildDownloadCompleted += async (s, e) => //{ // await Task.Delay(TimeSpan.FromSeconds(2)).ConfigureAwait(false); // throw new Exception("Flippin' tables"); //}; // voice config and the voice service itself var vcfg = new VoiceNextConfiguration { AudioFormat = AudioFormat.Default, EnableIncoming = true }; this.VoiceService = this.Discord.UseVoiceNext(vcfg); // build a dependency collection for commandsnext var depco = new ServiceCollection(); // commandsnext config and the commandsnext service itself var cncfg = new CommandsNextConfiguration { StringPrefixes = this.Config.CommandPrefixes, EnableDms = true, EnableMentionPrefix = true, CaseSensitive = false, Services = depco.BuildServiceProvider(true), IgnoreExtraArguments = false, UseDefaultCommandHandler = true, }; this.CommandsNextService = this.Discord.UseCommandsNext(cncfg); this.CommandsNextService.CommandErrored += this.CommandsNextService_CommandErrored; this.CommandsNextService.CommandExecuted += this.CommandsNextService_CommandExecuted; this.CommandsNextService.RegisterCommands(typeof(TestBot).GetTypeInfo().Assembly); this.CommandsNextService.SetHelpFormatter <TestBotHelpFormatter>(); // interactivity service var icfg = new InteractivityConfiguration() { Timeout = TimeSpan.FromSeconds(10), AckPaginationButtons = true, ResponseBehavior = InteractionResponseBehavior.Respond, PaginationBehaviour = PaginationBehaviour.Ignore, ResponseMessage = "Sorry, but this wasn't a valid option, or does not belong to you!", PaginationButtons = new PaginationButtons() { Stop = new DiscordButtonComponent(ButtonStyle.Danger, "stop", null, false, new DiscordComponentEmoji(862259725785497620)), Left = new DiscordButtonComponent(ButtonStyle.Secondary, "left", null, false, new DiscordComponentEmoji(862259522478800916)), Right = new DiscordButtonComponent(ButtonStyle.Secondary, "right", null, false, new DiscordComponentEmoji(862259691212242974)), SkipLeft = new DiscordButtonComponent(ButtonStyle.Primary, "skipl", null, false, new DiscordComponentEmoji(862259605464023060)), SkipRight = new DiscordButtonComponent(ButtonStyle.Primary, "skipr", null, false, new DiscordComponentEmoji(862259654403031050)) } }; this.InteractivityService = this.Discord.UseInteractivity(icfg); this.LavalinkService = this.Discord.UseLavalink(); //this.Discord.MessageCreated += async e => //{ // if (e.Message.Author.IsBot) // return; // _ = Task.Run(async () => await e.Message.RespondAsync(e.Message.Content)).ConfigureAwait(false); //}; }