public static async Task HandleAuthorCommand(SocketMessage message, CommunityRepository repository) { string originalMessage = message.Content; string[] splitMessages = originalMessage.Split(new char[] { ' ' }, 3); if (splitMessages.Length < 3) { await message.Channel.SendMessageAsync(@"You did not specify a stage name or author. Type in ""!help author"" if you need help."); return; } string author = splitMessages[1]; string stageName = splitMessages[2]; Stage stage = new Stage() { Name = stageName, Author = author, Date = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }; if (!repository.StageExists(stage)) { await message.Channel.SendMessageAsync(String.Format(@"Failed to update the author for the stage ""{0}"" because the stage does not exist in the community repository.", stageName)); return; } Stage oldStage = repository.GetStage(stage.Name); string messageAuthor = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower()); if (oldStage.Author != messageAuthor) { await message.Channel.SendMessageAsync("Failed to update the author of the stage because you are not the author"); return; } repository.UpdateStage(oldStage, stage); await message.Channel.SendMessageAsync("Updating the author for the stage in the community repository now..."); string commitMessage = String.Format(@"Updated the author for the stage {0} from ""{1}"" to ""{2}"".", stageName, oldStage.Author, stage.Author); MainClass.UpdateGitHub(commitMessage); await message.Channel.SendMessageAsync("Successfully updated the author of the stage!"); }
public async static Task HandleUpdateCommand(SocketMessage message, CommunityRepository repository) { var attachments = message.Attachments; if (attachments.Count == 0) { await message.Channel.SendMessageAsync("You did not upload a file for me to update in the community repository"); return; } if (attachments.Count > 1) { await message.Channel.SendMessageAsync("Please only send one file at a time."); return; } var attachment = message.Attachments.ElementAt(0); string stageName = Path.GetFileNameWithoutExtension(attachment.Filename).Replace("_", " ").Replace("-", " "); Stage stage = new Stage() { Name = stageName, Author = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower()), Date = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }; if (!repository.StageExists(stage)) { await message.Channel.SendMessageAsync("Failed to update the stage because the stage does not exist in the community repository."); return; } Stage repositoryStage = repository.GetStage(stage.Name); if (stage.Author != repositoryStage.Author) { await message.Channel.SendMessageAsync("Failed to update the stage because you are not the author of the stage."); return; } string URL = attachment.Url; string fileName = attachment.Filename.Replace("_", " ").Replace("-", " "); int randomNumber = new Random().Next(); string damnedStageCheckerDirectoryName = String.Format("DamnedStageChecker_{0}", randomNumber); string tempArchive = Path.Combine(Path.GetTempPath(), damnedStageCheckerDirectoryName, fileName); string parentTempArchive = Path.Combine(Path.GetTempPath(), damnedStageCheckerDirectoryName); if (Directory.Exists(parentTempArchive)) { Directory.Delete(parentTempArchive, true); } Directory.CreateDirectory(parentTempArchive); using (WebClient client = new WebClient()) { client.DownloadFile(new Uri(URL), tempArchive); } DamnedPackage package = new DamnedPackage(); await message.Channel.SendMessageAsync("Checking your updated stage archive now..."); if (!package.Check(tempArchive)) { Directory.Delete(parentTempArchive, true); Directory.Delete(package.tempDirectory, true); await message.Channel.SendMessageAsync(package.reasonForFailedCheck); return; } await message.Channel.SendMessageAsync("Stage check successful! I am updating your stage in the community repository now..."); string oldFilePath = repository.GetPathToStageInCommunityRepository(repositoryStage); File.Delete(oldFilePath); File.Copy(tempArchive, fileName); Directory.Delete(parentTempArchive, true); Directory.Delete(package.tempDirectory, true); repository.UpdateStage(repositoryStage, stage); string commitMessage = String.Format("Updated the stage {0} in the community repository", stage.Name); MainClass.UpdateGitHub(commitMessage); await message.Channel.SendMessageAsync("Succcessfully updated your stage that is in the community repository!"); }