Example #1
0
 public VoiceAssistantWorker(SocketGuildUser user, VoiceChannelWorker voiceChannelWorker, MetadataManager metadataManager, WitAiClient witAiClient)
 {
     _voiceChannelWorker = voiceChannelWorker;
     _metadataManager    = metadataManager;
     _witAiClient        = witAiClient;
     _user = user;
 }
Example #2
0
 public VoiceChannelWorker(SocketVoiceChannel voiceChannel, MetadataManager metadataManager, PlayHistoryManager playHistoryManager, WitAiClient witAiClient)
 {
     _voiceChannel       = voiceChannel;
     _metadataManager    = metadataManager;
     _playHistoryManager = playHistoryManager;
     _witAiClient        = witAiClient;
 }
        public static async Task Main(string[] args)
        {
            var cts = new CancellationTokenSource();

            if (DataDir != null)
            {
                Directory.SetCurrentDirectory(DataDir);
            }

            var audioTmpDir = Path.Join(_audioDir, "tmp");

            if (Directory.Exists(audioTmpDir))
            {
                Directory.Delete(audioTmpDir, recursive: true);
            }
            Directory.CreateDirectory(audioTmpDir);

            var secrets = JsonConvert.DeserializeObject <Secrets>(File.ReadAllText("secrets.json"));

            if (secrets == null)
            {
                throw new Exception("secrets object was null");
            }
            secrets.DiscordApiKey = DiscordApiKeyOverride ?? secrets.DiscordApiKey;
            secrets.WitAiApiKey   = WitAiApiKeyOverride ?? secrets.WitAiApiKey;

            using var db = new LiteDatabaseAsync($"Filename=metadata.db;Connection=shared");
            using var metadataManager    = new MetadataManager(db);
            using var playHistoryManager = new PlayHistoryManager(db);
            _metadataManager             = metadataManager;

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Task.Run(() => _autoPopulate(cts.Token));
            Task.Run(() => _autoPrefetch(cts.Token));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            if (secrets.WitAiApiKey == null)
            {
                throw new ArgumentNullException("WitAiApiKey must be provided.");
            }
            var aiClient = new WitAiClient(secrets.WitAiApiKey);

            if (secrets.DiscordApiKey == null)
            {
                throw new ArgumentNullException("DiscordApiKey must be provided.");
            }
            var client = new DiscordClient(secrets.DiscordApiKey, aiClient, _metadataManager, playHistoryManager);
            await client.StartAsync();

            Console.CancelKeyPress += (o, e) => cts.Cancel();
            AppDomain.CurrentDomain.ProcessExit += (s, ev) => cts.Cancel();

            await cts.Token.WhenCancelled();
        }
Example #4
0
        public DiscordClient(string apiKey, WitAiClient witAiClient, MetadataManager metadataManager, PlayHistoryManager playHistoryManager)
        {
            _client = new DiscordSocketClient(new DiscordSocketConfig()
            {
            });
            _client.Log             += OnLog;
            _client.Ready           += OnReady;
            _client.MessageReceived += OnMessageReceived;

            _apiKey             = apiKey;
            _witAiClient        = witAiClient;
            _metadataManager    = metadataManager;
            _playHistoryManager = playHistoryManager;
        }