Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHaber authored Apr 20, 2021
1 parent be05b37 commit a998028
Showing 1 changed file with 55 additions and 14 deletions.
69 changes: 55 additions & 14 deletions src/main/java/ru/Haber/VkAPI/bootstrap/BotClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ static void sendMessageTo(@NotNull String text, @NotNull Integer[] userIds) {
logger.info("[VKAPI] Message cannot be sent due to: " + e.toString());
}
}


static final String EMPTY_MESSAGE = "
";

IBotUtils get(@NotNull Message message);
Expand Down Expand Up @@ -736,6 +738,8 @@ static void sendMessageTo(@NotNull String text, @NotNull Integer[] userIds) {

boolean senderIsMember();

boolean userIsMember(@NotNull Integer id);

boolean objectIsGroup(@NotNull Integer id);

boolean messageFromGroup();
Expand Down Expand Up @@ -1517,7 +1521,12 @@ public KeyBoardBuilder addButtonX(@NotNull KeyboardButton button_y) {
payloads.put(this, Arrays.asList(Arrays.asList(button_y)));
return this;
}

public KeyBoardBuilder singleComplete() {

addButtonY(buttons_x);

return this;
}
public KeyBoardBuilder completeRow(@NotNull KeyboardButton... button_y) {
addButtonY(buttons_x);
addButtonY(Arrays.asList(button_y));
Expand Down Expand Up @@ -1738,21 +1747,33 @@ public final VkUserCache unsafeUserCache() {
static class VkCaptcha {
private static final BiMap<Integer, Integer> captchaCache = HashBiMap.create();

private Integer attempts;
public void setupAttempts() {

captchaCache.put(userId, attempts);

private Integer userId;
}

@NotNull private Integer attempts;

@NotNull private Integer userId;

public Integer attempts() {
return this.attempts;
}

public Integer decrementsAttempts(@NotNull Integer user) {
return captchaCache.forcePut(user, captchaCache.get(user)-1);
}

public Integer userId() {
return this.userId;
}

public VkCaptcha() {

}
public VkCaptchaGenerator generator() {
return new VkCaptchaGenerator(this.userId);
}


@Getter
@NoArgsConstructor
@EqualsAndHashCode
Expand Down Expand Up @@ -1782,9 +1803,9 @@ protected static final class VkCaptchaGenerator {

private VkCaptchaForm form;

@Setter
private String answer;
private static final Map<Integer, String> answer = Maps.newConcurrentMap();

private Integer capchaHolder;

public VkCaptchaGenerator size(@NotNull Integer x, @NotNull Integer y) {

Expand All @@ -1796,6 +1817,11 @@ public VkCaptchaGenerator size(@NotNull Integer x, @NotNull Integer y) {

}


public VkCaptchaGenerator(@NotNull Integer holder) {
this.capchaHolder = holder;
}

public VkCaptchaGenerator lenght(@NotNull Integer lenght) {
this.captcha_lenght = lenght;
return this;
Expand Down Expand Up @@ -1831,9 +1857,7 @@ public final <T> void safeVoidResponse(@NotNull Function<? super T[], Runnable>
if(value.test(objects) && Arrays.stream(objects).allMatch(Objects::nonNull)) {
then.apply(objects).run();
}else {

elseIf.run();

}
}
}
Expand All @@ -1843,9 +1867,11 @@ public File build(@NotNull String path, @NotNull String fileName) {
new BasicCaptcha(CAPTCHA_SIZE_X, CAPTCHA_SIZE_Y), null,
this.size_x, this.size_y);

safeVoidResponse(objects -> () -> captcha.text(objects[0]), () -> captcha.text(DEFAULT_LENGHT), objects -> objects[0] == 0, this.captcha_lenght);
safeVoidResponse(objects ->
() -> captcha.text(objects[0]), () -> captcha.text(DEFAULT_LENGHT), objects -> objects[0] == 0, this.captcha_lenght);

safeVoidResponse(objects -> () -> captcha.background(background), () -> captcha.background(DEFAULT_CAPTHA_BACKGROUND), null, this.background);
safeVoidResponse(objects ->
() -> captcha.background(background), () -> captcha.background(DEFAULT_CAPTHA_BACKGROUND), null, this.background);

safeVoidResponse(objects -> () -> {
if(objects[0] == VkCaptchaNoise.NOISE_STRAIGHT_LINE) {
Expand Down Expand Up @@ -1878,6 +1904,9 @@ public File build(@NotNull String path, @NotNull String fileName) {
}, () -> captcha.distortionShear(), null, this.form);

try {

answer.put(this.capchaHolder, captcha.getText());

captcha.save(path + fileName + ".png");

} catch (IOException e) {
Expand Down Expand Up @@ -1905,8 +1934,7 @@ public static enum VkCaptchaForm {
ELECTRIC2
}

}

}

}
@Data
Expand Down Expand Up @@ -2541,6 +2569,19 @@ public void sendMessageToAllDialogs(@NotNull Integer startMessageId, @NotNull In
}
}

@Override
public boolean userIsMember(@NotNull Integer id) {

try {
return client.groups().isMember(actor, String.valueOf(actor.getGroupId())).userId(id).execute() != BoolInt.NO;
} catch (ApiException | ClientException e) {
logger.info("(BotUtils) UserIsMember called exception from: " + e.toString());

e.printStackTrace();
}
return false;
}




Expand Down

0 comments on commit a998028

Please sign in to comment.