Example #1
0
        private async Task AddSong(ICommandContext context, object[] parameters, IServiceProvider services, CommandInfo info)
        {
            if (context.Message.Attachments.Count != 1)
            {
                await context.Channel.SendMessageAsync("Number of files incorrect");

                return;
            }

            IAttachment att = context.Message.Attachments.First();

            if (att.Filename.EndsWith(".mp3"))
            {
                string filePath = Path.Combine(services.GetService <ConfigHandler>().GetSongDir(), att.Filename).Replace(@"\", @"\\");
                webClient.DownloadFile(att.Url, filePath);
                MP3 mp3 = new MP3
                {
                    command = (string)parameters[0],
                    name    = filePath
                };
                try
                {
                    songList.Add(mp3.command, mp3.name);
                    using (StreamWriter sw = File.AppendText(services.GetService <ConfigHandler>().GetSongConf()))
                    {
                        sw.WriteLine(JsonConvert.SerializeObject(mp3));
                    }
                    await commands.RemoveModuleAsync(customModule);
                    await AddCommands();
                }
                catch (ArgumentException ex)
                {
                    await context.Channel.SendMessageAsync(ex.Message);

                    return;
                }
            }
        }