Example #1
0
        static async Task MainAsync()
        {
            await setupDiscord();
            await setupGithub();

            //var latest = await getLatestVersion();
            discord.GuildMemberUpdated += DiscordOnGuildMemberUpdated;
            discord.Ready += DiscordOnReady;
            //var tt = await runBuildScript(latest.incrementPatch());
            _logger.Info($"idle");
            var clientWrapper = new DiscordClientWrapper(discord);

            audioService = new LavalinkNode(new LavalinkNodeOptions
            {
                RestUri      = $"http://{Settings.PSettings.lavalinkConnectionString}/",
                WebSocketUri = $"ws://{Settings.PSettings.lavalinkConnectionString}/",
                Password     = $"{Settings.PSettings.lavalinkPassword}"
            }, clientWrapper);

            var service = new InactivityTrackingService(
                audioService,  // The instance of the IAudioService (e.g. LavalinkNode)
                clientWrapper, // The discord client wrapper instance
                new InactivityTrackingOptions
            {
                DisconnectDelay = TimeSpan.Zero,
                TrackInactivity = false
            });

            service.RemoveTracker(DefaultInactivityTrackers.ChannelInactivityTracker);
            service.BeginTracking();
            await Task.Delay(-1); //Never returns.
        }
        private async System.Threading.Tasks.Task DiscordShardedclient_ShardReady(DiscordSocketClient arg)
        {
            discordClientWrapper = new DiscordClientWrapper(arg);
            lavalinkCluster      = new LavalinkCluster(new LavalinkClusterOptions()
            {
                StayOnline = true,
                Nodes      = new[] { new Lavalink4NET.LavalinkNodeOptions()
                                     {
                                         RestUri       = $"http://lavalink.alivecreation.fr:80/",
                                         WebSocketUri  = $"ws://lavalink.alivecreation.fr:80/",
                                         Password      = Uri.EscapeDataString("AyF6c62M3Lu2t5jcRCMMfhcGZ34dGjBv95cVPJsbbhKcBUBcnFEDDbvXBzU7EFgAN2ucE2ZLz6gnrwWRDxYKwvWsvqYntxLYYb4quUdhQAPLvDWqYanwAusE3rcGxhyC6aswGgDDWwEZ8ZNWR5bUBWfTm62fzeXafmzjNTwNFRwDz9ksJHj9BCT2MwBgdcqTxpGMQ8QLNQdJqEUmuPR3Xn8SczmecFpjpSfDcC42xAL5LyNQMtZur6YAZRu5t85g"),
                                         AllowResuming = true
                                     }, },

                LoadBalacingStrategy = LoadBalancingStrategies.LoadStrategy
            }, discordClientWrapper);
            await lavalinkCluster.InitializeAsync();

            inactivityTracker = new InactivityTrackingService(lavalinkCluster, discordClientWrapper, new InactivityTrackingOptions()
            {     // Disconnect the player after 10 seconds if it inactive.
                DisconnectDelay = TimeSpan.FromSeconds(10),

                // Check every 4 seconds for an inactive player.
                PollInterval = TimeSpan.FromSeconds(4),

                // Start Tracking after calling the constructor.
                TrackInactivity = true
            });
        }
Example #3
0
        public BotMain(IServiceProvider services, MessageRemoverService responseRemover, ErrorHandlerService errorHandler, Statistics statistics, IConfiguration configuration, IAudioService audioService, DiscordSocketClient client, PlayerService playerService, ConfigurationRepository configurationRepository, InactivityTrackingService inactivityTrackingService)
        {
            _configuration             = configuration;
            _responseRemover           = responseRemover;
            _errorHandler              = errorHandler;
            _statistics                = statistics;
            _serviceProvider           = services;
            _audioService              = audioService;
            _client                    = client;
            _playerService             = playerService;
            _configurationRepository   = configurationRepository;
            _inactivityTrackingService = inactivityTrackingService;

            _commands = new CommandService();
        }
