Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
polish some things + clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pizzabelly committed Jul 16, 2018
1 parent d0db1fd commit 3549c67
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 117 deletions.
115 changes: 115 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...

14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# EasyRP (Custom Discord Rich Presence)

EasyRP is a small program to use the DiscordRPC library without any knowledge of programming.
Instead just use an easy conifg file
EasyRP is a small program to use the discord-rpc, to make a custom rich presence/game on discord.
using just an easy config file.

**Usage**
- First you need to register a Rich Presence application with discord
- Go here https://discordapp.com/developers/applications/me
- Make a new application **The name of the app will be the main name for the rich presence**
- Enable rich presence for your app and add some assets
- Download the latest release of EasyRP from here https://github.com/Pizzabelly/EasyRP/releases
- Download the latest release of EasyRP from here https://github.com/Pizzabelly/EasyRP/releases
- Edit the config file with the information from your newly registered app
- Run [EasyRP.exe](https://github.com/Pizzabelly/EasyRP/releases) (it should open a cmd window)
- It should report errors from your config file (if there are any)
- Go into discord settings and add the [EasyRP.exe](https://github.com/Pizzabelly/EasyRP/releases) as a game
- Discord should automatically change the path of [EasyRP.exe](https://github.com/Pizzabelly/EasyRP/releases) to your Discord Rich Presence
- Run [easyrp application binary](https://github.com/Pizzabelly/EasyRP/releases) (it should open a cmd window)
- It *should* report errors from your config file (if there are any)
- Discord should show the game on your profile
- if not, add the exe as a game on discord and the file path should change to your presence

- You can edit the config any time while the program is running to change the presence
88 changes: 52 additions & 36 deletions config.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,81 @@
#include <sstream>
#include <iostream>
#include <fstream>
#include <algorithm>
#include "config.hpp"
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>

#define CONFIG_PATH "config.ini"

std::string setVar(std::string val, config_t* c)
{
c->changed = true;
return val;
std::string setVar(std::string val, config_t *c) {
c->changed = true;
return val;
}

// check and set the global presence config
void config_t::update()
{
// check and set the global presence config
void config_t::update() {
// open config file
std::ifstream config_file(CONFIG_PATH);

// "parse" config file
// this is super specific and is NOT proper ini parsing
// but it works, saves memory and avoids massive dependencies
for (std::string line; std::getline(config_file, line);)
{
for (std::string line; std::getline(config_file, line);) {
// if line is ini comment (;), whitespace, or '[', skip it
char first = line.front();
if (first == ';' || first == ' ' || first == '[') continue;
if (first == ';' || first == ' ' || first == '[')
continue;

std::istringstream line_stream;
line_stream.str(line);

std::string key;
if (std::getline(line_stream, key, '='))
{
key.erase(std::remove_if(key.begin(), key.end(), ::isspace), key.end());
if (std::getline(line_stream, key, '=')) {
key.erase(std::remove_if(key.begin(), key.end(), ::isspace),
key.end());
std::string value;
if (std::getline(line_stream, value))
{
if (isspace(value.front())) value.erase(0, 1);
if (key == "ClientID" && value.compare(this->clientId) != 0) this->clientId = setVar(value, this);
else if (key == "State" && value.compare(this->state) != 0) this->state = setVar(value, this);
else if (key == "Details" && value.compare(this->details) != 0) this->details = setVar(value, this);
else if (key == "LargeImage" && value.compare(this->largeImg.key) !=0) this->largeImg.key = setVar(value, this);
else if (key == "SmallImage" && value.compare(this->smallImg.key) != 0) this->smallImg.key = setVar(value, this);
else if (key == "LargeImageTooltip" && value.compare(this->largeImg.text) != 0) this->largeImg.text = setVar(value, this);
else if (key == "SmallImageTooltip" && value.compare(this->smallImg.text) != 0) this->smallImg.text = setVar(value, this);
else if (key == "StartTimestamp" && value.compare(std::to_string(this->startTime)) != 0) this->startTime = std::strtoll(setVar(value, this).c_str(), NULL, 10);
else if (key == "EndTimestamp" && value.compare(std::to_string(this->endTime)) != 0) this->endTime = std::strtoll(setVar(value, this).c_str(), NULL, 10);
if (std::getline(line_stream, value)) {
if (isspace(value.front()))
value.erase(0, 1);
if (key == "ClientID" && value.compare(this->client_id) != 0)
this->client_id = setVar(value, this);
else if (key == "State" && value.compare(this->state) != 0)
this->state = setVar(value, this);
else if (key == "Details" && value.compare(this->details) != 0)
this->details = setVar(value, this);
else if (key == "LargeImage" &&
value.compare(this->large_img.key) != 0)
this->large_img.key = setVar(value, this);
else if (key == "SmallImage" &&
value.compare(this->small_img.key) != 0)
this->small_img.key = setVar(value, this);
else if (key == "LargeImageTooltip" &&
value.compare(this->large_img.text) != 0)
this->large_img.text = setVar(value, this);
else if (key == "SmallImageTooltip" &&
value.compare(this->small_img.text) != 0)
this->small_img.text = setVar(value, this);
else if (key == "StartTimestamp" &&
value.compare(std::to_string(this->start_time)) != 0)
this->start_time =
std::strtoll(setVar(value, this).c_str(), NULL, 10);
else if (key == "EndTimestamp" &&
value.compare(std::to_string(this->end_time)) != 0)
this->end_time =
std::strtoll(setVar(value, this).c_str(), NULL, 10);
}
}
}
}

// print values for the current settings from the config file
void config_t::print()
{
printf("\nCurrent Presence (%s) :", this->clientId.c_str());
void config_t::print() {
printf("\nCurrent Presence (%s) :", this->client_id.c_str());
printf("\nState: %s", this->state.c_str());
printf("\nDetails: %s", this->details.c_str());
printf("\nLarge Image: '%s' with toolip, '%s'", this->largeImg.key.c_str(), this->largeImg.text.c_str());
printf("\nSmall Image: '%s' with toolip, '%s'", this->smallImg.key.c_str(), this->smallImg.text.c_str());
printf("\nStart Time: %lld", this->startTime);
printf("\nEnd Time: %lld\n", this->endTime);
printf("\nLarge Image: '%s' with toolip, '%s'", this->large_img.key.c_str(),
this->large_img.text.c_str());
printf("\nSmall Image: '%s' with toolip, '%s'", this->small_img.key.c_str(),
this->small_img.text.c_str());
printf("\nStart Time: %lld", this->start_time);
printf("\nEnd Time: %lld\n", this->end_time);
}
23 changes: 11 additions & 12 deletions config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@ struct pimage_t {
};

// struct type to hold info about the games configuration
struct config_t
{
// id for the discord developer app
std::string clientId;
struct config_t {
// id for the discord developer app
std::string client_id;

// text to show for now playing
std::string details;
std::string state;

// images to show for now playing
pimage_t smallImg;
pimage_t largeImg;
pimage_t small_img;
pimage_t large_img;

// timestamps for game; note: these usually have to be within about 24 hours :(
long long startTime = 0;
long long endTime = 0;
long long start_time = 0;
long long end_time = 0;

// true if presence needs to be updated
bool changed = true;
// true if presence needs to be updated
bool changed = true;

void update();
void print();
void update();
void print();
};

extern struct config_t config;
5 changes: 3 additions & 2 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
;# | |___| (_| \__ \ |_| | | \ \| | #
;# |______\__,_|___/\__, |_| \_\_| #
;# __/ | #
;# |___/ #
;# |___/ https://github.com/Pizzabelly/EasyRP # #
;# #
;# #
;# Optional Settings: SmallImage, LargeImageTooltip, SmallImageTooltip, #
;# StartTimestamp, EndTimestamp #
;# *ALL OTHERS ARE REQUIRED* #
;# #
;# https://github.com/Pizzabelly/EasyRP #
;# timestamps are in unix time -> https://www.epochconverter.com/ #
;# #
;########################################################################

[Identifiers]
Expand Down
Loading

0 comments on commit 3549c67

Please sign in to comment.