Добавлена команда кек4

This commit is contained in:
Victor 2016-04-29 16:53:36 +03:00
parent 7b5154ece8
commit e8b0acfcde
3 changed files with 65 additions and 46 deletions

View File

@ -46,6 +46,7 @@ public class MainThread implements Runnable {
new When(),
new Shakal(),
new ImageEffect(ImageEffect.Type.KEK),
new ImageEffect(ImageEffect.Type.KEK4),
new ImageEffect(ImageEffect.Type.DECOLOR),
new ImageEffect(ImageEffect.Type.NEGATIVE),
new ImageEffect(ImageEffect.Type.SOLARIZE),
@ -78,7 +79,7 @@ public class MainThread implements Runnable {
JSONArray jsonMessages = response.getJSONObject("messages").getJSONArray("items");
JSONArray jsonProfiles = response.getJSONArray("profiles");
final int messagesLength = jsonMessages.length();
if (messagesLength == 0 && Util.random(80) == 5) {
if (false && messagesLength == 0 && Util.random(80) == 5) {
String message;
if (Util.random(6) == 2) {
message = MESSAGES[Util.random(MESSAGES.length)];

View File

@ -2,14 +2,11 @@ package holdfast.samobot.commands;
import holdfast.samobot.IOUtil;
import holdfast.samobot.Util;
import holdfast.samobot.VK;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
*
@ -19,6 +16,7 @@ public class ImageEffect extends PhotoAttachmentCommand {
public enum Type {
KEK(new String[] { "кек" }),
KEK4(new String[] { "кек4" }),
DECOLOR(new String[] { "обесцвечивание", "ч/б", "чб", "decolor" }),
NEGATIVE(new String[] { "негатив", "negative" }),
SOLARIZE(new String[] { "передержка", "solarize" }),
@ -67,29 +65,36 @@ public class ImageEffect extends PhotoAttachmentCommand {
result = processEffect(image, Mode.SOLARIZE);
break;
case KEK4:
send(userName, String.format("%s,%s,%s,%s",
upload(processKek(image, 0)),
upload(processKek(image, 1)),
upload(processKek(image, 2)),
upload(processKek(image, 3))
));
return true;
case KEK:
default:
result = processKek(image);
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(result, "jpg", baos);
baos.flush();
final String photo = VK.uploadPhoto(baos.toByteArray(), "jpg");
baos.close();
send(userName, photo);
send(userName, upload(result));
return true;
}
private BufferedImage processKek(BufferedImage image) {
return processKek(image, Util.random(4));
}
private BufferedImage processKek(BufferedImage image, int mode) {
final int width = image.getWidth();
final int height = image.getHeight();
final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
final Graphics2D g2d = result.createGraphics();
g2d.drawImage(image, 0, 0, null);
switch (Util.random(4)) {
switch (mode) {
case 0: {
// copy top part to bottom
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);

View File

@ -1,6 +1,10 @@
package holdfast.samobot.commands;
import holdfast.samobot.VK;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.json.JSONArray;
import org.json.JSONObject;
@ -42,4 +46,13 @@ public abstract class PhotoAttachmentCommand extends Command {
}
protected abstract boolean execute(String message, String userName, String photoUrl) throws IOException;
protected String upload(BufferedImage image) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
baos.flush();
final String photo = VK.uploadPhoto(baos.toByteArray(), "jpg");
baos.close();
return photo;
}
}