Beispiel #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
            });
        }
Beispiel #3
0
        public DDBLService(DiscordSocketClient client, ClientConfiguration configuration)
        {
            _discord            = new DiscordSocketClientWrapper(ref client);
            _config             = configuration;
            client.JoinedGuild += async(guild) => await UpdateStats();

            client.LeftGuild += async(guild) => await UpdateStats();

            client.Ready += async() => await Init();
        }
        /// <summary>
        /// Used to create the service.
        /// </summary>
        public DDBLService(DiscordShardedClient client, ClientConfiguration configuration)
        {
            _config  = configuration;
            _discord = new DiscordShardedClientWrapper(ref client);
            client.GuildAvailable += async(guild) => await UpdateStats();

            client.GuildDeleted += async(guild) => await UpdateStats();

            client.Ready += async(args) => await Init();
        }
Beispiel #5
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
        }
Beispiel #6
0
        /// <summary>
        /// Used to create the service.
        /// </summary>
        public DDBLService(DiscordShardedClient client, ClientConfiguration configuration)
        {
            _config  = configuration;
            _discord = new DiscordShardedClientWrapper(ref client);
            int shardsConnected = 0;

            client.JoinedGuild += async(guild) => await UpdateStats();

            client.LeftGuild += async(guild) => await UpdateStats();

            client.ShardReady += async(shard) =>
            {
                if (shardsConnected != -1)
                {
                    shardsConnected++;
                    if (shardsConnected == client.Shards.Count)
                    {
                        shardsConnected = -1;
                        await Init();
                    }
                }
            };
        }
 public DDBLService(DiscordClient client, ClientConfiguration configuration)
 {
     _discord      = new DiscordSocketClientWrapper(ref client);
     _config       = configuration;
     client.Ready += async(shard) => await Init();
 }
Beispiel #8
0
        public async Task Start()
        {
            var settings = new MainSettings("Config/mainSettings.xml", "Config/Local/mainSettings.xml");

            settings.LoadLanguage();

            var connection = new SqliteConnection($"Data Source={settings.DatabasePath};");

            connection.Open();
            Migrate(connection);

            Connection = connection;
            Settings   = settings;

            async Task clientReadyHandler()
            {
                commands = new CommandService();

                var serviceCollection = new ServiceCollection();

                serviceCollection.AddSingleton(clientWrapper.MainClient);
                serviceCollection.AddSingleton(clientWrapper);
                serviceCollection.AddSingleton(connection);
                serviceCollection.AddSingleton(settings);
                serviceCollection.AddSingleton(commands);
                serviceCollection.AddSingleton <Services.Notifier>();
                serviceCollection.AddSingleton <System.Threading.SynchronizationContext>(SyncContext);
                serviceCollection.AddSingleton <Game>();
                serviceCollection.AddSingleton <Base.Game.IGame>(p => p.GetRequiredService <Game>());
                serviceCollection.AddSingleton <DIContractResolver>();

                services = serviceCollection.BuildServiceProvider();
                _game    = services.GetRequiredService <Game>();
                _game.LoadSettings();

                await InstallCommands();

                await clientWrapper.MainClient.SetGameAsync(null);

                clientWrapper.MainClient.Ready -= clientReadyHandler;
            }

            clientWrapper = new DiscordClientWrapper(settings, clientReadyHandler);

            clientWrapper.MainClient.Log += Log;

            if (clientWrapper.MainClient != clientWrapper.AnnouncerClient)
            {
                clientWrapper.AnnouncerClient.Log += AnnouncerLog;
            }

            try
            {
                SyncContext.RunMessagePump();
            }
            catch (Exception ex)
            {
                var message = $"[{DateTime.Now:s}] {ex}";
                Console.Error.WriteLine(message);
                System.IO.File.AppendAllText("error.log", message);
            }

            await Task.CompletedTask;
        }
 public GameActionsModule(Game game, DiscordSocketClient client, DiscordClientWrapper clientWrapper)
 {
     _game          = game;
     _client        = client;
     _clientWrapper = clientWrapper;
 }
Beispiel #10
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);
        }
Beispiel #11
0
 public Notifier(DiscordClientWrapper clientWrapper)
 {
     _clientWrapper  = clientWrapper;
     _timer.Elapsed += TimeOfDayTimerElapsed;
     IsEnabled       = _clientWrapper.AnnouncerClient != _clientWrapper.MainClient;
 }