Skip to content

Commit

Permalink
Merge pull request #4 from 42tm/new_rem
Browse files Browse the repository at this point in the history
Bump to version 1.1.0
  • Loading branch information
dungwinux authored May 3, 2018
2 parents 1e9f81c + afe6752 commit 8d35bef
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions src/ctimmy.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
ctimmy - C++ port of Timmy Pascal unit
ctimmy - C++ port of timmy - Pascal unit for creating chat bots
Version 1.1.0
Copyright (C) 2018 42tm Team <fourtytwotm@gmail.com>
This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -53,32 +54,30 @@ class timmy;
class timmy
{
public:
bool enabled = false;
bool dupesCheck = true;
int tPercent = 0;
bool enabled;
bool dupesCheck;
int tPercent;
std::string noUdstdRep;

timmy();
int add(tStrArray mKeywords, tStrArray replies);
// int add(std::string keywordsStr, std::string repStr);
int add(std::string keywordsStr, std::string repStr, char kStrDeli, char mStrDeli);
int remove(tStrArray mKeywords);
int remove(int aIndex);
int remove(std::string keywordsStr, char kStrDeli);
std::string answer(std::string tMessage);

private:
int nOfEntries = 0;
std::vector<tStrArray> mKeywordsList;
std::vector<tStrArray> replyList;

// Deprecated
// void Update();
};

std::string strTrim(std::string s);
tStrArray strSplit(std::string s, char delimiter);
bool compareStrArrays(tStrArray arrayA, tStrArray arrayB);

// Implementation
/*
Given a string, process it so that the first and the last
character are not space, and there is no multiple spaces
Expand Down Expand Up @@ -142,16 +141,16 @@ bool compareStrArrays(tStrArray arrayA, tStrArray arrayB)
*/
timmy::timmy()
{
dupesCheck = true;
enabled = true;
noUdstdRep = "Sorry, I didn't get that";
dupesCheck = true;
tPercent = 70;
nOfEntries = 0;
enabled = true;
}

/*
add data to bot object's metadata base.
Add data to bot object's metadata base.
Data include message's keywords and possible replies to the message.
Return: 102 if object is not enabled
202 if dupesCheck = True and found a match to mKeywords in mKeywordsList
200 if the adding operation succeed
Expand All @@ -174,31 +173,26 @@ int timmy::add(tStrArray mKeywords, tStrArray replies)
}

/*
add data to bot but this one gets string inputs instead of tStrArray inputs.
Add data to bot but this one gets string inputs instead of tStrArray inputs.
This use strSplit() to split the string inputs (with a space character as the delimiter
for the message keywords string input and a semicolon character for the replies string input).
The main work is done by the primary implementation of timmy.add().
int add(std::string keywordsStr, std::string repStr);
{
return (add(strSplit(keywordsStr, ' '), strSplit(repStr, ';')));
}
Custom delimiters is accepted through default parameters.
Return: timmy.add(mKeywords, replies: tStrArray)
*/

int timmy::add(std::string keywordsStr, std::string repStr, char kStrDeli = ' ', char mStrDeli = ';')
{
return (add(strSplit(keywordsStr, kStrDeli), strSplit(repStr, mStrDeli)));
return (timmy::add(strSplit(keywordsStr, kStrDeli), strSplit(repStr, mStrDeli)));
}

/*
Given a set of keywords, find matches to that set in mKeywordsList,
remove the matches, and remove the correspondants in replyList as well.
This function simply saves offsets of the matching arrays in mKeywordsList
and then call timmy.removeByIndex().
and then call timmy.remove(int aIndex).
Return: 102 if object is not enabled
308 if the operation succeed
Expand All @@ -213,7 +207,7 @@ int timmy::remove(tStrArray mKeywords)
std::vector<int> indexes(mKeywordsList.size());

// Get offsets of keywords set that match the given mKeywords parameter
// and later deal with them using timmy.removeByIndex
// and later deal with them using timmy.remove(int aIndex)

for (auto iter = mKeywordsList.begin(); iter != mKeywordsList.end(); ++iter)
if (compareStrArrays(*iter, mKeywords))
Expand All @@ -227,7 +221,12 @@ int timmy::remove(tStrArray mKeywords)
}
return 308;
}

/*
Remove data from mKeywordsList at mKeywordsList[aIndex].
Return: 102 if object is not enabled
305 if the given index is invalid (out of bound)
300 if operation successful
*/
int timmy::remove(int aIndex)
{
if (!enabled)
Expand All @@ -243,7 +242,20 @@ int timmy::remove(int aIndex)
}

/*
answer the given message, using assets in the metadata
An implementation of `remove` that uses string as an argument
instead of a tStrArray. The string is delimited using the space character
to form a tStrArray, and then pass that tStrArray to the
common remove function. Default value of kStrDeli is ' '
Return timmy.remove(tStrArray mKeywords)
*/
int timmy::remove(std::string keywordsStr, char kStrDeli = ' ')
{
return (timmy::remove(strSplit(keywordsStr, kStrDeli)));
}

/*
Answer the given message, using assets in the metadata
*/
std::string timmy::answer(std::string tMessage)
{
Expand Down

0 comments on commit 8d35bef

Please sign in to comment.