Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
koishi-plugin-wyblacklist
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
3rdeye
koishi-plugin-wyblacklist
Commits
457f2fb4
Commit
457f2fb4
authored
Nov 25, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add auto manage guild
parent
ff5b8068
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
22 deletions
+103
-22
src/config.ts
src/config.ts
+6
-0
src/index.ts
src/index.ts
+97
-22
No files found.
src/config.ts
View file @
457f2fb4
...
@@ -10,6 +10,12 @@ export class WyWallBacklistPluginConfig {
...
@@ -10,6 +10,12 @@ export class WyWallBacklistPluginConfig {
default
:
'
https://blapi.wenaiwu.net
'
,
default
:
'
https://blapi.wenaiwu.net
'
,
})
})
endpoint
:
string
;
endpoint
:
string
;
@
SchemaProperty
({
description
:
'
自动管理群聊。
'
,
default
:
false
,
})
autoManage
:
boolean
;
}
}
export
type
WyWallBacklistPluginConfigLike
=
Partial
<
WyWallBacklistPluginConfig
>
;
export
type
WyWallBacklistPluginConfigLike
=
Partial
<
WyWallBacklistPluginConfig
>
;
src/index.ts
View file @
457f2fb4
...
@@ -5,17 +5,84 @@ import {
...
@@ -5,17 +5,84 @@ import {
CommandLocale
,
CommandLocale
,
CRenderer
,
CRenderer
,
DefinePlugin
,
DefinePlugin
,
If
,
Inject
,
Inject
,
InjectLogger
,
InjectLogger
,
Isolate
,
OnGuild
,
OnPlatform
,
PluginDef
,
Provide
,
PutArg
,
PutArg
,
PutCommonRenderer
,
PutCommonRenderer
,
StarterPlugin
,
StarterPlugin
,
UseCommand
,
UseCommand
,
UseEvent
,
UseMiddleware
,
UsePlugin
,
}
from
'
koishi-thirdeye
'
;
}
from
'
koishi-thirdeye
'
;
import
{
Logger
,
Quester
}
from
'
koishi
'
;
import
{
Logger
,
Next
,
Quester
,
Session
}
from
'
koishi
'
;
import
{
BlacklistReturn
}
from
'
./types
'
;
import
{
BlacklistReturn
}
from
'
./types
'
;
export
*
from
'
./config
'
;
export
*
from
'
./config
'
;
@
OnPlatform
(
'
onebot
'
)
@
OnGuild
()
@
DefinePlugin
()
class
ManageHandler
extends
StarterPlugin
()
{
@
Inject
()
private
wybl
:
WyWallBacklistPlugin
;
async
handleAccount
(
session
:
Session
,
skipAdminCheck
=
false
)
{
if
(
!
skipAdminCheck
)
{
const
selfInfo
=
await
session
.
bot
.
getGuildMember
(
session
.
guildId
,
session
.
selfId
,
);
if
(
!
selfInfo
||
(
!
selfInfo
.
roles
.
includes
(
'
admin
'
)
&&
!
selfInfo
.
roles
.
includes
(
'
owner
'
))
)
{
return
[];
}
}
return
await
this
.
wybl
.
checkAccount
(
session
.
userId
);
}
@
UseMiddleware
(
true
)
async
onGuildMessage
(
session
:
Session
,
next
:
Next
)
{
const
result
=
await
this
.
handleAccount
(
session
);
if
(
result
.
length
)
{
await
session
.
bot
.
deleteMessage
(
session
.
channelId
,
session
.
messageId
);
await
session
.
bot
.
kickGuildMember
(
session
.
guildId
,
session
.
userId
);
return
[
`用户
${
session
.
username
}
(
${
session
.
userId
}
) 位于蔷蔷黑名单,已被踢出群聊。`
,
''
,
...
result
,
].
join
(
'
\n
'
);
}
return
next
();
}
@
UseEvent
(
'
guild-member-request
'
)
async
onGuildMemberRequest
(
session
:
Session
)
{
const
result
=
await
this
.
handleAccount
(
session
,
true
);
if
(
result
.
length
)
{
await
session
.
bot
.
handleGuildMemberRequest
(
session
.
messageId
,
false
,
result
.
join
(
'
,
'
),
);
await
session
.
bot
.
sendMessage
(
session
.
guildId
,
[
`用户
${
session
.
userId
}
位于蔷蔷黑名单,已禁止入群。`
,
''
,
...
result
,
]);
}
}
}
@
Isolate
(
'
wybl
'
)
@
Provide
(
'
wybl
'
,
{
immediate
:
true
})
@
DefinePlugin
({
name
:
'
wyblacklist
'
})
@
DefinePlugin
({
name
:
'
wyblacklist
'
})
export
default
class
WyWallBacklistPlugin
extends
StarterPlugin
(
export
default
class
WyWallBacklistPlugin
extends
StarterPlugin
(
WyWallBacklistPluginConfig
,
WyWallBacklistPluginConfig
,
...
@@ -26,6 +93,32 @@ export default class WyWallBacklistPlugin extends StarterPlugin(
...
@@ -26,6 +93,32 @@ export default class WyWallBacklistPlugin extends StarterPlugin(
@
InjectLogger
()
@
InjectLogger
()
private
logger
:
Logger
;
private
logger
:
Logger
;
@
If
<
WyWallBacklistPlugin
>
((
p
)
=>
p
.
config
.
autoManage
)
@
UsePlugin
()
loadManage
()
{
this
.
logger
.
info
(
`Auto manage is enabled.`
);
return
PluginDef
(
ManageHandler
);
}
async
checkAccount
(
account
:
string
|
number
)
{
const
result
=
await
this
.
http
.
get
<
BlacklistReturn
>
(
`
${
this
.
config
.
endpoint
}
/api/blacklist`
,
{
responseType
:
'
json
'
,
params
:
{
recordsPerPage
:
100
,
account
,
},
},
);
return
result
.
data
.
map
(
(
item
)
=>
`
${
new
Date
(
item
.
blacklist
.
time
).
toLocaleString
()}
${
item
.
blacklist
.
content
}
`
,
);
}
@
UseCommand
(
'
wybl <account:posint>
'
)
@
UseCommand
(
'
wybl <account:posint>
'
)
@
CommandExample
(
'
wybl 123456789
'
)
@
CommandExample
(
'
wybl 123456789
'
)
@
CommandLocale
(
'
zh
'
,
{
@
CommandLocale
(
'
zh
'
,
{
...
@@ -52,29 +145,11 @@ export default class WyWallBacklistPlugin extends StarterPlugin(
...
@@ -52,29 +145,11 @@ export default class WyWallBacklistPlugin extends StarterPlugin(
}
}
try
{
try
{
const
result
=
await
this
.
http
.
get
<
BlacklistReturn
>
(
const
result
=
await
this
.
checkAccount
(
account
);
`
${
this
.
config
.
endpoint
}
/api/blacklist`
,
if
(
!
result
.
length
)
{
{
responseType
:
'
json
'
,
params
:
{
recordsPerPage
:
100
,
account
,
},
},
);
if
(
!
result
.
data
.
length
)
{
return
r
(
'
.safe
'
,
{
account
});
return
r
(
'
.safe
'
,
{
account
});
}
}
return
[
return
[
r
(
'
.unsafe
'
,
{
account
}),
''
,
...
result
].
join
(
'
\n
'
);
r
(
'
.unsafe
'
,
{
account
}),
''
,
...
result
.
data
.
map
(
(
item
)
=>
`
${
new
Date
(
item
.
blacklist
.
time
).
toLocaleString
()}
${
item
.
blacklist
.
content
}
`
,
),
].
join
(
'
\n
'
);
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
logger
.
error
(
`Failed to fetch blacklist of
${
account
}
:
${
e
}
`
);
this
.
logger
.
error
(
`Failed to fetch blacklist of
${
account
}
:
${
e
}
`
);
return
r
(
'
.fail
'
);
return
r
(
'
.fail
'
);
...
...
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