Example #1
0
        public async Task DisconnectAllPlayersAsync(string warnMsg, bool isRestart = false)
        {
            int             count   = this.Players.Count;
            IRestartService restart = this.ServiceManager.GetService <IRestartService>("Restart");

            foreach ((ulong _, IEnergizePlayer ply) in this.Players)
            {
                if (ply.VoiceChannel == null)
                {
                    continue;
                }

                await this.DisconnectAsync(ply.VoiceChannel);

                if (ply.TextChannel != null)
                {
                    if (isRestart)
                    {
                        await restart.WarnChannelAsync(ply.TextChannel, warnMsg);
                    }
                    else
                    {
                        await this.MessageSender.SendWarningAsync(ply.TextChannel, "music player", warnMsg);
                    }
                }
            }

            this.Logger.Nice("MusicPlayer", ConsoleColor.Yellow, $"Disconnected {count} players");
        }
Example #2
0
        public async Task Execute(IJobExecutionContext context)
        {
            JobDataMap           dataMap        = context.JobDetail.JobDataMap;
            IServiceManager      serviceManager = (IServiceManager)dataMap["ServiceManager"];
            DiscordShardedClient discordClient  = (DiscordShardedClient)dataMap["DiscordClient"];

            IMusicPlayerService music   = serviceManager.GetService <IMusicPlayerService>("Music");
            IRestartService     restart = serviceManager.GetService <IRestartService>("Restart");

            await music.DisconnectAllPlayersAsync("Weekly update on-going, disconnecting", true);

            SocketChannel updateChan = discordClient.GetChannel(Config.Instance.Discord.UpdateChannelID);

            if (updateChan != null)
            {
                await restart.WarnChannelAsync(updateChan, "Updating to the latest changes...");
            }

            await restart.RestartAsync();
        }