diff --git a/build.gradle b/build.gradle
index 140c3c5..fb0257b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,18 +1,15 @@
-buildscript {
- repositories {
- mavenCentral()
- }
- dependencies {
- classpath 'com.github.jengelman.gradle.plugins:shadow:5.0.0'
- }
-}
-
plugins {
id 'java'
+ id 'maven-publish'
+ id 'application'
+ id 'com.github.johnrengelman.shadow' version '7.1.0'
}
group 'cc.sukazyo'
-version '0.2.0'
+version '0.3.0'
+project.ext.archiveBaseName = 'Coeur_Morny_Cono'
+project.ext.artifactId = 'morny-coeur'
+mainClassName = 'cc.sukazyo.cono.morny.MornyCoeur'
repositories {
mavenCentral()
@@ -31,6 +28,10 @@ test {
useJUnitPlatform()
}
+java {
+ withSourcesJar()
+}
+
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
@@ -49,7 +50,38 @@ apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'
shadowJar {
- mainClassName = 'cc.sukazyo.cono.morny.MornyCoeur'
- archiveBaseName.set("Morny_Coeur")
- archiveVersion.set(version)
+ archiveBaseName.set("${project.ext.archiveBaseName}")
+ archiveVersion.set("${project.version}")
+ archiveClassifier.set("fat")
+}
+
+shadowJar {
+ archiveBaseName.set("${project.ext.archiveBaseName}")
+ archiveVersion.set("${project.version}")
+ archiveClassifier.set("fat")
+}
+
+publishing {
+ repositories{
+ maven {
+ name 'builds'
+ url = "file://" + new File("./build/publishing").getAbsolutePath()
+ }
+ maven {
+ name '-ws-'
+ url publishMvnRepoUrl
+ credentials {
+ username publishMvnRepoUsername
+ password publishMvnRepoPassword
+ }
+ }
+ }
+ publications {
+ main (MavenPublication) {
+ from components.java
+ groupId = project.group
+ artifactId = project.ext.artifactId
+ version = project.version
+ }
+ }
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 69a9715..e750102 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java
index 03ca922..e6fd6cd 100644
--- a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java
+++ b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java
@@ -52,7 +52,7 @@ public class MornyCoeur {
try {
String username = account.execute(new GetMe()).user().username();
if (!USERNAME.equals(username))
- throw new RuntimeException("Required the bot @"+USERNAME + " but @"+username + "logged in!");
+ throw new RuntimeException("Required the bot @"+USERNAME + " but @"+username + " logged in!");
logger.info("Succeed login to @" + username);
return account;
} catch (Exception e) {
diff --git a/src/main/java/cc/sukazyo/cono/morny/MornySystem.java b/src/main/java/cc/sukazyo/cono/morny/MornySystem.java
new file mode 100644
index 0000000..bedb6b3
--- /dev/null
+++ b/src/main/java/cc/sukazyo/cono/morny/MornySystem.java
@@ -0,0 +1,20 @@
+package cc.sukazyo.cono.morny;
+
+import cc.sukazyo.cono.morny.util.FileUtils;
+
+import java.net.URISyntaxException;
+
+public class MornySystem {
+
+ public static final String VERSION = "0.3.0";
+
+ public static String getJarMd5() {
+ try {
+ return FileUtils.getMD5Three(MornyCoeur.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
+ } catch (URISyntaxException e) {
+ e.printStackTrace(System.out);
+ return e.getMessage();
+ }
+ }
+
+}
diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java
index a6653d2..67af138 100644
--- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java
+++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java
@@ -1,9 +1,12 @@
package cc.sukazyo.cono.morny.bot.event;
import cc.sukazyo.cono.morny.MornyCoeur;
+import cc.sukazyo.cono.morny.MornySystem;
import cc.sukazyo.cono.morny.MornyTrusted;
import cc.sukazyo.cono.morny.bot.api.EventListener;
import com.pengrad.telegrambot.model.Update;
+import com.pengrad.telegrambot.model.request.ParseMode;
+import com.pengrad.telegrambot.request.SendMessage;
import com.pengrad.telegrambot.request.SendSticker;
import static cc.sukazyo.cono.morny.Logger.logger;
@@ -35,6 +38,10 @@ public class OnCommandExecute extends EventListener {
case "/exit@" + MornyCoeur.USERNAME:
onCommandExitExec(event);
break;
+ case "/version":
+ case "/version@" + MornyCoeur.USERNAME:
+ onCommandVersionExec(event);
+ break;
default:
return false;
}
@@ -76,4 +83,18 @@ public class OnCommandExecute extends EventListener {
}
}
+ private void onCommandVersionExec (Update event) {
+ MornyCoeur.getAccount().execute(new SendMessage(
+ event.message().chat().id(),
+ String.format(
+ "version:\n" +
+ "\t%s
\n" +
+ "core md5_hash:\n" +
+ "\t%s
",
+ MornySystem.VERSION,
+ MornySystem.getJarMd5()
+ )
+ ).parseMode(ParseMode.HTML));
+ }
+
}
diff --git a/src/main/java/cc/sukazyo/cono/morny/util/FileUtils.java b/src/main/java/cc/sukazyo/cono/morny/util/FileUtils.java
new file mode 100644
index 0000000..73b17eb
--- /dev/null
+++ b/src/main/java/cc/sukazyo/cono/morny/util/FileUtils.java
@@ -0,0 +1,33 @@
+package cc.sukazyo.cono.morny.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class FileUtils {
+
+ public static String getMD5Three (String path) {
+ BigInteger bi;
+ try {
+ byte[] buffer = new byte[8192];
+ int len;
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ File f = new File(path);
+ FileInputStream fis = new FileInputStream(f);
+ while ((len = fis.read(buffer)) != -1) {
+ md.update(buffer, 0, len);
+ }
+ fis.close();
+ byte[] b = md.digest();
+ bi = new BigInteger(1, b);
+ } catch (NoSuchAlgorithmException | IOException e) {
+ e.printStackTrace(System.out);
+ return e.getMessage();
+ }
+ return bi.toString(16);
+ }
+
+}