summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/taskmanager/tasks/IrcNotification.java
blob: 92f29f41e71a4ad6c09c6dbda5ac28704a0e7b2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.openslx.taskmanager.tasks;

import java.util.ArrayList;

import org.openslx.satserver.util.IrcClient;
import org.openslx.satserver.util.Util;
import org.openslx.taskmanager.api.AbstractTask;

import com.google.gson.annotations.Expose;

public class IrcNotification extends AbstractTask
{

	@Expose
	private String serverAddress;

	@Expose
	private String channel;

	@Expose
	private String message;

	@Expose
	private String nickName;

	private Output status = new Output();

	@Override
	protected boolean initTask()
	{
		this.setStatusObject( status );
		if ( Util.isEmpty( serverAddress ) ) {
			status.add( "serverAddress empty" );
			return false;
		}
		if ( Util.isEmpty( channel ) ) {
			status.add( "channel empty" );
			return false;
		}
		if ( Util.isEmpty( message ) ) {
			status.add( "message empty" );
			return false;
		}
		if ( Util.isEmpty( nickName ) ) {
			nickName = "bwlp-" + (int) ( Math.random() * 10000 );
		}
		return true;
	}

	@Override
	protected boolean execute()
	{
		ArrayList<String> errors = new ArrayList<>( 0 );
		IrcClient.sendMessage( serverAddress, channel, nickName, message, errors );
		return true;
	}

	public static class Output
	{
		private String messages;

		public void add( String message )
		{
			this.messages += message + "\n";
		}
	}

}