diff --git a/create-db.sql b/create-db.sql new file mode 100644 index 0000000..91bada6 --- /dev/null +++ b/create-db.sql @@ -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) +; + diff --git a/src/notifier/PokeNotificationSender.java b/src/notifier/PokeNotificationSender.java index f7b95c3..2cc014a 100644 --- a/src/notifier/PokeNotificationSender.java +++ b/src/notifier/PokeNotificationSender.java @@ -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 @@ -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 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); } } } @@ -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()) { @@ -114,7 +110,7 @@ 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)); @@ -122,7 +118,7 @@ private void postToChannel(PokeChannel channel, PokeSpawn pokeSpawn) { } 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"); } @@ -139,7 +135,6 @@ private void sendPublicAlert(Message message, ArrayList geof channel.getChannel().sendMessage(message).queue(m -> notificationLog.log(INFO, "Successfully sent message.")); } - } } } diff --git a/src/pokemon/PokeSpawn.java b/src/pokemon/PokeSpawn.java index bd0bbc5..86777be 100644 --- a/src/pokemon/PokeSpawn.java +++ b/src/pokemon/PokeSpawn.java @@ -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; @@ -418,23 +417,4 @@ public String getAppleMapsLink() { public ArrayList 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; - } }