Skip to content

Commit

Permalink
v0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
SantaSpeen committed Aug 16, 2020
1 parent f241f52 commit acac512
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 89 deletions.
17 changes: 13 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<groupId>com.github.santaspeen</groupId>
<artifactId>vk-api</artifactId>
<version>0.8</version>
<version>0.8.1</version>
<packaging>jar</packaging>

<name>Devourer</name>
<description>Feeds on XML and produces objects</description>
<name>Vk API</name>
<description>Vk Api wrapper</description>
<url>https://github.com/SantaSpeen/VkApi.Java</url>

<licenses>
Expand Down Expand Up @@ -57,6 +57,16 @@
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
Expand All @@ -67,7 +77,6 @@
<version>20200518</version>
</dependency>


</dependencies>

</project>
7 changes: 3 additions & 4 deletions src/main/java/santaspeen/vk/api/Exceptions/VkApiError.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package santaspeen.vk.api.Exceptions;
package santaspeen.vk.api.exceptions;


public class VkApiError extends Exception{
public VkApiError(String error){
super(error);
}
public VkApiError(String error){super(error);}
public VkApiError(Exception error){super(error);}
}
16 changes: 16 additions & 0 deletions src/main/java/santaspeen/vk/api/features/VkAPIAccountTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package santaspeen.vk.api.features;

public enum VkAPIAccountTypes {
USER("user"),
GROUP("group");

private final String accountType;

VkAPIAccountTypes(String type) {
this.accountType = type;
}

public String getAccountType() {
return accountType;
}
}
19 changes: 19 additions & 0 deletions src/main/java/santaspeen/vk/api/features/onVkMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package santaspeen.vk.api.features;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface onVkMessage {

String text();
int[] onlyBy() default {};

boolean startsWith() default false;
boolean returnLongPoll() default false;

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package santaspeen.vk.api;
package santaspeen.vk.api.parsers;

import org.json.JSONArray;
import org.json.JSONObject;
import santaspeen.vk.api.features.VkAPIAccountTypes;

public class parseLongPoll{

Expand Down Expand Up @@ -53,18 +54,18 @@ private boolean getBool(Object to){
* @param accountType > Account type (Need for parseMessage)
* @param userId > This is secret :) (Need for parseMessage)
*/
public parseLongPoll(JSONObject event, String accountType, long userId){
public parseLongPoll(JSONObject event, VkAPIAccountTypes accountType, long userId){
this.userId = userId;

if (event.opt("failed") != null)
failed = Integer.parseInt(event.get("failed").toString());

updates = event.getJSONArray("updates");
updates = event.optJSONArray("updates");
if (failed == 0)
if (!updates.toString().equals("[]")){
int i = updates.length() - 1;

if (accountType.equals(vkApi.GROUP)) {
if (accountType.equals(VkAPIAccountTypes.GROUP)) {

ts = getLong(event.get("ts")); // Оно тут в стринге приходит, ОБОЖАЮ КОСТЫЛИ

Expand All @@ -76,7 +77,7 @@ public parseLongPoll(JSONObject event, String accountType, long userId){
groupObject = lastGroupUpdate.getJSONObject("object");
groupMessage = groupObject.getJSONObject("message");
}
} else if (accountType.equals(vkApi.USER)){
} else if (accountType.equals(VkAPIAccountTypes.USER)){
ts = event.getLong("ts");

pts = event.getLong("pts");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package santaspeen.vk.api;
package santaspeen.vk.api.parsers;

import org.json.JSONArray;
import org.json.JSONObject;
import santaspeen.vk.api.utils;

public class parseMessage{

Expand Down Expand Up @@ -34,14 +35,14 @@ public class parseMessage{
public parseMessage(JSONObject groupMessage, JSONArray userMessage, long userId){
if (groupMessage != null){
date = utils.getLong(groupMessage.get("date"));
important = utils.getBool(groupMessage.get("important"));
fromId = utils.getLong(groupMessage.get("from_id"));
groupAttachments = (JSONArray) groupMessage.get("attachments");
isHidden = utils.getBool(groupMessage.get("is_hidden"));
fwdMessages = (JSONArray) groupMessage.get("fwd_messages");
id = utils.getLong(groupMessage.get("id"));
important = groupMessage.getBoolean("important");
fromId = groupMessage.getLong("from_id");
groupAttachments = groupMessage.getJSONArray("attachments");
isHidden = groupMessage.getBoolean("is_hidden");
fwdMessages = groupMessage.getJSONArray("fwd_messages");
id = groupMessage.getLong("id");
text = (String) groupMessage.get("text");
randomId = utils.getLong(groupMessage.get("random_id"));
randomId = groupMessage.getLong("random_id");
out = utils.getLong(groupMessage.get("out"));
peerId = utils.getLong(groupMessage.get("peer_id"));
conversationMessageId = utils.getLong(groupMessage.get("conversation_message_id"));
Expand All @@ -50,16 +51,16 @@ public parseMessage(JSONObject groupMessage, JSONArray userMessage, long userId)

date = utils.getLong(userMessage.get(4));

if (((JSONObject) userMessage.get(6)).get("title") != null)
if (((JSONObject) userMessage.get(6)).opt("title") != null)
fromId = userId;
else
fromId = Long.parseLong((String) ((JSONObject) userMessage.get(6)).get("from"));
fromId = Long.parseLong((userMessage.getJSONObject(6)).getString("from"));

userAttachments = (JSONObject) userMessage.get(7);
id = utils.getLong(userMessage.get(1));
text = (String) userMessage.get(5);
randomId = utils.getLong(userMessage.get(8));
peerId = utils.getLong(userMessage.get(3));
userAttachments = userMessage.getJSONObject(7);
id = userMessage.getLong(1);
text = userMessage.getString(5);
randomId = userMessage.getLong(8);
peerId = userMessage.getLong(3);

}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/santaspeen/vk/api/utils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package santaspeen.vk.api;

class utils {
public class utils {

public static long getLong(Object to){
try {
Expand Down
Loading

0 comments on commit acac512

Please sign in to comment.