Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
YuzuDice
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
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
nanahira
YuzuDice
Commits
a26ca2e8
Commit
a26ca2e8
authored
May 02, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
readme
parent
415410b9
Pipeline
#3102
passed with stages
in 45 minutes and 38 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
17 deletions
+117
-17
README.md
README.md
+63
-15
src/app.controller.ts
src/app.controller.ts
+26
-1
src/http-server/http-server.service.ts
src/http-server/http-server.service.ts
+28
-1
No files found.
README.md
View file @
a26ca2e8
#YuzuDice
# YuzuDice
## Description
下一代的骰娘。
下一代的骰娘。
## 环境变量
*
`DB_HOST`
`DB_PORT`
`DB_USER`
`DB_PASS`
`DB_NAME`
数据库配置。
*
`CQ_ID`
QQ 号。
*
`CQ_SERVER`
OneBot 服务端地址。
*
`CQ_TOKEN`
OneBot 密钥。
*
`ADMIN_TOKEN`
http api 密钥,请求需要放在
`Authorization`
头。
*
`DICE_MAX_COUNT`
最大的骰子数量。 默认 1000。
*
`DICE_MAX_SIZE`
最大的骰子面数。 默认 1000。
## 推荐 docker-compose
```
yaml
version
:
'
2.4'
services
:
mysql
:
restart
:
always
image
:
mariadb:10
volumes
:
-
'
./db:/var/lib/mysql'
environment
:
MYSQL_ROOT_PASSWORD
:
db_rootpass
MYSQL_DATABASE
:
yuzudice
MYSQL_USER
:
yuzudice
MYSQL_PASSWORD
:
db_pass
cqhttp
:
restart
:
always
image
:
git-registry.mycard.moe/nanahira/docker-mirai-cqhttp:novnc
volumes
:
-
./cqhttp/data:/usr/src/app/data
-
./cqhttp/config:/usr/src/app/config
-
./cqhttp/bots:/usr/src/app/bots
environment
:
QQ_ID
:
11111111
QQ_PASS
:
qq_pass
WS_TOKEN
:
cq_token
yuzudice
:
restart
:
always
image
:
git-registry.mycard.moe/nanahira/yuzudice
ports
:
-
3000:3000
environment
:
DB_HOST
:
mysql
DB_PORT
:
3306
DB_USER
:
yuzudice
DB_PASS
:
db_pass
CQ_ID
:
11111111
CQ_SERVER
:
ws://cqhttp
CQ_TOKEN
:
cq_token
ADMIN_TOKEN
:
admin_token
DICE_MAX_COUNT
:
1000
DICE_MAX_SIZE
:
1000
```
之后使用命令
`curl -H 'Authorization: admin_token' http://<服务器IP>:3000/api/user -d 'id=<你的QQ号> -d 'permissions=0xffffffff'`
赋予自己管理员权限。
## Installation
## Installation
```
bash
```
bash
...
@@ -23,18 +83,6 @@ $ npm run start:dev
...
@@ -23,18 +83,6 @@ $ npm run start:dev
$
npm run start:prod
$
npm run start:prod
```
```
## Test
```
bash
# unit tests
$
npm run
test
# e2e tests
$
npm run
test
:e2e
# test coverage
$
npm run
test
:cov
```
## License
## License
AGPLv3
AGPLv3
src/app.controller.ts
View file @
a26ca2e8
import
{
Body
,
Controller
,
Get
,
Post
,
Query
,
Headers
}
from
'
@nestjs/common
'
;
import
{
Body
,
Controller
,
Get
,
Post
,
Query
,
Headers
}
from
'
@nestjs/common
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
HttpServerService
}
from
'
./http-server/http-server.service
'
;
import
{
HttpServerService
}
from
'
./http-server/http-server.service
'
;
import
{
UserPermissions
}
from
'
./constants
'
;
import
{
DefaultTemplate
}
from
'
./entities/DefaultTemplate
'
;
import
{
defaultTemplateMap
}
from
'
./DefaultTemplate
'
;
@
Controller
(
'
api
'
)
@
Controller
(
'
api
'
)
export
class
AppController
{
export
class
AppController
{
...
@@ -22,9 +25,31 @@ export class AppController {
...
@@ -22,9 +25,31 @@ export class AppController {
@
Body
(
'
id
'
)
id
,
@
Body
(
'
id
'
)
id
,
@
Body
(
'
name
'
)
name
,
@
Body
(
'
name
'
)
name
,
@
Body
(
'
permissions
'
)
permissions
,
@
Body
(
'
permissions
'
)
permissions
,
@
Body
(
'
addperm
'
)
addperm
,
@
Body
(
'
removeperm
'
)
removeperm
,
)
{
)
{
this
.
httpServerService
.
checkAccess
(
token
);
this
.
httpServerService
.
checkAccess
(
token
);
await
this
.
httpServerService
.
setUser
(
id
,
name
,
parseInt
(
permissions
));
await
this
.
httpServerService
.
setUser
(
id
,
name
,
parseInt
(
permissions
),
addperm
,
removeperm
,
);
return
{
success
:
true
};
return
{
success
:
true
};
}
}
@
Get
(
'
/values/perms
'
)
getAllPermissionValues
()
{
return
{
success
:
true
,
data
:
{
perms
:
Array
.
from
(
Object
.
keys
(
UserPermissions
))
},
};
}
@
Get
(
'
/values/templates
'
)
getAllTemplateKeys
()
{
return
{
success
:
true
,
data
:
{
perms
:
Array
.
from
(
defaultTemplateMap
.
keys
())
},
};
}
}
}
src/http-server/http-server.service.ts
View file @
a26ca2e8
...
@@ -10,6 +10,7 @@ import { AppLogger } from '../app.logger';
...
@@ -10,6 +10,7 @@ import { AppLogger } from '../app.logger';
import
{
BotService
}
from
'
../bot/bot.service
'
;
import
{
BotService
}
from
'
../bot/bot.service
'
;
import
{
User
}
from
'
../entities/User
'
;
import
{
User
}
from
'
../entities/User
'
;
import
{
HttpServerLogger
}
from
'
./http-server.logger
'
;
import
{
HttpServerLogger
}
from
'
./http-server.logger
'
;
import
{
UserPermissions
}
from
'
../constants
'
;
@
Injectable
()
@
Injectable
()
export
class
HttpServerService
{
export
class
HttpServerService
{
...
@@ -49,7 +50,13 @@ export class HttpServerService {
...
@@ -49,7 +50,13 @@ export class HttpServerService {
}
}
}
}
async
setUser
(
id
:
string
,
name
:
string
,
permissions
:
number
)
{
async
setUser
(
id
:
string
,
name
:
string
,
permissions
:
number
,
addperm
:
string
,
removeperm
:
string
,
)
{
try
{
try
{
const
user
=
await
this
.
botService
.
findOrCreateUser
(
id
);
const
user
=
await
this
.
botService
.
findOrCreateUser
(
id
);
if
(
name
)
{
if
(
name
)
{
...
@@ -64,6 +71,26 @@ export class HttpServerService {
...
@@ -64,6 +71,26 @@ export class HttpServerService {
}
}
user
.
permissions
=
permissions
;
user
.
permissions
=
permissions
;
}
}
if
(
addperm
)
{
const
value
:
number
=
UserPermissions
[
addperm
];
if
(
!
value
)
{
throw
new
BadRequestException
({
success
:
false
,
message
:
`Permission not found:
${
addperm
}
`
,
});
}
user
.
permissions
|=
value
;
}
if
(
removeperm
)
{
const
value
:
number
=
UserPermissions
[
removeperm
];
if
(
!
value
)
{
throw
new
BadRequestException
({
success
:
false
,
message
:
`Permission not found:
${
removeperm
}
`
,
});
}
user
.
permissions
&=
~
value
;
}
await
this
.
db
.
getRepository
(
User
).
save
(
user
);
await
this
.
db
.
getRepository
(
User
).
save
(
user
);
}
catch
(
e
)
{
}
catch
(
e
)
{
throw
new
NotFoundException
({
throw
new
NotFoundException
({
...
...
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