-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TelegramChat object (not all fields are present in the current ve…
…rsion)
- Loading branch information
Showing
3 changed files
with
117 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package exh3y.telebot.data; | ||
|
||
import org.json.JSONObject; | ||
|
||
import exh3y.telebot.data.enums.ETelegramChatType; | ||
|
||
public class TelegramChat extends JSONObject { | ||
|
||
private ETelegramChatType type; | ||
|
||
/** | ||
* Creates a new TelegramChat object from a given JSON-String | ||
* | ||
* @param chat | ||
* @since 0.0.6 | ||
*/ | ||
public TelegramChat(JSONObject chat) { | ||
|
||
super(chat.toString()); | ||
|
||
this.type = ETelegramChatType.getEnumByName(chat.getString("type")); | ||
} | ||
|
||
/** | ||
* Returns the chat's type | ||
* | ||
* @return The chat's type | ||
* @since 0.0.6 | ||
*/ | ||
public ETelegramChatType getType() { | ||
|
||
return type; | ||
} | ||
|
||
/** | ||
* Returns the chat's id | ||
* | ||
* @return The chat's id | ||
* @since 0.0.6 | ||
*/ | ||
public int getId() { | ||
|
||
return this.getInt("id"); | ||
} | ||
|
||
/** | ||
* Returns the chat's title | ||
* | ||
* @return The title | ||
* @since 0.0.6 | ||
*/ | ||
public String getTitle() { | ||
|
||
return this.getString("title"); | ||
} | ||
|
||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/exh3y/telebot/data/enums/ETelegramChatType.java
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,42 @@ | ||
package exh3y.telebot.data.enums; | ||
|
||
/** | ||
* Contains all possible chat types. | ||
* | ||
* @since 0.0.6 | ||
*/ | ||
public enum ETelegramChatType { | ||
|
||
PRIVATE("private"), | ||
GROUP("group"), | ||
SUPERGROUP("supergroup"), | ||
CHANNEL("channel"); | ||
|
||
private String chatTypeString; | ||
ETelegramChatType(String chatTypeString) { | ||
this.chatTypeString = chatTypeString; | ||
} | ||
|
||
public String getChatTypeString() { return chatTypeString; } | ||
|
||
/** | ||
* Returns the ETelegramChatType (determined by the content of the type field) | ||
* | ||
* @param name | ||
* @return The ETelegramChatType | ||
* @since 0.0.6 | ||
*/ | ||
public static ETelegramChatType getEnumByName(String name) { | ||
|
||
for (ETelegramChatType singleEnum : ETelegramChatType.values()) { | ||
|
||
if (singleEnum.getChatTypeString().equals(name)) { | ||
return singleEnum; | ||
} | ||
} | ||
|
||
return null; | ||
|
||
} | ||
|
||
} |