summaryrefslogblamecommitdiffstats
path: root/src/main/java/org/openslx/taskmanager/tasks/IrcNotification.java
blob: ac0c6a12894560dccff512d723d1058b01e6fd79 (plain) (tree)
































































                                                                                           




                                             


         
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";
		}

		public String getMessages()
		{
			return this.messages;
		}
	}

}