Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
happy-botday
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guillaume Vagner
happy-botday
Commits
49047238
Commit
49047238
authored
6 years ago
by
Guillaume Vagner
Browse files
Options
Downloads
Patches
Plain Diff
saving usernames
parent
de3cc1d7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mysql.js
+48
-10
48 additions, 10 deletions
mysql.js
requests.js
+10
-1
10 additions, 1 deletion
requests.js
with
58 additions
and
11 deletions
mysql.js
+
48
−
10
View file @
49047238
...
@@ -36,11 +36,15 @@ Promise.all([
...
@@ -36,11 +36,15 @@ Promise.all([
expiration TEXT,
expiration TEXT,
schedule TEXT
schedule TEXT
)`
),
)`
),
query
(
`CREATE TABLE IF NOT EXISTS groups(
query
(
`CREATE TABLE IF NOT EXISTS groups(
chatId BIGINT NOT NULL,
chatId BIGINT NOT NULL,
grp INT,
grp INT,
primary key (chatId, grp)
primary key (chatId, grp)
)`
),
query
(
`CREATE TABLE IF NOT EXISTS users(
userid INT PRIMARY KEY NOT NULL,
name TEXT,
username TEXT
)`
)
)`
)
]).
then
(
_
=>
{
]).
then
(
_
=>
{
...
@@ -127,5 +131,39 @@ function getSchedules() {
...
@@ -127,5 +131,39 @@ function getSchedules() {
`
)
`
)
}
}
function
addUser
(
data
)
{
return
query
(
`
SELECT *
FROM users
WHERE userid=
${
data
.
userid
}
`
).
then
(
rep
=>
{
if
(
rep
.
length
===
0
)
{
return
query
(
`
INSERT INTO users
VALUES(
${
data
.
userid
}
, "
${
data
.
name
}
", "
${
data
.
username
}
")
`
)
}
else
{
return
query
(
`
UPDATE users
SET username="
${
data
.
username
}
"
WHERE userid=
${
data
.
userid
}
`
)
}
})
}
module
.
exports
=
{
query
,
getChanByChatId
,
createChan
,
deleteChanByChatId
,
modifyChan
,
getChanByState
,
addGroup
,
removeGroup
,
removeAllGroups
,
getCompos
,
getSchedules
};
module
.
exports
=
{
\ No newline at end of file
query
,
getChanByChatId
,
createChan
,
deleteChanByChatId
,
modifyChan
,
getChanByState
,
addGroup
,
removeGroup
,
removeAllGroups
,
getCompos
,
getSchedules
,
addUser
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
requests.js
+
10
−
1
View file @
49047238
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
const
rp
=
require
(
'
request-promise
'
);
const
rp
=
require
(
'
request-promise
'
);
// Modules propres
// Modules propres
var
{
modifyChan
,
getChanByState
}
=
require
(
'
./mysql
'
);
var
{
modifyChan
,
getChanByState
,
addUser
}
=
require
(
'
./mysql
'
);
// Configurations
// Configurations
const
config
=
require
(
'
./config
'
);
const
config
=
require
(
'
./config
'
);
...
@@ -119,6 +119,15 @@ function getFirstToken(code, state) {
...
@@ -119,6 +119,15 @@ function getFirstToken(code, state) {
chan
.
refresh
=
rep
.
refresh_token
;
chan
.
refresh
=
rep
.
refresh_token
;
chan
.
expiration
=
rep
.
expires_at
;
chan
.
expiration
=
rep
.
expires_at
;
chan
.
state
=
''
;
chan
.
state
=
''
;
if
(
chan
.
chatId
>
0
)
{
getMe
(
chan
).
then
(
me
=>
{
addUser
({
userid
:
me
.
id
,
name
:
`
${
me
.
firstName
}
${
me
.
lastName
}
`
,
username
:
chan
.
username
})
})
}
return
modifyChan
(
chan
)
return
modifyChan
(
chan
)
})
})
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment