-
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.
Merge pull request #12 from kopytovskiy/stage
* Updated Telegram Bot library to 7.10 * Added ability to restrict locations * Updated URL for Wallet for direct access * Additional minor fixes
- Loading branch information
Showing
14 changed files
with
135 additions
and
24 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
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/companerobot/helpers/RestrictionHelper.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,24 @@ | ||
package com.companerobot.helpers; | ||
|
||
import com.companerobot.misc.RestrictedAreasCollection; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class RestrictionHelper { | ||
|
||
private static final ArrayList<String> restrictedCountries = RestrictedAreasCollection.getRestrictedCountriesList(); | ||
private static final ArrayList<String> restrictedPhoneNumbersList = RestrictedAreasCollection.getRestrictedPhoneNumbersList(); | ||
|
||
|
||
public static boolean isRestrictedLocation(double latitude, double longitude) { | ||
return restrictedCountries.contains(AddressHelper.getAddressByCoordinates(latitude, longitude, 1) | ||
.getJSONObject("address").getString("country_code").toUpperCase()); | ||
} | ||
|
||
public static boolean isRestrictedPhoneNumber(String phoneNumber) { | ||
return restrictedPhoneNumbersList.stream() | ||
.anyMatch(phoneNumber::startsWith); | ||
} | ||
|
||
|
||
} |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/companerobot/misc/RestrictedAreasCollection.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,37 @@ | ||
package com.companerobot.misc; | ||
|
||
import com.mongodb.client.FindIterable; | ||
import com.mongodb.client.MongoCollection; | ||
import org.bson.Document; | ||
|
||
import java.util.ArrayList; | ||
|
||
import static com.companerobot.misc.MongoBaseClass.database; | ||
|
||
public class RestrictedAreasCollection { | ||
|
||
private static final MongoCollection<Document> restrictedAreasCollection = database.getCollection("restrictedAreas"); | ||
|
||
public static ArrayList<String> getRestrictedCountriesList() { | ||
ArrayList<String> restrictedAreas = new ArrayList<>(); | ||
FindIterable<Document> restictedAreasDocumentsCollection = restrictedAreasCollection.find(); | ||
|
||
for (Document document : restictedAreasDocumentsCollection) { | ||
restrictedAreas.add(document.get("countryCode").toString()); | ||
} | ||
|
||
return restrictedAreas; | ||
} | ||
|
||
public static ArrayList<String> getRestrictedPhoneNumbersList() { | ||
ArrayList<String> restrictedPhoneCodes = new ArrayList<>(); | ||
FindIterable<Document> restictedAreasDocumentsCollection = restrictedAreasCollection.find(); | ||
|
||
for (Document document : restictedAreasDocumentsCollection) { | ||
restrictedPhoneCodes.add(document.get("phoneCode").toString()); | ||
} | ||
|
||
return restrictedPhoneCodes; | ||
} | ||
|
||
} |
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
33 changes: 27 additions & 6 deletions
33
src/main/java/com/companerobot/parsers/LocationParser.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 |
---|---|---|
@@ -1,21 +1,42 @@ | ||
package com.companerobot.parsers; | ||
|
||
import com.companerobot.enums.CountryCode; | ||
import com.companerobot.enums.UserRole; | ||
import com.companerobot.helpers.LocalizationHelper; | ||
import com.companerobot.helpers.RestrictionHelper; | ||
import com.companerobot.misc.UserCollection; | ||
import org.telegram.telegrambots.meta.api.objects.message.Message; | ||
|
||
import static com.companerobot.enums.UserRole.DRIVER; | ||
import static com.companerobot.enums.UserRole.PASSENGER; | ||
import static com.companerobot.constants.TextMessages.RESTRICTED_LOCATION_MESSAGE; | ||
import static com.companerobot.parsers.location_parsers.DriverLocationParser.parseDriverLocation; | ||
import static com.companerobot.parsers.location_parsers.PassengerLocationParser.parsePassengerLocation; | ||
import static com.companerobot.helpers.MessageExecutionHelper.sendMessageToUser; | ||
|
||
public class LocationParser { | ||
|
||
public static void parseLocation(Message message) { | ||
if (UserCollection.getUserRole(message.getFrom().getId()) == PASSENGER) { | ||
parsePassengerLocation(message); | ||
|
||
} else if (UserCollection.getUserRole(message.getFrom().getId()) == DRIVER) { | ||
parseDriverLocation(message); | ||
double latitude = message.getLocation().getLatitude(); | ||
double longitude = message.getLocation().getLongitude(); | ||
Long userId = message.getFrom().getId(); | ||
CountryCode userLocale = UserCollection.getUserLocale(userId); | ||
|
||
if (RestrictionHelper.isRestrictedLocation(latitude, longitude)) { | ||
sendMessageToUser(userId, LocalizationHelper.getValueByCode(RESTRICTED_LOCATION_MESSAGE, userLocale)); | ||
return; | ||
} | ||
|
||
UserRole userRole = UserCollection.getUserRole(userId); | ||
|
||
switch (userRole) { | ||
case PASSENGER: | ||
parsePassengerLocation(message); | ||
break; | ||
case DRIVER: | ||
parseDriverLocation(message); | ||
break; | ||
case null, default: | ||
break; | ||
} | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.