Example #4
0
        static async Task Main(string[] args)
        {
            _logger.Debug("I'm alive!");
            _logger.Debug("Starting discord....");
            discord = new DiscordClient(new DiscordConfiguration
            {
                AutoReconnect = true,
                Token         = Settings.PersistentSettings.BotToken,
                TokenType     = TokenType.Bot
            });
            var commands = discord.UseCommandsNext(new CommandsNextConfiguration
            {
                StringPrefixes      = new[] { ".." },
                EnableMentionPrefix = true
            });
            var clientWrapper = new DiscordClientWrapper(discord);

            audioService = new LavalinkNode(new LavalinkNodeOptions
            {
                RestUri      = $"http://{Settings.PersistentSettings.lavalinkConnectionString}/",
                WebSocketUri = $"ws://{Settings.PersistentSettings.lavalinkConnectionString}/",
                Password     = $"{Settings.PersistentSettings.lavalinkPassword}"
            }, clientWrapper);
            var service = new InactivityTrackingService(
                audioService,  // The instance of the IAudioService (e.g. LavalinkNode)
                clientWrapper, // The discord client wrapper instance
                new InactivityTrackingOptions
            {
                DisconnectDelay = TimeSpan.Zero,
                TrackInactivity = false
            });

            service.RemoveTracker(DefaultInactivityTrackers.ChannelInactivityTracker);
            service.BeginTracking();
            discord.Ready += DiscordOnReady;
            commands.RegisterCommands <Commands>();
            await discord.ConnectAsync();

            Thread.Sleep(5000);
            await audioService.InitializeAsync();

            //var connections = await discord.GetConnectionsAsync();

            await Task.Delay(-1); //Run forever
        }
Example #5
0
        public async Task RunBotAsync()
        {
            //Init log
            var dates = DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".log";

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console()
                         .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Information).WriteTo.File(@".\Logs\Info\" + dates))
#if DEBUG
                         .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Debug).WriteTo.File(@".\Logs\Debug\" + dates))
                         .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Verbose).WriteTo.File(@".\Logs\Verbose\" + dates))
#endif
                         .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning).WriteTo.File(@".\Logs\Warning\" + dates))
                         .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Error).WriteTo.File(@".\Logs\Error\" + dates))
                         .CreateLogger();

            discordClient  = new DiscordSocketClient();
            clientWrapper  = new DiscordClientWrapper(discordClient);
            commandService = new CommandService();
            services       = new ServiceCollection().AddSingleton(discordClient).AddSingleton(commandService)                                                                                      // Discord.NET
                             .AddSingleton <IAudioService, LavalinkNode>().AddSingleton <IDiscordClientWrapper, DiscordClientWrapper>().AddSingleton <Lavalink4NET.Logging.ILogger, EventLogger>() //Lavalink4NET
                             .BuildServiceProvider();

            //Init audio service
            string lavalinkIP   = ConfigurationManager.AppSettings["lavalinkIP"];
            string lavalinkPort = ConfigurationManager.AppSettings["lavalinkPort"];
            string lavalinkPw   = ConfigurationManager.AppSettings["lavalinkPassword"];

            var logger = services.GetRequiredService <Lavalink4NET.Logging.ILogger>() as EventLogger;
            logger.LogMessage += AudioLog;

            audioService = new LavalinkNode(new LavalinkNodeOptions
            {
                RestUri          = $"http://{lavalinkIP}:{lavalinkPort}/",
                WebSocketUri     = $"ws://{lavalinkIP}:{lavalinkPort}/",
                Password         = lavalinkPw,
                DisconnectOnStop = false
            }, clientWrapper, logger);

            discordClient.Log   += LogMessage;
            discordClient.Ready += () => audioService.InitializeAsync();


            bool enableInactiveCheck = Convert.ToBoolean(ConfigurationManager.AppSettings["enableInactiveCheck"]);
            if (enableInactiveCheck)
            {
                int disconnectDelay = Convert.ToInt32(ConfigurationManager.AppSettings["disconnectDelay"]);
                int pollInterval    = Convert.ToInt32(ConfigurationManager.AppSettings["pollInterval"]);
                var trackingService = new InactivityTrackingService(
                    audioService,
                    clientWrapper,
                    new InactivityTrackingOptions
                {
                    DisconnectDelay = TimeSpan.FromSeconds(disconnectDelay),
                    PollInterval    = TimeSpan.FromSeconds(pollInterval),
                    TrackInactivity = false
                });

                // Start tracking inactive players
                trackingService.BeginTracking();
            }

            KeywordHolder.LoadKeywordList();
            LanguageHolder.LoadLanguageList();

            await RegisterCommandsAsync();

            await discordClient.LoginAsync(TokenType.Bot, ConfigurationManager.AppSettings["BotToken"]);

            await discordClient.StartAsync();

            await Task.Delay(-1);
        }
Example #6
0
 public AudioModule(IAudioService audioService, InactivityTrackingService trackingService)
 {
     _audioService = audioService;
     trackingService.InactivePlayer += Disconnect;
 }