Skip to content

Commit

Permalink
Merging changes from cbrsightings branch to implement pokealarm funct…
Browse files Browse the repository at this point in the history
…ionality
  • Loading branch information
CBRSightings committed Oct 25, 2017
1 parent 5b44770 commit 5a1ede8
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 39 deletions.
71 changes: 71 additions & 0 deletions create-db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
create table geocoding
(
lat double not null,
lon double not null,
suburb varchar(30) default 'NULL' null,
street_num varchar(15) default 'NULL' null,
street varchar(100) default 'NULL' null,
state varchar(30) default 'NULL' null,
postal varchar(15) default 'NULL' null,
neighbourhood varchar(50) default 'NULL' null,
sublocality varchar(50) default 'NULL' null,
country varchar(50) default 'NULL' null,
primary key (lat, lon)
)
;

create table pokemon
(
user_id varchar(50) default 'NULL' null,
id varchar(30) default 'NULL' null,
max_iv float default '100' null,
min_iv float default '0' null,
location varchar(30) default 'NULL' null,
constraint pokemon_user_id_id_channel_max_iv_min_iv_pk
unique (user_id, id, location, max_iv, min_iv)
)
;

create table raid
(
user_id varchar(50) not null,
boss_id int not null,
location varchar(30) not null,
primary key (user_id, boss_id, location)
)
;

create table raidlobby
(
lobby_id int not null
primary key,
gym_id varchar(50) default 'NULL' null,
members int default '0' null,
role_id varchar(50) default 'NULL' null,
channel_id varchar(50) default 'NULL' null,
next_timeleft_update int default 15 null,
invite_code varchar(10) default 'NULL' null
)
;

create table users
(
id varchar(50) not null
primary key,
joindate timestamp default current_timestamp() not null,
paused tinyint(1) default '0' null,
constraint users_id_uindex
unique (id)
)
;

alter table pokemon
add constraint pokemon_users_id_fk
foreign key (user_id) references users (id)
;

alter table raid
add constraint raid_users_id_fk
foreign key (user_id) references users (id)
;

33 changes: 14 additions & 19 deletions src/notifier/PokeNotificationSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ private void notifyUser(final String userID, final Message message) {
final User user = this.jda.getUserById(userID);
final Thread thread = new Thread(new UserNotifier(user, message, false));
thread.start();
//
// UserNotifier notifier = new UserNotifier(user,message);
// notifier.run();
}

@Override
Expand All @@ -59,27 +56,27 @@ public void run() {
if (userIDs.size() == 0) {
notificationLog.log(INFO, "no-one wants this pokemon");
} else {
Message supporterMessage = pokeSpawn.buildMessage();
Message publicMessage = pokeSpawn.buildPublicMessage();

final Message message = pokeSpawn.buildMessage();
notificationLog.log(INFO, "Built message for pokespawn");

userIDs.stream().filter(MessageListener::isSupporter).forEach(userID -> this.notifyUser(userID, supporterMessage));
userIDs.stream().filter((u) -> !MessageListener.isSupporter(u)).forEach(userID -> this.notifyUser(userID,publicMessage));
if (config.isSupporterOnly()) {
userIDs.stream().filter(MessageListener::isSupporter).forEach(userID -> this.notifyUser(userID, message));
} else {
userIDs.forEach(userID -> this.notifyUser(userID, message));
}
}

if(pokeSpawn.getGeofenceIds().size() == 0){
if (pokeSpawn.getGeofenceIds().size() == 0) {
ArrayList<PokeChannel> noGeofences = config.getNonGeofencedChannels();

if(noGeofences != null) {
if (noGeofences != null) {
for (PokeChannel channel : config.getNonGeofencedChannels()) {
postToChannel(channel, pokeSpawn);
}
}
}else {
} else {
for (GeofenceIdentifier geofenceIdentifier : pokeSpawn.getGeofenceIds()) {
for (PokeChannel channel : config.getPokeChannels(geofenceIdentifier)) {
postToChannel(channel,pokeSpawn);
postToChannel(channel, pokeSpawn);
}
}
}
Expand All @@ -98,9 +95,8 @@ public void run() {

private void postToChannel(PokeChannel channel, PokeSpawn pokeSpawn) {
JsonElement pokeFilter = config.searchPokemonFilter(config.filters.get(channel.filterName), pokeSpawn.id);
//
if (pokeFilter == null){
System.out.println(String.format("wtf pokeFilter %s is null for channel with id %s",channel.filterName, channel.channelId));
if (pokeFilter == null) {
System.out.println(String.format("wtf pokeFilter %s is null for channel with id %s", channel.filterName, channel.channelId));
return;
}
if (pokeFilter.isJsonObject()) {
Expand All @@ -114,15 +110,15 @@ private void postToChannel(PokeChannel channel, PokeSpawn pokeSpawn) {

if (pokeSpawn.iv <= max && pokeSpawn.iv >= min) {
notificationLog.log(INFO, String.format("Pokemon between specified ivs (%s,%s), posting to Discord", min, max));
sendPublicAlert(pokeSpawn.buildPublicMessage(), pokeSpawn.getGeofenceIds());
sendPublicAlert(pokeSpawn.buildMessage(), pokeSpawn.getGeofenceIds());
} else {
notificationLog.log(INFO, String.format("Pokemon not specified ivs (%s,%s), posting to Discord", min, max));

}
} else {
if (pokeFilter.getAsBoolean()) {
notificationLog.log(INFO, "Pokemon enabled in filter, posting to Discord");
sendPublicAlert(pokeSpawn.buildPublicMessage(), pokeSpawn.getGeofenceIds());
sendPublicAlert(pokeSpawn.buildMessage(), pokeSpawn.getGeofenceIds());
} else {
notificationLog.log(INFO, "Pokemon not enabled in filter, not posting");
}
Expand All @@ -139,7 +135,6 @@ private void sendPublicAlert(Message message, ArrayList<GeofenceIdentifier> geof
channel.getChannel().sendMessage(message).queue(m -> notificationLog.log(INFO, "Successfully sent message."));

}

}
}
}
20 changes: 0 additions & 20 deletions src/pokemon/PokeSpawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class PokeSpawn

public static final SimpleDateFormat printFormat = new SimpleDateFormat("HH:mm:ss");
private Message builtMessage = null;
private Message builtPublicMessage = null;

public PokeSpawn(final int id, final String suburb, final Region region, final float iv, final String move_1, final String move_2) {
this.imageUrl = null;
Expand Down Expand Up @@ -418,23 +417,4 @@ public String getAppleMapsLink() {
public ArrayList<GeofenceIdentifier> getGeofenceIds() {
return geofenceIdentifiers;
}

public Message buildPublicMessage() {
if(builtPublicMessage == null) {
final MessageBuilder messageBuilder = new MessageBuilder();
final EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(getColor());
embedBuilder.setTitle(config.formatStr(pokeProperties, config.getTitleFormatting("pokemon")), config.formatStr(pokeProperties, config.getTitleUrl("pokemon")));
embedBuilder.setDescription(config.formatStr(pokeProperties, config.getBodyFormatting("pokemon")));
embedBuilder.setThumbnail(Pokemon.getIcon(this.id));
if (config.showMap("pokemon")) {
embedBuilder.setImage(this.getImage());
}
embedBuilder.setFooter(config.getFooterText(), null);
embedBuilder.setTimestamp(Instant.now());
messageBuilder.setEmbed(embedBuilder.build());
builtPublicMessage = messageBuilder.build();
}
return builtPublicMessage;
}
}

0 comments on commit 5a1ede8

Please sign in to comment.