예제 #1
0
    public async static Task HandleInformationCommand(SocketMessage message, CommunityRepository repository)
    {
        string originalMessage = message.Content;

        string[] splitMessage = originalMessage.Split(new char[] { ' ' }, 2);
        string   stageName    = splitMessage[1];

        Stage stage = new Stage()
        {
            Name = stageName.ToLower(),
        };

        if (!repository.StageExists(stage))
        {
            string possibleStrings = repository.GetPossibleStageNames(stage.Name);

            if (possibleStrings != String.Empty)
            {
                string reply = String.Format("Failed to grab information for the stage \"{0}\" because it does not exist in the repository.\n\n Could you mean one of these?\n\n{1}", stageName, possibleStrings);
                await message.Channel.SendMessageAsync(reply);

                return;
            }

            string response = String.Format(@"Failed to grab information for the stage ""{0}""  because it does not exist in the community repository", stageName);
            await message.Channel.SendMessageAsync(response);

            return;
        }

        Stage foundStage = repository.GetStage(stage.Name);

        string reponse = String.Format("Information for stage {0}\n\nAuthor: {1}\n\nUpload Date: {2}\n\nDescription: {3}", foundStage.Name, foundStage.Author, foundStage.Date, foundStage.Description);
        await message.Channel.SendMessageAsync(reponse);
    }
예제 #2
0
    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!");
    }
예제 #3
0
    public async static Task HandleRemoveCommand(SocketMessage message, CommunityRepository repository)
    {
        string originalMessage = message.Content;

        string[] splitMessage = originalMessage.Split(new char[] { ' ' }, 2);
        string   stageName    = splitMessage[1];

        Stage stage = new Stage()
        {
            Name   = stageName.ToLower(),
            Author = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower())
        };

        if (!repository.StageExists(stage))
        {
            string reply = String.Format(@"Failed to remove the stage ""{0}"" from the community repository because it does not exist", stageName);
            await message.Channel.SendMessageAsync(reply);

            return;
        }

        Stage repositoryStage = repository.GetStage(stage.Name);

        if (repositoryStage.Author.ToLower() != stage.Author.ToLower())
        {
            string reply = String.Format(@"Failed to remove the stage ""{0}"" from the community repository because you are not the author for that stage.", stageName);
            await message.Channel.SendMessageAsync(reply);

            return;
        }

        await message.Channel.SendMessageAsync("Removing your stage from the community repository now...");

        repository.RemoveStage(stage);
        string commitMessage = String.Format("Removed the stage {0} from the community repository", repositoryStage.Name);

        MainClass.UpdateGitHub(commitMessage);
        string response = String.Format(@"Successfully removed the stage ""{0}"" from the community repository!", stageName);
        await message.Channel.SendMessageAsync(response);
    }
예제 #4
0
    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!");
    }
예제 #5
0
    public async static Task HandleUploadCommand(SocketMessage message, CommunityRepository repository)
    {
        var attachments = message.Attachments;

        if (attachments.Count == 0)
        {
            await message.Channel.SendMessageAsync("You did not attach a zip file to your message. Please try again.");

            return;
        }

        if (attachments.Count > 1)
        {
            await message.Channel.SendMessageAsync("Please upload only one stage package at a time.");

            return;
        }

        Attachment attachment  = attachments.ElementAt(0);
        string     oldFileName = attachment.Filename;
        bool       changesMade = false;

        if (oldFileName.Contains("-") || oldFileName.Contains("_"))
        {
            changesMade = true;
        }

        string fileName = oldFileName.Replace("-", " ").Replace("_", " ");

        Stage stage = new Stage()
        {
            Name   = Path.GetFileNameWithoutExtension(fileName),
            Author = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower()),
            Date   = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString()
        };

        if (repository.StageExists(stage))
        {
            string response = String.Format("This stage already exists in the community repository. If you are the author of the existing stage, please use !update instead to update your stage.");
            await message.Channel.SendMessageAsync(response);

            return;
        }

        string URL = attachment.Url;

        using (WebClient client = new WebClient())
        {
            client.DownloadFile(new Uri(URL), fileName);
        }

        DamnedPackage package = new DamnedPackage();

        await message.Channel.SendMessageAsync("Checking your stage archive now...");

        if (!package.Check(fileName))
        {
            string reason = package.reasonForFailedCheck;
            await message.Channel.SendMessageAsync(reason);

            Directory.Delete(package.tempDirectory, true);
            Directory.Delete(fileName);
            return;
        }

        await message.Channel.SendMessageAsync("Stage check successful! I am adding your stage into the community repository now...");

        repository.AddStage(stage);
        string commitMessage = String.Format("Added in new stage {0} to the community repository", stage.Name);

        MainClass.UpdateGitHub(commitMessage);
        Directory.Delete(package.tempDirectory, true);

        if (changesMade)
        {
            string response = String.Format("Success! Your stage has been added into the community repository!\n\nBy the way, I have renamed your zip file from \"{0}\" to \"{1}.zip\" because it looks nicer and is slightly easier to search for", fileName, stage.Name);
            await message.Channel.SendMessageAsync(response);

            return;
        }

        await message.Channel.SendMessageAsync("Success! Your stage has been added into the community repository!");
    }