-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added chat command for rolling dice
- Loading branch information
Ro_bat
authored and
Ro_bat
committed
Sep 18, 2023
1 parent
849acae
commit 60450f1
Showing
6 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "chatcommand.h" | ||
|
||
const QString ChatCommand::sCommand = "command"; | ||
const QString ChatCommand::sArguments = "arguments"; | ||
const QRegularExpression ChatCommand::sParserString = | ||
QRegularExpression("^" | ||
"\\/(?<"+sCommand+">[a-zA-Z0-9_]+)([\\s\\t](?<"+sArguments+">.*))?" | ||
"$"); | ||
|
||
ChatCommand::ChatCommand() | ||
{ | ||
mType = ChatCommandType::INVALID; | ||
} | ||
|
||
ChatCommand::ChatCommand(ChatCommandType type, const QString& commandString, const QString& argumentString) { | ||
mType = type; | ||
mCommandString = commandString; | ||
mArgumentString = argumentString; | ||
} | ||
|
||
std::optional<ChatCommand> ChatCommand::parse(const QString& chatMessage) { | ||
const QRegularExpressionMatch match = sParserString.match(chatMessage); | ||
|
||
if(match.hasMatch()) { | ||
ChatCommandType type = ChatCommandType::INVALID; | ||
QString commandString = match.captured(sCommand); | ||
if(commandString == "roll" || commandString == "dice" || commandString == "diceroll" || commandString == "r") { | ||
type = ChatCommandType::DICEROLL; | ||
} | ||
return ChatCommand(type, commandString, match.captured(sArguments)); | ||
} else { | ||
return std::optional<ChatCommand>(); | ||
} | ||
} | ||
|
||
ChatCommandType ChatCommand::type() const { | ||
return mType; | ||
} | ||
|
||
const QString& ChatCommand::commandString() const { | ||
return mCommandString; | ||
} | ||
|
||
const QString& ChatCommand::argumentString() const { | ||
return mArgumentString; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef CHATCOMMAND_H | ||
#define CHATCOMMAND_H | ||
|
||
#include<QString> | ||
#include<optional> | ||
#include<QRegularExpression> | ||
|
||
enum class ChatCommandType { | ||
DICEROLL, | ||
INVALID | ||
}; | ||
|
||
class ChatCommand | ||
{ | ||
static const QString sCommand; | ||
static const QString sArguments; | ||
static const QRegularExpression sParserString; | ||
ChatCommandType mType; | ||
QString mCommandString; | ||
QString mArgumentString; | ||
public: | ||
ChatCommand(); | ||
ChatCommand(ChatCommandType type, const QString& commandString, const QString& argumentString); | ||
static std::optional<ChatCommand> parse(const QString& chatMessage); | ||
|
||
ChatCommandType type() const; | ||
const QString& commandString() const; | ||
const QString& argumentString() const; | ||
}; | ||
|
||
#endif // CHATCOMMAND_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
win32:VERSION = 0.5.4.0 # major.minor.patch.build | ||
else:VERSION = 0.5.4 # major.minor.patch | ||
win32:VERSION = 0.5.5.0 # major.minor.patch.build | ||
else:VERSION = 0.5.5 # major.minor.patch | ||
DEFINES += APP_VERSION="\\\"$$VERSION\\\"" | ||
DEFINES += PROTOCOL_VERSION="\\\"0.2.0\\\"" |