Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
Rank Provide Bot
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
Rank Provide Bot
Commits
40df169a
Commit
40df169a
authored
Apr 23, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add admin modify
parent
a3eabca3
Pipeline
#12017
passed with stages
in 2 minutes and 55 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
17 deletions
+66
-17
src/app.module.ts
src/app.module.ts
+1
-0
src/command/command.service.ts
src/command/command.service.ts
+49
-13
src/entities/rank-record.entity.ts
src/entities/rank-record.entity.ts
+12
-1
src/record/record.service.ts
src/record/record.service.ts
+4
-3
No files found.
src/app.module.ts
View file @
40df169a
...
...
@@ -37,6 +37,7 @@ import { CommandService } from './command/command.service';
minSimilarity
:
0
,
help
:
false
,
prefix
:
'
.
'
,
actionErrorMessage
:
''
,
usePlugins
:
[
PluginDef
(
OneBot
,
{
bots
:
[
...
...
src/command/command.service.ts
View file @
40df169a
import
{
ConsoleLogger
,
Injectable
}
from
'
@nestjs/common
'
;
import
{
OnGuild
,
PutArg
,
PutSession
,
UseCommand
}
from
'
koishi-nestjs
'
;
import
{
Session
}
from
'
koishi
'
;
import
{
OnGuild
,
PutArg
,
PutOption
,
PutSession
,
UseCommand
,
}
from
'
koishi-nestjs
'
;
import
{
Bot
,
Session
}
from
'
koishi
'
;
import
{
RecordService
}
from
'
../record/record.service
'
;
import
{
OneBotBot
}
from
'
@koishijs/plugin-adapter-onebot
'
;
...
...
@@ -10,35 +16,65 @@ export class CommandService extends ConsoleLogger {
super
(
'
CommandService
'
);
}
private
async
getMember
(
session
:
Session
,
id
:
string
)
{
try
{
const
member
=
await
session
.
bot
.
getGuildMember
(
session
.
guildId
,
id
);
return
member
;
}
catch
(
e
)
{
this
.
warn
(
`Member
${
id
}
not found.`
);
}
return
;
}
@
OnGuild
(...(
process
.
env
.
TARGET_GUILDS
?.
split
(
'
,
'
)
||
[]))
@
UseCommand
(
'
rank [rank:string]
'
,
'
Ask for a rank
'
)
async
rankCommand
(@
PutSession
()
session
:
Session
,
@
PutArg
(
0
)
rank
:
string
)
{
async
rankCommand
(
@
PutSession
()
session
:
Session
,
@
PutArg
(
0
)
rank
:
string
,
@
PutOption
(
'
targetId
'
,
'
-t <targetId>
'
)
targetId
:
string
,
)
{
const
rankUserId
=
targetId
||
session
.
userId
;
const
actionDescription
=
`rank
${
rank
}
to
${
rankUserId
}
by
${
session
.
userId
}
`
;
if
(
targetId
)
{
const
self
=
await
this
.
getMember
(
session
,
session
.
userId
);
if
(
!
self
||
self
.
roles
[
0
]
===
'
member
'
)
{
this
.
warn
(
`Skipped giving
${
actionDescription
}
because of insufficient permissions.`
,
);
return
;
}
const
target
=
await
this
.
getMember
(
session
,
targetId
);
if
(
!
target
)
{
this
.
warn
(
`Skipped giving
${
actionDescription
}
because of target not found.`
,
);
return
;
}
}
rank
??
=
''
;
if
(
rank
.
length
>
6
)
{
this
.
warn
(
`Skipped giving
rank
${
rank
}
to
${
session
.
userId
}
because too long:
${
rank
.
length
}
`
,
`Skipped giving
${
actionDescription
}
because too long:
${
rank
.
length
}
`
,
);
return
;
}
if
(
!
(
await
this
.
record
.
isCanGiveRecord
(
session
)))
{
if
(
!
targetId
&&
!
(
await
this
.
record
.
isCanGiveRecord
(
session
)))
{
this
.
warn
(
`Skipped giving
rank
${
rank
}
to
${
session
.
userId
}
because already given within 2 hours.`
,
`Skipped giving
${
actionDescription
}
because already given within 2 hours.`
,
);
return
;
}
this
.
log
(
`Giving
${
rank
}
to
${
session
.
userId
}
in
${
session
.
guildId
}
`
);
this
.
log
(
`Giving
${
actionDescription
}
`
);
try
{
await
(
session
.
bot
as
OneBotBot
).
internal
.
setGroupSpecialTitle
(
session
.
guildId
,
session
.
u
serId
,
rankU
serId
,
rank
,
);
await
this
.
record
.
recordGiven
(
session
,
rank
);
this
.
log
(
`Given
${
rank
}
to
${
session
.
userId
}
in
${
session
.
guildId
}
`
);
await
this
.
record
.
recordGiven
(
session
,
rank
,
targetId
);
this
.
log
(
`Given
${
actionDescription
}
`
);
}
catch
(
e
)
{
this
.
error
(
`Error when giving rank
${
rank
}
to
${
session
.
userId
}
in
${
session
.
guildId
}
:
${
e
.
message
}
`
,
);
this
.
error
(
`Error when giving
${
actionDescription
}
:
${
e
.
message
}
`
);
}
}
}
src/entities/rank-record.entity.ts
View file @
40df169a
...
...
@@ -8,6 +8,10 @@ import { applyQueryProperty, applyQueryPropertySearch } from './utility/query';
@
Entity
()
export
class
RankRecord
extends
IdBase
{
@
Index
()
@
StringColumn
(
11
,
'
Operator ID
'
,
undefined
)
operatorId
:
string
;
@
Index
()
@
StringColumn
(
11
,
'
User ID
'
,
undefined
,
true
)
userId
:
string
;
...
...
@@ -27,7 +31,14 @@ export class RankRecord extends IdBase {
@
StringColumn
(
6
,
'
Rank content
'
,
undefined
,
true
)
rankName
:
string
;
fromSession
(
session
:
Session
)
{
fromSession
(
session
:
Session
,
targetId
?:
string
)
{
if
(
targetId
)
{
this
.
userId
=
targetId
;
this
.
operatorId
=
session
.
userId
;
}
else
{
this
.
userId
=
session
.
userId
;
this
.
operatorId
=
null
;
}
this
.
userId
=
session
.
userId
;
this
.
guildId
=
session
.
guildId
;
this
.
rankDate
=
new
Date
();
...
...
src/record/record.service.ts
View file @
40df169a
...
...
@@ -4,7 +4,7 @@ import { RankRecord } from '../entities/rank-record.entity';
import
{
InjectRepository
}
from
'
@nestjs/typeorm
'
;
import
{
Session
}
from
'
koishi
'
;
import
moment
from
'
moment
'
;
import
{
MoreThanOrEqual
}
from
'
typeorm
'
;
import
{
IsNull
,
MoreThanOrEqual
}
from
'
typeorm
'
;
@
Injectable
()
export
class
RecordService
extends
CrudBase
<
RankRecord
>
{
...
...
@@ -18,14 +18,15 @@ export class RecordService extends CrudBase<RankRecord> {
where
:
{
userId
:
session
.
userId
,
guildId
:
session
.
guildId
,
operatorId
:
IsNull
(),
rankDate
:
MoreThanOrEqual
(
moment
().
subtract
(
2
,
'
hours
'
).
toDate
()),
},
});
return
!
previous
;
}
async
recordGiven
(
session
:
Session
,
content
:
string
)
{
const
record
=
new
RankRecord
().
fromSession
(
session
);
async
recordGiven
(
session
:
Session
,
content
:
string
,
targetId
?:
string
)
{
const
record
=
new
RankRecord
().
fromSession
(
session
,
targetId
);
record
.
rankName
=
content
;
try
{
await
this
.
create
(
record
);
...
...
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