Now using coroutines in ThreadedModule.
This commit is contained in:
parent
f4c6bf48fa
commit
25a0850b71
5 changed files with 20 additions and 10 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -4,5 +4,5 @@
|
||||||
<pattern value="net.thauvin.erik.mobibot.modules.War" method="War" />
|
<pattern value="net.thauvin.erik.mobibot.modules.War" method="War" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="16" project-jdk-type="JavaSDK" />
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="15" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
|
@ -2,7 +2,7 @@ plugins {
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'com.github.ben-manes.versions' version '0.39.0'
|
id 'com.github.ben-manes.versions' version '0.39.0'
|
||||||
id 'idea'
|
id 'idea'
|
||||||
id 'io.gitlab.arturbosch.detekt' version '1.18.0'
|
id 'io.gitlab.arturbosch.detekt' version '1.18.1'
|
||||||
id 'jacoco'
|
id 'jacoco'
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'net.thauvin.erik.gradle.semver' version '1.0.4'
|
id 'net.thauvin.erik.gradle.semver' version '1.0.4'
|
||||||
|
@ -39,7 +39,7 @@ dependencies {
|
||||||
compileOnly 'pircbot:pircbot:1.5.0:sources'
|
compileOnly 'pircbot:pircbot:1.5.0:sources'
|
||||||
|
|
||||||
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
|
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
|
||||||
|
|
||||||
implementation "org.apache.logging.log4j:log4j-api:$versions.log4j"
|
implementation "org.apache.logging.log4j:log4j-api:$versions.log4j"
|
||||||
implementation "org.apache.logging.log4j:log4j-core:$versions.log4j"
|
implementation "org.apache.logging.log4j:log4j-core:$versions.log4j"
|
||||||
|
@ -97,6 +97,7 @@ kotlin {
|
||||||
}
|
}
|
||||||
|
|
||||||
kapt {
|
kapt {
|
||||||
|
includeCompileClasspath = false
|
||||||
arguments {
|
arguments {
|
||||||
arg('semver.project.dir', projectDir)
|
arg('semver.project.dir', projectDir)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot
|
package net.thauvin.erik.mobibot
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
@ -47,12 +48,14 @@ import java.util.Date
|
||||||
* Handles posts to pinboard.in.
|
* Handles posts to pinboard.in.
|
||||||
*/
|
*/
|
||||||
object PinboardUtils {
|
object PinboardUtils {
|
||||||
|
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a pin.
|
* Adds a pin.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun addPin(poster: PinboardPoster, ircServer: String, entry: EntryLink) = runBlocking {
|
fun addPin(poster: PinboardPoster, ircServer: String, entry: EntryLink) = runBlocking {
|
||||||
withContext(Dispatchers.Default) {
|
withContext(dispatcher) {
|
||||||
poster.addPin(
|
poster.addPin(
|
||||||
entry.link,
|
entry.link,
|
||||||
entry.title,
|
entry.title,
|
||||||
|
@ -68,7 +71,7 @@ object PinboardUtils {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun deletePin(poster: PinboardPoster, entry: EntryLink) = runBlocking {
|
fun deletePin(poster: PinboardPoster, entry: EntryLink) = runBlocking {
|
||||||
withContext(Dispatchers.Default) {
|
withContext(dispatcher) {
|
||||||
poster.deletePin(entry.link)
|
poster.deletePin(entry.link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +81,7 @@ object PinboardUtils {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun updatePin(poster: PinboardPoster, ircServer: String, oldUrl: String, entry: EntryLink) = runBlocking {
|
fun updatePin(poster: PinboardPoster, ircServer: String, oldUrl: String, entry: EntryLink) = runBlocking {
|
||||||
withContext(Dispatchers.Default) {
|
withContext(dispatcher) {
|
||||||
with(entry) {
|
with(entry) {
|
||||||
if (oldUrl != link) {
|
if (oldUrl != link) {
|
||||||
poster.deletePin(oldUrl)
|
poster.deletePin(oldUrl)
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
*/
|
*/
|
||||||
package net.thauvin.erik.mobibot.modules
|
package net.thauvin.erik.mobibot.modules
|
||||||
|
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import net.thauvin.erik.mobibot.Mobibot
|
import net.thauvin.erik.mobibot.Mobibot
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,7 +46,11 @@ abstract class ThreadedModule(bot: Mobibot) : AbstractModule(bot) {
|
||||||
isPrivate: Boolean
|
isPrivate: Boolean
|
||||||
) {
|
) {
|
||||||
if (isEnabled && args.isNotEmpty()) {
|
if (isEnabled && args.isNotEmpty()) {
|
||||||
Thread { run(sender, cmd, args, isPrivate) }.start()
|
runBlocking {
|
||||||
|
launch {
|
||||||
|
run(sender, cmd, args, isPrivate)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
helpResponse(sender, isPrivate)
|
helpResponse(sender, isPrivate)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#Generated by the Semver Plugin for Gradle
|
#Generated by the Semver Plugin for Gradle
|
||||||
#Tue Aug 24 11:34:08 PDT 2021
|
#Wed Sep 15 13:00:35 PDT 2021
|
||||||
version.buildmeta=1366
|
version.buildmeta=1390
|
||||||
version.major=0
|
version.major=0
|
||||||
version.minor=8
|
version.minor=8
|
||||||
version.patch=0
|
version.patch=0
|
||||||
version.prerelease=beta
|
version.prerelease=beta
|
||||||
version.project=mobibot
|
version.project=mobibot
|
||||||
version.semver=0.8.0-beta+1366
|
version.semver=0.8.0-beta+1390
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue