MittweidaForFuture/src/main/java/Modules/Welcome.java
2021-03-18 10:18:13 +01:00

46 lines
1.7 KiB
Java

package Modules;
import CORE.Core;
import Utility.MessageConstants;
import org.telegram.telegrambots.meta.api.methods.ParseMode;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import static CORE.Core.SLOWMODETIMER;
public class Welcome implements Module {
private Core core;
public Welcome(Core core){
this.core = core;
}
@Override
public void execute(Update update) {
//TODO Welcome Hardcoded, may do it dynamical
//When new member joined Utility.chat, welcome him and dont go on further
if (update.hasMessage() && (update.getMessage().getChat().isGroupChat() || update.getMessage().getChat().isSuperGroupChat())
&& update.getMessage().getNewChatMembers().size() > 0
&& update.getMessage().getChatId() == (long) (-1001287901992L)) {
for (User i : update.getMessage().getNewChatMembers()) {
SendMessage message = new SendMessage()
.setParseMode(ParseMode.HTML)
.setChatId(update.getMessage().getChat().getId())
.setText(MessageConstants.WELCOME_MESSAGE
.replaceAll("\\$user", Core.getUserAsMention(i))
.replaceAll("\\$time", SLOWMODETIMER + "")
);
try {
core.execute(message);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
}
}