All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.niccolomattei.api.telegram.commands.Commands Maven / Gradle / Ivy

There is a newer version: 1.4_PRERELEASE-2
Show newest version
package me.niccolomattei.api.telegram.commands;

import java.util.ArrayList;
import java.util.List;

import me.niccolomattei.api.telegram.Bot;
import me.niccolomattei.api.telegram.Message;

public class Commands {

	private static List cmds = new ArrayList();

	public static void registerCommandListener(CommandListener commandListener) {
		cmds.add(commandListener);
	}

	public static List getCommands() {
		return cmds;
	}

	public static void trigger(Message latestMessage) {
		String splitted = latestMessage.getText().replaceFirst("/", "");
		String cmd = "";
		String[] args = new String[0];

		String[] splitted2 = splitted.split(" ");

		cmd = splitted2[0];
		String[] splitted3 = cmd.split("@");

		if (splitted3.length > 1) {
			if (Bot.currentBot.getMe().getUsername().toLowerCase().equalsIgnoreCase(splitted3[1].toLowerCase())) {
				if (splitted2.length >= 1) {
					args = new String[splitted2.length - 1];

					for (int z = 0; z < args.length; z++) {
						args[z] = splitted2[z + 1];
					}
				}

				for (int c = 0; c < Commands.getCommands().size(); c++) {
					Commands.getCommands().get(c).onCommand(splitted3[0], args, latestMessage.getFrom(),
							latestMessage.getChat().getId(), latestMessage.getChat().getType());
				}
			}
		} else {

			if (splitted2.length >= 1) {
				args = new String[splitted2.length - 1];

				for (int z = 0; z < args.length; z++) {
					args[z] = splitted2[z + 1];
				}
			}

			for (int c = 0; c < Commands.getCommands().size(); c++) {
				Commands.getCommands().get(c).onCommand(cmd, args, latestMessage.getFrom(),
						latestMessage.getChat().getId(), latestMessage.getChat().getType());
			}
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy