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
415410b9
Commit
415410b9
authored
May 02, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish
parent
d71c92e7
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
655 additions
and
106 deletions
+655
-106
src/DefaultTemplate.ts
src/DefaultTemplate.ts
+37
-6
src/app.service.ts
src/app.service.ts
+295
-44
src/bot/bot.controller.ts
src/bot/bot.controller.ts
+250
-43
src/bot/bot.service.ts
src/bot/bot.service.ts
+8
-2
src/config.ts
src/config.ts
+2
-1
src/constants.ts
src/constants.ts
+4
-2
src/entities/Group.ts
src/entities/Group.ts
+4
-0
src/entities/GroupTemplate.ts
src/entities/GroupTemplate.ts
+0
-3
src/entities/GroupUserProfile.ts
src/entities/GroupUserProfile.ts
+40
-0
src/entities/QQIDBase.ts
src/entities/QQIDBase.ts
+2
-2
src/entities/TextTemplate.ts
src/entities/TextTemplate.ts
+4
-2
src/entities/User.ts
src/entities/User.ts
+9
-1
No files found.
src/DefaultTemplate.ts
View file @
415410b9
export
const
defaultTemplateMap
=
new
Map
<
string
,
string
>
();
export
const
DefaultRollText
=
'
{{&name}} {{#reason}}因为 {{&reason}} 而{{/reason}}投掷了 {{count}} 个 {{size}} 面骰子,投掷出了 {{result}} 点。
\n
{{&formula}}={{result}}
'
;
'
{{&name}} {{#reason}}因为 {{&reason}} 而{{/reason}}投掷了 {{count}} 个 {{size}} 面骰子,投掷出了 {{result}} 点。{{#formula}}
\n
{{&formula}}{{/formula}}
'
;
defaultTemplateMap
.
set
(
'
roll
'
,
DefaultRollText
);
export
const
TooMuchCountText
=
'
{{&name}} {{#reason}}因为 {{&reason}} 而{{/reason}}投掷了 {{count}} 个 {{size}} 面骰子。
\n
骰子滚落了一地,找不到了。
'
;
defaultTemplateMap
.
set
(
'
too_much_count
'
,
TooMuchCountText
);
export
const
TooMuchSizeText
=
'
{{&name}} {{#reason}}因为 {{&reason}} 而{{/reason}}投掷了 {{count}} 个 {{size}} 面骰子。
\n
丢了个球。丢个球啊!
'
;
export
const
BadUserText
=
'
非法用户。
'
;
export
const
defaultTemplateMap
=
new
Map
<
string
,
string
>
();
defaultTemplateMap
.
set
(
'
roll
'
,
DefaultRollText
);
defaultTemplateMap
.
set
(
'
too_much_count
'
,
TooMuchCountText
);
defaultTemplateMap
.
set
(
'
too_much_size
'
,
TooMuchSizeText
);
export
const
BadUserText
=
'
您已被禁止使用该骰娘。{{#reason}}原因是: {{&reason}}{{/reason}}
'
;
defaultTemplateMap
.
set
(
'
bad_user
'
,
BadUserText
);
export
const
BadNameText
=
`你的名字 {{&name}} 不合法或者太长啦!`
;
defaultTemplateMap
.
set
(
'
bad_name
'
,
BadNameText
);
export
const
GroupNameChangedText
=
`成功修改您在本群的昵称为 {{&name}}。`
;
defaultTemplateMap
.
set
(
'
group_name_changed
'
,
GroupNameChangedText
);
export
const
GlobalNameChangedText
=
`成功修改您的昵称为 {{&name}}。`
;
defaultTemplateMap
.
set
(
'
global_name_changed
'
,
GlobalNameChangedText
);
const
banReasonText
=
'
{{#banReason}}
\n
被封禁: 是
\n
封禁原因: {{&banReason}}{{/banReason}}
'
;
export
const
GroupUserProfileText
=
`{{&displayUsername}}({{&user.id}}) 在群 {{&group.id}} 的资料:\n昵称: {{&displayUsername}}
${
banReasonText
}
`
;
defaultTemplateMap
.
set
(
'
group_user_profile
'
,
GroupUserProfileText
);
export
const
GlobalUserProfileText
=
`{{&name}}({{id}}) 的资料:\n昵称: {{&name}}
${
banReasonText
}
\n\n在过的群:{{#groupProfiles}}\n{{group.id}} -> {{&name}}{{/groupProfiles}}`
;
defaultTemplateMap
.
set
(
'
global_user_profile
'
,
GlobalUserProfileText
);
export
const
UserNotFoundText
=
`用户 {{&field}} 不存在。`
;
defaultTemplateMap
.
set
(
'
user_not_found
'
,
UserNotFoundText
);
export
const
PermissionDeniedText
=
`你没有权限进行 {{&action}} 。`
;
defaultTemplateMap
.
set
(
'
permission_denied
'
,
PermissionDeniedText
);
export
const
BadParamsText
=
`参数不正确。`
;
defaultTemplateMap
.
set
(
'
bad_params
'
,
BadParamsText
);
src/app.service.ts
View file @
415410b9
This diff is collapsed.
Click to expand it.
src/bot/bot.controller.ts
View file @
415410b9
This diff is collapsed.
Click to expand it.
src/bot/bot.service.ts
View file @
415410b9
...
...
@@ -17,7 +17,10 @@ export class BotService {
async
findOrCreateUser
(
id
:
string
,
name
?:
string
)
{
const
repo
=
this
.
db
.
getRepository
(
User
);
let
ent
=
await
repo
.
findOne
({
where
:
{
id
}
});
let
ent
=
await
repo
.
findOne
({
where
:
{
id
},
relations
:
[
'
groupProfiles
'
,
'
groupProfiles.group
'
],
});
if
(
ent
)
{
if
(
!
ent
.
name
&&
name
)
{
ent
.
name
=
name
;
...
...
@@ -39,7 +42,10 @@ export class BotService {
}
async
findOrCreateGroup
(
id
:
string
)
{
const
repo
=
this
.
db
.
getRepository
(
Group
);
let
ent
=
await
repo
.
findOne
({
where
:
{
id
},
relations
:
[
'
templates
'
]
});
let
ent
=
await
repo
.
findOne
({
where
:
{
id
},
relations
:
[
'
templates
'
,
'
userProfiles
'
,
'
userProfiles.user
'
],
});
if
(
ent
)
{
return
ent
;
}
...
...
src/config.ts
View file @
415410b9
...
...
@@ -3,6 +3,7 @@ import { User } from './entities/User';
import
{
Group
}
from
'
./entities/Group
'
;
import
{
DefaultTemplate
}
from
'
./entities/DefaultTemplate
'
;
import
{
GroupTemplate
}
from
'
./entities/GroupTemplate
'
;
import
{
GroupUserProfile
}
from
'
./entities/GroupUserProfile
'
;
export
function
dbConfig
()
{
return
{
...
...
@@ -17,7 +18,7 @@ export function typeormConfig(): TypeOrmModuleOptions {
return
{
name
:
'
app
'
,
type
:
'
mysql
'
,
entities
:
[
User
,
Group
,
DefaultTemplate
,
GroupTemplate
],
// entities here
entities
:
[
User
,
Group
,
DefaultTemplate
,
GroupTemplate
,
GroupUserProfile
],
// entities here
synchronize
:
true
,
...
dbConfig
(),
};
...
...
src/constants.ts
View file @
415410b9
export
const
UserPermissions
=
{
// read
UserRead
:
0x1
,
GroupRead
:
0x2
,
Group
User
Read
:
0x2
,
TemplateRead
:
0x4
,
GroupTemplateRead
:
0x8
,
// write
UserWrite
:
0x100
,
GroupWrite
:
0x200
,
Group
User
Write
:
0x200
,
TemplateWrite
:
0x400
,
GroupTemplateWrite
:
0x800
,
// others
inviteBot
:
0x10000
,
};
src/entities/Group.ts
View file @
415410b9
import
{
QQIDBase
}
from
'
./QQIDBase
'
;
import
{
Column
,
Entity
,
OneToMany
}
from
'
typeorm
'
;
import
{
GroupTemplate
}
from
'
./GroupTemplate
'
;
import
{
GroupUserProfile
}
from
'
./GroupUserProfile
'
;
@
Entity
()
export
class
Group
extends
QQIDBase
{
@
OneToMany
((
type
)
=>
GroupTemplate
,
(
template
)
=>
template
.
group
)
templates
:
GroupTemplate
[];
@
OneToMany
((
type
)
=>
GroupUserProfile
,
(
profile
)
=>
profile
.
group
)
userProfiles
:
GroupUserProfile
[];
renderText
(
key
:
string
,
data
:
any
)
{
const
template
=
this
.
templates
.
find
((
t
)
=>
key
===
t
.
key
);
if
(
this
.
templates
)
{
...
...
src/entities/GroupTemplate.ts
View file @
415410b9
...
...
@@ -20,7 +20,4 @@ export class GroupTemplate extends TextTemplate {
@
ManyToOne
((
type
)
=>
Group
,
(
group
)
=>
group
.
templates
)
group
:
Group
;
@
RelationId
((
template
:
GroupTemplate
)
=>
template
.
group
)
groupId
:
string
;
}
src/entities/GroupUserProfile.ts
0 → 100644
View file @
415410b9
import
{
TimeBase
}
from
'
./TimeBase
'
;
import
{
Column
,
Entity
,
Index
,
ManyToOne
,
PrimaryGeneratedColumn
,
}
from
'
typeorm
'
;
import
{
User
}
from
'
./User
'
;
import
{
Group
}
from
'
./Group
'
;
@
Entity
()
export
class
GroupUserProfile
extends
TimeBase
{
@
PrimaryGeneratedColumn
(
'
uuid
'
)
id
:
string
;
@
ManyToOne
((
type
)
=>
User
,
(
user
)
=>
user
.
groupProfiles
)
user
:
User
;
@
ManyToOne
((
type
)
=>
Group
,
(
group
)
=>
group
.
userProfiles
)
group
:
Group
;
@
Index
()
@
Column
(
'
varchar
'
,
{
nullable
:
true
,
length
:
32
})
name
:
string
;
@
Column
(
'
varchar
'
,
{
nullable
:
true
,
length
:
100
})
banReason
:
string
;
getDisplayUsername
(
fallback
?:
string
)
{
return
this
.
name
||
this
.
user
.
name
||
fallback
;
}
toDscriptionObject
()
{
return
{
displayUsername
:
this
.
getDisplayUsername
(),
...
this
,
};
}
}
src/entities/QQIDBase.ts
View file @
415410b9
...
...
@@ -5,6 +5,6 @@ export class QQIDBase extends TimeBase {
@
PrimaryColumn
(
'
varchar
'
,
{
length
:
12
})
id
:
string
;
@
Column
(
'
tinyint
'
,
{
default
:
0
})
isBanned
:
number
;
@
Column
(
'
varchar
'
,
{
nullable
:
true
,
length
:
10
0
})
banReason
:
string
;
}
src/entities/TextTemplate.ts
View file @
415410b9
...
...
@@ -9,11 +9,13 @@ export class TextTemplate extends TimeBase {
content
:
string
;
changeContent
(
content
:
string
)
{
this
.
content
=
Buffer
.
from
(
decode
(
content
),
'
utf-8
'
).
toString
(
'
base64
'
);
//this.content = Buffer.from(decode(content), 'utf-8').toString('base64');
this
.
content
=
decode
(
content
);
}
getContent
()
{
return
Buffer
.
from
(
this
.
content
,
'
base64
'
).
toString
(
'
utf-8
'
);
//return Buffer.from(this.content, 'base64').toString('utf-8');
return
this
.
content
;
}
render
(
data
:
any
)
{
...
...
src/entities/User.ts
View file @
415410b9
import
{
QQIDBase
}
from
'
./QQIDBase
'
;
import
{
Column
,
Entity
,
Index
}
from
'
typeorm
'
;
import
{
Column
,
Entity
,
Index
,
OneToMany
}
from
'
typeorm
'
;
import
{
GroupUserProfile
}
from
'
./GroupUserProfile
'
;
@
Entity
()
export
class
User
extends
QQIDBase
{
...
...
@@ -10,7 +11,14 @@ export class User extends QQIDBase {
@
Column
(
'
int
'
,
{
default
:
0
,
unsigned
:
true
})
// default with all read permissions
permissions
:
number
;
@
OneToMany
((
type
)
=>
GroupUserProfile
,
(
profile
)
=>
profile
.
user
)
groupProfiles
:
GroupUserProfile
[];
checkPermissions
(
permissionNeeded
:
number
)
{
return
!!
(
this
.
permissions
&
permissionNeeded
);
}
toDscriptionObject
()
{
return
this
;
}
}
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