-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bceed72
Showing
25 changed files
with
3,576 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"javaSemanticDBVersion": "0.9.8", | ||
"semanticDBVersion": "4.8.14", | ||
"supportedScalaVersions": [ | ||
"2.13.12", | ||
"2.12.18", | ||
"2.12.17", | ||
"2.12.16", | ||
"2.12.15", | ||
"2.13.9", | ||
"2.13.10", | ||
"2.13.11", | ||
"2.11.12", | ||
"2.12.11", | ||
"2.12.12", | ||
"2.12.13", | ||
"2.12.14", | ||
"2.13.5", | ||
"2.13.6", | ||
"2.13.7", | ||
"2.13.8" | ||
] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created | ||
# For more information see: https://github.com/actions/setup-java#apache-maven-with-a-settings-path | ||
|
||
name: Maven Package | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.8 | ||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml | ||
settings-path: ${{ github.workspace }} # location for the settings.xml file | ||
|
||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml | ||
|
||
- name: Publish to GitHub Packages Apache Maven | ||
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# local setup | ||
audit | ||
target | ||
.idea | ||
.DS_Store | ||
|
||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#FileLock | ||
#Thu Mar 28 12:57:19 CET 2024 | ||
server=localhost\:35291 | ||
hostName=localhost | ||
method=file | ||
id=18e84ebf298e112138d84745b9c11f3c263021d6a6d |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# stereotypez-mattermost | ||
|
||
Akka-typed behaviors for the Mattermost API. | ||
|
||
## Example (using akka-typed) | ||
|
||
```scala | ||
import de.ship.mattermost.ws.BotActor | ||
import de.ship.mattermost.ws.Protocol._ | ||
import de.ship.mattermost.ws.events._ | ||
import akka.actor.typed.ActorSystem | ||
|
||
object SomeProject { | ||
val system = ActorSystem[Nothing]( | ||
Behaviors.setup { ctx => | ||
val logger = ctx.spawnAnonymous(Behaviors.setup { ctx => | ||
// ws ! RegisterHook(ctx.self) // or hook your self | ||
Behaviors.receiveMessage { msg => | ||
ctx.log.info(s"received $msg") | ||
|
||
} | ||
}) | ||
val ws = ctx.spawnAnonymous( | ||
BotActor.apply( | ||
websocketUrl = " ... ", | ||
botToken = " ... ", | ||
initialHooks = Seq(logger) | ||
) | ||
) | ||
|
||
Behaviors.ignore | ||
}, | ||
"some-system" | ||
) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>de.ship</groupId> | ||
<artifactId>ship-mattermost_${scala.version.major}</artifactId> | ||
<version>1.2-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<!-- scala --> | ||
<scala.version.major>2.13</scala.version.major> | ||
<scala.version>${scala.version.major}.12</scala.version> | ||
|
||
<!-- akka --> | ||
<akka.version>2.6.15</akka.version> | ||
<akka.http.version>10.2.6</akka.http.version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<!-- Unit Tests --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.0.0-M1</version> | ||
</plugin> | ||
<!-- Disable --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<executions> | ||
<execution> | ||
<id>default-compile</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<!-- Scala Build --> | ||
<plugin> | ||
<groupId>net.alchim31.maven</groupId> | ||
<artifactId>scala-maven-plugin</artifactId> | ||
<version>4.3.1</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
<goal>testCompile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<scalaVersion>${scala.version}</scalaVersion> | ||
<args> | ||
<arg>-Yrangepos</arg> | ||
<arg>-Xlint</arg> | ||
<arg>-deprecation</arg> | ||
<arg>-feature</arg> | ||
</args> | ||
</configuration> | ||
</plugin> | ||
|
||
</plugins> | ||
|
||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>3.0.0-M1</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
|
||
</build> | ||
|
||
<reporting> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.scala-tools</groupId> | ||
<artifactId>maven-scala-plugin</artifactId> | ||
<configuration> | ||
<scalaVersion>${scala.version}</scalaVersion> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</reporting> | ||
|
||
<repositories> | ||
<repository> | ||
<id>oss-snapshots</id> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url> | ||
</repository> | ||
<repository> | ||
<id>scala-tools.org</id> | ||
<name>Scala-Tools Maven2 Repository</name> | ||
<url>http://scala-tools.org/repo-releases</url> | ||
</repository> | ||
</repositories> | ||
|
||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>scala-tools.org</id> | ||
<name>Scala-Tools Maven2 Repository</name> | ||
<url>http://scala-tools.org/repo-releases</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>net.bis5.mattermost4j</groupId> | ||
<artifactId>mattermost4j-core</artifactId> | ||
<version>0.25.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.scala-lang</groupId> | ||
<artifactId>scala-library</artifactId> | ||
<version>${scala.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.typesafe.akka</groupId> | ||
<artifactId>akka-actor-typed_${scala.version.major}</artifactId> | ||
<version>${akka.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.typesafe.akka</groupId> | ||
<artifactId>akka-stream-typed_${scala.version.major}</artifactId> | ||
<version>${akka.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.typesafe.akka</groupId> | ||
<artifactId>akka-http_${scala.version.major}</artifactId> | ||
<version>${akka.http.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.typesafe.scala-logging</groupId> | ||
<artifactId>scala-logging_${scala.version.major}</artifactId> | ||
<version>3.9.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.spray</groupId> | ||
<artifactId>spray-json_${scala.version.major}</artifactId> | ||
<version>1.3.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.2.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.scalactic</groupId> | ||
<artifactId>scalactic_${scala.version.major}</artifactId> | ||
<version>3.2.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.scalatest</groupId> | ||
<artifactId>scalatest_${scala.version.major}</artifactId> | ||
<version>3.2.10</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
88 changes: 88 additions & 0 deletions
88
src/main/scala/de/ship/mattermost/client/MattermostExt.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package de.ship.mattermost.client | ||
|
||
import akka.http.scaladsl.model.StatusCodes | ||
import de.ship.mattermost.client.model.Attachments | ||
import net.bis5.mattermost.client4.{MattermostClient, Pager} | ||
import net.bis5.mattermost.model.{Post, PostList, PostPatch, PostType} | ||
|
||
import scala.collection.mutable | ||
import scala.jdk.CollectionConverters._ | ||
import scala.util.{Failure, Success, Try} | ||
|
||
object MattermostExt { | ||
|
||
implicit class MattermostClientExt(mmc: MattermostClient) { | ||
|
||
def getAllPosts(channelId: String): Seq[Post] = { | ||
val buffer = mutable.Buffer.empty[Post] | ||
|
||
var page = 0 | ||
var posts: PostList = null | ||
do { | ||
posts = mmc.getPostsForChannel(channelId, Pager.of(page, 100)).readEntity() | ||
posts.getPosts.asScala.foreach { | ||
case (id, post) => buffer.append(post) | ||
} | ||
page += 1 | ||
} while (posts.size() > 0) | ||
|
||
buffer.toSeq | ||
} | ||
|
||
def post(channelId: String, | ||
message: String, | ||
pinned: Boolean = false, | ||
postType: PostType = PostType.DEFAULT, | ||
props: Map[String, AnyRef] = Map.empty, | ||
attachments: Option[Attachments] = None, | ||
fileIds: Seq[String] = Seq.empty): Try[String] = { | ||
|
||
val post = new Post() | ||
post.setChannelId(channelId) | ||
post.setMessage(message) | ||
post.setPinned(pinned) | ||
post.setType(postType) | ||
|
||
(props, attachments) match { | ||
case (p, Some(a)) if p.nonEmpty => | ||
post.setProps((p ++ Map("attachments" -> a.forMM)).asJava) | ||
case (p, Some(a)) if p.isEmpty => | ||
post.setProps(Map("attachments" -> a.forMM).map(t => (t._1, t._2.asInstanceOf[AnyRef])).asJava) | ||
case (p, None) if p.nonEmpty => | ||
post.setProps(p.asJava) | ||
case _ => // do nothing | ||
} | ||
|
||
if (fileIds.nonEmpty) post.setFileIds(fileIds.asJava) | ||
mmc.createPost(post) match { | ||
case r if r.getRawResponse.getStatus != StatusCodes.Created.intValue => | ||
Failure(new RuntimeException("Error creating post: " + r.getRawResponse)) | ||
case r => | ||
Success(r.readEntity().getId) | ||
} | ||
} | ||
|
||
def patchPost(postId: String, | ||
message: Option[String] = None, | ||
pinned: Option[Boolean] = None, | ||
fileIds: Seq[String] = Seq.empty, | ||
props: Map[String, String] = Map.empty): Try[String] = { | ||
|
||
val patch = new PostPatch | ||
|
||
message.foreach(patch.setMessage) | ||
pinned.foreach(patch.setPinned) | ||
if (fileIds.nonEmpty) patch.setFileIds(fileIds.asJava) | ||
if (props.nonEmpty) patch.setProps(props.asJava) | ||
|
||
mmc.patchPost(postId, patch) match { | ||
case r if r.getRawResponse.getStatus != StatusCodes.OK.intValue => | ||
Failure(new RuntimeException(s"Error patching post '$postId': ${r.getRawResponse}")) | ||
case r => | ||
Success(r.readEntity().getId) | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.