Добавлена команда кек4
This commit is contained in:
parent
7b5154ece8
commit
e8b0acfcde
@ -46,6 +46,7 @@ public class MainThread implements Runnable {
|
|||||||
new When(),
|
new When(),
|
||||||
new Shakal(),
|
new Shakal(),
|
||||||
new ImageEffect(ImageEffect.Type.KEK),
|
new ImageEffect(ImageEffect.Type.KEK),
|
||||||
|
new ImageEffect(ImageEffect.Type.KEK4),
|
||||||
new ImageEffect(ImageEffect.Type.DECOLOR),
|
new ImageEffect(ImageEffect.Type.DECOLOR),
|
||||||
new ImageEffect(ImageEffect.Type.NEGATIVE),
|
new ImageEffect(ImageEffect.Type.NEGATIVE),
|
||||||
new ImageEffect(ImageEffect.Type.SOLARIZE),
|
new ImageEffect(ImageEffect.Type.SOLARIZE),
|
||||||
@ -78,7 +79,7 @@ public class MainThread implements Runnable {
|
|||||||
JSONArray jsonMessages = response.getJSONObject("messages").getJSONArray("items");
|
JSONArray jsonMessages = response.getJSONObject("messages").getJSONArray("items");
|
||||||
JSONArray jsonProfiles = response.getJSONArray("profiles");
|
JSONArray jsonProfiles = response.getJSONArray("profiles");
|
||||||
final int messagesLength = jsonMessages.length();
|
final int messagesLength = jsonMessages.length();
|
||||||
if (messagesLength == 0 && Util.random(80) == 5) {
|
if (false && messagesLength == 0 && Util.random(80) == 5) {
|
||||||
String message;
|
String message;
|
||||||
if (Util.random(6) == 2) {
|
if (Util.random(6) == 2) {
|
||||||
message = MESSAGES[Util.random(MESSAGES.length)];
|
message = MESSAGES[Util.random(MESSAGES.length)];
|
||||||
|
@ -2,14 +2,11 @@ package holdfast.samobot.commands;
|
|||||||
|
|
||||||
import holdfast.samobot.IOUtil;
|
import holdfast.samobot.IOUtil;
|
||||||
import holdfast.samobot.Util;
|
import holdfast.samobot.Util;
|
||||||
import holdfast.samobot.VK;
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.image.AffineTransformOp;
|
import java.awt.image.AffineTransformOp;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -19,6 +16,7 @@ public class ImageEffect extends PhotoAttachmentCommand {
|
|||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
KEK(new String[] { "кек" }),
|
KEK(new String[] { "кек" }),
|
||||||
|
KEK4(new String[] { "кек4" }),
|
||||||
DECOLOR(new String[] { "обесцвечивание", "ч/б", "чб", "decolor" }),
|
DECOLOR(new String[] { "обесцвечивание", "ч/б", "чб", "decolor" }),
|
||||||
NEGATIVE(new String[] { "негатив", "negative" }),
|
NEGATIVE(new String[] { "негатив", "negative" }),
|
||||||
SOLARIZE(new String[] { "передержка", "solarize" }),
|
SOLARIZE(new String[] { "передержка", "solarize" }),
|
||||||
@ -67,29 +65,36 @@ public class ImageEffect extends PhotoAttachmentCommand {
|
|||||||
result = processEffect(image, Mode.SOLARIZE);
|
result = processEffect(image, Mode.SOLARIZE);
|
||||||
break;
|
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:
|
case KEK:
|
||||||
default:
|
default:
|
||||||
result = processKek(image);
|
result = processKek(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
send(userName, upload(result));
|
||||||
ImageIO.write(result, "jpg", baos);
|
|
||||||
baos.flush();
|
|
||||||
final String photo = VK.uploadPhoto(baos.toByteArray(), "jpg");
|
|
||||||
baos.close();
|
|
||||||
|
|
||||||
send(userName, photo);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BufferedImage processKek(BufferedImage image) {
|
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 width = image.getWidth();
|
||||||
final int height = image.getHeight();
|
final int height = image.getHeight();
|
||||||
final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||||
final Graphics2D g2d = result.createGraphics();
|
final Graphics2D g2d = result.createGraphics();
|
||||||
g2d.drawImage(image, 0, 0, null);
|
g2d.drawImage(image, 0, 0, null);
|
||||||
|
|
||||||
switch (Util.random(4)) {
|
switch (mode) {
|
||||||
case 0: {
|
case 0: {
|
||||||
// copy top part to bottom
|
// copy top part to bottom
|
||||||
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
|
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package holdfast.samobot.commands;
|
package holdfast.samobot.commands;
|
||||||
|
|
||||||
|
import holdfast.samobot.VK;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
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 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user