Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
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
MyCard
Mirai
Commits
aa427c20
Commit
aa427c20
authored
Jan 18, 2020
by
jiahua.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin supporting
parent
350fe5aa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
1 deletion
+58
-1
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
...sole/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
+13
-1
mirai-plugins/image-sender/build.gradle.kts
mirai-plugins/image-sender/build.gradle.kts
+3
-0
mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageProvider.kt
...rc/main/java/net/mamoe/mirai/imageplugin/ImageProvider.kt
+42
-0
No files found.
mirai-console/src/main/kotlin/net/mamoe/mirai/plugin/PluginBase.kt
View file @
aa427c20
package
net.mamoe.mirai.plugin
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.utils.DefaultLogger
import
net.mamoe.mirai.utils.io.encodeToString
import
java.io.File
...
...
@@ -25,6 +26,11 @@ abstract class PluginBase constructor() {
}
open
fun
onBotAdd
(
bot
:
Bot
)
{
}
private
lateinit
var
pluginDescription
:
PluginDescription
internal
fun
init
(
pluginDescription
:
PluginDescription
)
{
...
...
@@ -200,7 +206,7 @@ object PluginManager {
val
subClass
=
pluginClass
.
asSubclass
(
PluginBase
::
class
.
java
)
val
plugin
:
PluginBase
=
subClass
.
getDeclaredConstructor
().
newInstance
()
description
.
loaded
=
true
logger
.
info
(
"successfully loaded plugin "
+
description
.
name
)
logger
.
info
(
"successfully loaded plugin "
+
description
.
name
+
" version "
+
description
.
version
+
" by "
+
description
.
author
)
logger
.
info
(
description
.
info
)
nameToPluginBaseMap
[
description
.
name
]
=
plugin
...
...
@@ -220,6 +226,12 @@ object PluginManager {
pluginsFound
.
values
.
forEach
{
loadPlugin
(
it
)
}
nameToPluginBaseMap
.
values
.
forEach
{
it
.
onEnable
()
}
}
...
...
mirai-plugins/image-sender/build.gradle.kts
View file @
aa427c20
...
...
@@ -22,6 +22,7 @@ kotlin {
}
}
fun
kotlinx
(
id
:
String
,
version
:
String
)
=
"org.jetbrains.kotlinx:kotlinx-$id:$version"
fun
ktor
(
id
:
String
,
version
:
String
)
=
"io.ktor:ktor-$id:$version"
...
...
@@ -36,6 +37,8 @@ dependencies {
api
(
kotlinx
(
"io"
,
kotlinXIoVersion
))
api
(
kotlinx
(
"coroutines-io"
,
coroutinesIoVersion
))
api
(
kotlinx
(
"coroutines-core"
,
coroutinesVersion
))
implementation
(
"org.jsoup:jsoup:1.12.1"
)
implementation
(
group
=
"com.alibaba"
,
name
=
"fastjson"
,
version
=
"1.2.62"
)
}
tasks
.
withType
<
JavaCompile
>()
{
...
...
mirai-plugins/image-sender/src/main/java/net/mamoe/mirai/imageplugin/ImageProvider.kt
0 → 100644
View file @
aa427c20
import
com.alibaba.fastjson.JSON
import
kotlinx.coroutines.*
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.uploadAsImage
import
org.jsoup.Jsoup
class
ImageProvider
{
lateinit
var
contact
:
Contact
// `Deferred<Image?>` causes a runtime ClassCastException
val
image
:
Deferred
<
Image
>
by
lazy
{
GlobalScope
.
async
{
//delay((Math.random() * 5000L).toLong())
class
Result
{
var
id
:
String
=
""
}
withTimeoutOrNull
(
5
*
1000
)
{
withContext
(
Dispatchers
.
IO
)
{
val
result
=
JSON
.
parseObject
(
Jsoup
.
connect
(
"http://dev.itxtech.org:10322/v2/randomImg.uue"
).
ignoreContentType
(
true
).
timeout
(
10
_0000
).
get
().
body
().
text
(),
Result
::
class
.
java
)
Jsoup
.
connect
(
"http://dev.itxtech.org:10322/img.uue?size=large&id=${result.id}"
)
.
userAgent
(
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; ja-jp) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27"
)
.
timeout
(
10
_0000
)
.
ignoreContentType
(
true
)
.
maxBodySize
(
Int
.
MAX_VALUE
)
.
execute
()
.
bodyStream
()
}
}
?.
uploadAsImage
(
contact
)
?:
error
(
"Unable to download image"
)
}
}
}
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