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
0fbf86e0
Commit
0fbf86e0
authored
May 02, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dismiss
parent
350642ec
Pipeline
#3106
passed with stages
in 3 minutes and 24 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
13 deletions
+101
-13
src/DefaultTemplate.ts
src/DefaultTemplate.ts
+3
-0
src/app.service.ts
src/app.service.ts
+15
-8
src/bot/bot.controller.ts
src/bot/bot.controller.ts
+81
-4
src/constants.ts
src/constants.ts
+1
-0
src/entities/User.ts
src/entities/User.ts
+1
-1
No files found.
src/DefaultTemplate.ts
View file @
0fbf86e0
...
@@ -42,3 +42,6 @@ defaultTemplateMap.set('permission_denied', PermissionDeniedText);
...
@@ -42,3 +42,6 @@ defaultTemplateMap.set('permission_denied', PermissionDeniedText);
export
const
BadParamsText
=
`参数不正确。`
;
export
const
BadParamsText
=
`参数不正确。`
;
defaultTemplateMap
.
set
(
'
bad_params
'
,
BadParamsText
);
defaultTemplateMap
.
set
(
'
bad_params
'
,
BadParamsText
);
export
const
AdminQuitGroup
=
`已退出群 {{groupId}}。`
;
defaultTemplateMap
.
set
(
'
admin_quit_group
'
,
AdminQuitGroup
);
src/app.service.ts
View file @
0fbf86e0
...
@@ -21,12 +21,15 @@ import Mustache from 'mustache';
...
@@ -21,12 +21,15 @@ import Mustache from 'mustache';
import
{
doc
}
from
'
prettier
'
;
import
{
doc
}
from
'
prettier
'
;
import
{
GroupUserProfile
}
from
'
./entities/GroupUserProfile
'
;
import
{
GroupUserProfile
}
from
'
./entities/GroupUserProfile
'
;
export
interface
Roll
Result
{
export
interface
Common
Result
{
name
:
string
;
name
:
string
;
reason
?:
string
;
reason
?:
string
;
result
?:
number
;
}
export
interface
RollResult
extends
CommonResult
{
count
:
number
;
count
:
number
;
size
:
number
;
size
:
number
;
result
?:
number
;
formula
?:
string
;
formula
?:
string
;
results
?:
number
[];
results
?:
number
[];
}
}
...
@@ -89,11 +92,15 @@ export class AppService {
...
@@ -89,11 +92,15 @@ export class AppService {
async
checkJoinGroup
(
userId
:
string
)
{
async
checkJoinGroup
(
userId
:
string
)
{
const
user
=
await
this
.
botService
.
findOrCreateUser
(
userId
);
const
user
=
await
this
.
botService
.
findOrCreateUser
(
userId
);
this
.
log
.
log
(
`Bot being invited by
${
user
.
name
}
${
userId
}
`
);
if
(
user
.
checkPermissions
(
UserPermissions
.
inviteBot
))
{
if
(
user
.
checkPermissions
(
UserPermissions
.
inviteBot
))
{
this
.
log
.
log
(
`Bot accepted.`
);
return
true
;
return
true
;
}
else
if
(
user
.
banReason
)
{
}
else
if
(
user
.
banReason
)
{
this
.
log
.
log
(
`Bot rejected because of banned user:
${
user
.
banReason
}
.`
);
return
false
;
return
false
;
}
}
this
.
log
.
log
(
`Bot ignored.`
);
return
undefined
;
return
undefined
;
}
}
...
@@ -227,11 +234,11 @@ export class AppService {
...
@@ -227,11 +234,11 @@ export class AppService {
const
notSetTemplateNames
=
Array
.
from
(
defaultTemplateMap
.
keys
()).
filter
(
const
notSetTemplateNames
=
Array
.
from
(
defaultTemplateMap
.
keys
()).
filter
(
(
tName
)
=>
!
group
.
templates
.
find
((
t
)
=>
t
.
key
===
tName
),
(
tName
)
=>
!
group
.
templates
.
find
((
t
)
=>
t
.
key
===
tName
),
);
);
return
`本群设置过的自定义模板有:\n
${
group
.
templates
return
`本群设置过的自定义模板有:\n
${
.
map
((
t
)
=>
t
.
display
())
group
.
templates
.
join
(
'
\n
'
)}
\n\n还没有设置的自定义模板有:\n
${
notSetTemplateNames
.
join
(
?
group
.
templates
.
map
((
t
)
=>
t
.
display
()).
join
(
'
\n
'
)
'
\n
'
,
:
'
无
'
)}
`
;
}
\n\n还没有设置的自定义模板有:\n
${
notSetTemplateNames
.
join
(
'
\n
'
)}
`
;
}
}
async
setGroupTemplate
(
async
setGroupTemplate
(
userData
:
KoishiSessionLike
,
userData
:
KoishiSessionLike
,
...
@@ -438,7 +445,7 @@ export class AppService {
...
@@ -438,7 +445,7 @@ export class AppService {
targetUsers
.
map
((
targetUser
)
=>
targetUsers
.
map
((
targetUser
)
=>
this
.
renderTemplate
(
this
.
renderTemplate
(
'
global_user_profile
'
,
'
global_user_profile
'
,
targetUser
.
toDscriptionObject
(),
targetUser
.
toD
e
scriptionObject
(),
userData
.
groupId
,
userData
.
groupId
,
),
),
),
),
...
...
src/bot/bot.controller.ts
View file @
0fbf86e0
import
{
Controller
}
from
'
@nestjs/common
'
;
import
{
Controller
}
from
'
@nestjs/common
'
;
import
{
AppService
,
RollResult
}
from
'
../app.service
'
;
import
{
AppService
,
RollResult
}
from
'
../app.service
'
;
import
{
BotService
}
from
'
./bot.service
'
;
import
{
BotService
}
from
'
./bot.service
'
;
import
{
App
,
Session
,
segment
}
from
'
koishi
'
;
import
{
App
,
Session
,
segment
,
AppConfig
}
from
'
koishi
'
;
import
*
as
koishiCommonPlugin
from
'
koishi-plugin-common
'
;
import
*
as
koishiCommonPlugin
from
'
koishi-plugin-common
'
;
import
*
as
adapter
from
'
koishi-adapter-onebot
'
;
import
*
as
adapter
from
'
koishi-adapter-onebot
'
;
import
{
defaultTemplateMap
}
from
'
../DefaultTemplate
'
;
import
{
defaultTemplateMap
}
from
'
../DefaultTemplate
'
;
import
{
UserPermissions
}
from
'
../constants
'
;
import
{
UserPermissions
}
from
'
../constants
'
;
import
{
User
}
from
'
../entities/User
'
;
import
{
User
}
from
'
../entities/User
'
;
import
{
CQBot
}
from
'
koishi-adapter-onebot
'
;
const
__
=
typeof
adapter
;
// just for import
const
__
=
typeof
adapter
;
// just for import
@
Controller
(
'
_bot
'
)
@
Controller
(
'
_bot
'
)
export
class
BotController
{
export
class
BotController
{
bot
:
App
;
bot
:
App
;
botConfig
:
AppConfig
;
constructor
(
constructor
(
private
readonly
appService
:
AppService
,
private
readonly
appService
:
AppService
,
private
readonly
botService
:
BotService
,
private
readonly
botService
:
BotService
,
...
@@ -19,13 +21,14 @@ export class BotController {
...
@@ -19,13 +21,14 @@ export class BotController {
this
.
initializeBot
();
this
.
initializeBot
();
}
}
async
initializeBot
()
{
async
initializeBot
()
{
this
.
bot
=
new
App
(
{
this
.
bot
Config
=
{
type
:
'
onebot:ws
'
,
type
:
'
onebot:ws
'
,
selfId
:
process
.
env
.
CQ_ID
,
selfId
:
process
.
env
.
CQ_ID
,
server
:
process
.
env
.
CQ_SERVER
,
server
:
process
.
env
.
CQ_SERVER
,
token
:
process
.
env
.
CQ_TOKEN
,
token
:
process
.
env
.
CQ_TOKEN
,
prefix
:
process
.
env
.
CQ_PREFIX
||
'
.
'
,
prefix
:
process
.
env
.
CQ_PREFIX
||
'
.
'
,
});
};
this
.
bot
=
new
App
(
this
.
botConfig
);
this
.
bot
.
plugin
(
koishiCommonPlugin
,
{
this
.
bot
.
plugin
(
koishiCommonPlugin
,
{
onFriendRequest
:
true
,
onFriendRequest
:
true
,
onGroupRequest
:
async
(
session
)
=>
{
onGroupRequest
:
async
(
session
)
=>
{
...
@@ -81,6 +84,29 @@ export class BotController {
...
@@ -81,6 +84,29 @@ export class BotController {
return
await
this
.
appService
.
rollDice
(
rollResult
,
session
);
return
await
this
.
appService
.
rollDice
(
rollResult
,
session
);
});
});
const
groupCommand
=
groupCtx
.
command
(
'
group
'
,
'
群内指令
'
);
const
groupCommand
=
groupCtx
.
command
(
'
group
'
,
'
群内指令
'
);
groupCommand
.
subcommand
(
'
.dismiss
'
,
'
退群
'
)
.
usage
(
'
群内数据会保留。
'
)
.
alias
(
'
dismiss
'
)
.
action
(
async
(
argv
)
=>
{
const
session
=
argv
.
session
;
if
(
!
(
await
this
.
checkGroupAdminOrPermission
(
session
,
UserPermissions
.
GroupDismiss
,
))
)
{
return
`
${
segment
(
'
at
'
,
{
id
:
session
.
userId
,
})}
${
await
this
.
appService
.
renderTemplate
(
'
permission_denied
'
,
{
action
:
'
退群
'
},
session
.
groupId
,
)}
`
;
}
await
this
.
groupDismiss
(
session
.
groupId
);
return
undefined
;
});
const
groupTemplateCommand
=
groupCommand
const
groupTemplateCommand
=
groupCommand
.
subcommand
(
'
.template
'
,
'
获取本群自定义模板
'
)
.
subcommand
(
'
.template
'
,
'
获取本群自定义模板
'
)
.
usage
(
.
usage
(
...
@@ -218,6 +244,7 @@ export class BotController {
...
@@ -218,6 +244,7 @@ export class BotController {
groupUserCommand
groupUserCommand
.
subcommand
(
'
.name <name:string>
'
,
'
修改群内用户昵称
'
)
.
subcommand
(
'
.name <name:string>
'
,
'
修改群内用户昵称
'
)
.
example
(
'
.group.user.name Nanahira
'
)
.
example
(
'
.group.user.name Nanahira
'
)
.
alias
(
'
nn
'
)
.
action
(
async
(
argv
,
name
)
=>
{
.
action
(
async
(
argv
,
name
)
=>
{
const
session
=
argv
.
session
;
const
session
=
argv
.
session
;
if
(
!
name
)
{
if
(
!
name
)
{
...
@@ -263,6 +290,41 @@ export class BotController {
...
@@ -263,6 +290,41 @@ export class BotController {
const
adminCommand
=
globalCtx
const
adminCommand
=
globalCtx
.
command
(
'
admin
'
,
'
管理接口
'
)
.
command
(
'
admin
'
,
'
管理接口
'
)
.
usage
(
'
这里的命令只有管理员可以用。
'
);
.
usage
(
'
这里的命令只有管理员可以用。
'
);
adminCommand
.
subcommand
(
'
.dismiss <groupId:string>
'
,
'
退指定群
'
)
.
usage
(
'
群内数据会保留。
'
)
.
action
(
async
(
argv
,
groupId
)
=>
{
const
session
=
argv
.
session
;
if
(
!
(
await
this
.
checkUserPermission
(
session
,
UserPermissions
.
GroupDismiss
,
))
)
{
return
`
${
segment
(
'
at
'
,
{
id
:
session
.
userId
,
})}
${
await
this
.
appService
.
renderTemplate
(
'
permission_denied
'
,
{
action
:
'
退群
'
},
session
.
groupId
,
)}
`
;
}
if
(
!
groupId
)
{
return
await
this
.
appService
.
renderTemplate
(
'
bad_params
'
,
{},
session
.
groupId
,
);
}
await
this
.
groupDismiss
(
groupId
);
return
await
this
.
appService
.
renderTemplate
(
'
admin_quit_group
'
,
{
groupId
,
},
session
.
groupId
,
);
});
const
adminTemplateCommand
=
adminCommand
const
adminTemplateCommand
=
adminCommand
.
subcommand
(
'
.template
'
,
'
获取默认模板
'
)
.
subcommand
(
'
.template
'
,
'
获取默认模板
'
)
.
usage
(
.
usage
(
...
@@ -420,10 +482,25 @@ export class BotController {
...
@@ -420,10 +482,25 @@ export class BotController {
|
'
honor
'
|
'
honor
'
>
,
>
,
)
{
)
{
const
{
role
}
=
await
session
.
bot
.
$getGroupMemberInfo
(
const
{
role
}
=
await
this
.
getBot
()
.
$getGroupMemberInfo
(
session
.
groupId
,
session
.
groupId
,
session
.
userId
,
session
.
userId
,
);
);
return
role
===
'
owner
'
||
role
===
'
admin
'
;
return
role
===
'
owner
'
||
role
===
'
admin
'
;
}
}
getBot
()
{
return
(
this
.
bot
.
bots
[
0
]
as
unknown
)
as
CQBot
;
}
async
groupDismiss
(
groupId
:
string
)
{
try
{
await
this
.
getBot
().
$setGroupLeave
(
groupId
,
false
);
return
null
;
}
catch
(
e
)
{
const
errorMessage
=
e
.
toString
();
this
.
botService
.
log
.
error
(
`Quit group
${
groupId
}
failed:
${
errorMessage
}
`
,
);
return
errorMessage
;
}
}
}
}
src/constants.ts
View file @
0fbf86e0
...
@@ -11,4 +11,5 @@ export const UserPermissions = {
...
@@ -11,4 +11,5 @@ export const UserPermissions = {
GroupTemplateWrite
:
0x800
,
GroupTemplateWrite
:
0x800
,
// others
// others
inviteBot
:
0x10000
,
inviteBot
:
0x10000
,
GroupDismiss
:
0x20000
,
};
};
src/entities/User.ts
View file @
0fbf86e0
...
@@ -18,7 +18,7 @@ export class User extends QQIDBase {
...
@@ -18,7 +18,7 @@ export class User extends QQIDBase {
return
!!
(
this
.
permissions
&
permissionNeeded
);
return
!!
(
this
.
permissions
&
permissionNeeded
);
}
}
toDscriptionObject
()
{
toD
e
scriptionObject
()
{
return
this
;
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