public void GetImplementationOrAbstractionFixture()
        {
            var list = ReflectiveEnumerator.GetInheritedFromAbstractClass <Functionality>();

            FileOperations.AppendLine("testing.log", JsonToFrom.Serialize(list));
            Assert.True(list.Count > 0);
        }
Esempio n. 2
0
        public void TotalLineFixture()
        {
            string filename = "newfile.txt";

            File.Delete(filename);
            FileOperations.AppendLine(filename, filename);
            FileOperations.AppendLine(filename, filename);
            FileOperations.AppendLine(filename, filename);
            Assert.Equal(3, FileOperations.GetTotalNoOfLinesInFile(filename));
            File.Delete(filename);
        }
Esempio n. 3
0
        public void ReadLineFixture()
        {
            string filename = "newfile.txt";

            File.Delete(filename);
            FileOperations.AppendLine(filename, "1");
            FileOperations.AppendLine(filename, "2");
            FileOperations.AppendLine(filename, "3");
            FileOperations.AppendLine(filename, "4");
            Assert.Equal("4", FileOperations.ReadLineNo(filename, 3));
            File.Delete(filename);
        }
        public async Task <string> ProcessAsync(DiscordMessage message)
        {
            if (_expletiveCommandText.Length + 2 > message.Content.Length)
            {
                return("Are you stupid?");
            }
            string nonCommand = message.Content.Substring(_expletiveCommandText.Length + 2);

            string[] words       = nonCommand.Split(' ');
            string[] subCommands = { "add", "confirm", "delete", "status" };
            if (IsMention(words[0]))
            {
                if (words.Length > 1)
                {
                    return("What are you doing?");
                }
                else
                {
                    if (_lastUseTime.Keys.Contains(message.Author.Id))
                    {
                        var diff    = DateTime.UtcNow - _lastUseTime[message.Author.Id];
                        int seconds = (int)Math.Ceiling(diff.TotalSeconds);
                        if (seconds < _timeLimitSecs)
                        {
                            return($"{message.Author.Mention} You can abuse again in {_timeLimitSecs - seconds} seconds.");
                        }
                    }
                    _lastUseTime[message.Author.Id] = DateTime.UtcNow;
                    return(GetRandomAbuse(message.MentionedUsers.First().Id));
                }
            }
            else
            {
                switch (words[0].ToLowerInvariant())
                {
                case "add":
                    await message.DeleteAsync();

                    if (UserAlreadyProcessing(message.Author.Id))
                    {
                        return("You cannot submit another expletive until your first one is processed.");
                    }
                    if (words.Where(x => x.IndexOf(":user:"******"There must be a `:user:` mentioned in the abuse.");
                    }
                    string encryptedExpletive = _crypter.Encrypt(string.Join(' ', words.Skip(1)));
                    string toStore            = $"{message.Author.Id}|{encryptedExpletive}";
                    FileOperations.AppendLine(ExpletiveConfig.UnconfiremedExpletivesFile, toStore);
                    return($"{message.Author.Mention}, your abuse has been submitted for processing.");

                case "status":
                    DiscordMember messageAuthor = IsMemberAuthorized(message.Author.Id, _members);
                    if (messageAuthor == null)
                    {
                        return("You are not authorized to use this command.");
                    }
                    using (StreamReader reader = new StreamReader(ExpletiveConfig.UnconfiremedExpletivesFile))
                    {
                        string line = null;
                        await messageAuthor.SendMessageAsync("Vote Status:");

                        while ((line = reader.ReadLine()) != null)
                        {
                            var    splitLine  = line.Split('|');
                            string actualLine = $"{GetNameFromId(splitLine[0], _members)} - {_crypter.Decrypt(splitLine[1])}";
                            await messageAuthor.SendMessageAsync(actualLine);
                        }
                    }
                    return("Status sent.");

                case "approve":
                    messageAuthor = IsMemberAuthorized(message.Author.Id, _members);
                    if (messageAuthor == null)
                    {
                        return("You are not authorized to use this command.");
                    }
                    if (words.Length != 2)
                    {
                        return("Usage: `approve @user`");
                    }
                    var    approvedUser = message.MentionedUsers.First();
                    int    lineNo       = -1;
                    string expletive    = null;
                    string submitter    = null;
                    using (StreamReader reader = new StreamReader(ExpletiveConfig.UnconfiremedExpletivesFile))
                    {
                        string line = null;
                        for (int i = 0; (line = reader.ReadLine()) != null; i++)
                        {
                            words = line.Split('|');
                            if (words[0].Equals(approvedUser.Id.ToString()))
                            {
                                lineNo    = i;
                                expletive = words[1];
                                submitter = words[0];
                                break;
                            }
                        }
                    }
                    if (lineNo < 0)
                    {
                        return("Submission not found for the user.");
                    }
                    FileOperations.AppendLine(ExpletiveConfig.StoredExpletivesFile, expletive);
                    FileOperations.DeleteLine(ExpletiveConfig.UnconfiremedExpletivesFile, lineNo);
                    return($"<@{submitter}>, your abuse has been approved.");

                case "reject":
                    messageAuthor = IsMemberAuthorized(message.Author.Id, _members);
                    if (messageAuthor == null)
                    {
                        return("You are not authorized to use this command.");
                    }
                    if (words.Length != 2)
                    {
                        return("Usage: `reject @user`");
                    }
                    approvedUser = message.MentionedUsers.First();
                    lineNo       = -1;
                    expletive    = null;
                    submitter    = null;
                    using (StreamReader reader = new StreamReader(ExpletiveConfig.UnconfiremedExpletivesFile))
                    {
                        string line = null;
                        for (int i = 0; (line = reader.ReadLine()) != null; i++)
                        {
                            words = line.Split('|');
                            if (words[0].Equals(approvedUser.Id.ToString()))
                            {
                                lineNo    = i;
                                expletive = line.Split('|')[1];
                                submitter = line.Split('|')[0];
                                break;
                            }
                        }
                    }
                    if (lineNo < 0)
                    {
                        return("Submission not found for the user.");
                    }
                    FileOperations.DeleteLine(ExpletiveConfig.UnconfiremedExpletivesFile, lineNo);
                    return($"<@{submitter}>, your abuse has been rejected.");
                }
            }
            return(string.Empty);
        }