Ejemplo n.º 1
0
 /// <summary>
 /// Initializes global instance.
 /// </summary>
 public AudioService()
 {
     INSTANCE = this;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the bot.
        /// </summary>
        ///
        /// <returns>the async task.</returns>
        public async Task RunBotAsync()
        {
            _client   = new DiscordSocketClient();
            _commands = new CommandService();
            _services = new ServiceCollection()
                        .AddSingleton(_client)
                        .AddSingleton(_commands)
                        .AddSingleton(new AudioService())
                        .BuildServiceProvider();
            _client.Log += Log;

            INSTANCE = this;

            await RegisterCommandsAsync();

            await _client.LoginAsync(Discord.TokenType.Bot, Definitions.Token);

            await _client.StartAsync();

            GetLogger().Log(Logger.Level.INFO, "Bot is starting...");

            bool rdy = false;

            _client.Ready += async() => {
                rdy = true;
            };

label:      //Got to love this...
            if (!rdy)
            {
                await Task.Delay(1000);

                goto label;
            }

            foreach (IGuild guild in _client.Guilds)
            {
                GetLogger().Log(Level.INFO, "Found guild: " + guild.Name);
                if (guild.Name.Equals("For All The Rejects"))
                {
                    GetLogger().Log(Level.INFO, "Auto joining: " + guild.Name);
                    IGuildChannel channel = null;
                    IReadOnlyCollection <IGuildChannel> collection = await guild.GetVoiceChannelsAsync();

                    IMessageChannel messageChannel = guild.GetDefaultChannelAsync() as IMessageChannel;

                    foreach (IGuildChannel channelA in collection)
                    {
                        if (channelA.Name.Equals("Hell"))
                        {
                            channel = channelA;
                        }
                    }

                    if (channel == null)
                    {
                        return;
                    }

                    await AudioService.GetInstance().LeaveAudioAsync(guild);

                    await AudioService.GetInstance().JoinAudioAsync(guild, channel as IVoiceChannel);

                    await AudioService.GetInstance().LoopAudioAsync(guild, messageChannel, "Nyan");
                }
            }

            _client.LoggedOut += async() => {
                GetLogger().Log(Level.WARN, "Logged out");
            };

            _client.Disconnected += async(e) => {
                GetLogger().Log(Level.WARN, "Disconnected" + e.ToString());
            };

            await Task.Delay(-1);
        }