-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add new telegram messager * release mutex * add send photo method * make bot private again * add image when detect rewards * swap all stop messages with stop photos * format pom file * simplify photos and add during stages
- Loading branch information
Showing
12 changed files
with
171 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package bh.bot.common; | ||
|
||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; | ||
import org.telegram.telegrambots.meta.api.methods.send.SendPhoto; | ||
import org.telegram.telegrambots.meta.api.objects.InputFile; | ||
import org.telegram.telegrambots.meta.api.objects.Update; | ||
import org.telegram.telegrambots.bots.TelegramLongPollingBot; | ||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; | ||
|
||
import static bh.bot.common.Log.*; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import javax.imageio.ImageIO; | ||
|
||
public class BitHeroesTelegramBot extends TelegramLongPollingBot { | ||
@Override | ||
public void onUpdateReceived(Update update) { | ||
} | ||
|
||
public void sendMessage(String msg) { | ||
SendMessage sendMsg = new SendMessage(); | ||
sendMsg.setChatId(Telegram.channelId); | ||
sendMsg.setText(msg); | ||
try { | ||
execute(sendMsg); | ||
} catch (TelegramApiException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
public void sendPhoto(BufferedImage img, String caption) { | ||
if (caption == null) { | ||
caption = ""; | ||
} | ||
SendPhoto sendPic = new SendPhoto(); | ||
sendPic.setChatId(Telegram.channelId); | ||
sendPic.setCaption(caption); | ||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||
try { | ||
ImageIO.write(img, "jpeg", os); // Passing: (RenderedImage im, String formatName, OutputStream output) | ||
InputStream is = new ByteArrayInputStream(os.toByteArray()); | ||
sendPic.setPhoto(new InputFile(is, caption)); | ||
try { | ||
execute(sendPic); | ||
} catch (TelegramApiException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getBotUsername() { | ||
// Return bot username | ||
// If bot username is @MyAmazingBot, it must return 'MyAmazingBot' | ||
return "Bit Heroes Bot"; | ||
} | ||
|
||
@Override | ||
public String getBotToken() { | ||
// Return bot token from BotFather | ||
return Telegram.token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters