Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
VeryVanilla
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
39
Issues
39
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
2
Merge Requests
2
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
RG Creators
VeryVanilla
Commits
43d5f59b
Commit
43d5f59b
authored
May 14, 2018
by
Tim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unescape characters on commands from discord
parent
1acb2ada
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletion
+30
-1
MQ2Discord/DiscordClient.cpp
MQ2Discord/DiscordClient.cpp
+30
-1
No files found.
MQ2Discord/DiscordClient.cpp
View file @
43d5f59b
...
...
@@ -27,6 +27,33 @@ std::string escape_json(const std::string &s) {
return
o
.
str
();
}
std
::
string
unescape_json
(
const
std
::
string
&
s
)
{
std
::
ostringstream
o
;
for
(
auto
c
=
s
.
cbegin
();
c
!=
s
.
cend
();
++
c
)
{
if
(
*
c
==
'\\'
)
{
++
c
;
switch
(
*
c
)
{
case
't'
:
{
o
<<
"
\t
"
;
break
;
}
case
'b'
:
{
o
<<
"
\b
"
;
break
;
}
case
'f'
:
{
o
<<
"
\f
"
;
break
;
}
case
'n'
:
{
o
<<
"
\n
"
;
break
;
}
case
'r'
:
{
o
<<
"
\r
"
;
break
;
}
case
'\\'
:
{
o
<<
"
\\
"
;
break
;
}
case
'/'
:
{
o
<<
"/"
;
break
;
}
case
'"'
:
{
o
<<
"
\"
"
;
break
;
}
default:
;
}
}
else
{
o
<<
*
c
;
}
}
return
o
.
str
();
}
// Real simple client, all it does is invoke a callback when a message is received
class
CallbackDiscordClient
:
public
SleepyDiscord
::
DiscordClient
{
public:
...
...
@@ -51,7 +78,9 @@ void DiscordThread(std::string token, std::string channelId, std::string control
{
CallbackDiscordClient
client
(
token
,
[
&
](
SleepyDiscord
::
Message
&
msg
)
{
if
(
msg
.
author
.
ID
==
controlUserId
&&
msg
.
channelID
==
channelId
)
fromDiscord
.
enqueue
(
msg
.
content
);
{
fromDiscord
.
enqueue
(
unescape_json
(
msg
.
content
));
}
});
fromDiscord
.
enqueue
(
connectMsg
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment