Skip to content

Commit 5bb3bd0

Browse files
authored
Merge pull request #32 from diaozxin007/master
update 0.1.3 support plugins
2 parents 00f2cea + 450d646 commit 5bb3bd0

File tree

11 files changed

+134
-83
lines changed

11 files changed

+134
-83
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ class Bot{
6262
}
6363
```
6464

65+
if use plugins
66+
```java
67+
class Bot{
68+
public static void main(String args[]){
69+
Wechaty bot = Wechaty.instance()
70+
.use(
71+
WechatyPlugins.ScanPlugin(),
72+
WechatyPlugins.DingDongPlugin(null))
73+
.start(true);
74+
}
75+
}
76+
```
77+
6578
## Development
6679

6780
To be writen:
@@ -265,6 +278,9 @@ mvn install wechaty
265278

266279
### master
267280

281+
### v0.1.3 (June 6 2020)
282+
1. support plugins!
283+
268284
### v0.1.2 (June 6 2020)
269285
1. change method `on(Event:String,Listener:listener)` to `onEvent(Listener:listener)`. See examples
270286
2. update version to 0.1.2

examples/pom.xml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<dependency>
2525
<groupId>io.github.wechaty</groupId>
2626
<artifactId>wechaty</artifactId>
27-
<version>0.1.2-SNAPSHOT</version>
27+
<version>0.1.3-SNAPSHOT</version>
2828
</dependency>
2929
<dependency>
3030
<groupId>org.apache.logging.log4j</groupId>
@@ -55,9 +55,50 @@
5555
<version>1.7.30</version>
5656
</dependency>
5757

58+
<dependency>
59+
<groupId>io.github.wechaty</groupId>
60+
<artifactId>java-wechaty-plugin-contrib</artifactId>
61+
<version>1.0.0-SNAPSHOT</version>
62+
</dependency>
63+
5864

5965
</dependencies>
6066

67+
<repositories>
68+
<repository>
69+
<id>oss-sonatype</id>
70+
<name>oss-sonatype</name>
71+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
72+
<snapshots>
73+
<enabled>true</enabled>
74+
</snapshots>
75+
</repository>
76+
<repository>
77+
<id>alimaven</id>
78+
<name>aliyun maven</name>
79+
<url>https://maven.aliyun.com/nexus/content/groups/public/</url>
80+
<releases>
81+
<enabled>true</enabled>
82+
</releases>
83+
<snapshots>
84+
<enabled>false</enabled>
85+
</snapshots>
86+
</repository>
87+
</repositories>
88+
89+
<pluginRepositories>
90+
<pluginRepository>
91+
<id>aliyun-plugin</id>
92+
<url>https://maven.aliyun.com/repository/public</url>
93+
<releases>
94+
<enabled>true</enabled>
95+
</releases>
96+
<snapshots>
97+
<enabled>false</enabled>
98+
</snapshots>
99+
</pluginRepository>
100+
</pluginRepositories>
101+
61102
<build>
62103
<plugins>
63104
<plugin>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.wechaty.example;
2+
3+
import io.github.wechaty.Wechaty;
4+
import io.github.wechaty.plugins.WechatyPlugins;
5+
6+
public class MainWithPlugin {
7+
8+
public static void main(String[] args) {
9+
10+
Wechaty bot = Wechaty.instance("your_token")
11+
.use(WechatyPlugins.ScanPlugin(), WechatyPlugins.DingDongPlugin(null))
12+
.start(true);
13+
14+
}
15+
16+
}

pom.xml

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>io.github.wechaty</groupId>
66
<artifactId>wechaty-parent</artifactId>
77
<packaging>pom</packaging>
8-
<version>0.1.2-SNAPSHOT</version>
8+
<version>0.1.3-SNAPSHOT</version>
99
<name>kotlin-wechaty</name>
1010

1111
<description>
@@ -71,30 +71,6 @@
7171
<version>2.8.1</version>
7272
</dependency>
7373

74-
75-
<dependency>
76-
<groupId>org.apache.logging.log4j</groupId>
77-
<artifactId>log4j-api</artifactId>
78-
<version>2.13.1</version>
79-
</dependency>
80-
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
81-
<dependency>
82-
<groupId>org.apache.logging.log4j</groupId>
83-
<artifactId>log4j-core</artifactId>
84-
<version>2.13.1</version>
85-
</dependency>
86-
<dependency> <!-- 桥接:告诉Slf4j使用Log4j2 -->
87-
<groupId>org.apache.logging.log4j</groupId>
88-
<artifactId>log4j-slf4j-impl</artifactId>
89-
<version>2.13.1</version>
90-
</dependency>
91-
<!-- https://mvnrepository.com/artifact/com.lmax/disruptor -->
92-
<dependency>
93-
<groupId>com.lmax</groupId>
94-
<artifactId>disruptor</artifactId>
95-
<version>3.4.2</version>
96-
</dependency>
97-
9874
<dependency>
9975
<groupId>org.slf4j</groupId>
10076
<artifactId>slf4j-api</artifactId>
@@ -180,26 +156,26 @@
180156

181157
<build>
182158
<plugins>
183-
<!-- <plugin>-->
184-
<!-- <groupId>org.apache.maven.plugins</groupId>-->
185-
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
186-
<!-- <version>1.6</version>-->
187-
<!-- <executions>-->
188-
<!-- <execution>-->
189-
<!-- <id>sign-artifacts</id>-->
190-
<!-- <phase>verify</phase>-->
191-
<!-- <goals>-->
192-
<!-- <goal>sign</goal>-->
193-
<!-- </goals>-->
194-
<!-- <configuration>-->
195-
<!-- <gpgArguments>-->
196-
<!-- <arg>&#45;&#45;pinentry-mode</arg>-->
197-
<!-- <arg>loopback</arg>-->
198-
<!-- </gpgArguments>-->
199-
<!-- </configuration>-->
200-
<!-- </execution>-->
201-
<!-- </executions>-->
202-
<!-- </plugin>-->
159+
<plugin>
160+
<groupId>org.apache.maven.plugins</groupId>
161+
<artifactId>maven-gpg-plugin</artifactId>
162+
<version>1.6</version>
163+
<executions>
164+
<execution>
165+
<id>sign-artifacts</id>
166+
<phase>verify</phase>
167+
<goals>
168+
<goal>sign</goal>
169+
</goals>
170+
<configuration>
171+
<gpgArguments>
172+
<arg>--pinentry-mode</arg>
173+
<arg>loopback</arg>
174+
</gpgArguments>
175+
</configuration>
176+
</execution>
177+
</executions>
178+
</plugin>
203179
</plugins>
204180
</build>
205181

wechaty-puppet-hostie/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.github.wechaty</groupId>
66
<artifactId>wechaty-parent</artifactId>
7-
<version>0.1.2-SNAPSHOT</version>
7+
<version>0.1.3-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>wechaty-puppet-hostie</artifactId>

wechaty-puppet-mock/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>wechaty-parent</artifactId>
77
<groupId>io.github.wechaty</groupId>
8-
<version>0.1.2-SNAPSHOT</version>
8+
<version>0.1.3-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -24,7 +24,6 @@
2424
<dependency>
2525
<groupId>org.mockito</groupId>
2626
<artifactId>mockito-core</artifactId>
27-
<version>3.3.3</version>
2827
</dependency>
2928
<dependency>
3029
<groupId>junit</groupId>

wechaty-puppet/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.github.wechaty</groupId>
66
<artifactId>wechaty-parent</artifactId>
7-
<version>0.1.2-SNAPSHOT</version>
7+
<version>0.1.3-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>wechaty-puppet</artifactId>

wechaty/pom.xml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.github.wechaty</groupId>
66
<artifactId>wechaty-parent</artifactId>
7-
<version>0.1.2-SNAPSHOT</version>
7+
<version>0.1.3-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>wechaty</artifactId>
@@ -59,24 +59,24 @@
5959
<artifactId>guava</artifactId>
6060
</dependency>
6161

62-
<dependency>
63-
<groupId>org.apache.logging.log4j</groupId>
64-
<artifactId>log4j-api</artifactId>
65-
</dependency>
66-
<dependency>
67-
<groupId>org.apache.logging.log4j</groupId>
68-
<artifactId>log4j-core</artifactId>
69-
</dependency>
70-
<dependency>
71-
<groupId>org.apache.logging.log4j</groupId>
72-
<artifactId>log4j-slf4j-impl</artifactId>
73-
</dependency>
62+
<!-- <dependency>-->
63+
<!-- <groupId>org.apache.logging.log4j</groupId>-->
64+
<!-- <artifactId>log4j-api</artifactId>-->
65+
<!-- </dependency>-->
66+
<!-- <dependency>-->
67+
<!-- <groupId>org.apache.logging.log4j</groupId>-->
68+
<!-- <artifactId>log4j-core</artifactId>-->
69+
<!-- </dependency>-->
70+
<!-- <dependency>-->
71+
<!-- <groupId>org.apache.logging.log4j</groupId>-->
72+
<!-- <artifactId>log4j-slf4j-impl</artifactId>-->
73+
<!-- </dependency>-->
7474

7575
<!-- https://mvnrepository.com/artifact/com.lmax/disruptor -->
76-
<dependency>
77-
<groupId>com.lmax</groupId>
78-
<artifactId>disruptor</artifactId>
79-
</dependency>
76+
<!-- <dependency>-->
77+
<!-- <groupId>com.lmax</groupId>-->
78+
<!-- <artifactId>disruptor</artifactId>-->
79+
<!-- </dependency>-->
8080

8181
<dependency>
8282
<groupId>org.slf4j</groupId>

wechaty/src/main/kotlin/io/github/wechaty/Wechaty.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.wechaty;
22

3-
//import io.github.io.github.user.Room
43

54
import io.github.wechaty.eventEmitter.Event
65
import io.github.wechaty.eventEmitter.EventEmitter
@@ -25,6 +24,7 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
2524

2625
private lateinit var puppet: Puppet
2726
private val puppetOptions: PuppetOptions = wechatyOptions.puppetOptions!!
27+
private val globalPluginList: MutableList<WechatyPlugin> = mutableListOf()
2828

2929
@Volatile
3030
private var readyState = StateEnum.OFF
@@ -40,9 +40,10 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
4040
val roomManager = RoomManager(this)
4141
val roomInvitationMessage = RoomInvitationManager(this)
4242

43-
// init {
43+
init {
4444
// this.memory = wechatyOptions.memory
45-
// }
45+
installGlobalPlugin()
46+
}
4647

4748

4849
fun start(await: Boolean = false):Wechaty {
@@ -99,6 +100,19 @@ class Wechaty private constructor(private var wechatyOptions: WechatyOptions) :
99100
return on(EventEnum.MESSAGE,listener)
100101
}
101102

103+
fun use(vararg plugins: WechatyPlugin):Wechaty{
104+
plugins.forEach {
105+
it(this)
106+
}
107+
return this
108+
}
109+
110+
private fun installGlobalPlugin(){
111+
for (item in globalPluginList) {
112+
item(this)
113+
}
114+
}
115+
102116
private fun on(event: Event,listener:LoginListener):Wechaty{
103117
super.on(event, object : Listener {
104118
override fun handler(vararg any: Any) {

wechaty/src/main/kotlin/io/github/wechaty/WechatyOptions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ class WechatyOptions {
1616
var ioToken:String? = null
1717

1818
}
19+
typealias WechatyPlugin = (Wechaty) -> Unit
20+

0 commit comments

Comments
 (0)