From a0b448627aa2b4b25048e17913540fd9bf51643d Mon Sep 17 00:00:00 2001 From: Savvy Date: Sun, 23 Jul 2017 21:34:57 -0400 Subject: [PATCH] Levels, Added External Invite Link Blocking --- .../2.13/taskArtifacts/cache.properties.lock | Bin 17 -> 17 bytes .gradle/2.13/taskArtifacts/fileHashes.bin | Bin 41019 -> 41579 bytes .gradle/2.13/taskArtifacts/fileSnapshots.bin | Bin 1040007 -> 1040007 bytes .gradle/2.13/taskArtifacts/taskArtifacts.bin | Bin 35285 -> 35285 bytes .idea/workspace.xml | 611 ++++++++---------- src/main/java/me/savvy/rixa/Rixa.java | 3 +- .../rixa/commands/admin/TwitterCommand.java | 25 + .../rixa/commands/general/LevelsCommand.java | 42 ++ .../rixa/commands/general/PingCommand.java | 8 + .../data/filemanager/LanguageManager.java | 4 - .../me/savvy/rixa/events/MessageEvent.java | 49 +- .../java/me/savvy/rixa/extras/polls/Poll.java | 12 +- .../java/me/savvy/rixa/guild/RixaGuild.java | 9 +- .../me/savvy/rixa/guild/user/UserData.java | 128 +++- .../rixa/modules/levels/LevelsModule.java | 40 +- .../rixa/modules/twitter/TwitterModule.java | 17 +- .../me/savvy/rixa/utils/MessageBuilder.java | 11 +- 17 files changed, 569 insertions(+), 390 deletions(-) create mode 100644 src/main/java/me/savvy/rixa/commands/admin/TwitterCommand.java create mode 100644 src/main/java/me/savvy/rixa/commands/general/LevelsCommand.java diff --git a/.gradle/2.13/taskArtifacts/cache.properties.lock b/.gradle/2.13/taskArtifacts/cache.properties.lock index a9a33bbcf2f34acccd05dd3e155ea0d939b80c14..355c78711593f1ee2f42e534313aac29f80ae38a 100644 GIT binary patch literal 17 VcmZRM`)gkj_?x4T0SqiQ001+D1mFMw literal 17 VcmZRM`)gkj_?x4T0Sxq>0su3m1q%QG diff --git a/.gradle/2.13/taskArtifacts/fileHashes.bin b/.gradle/2.13/taskArtifacts/fileHashes.bin index fb16ff59c6db771c27f94d8baa3aeeaf59d2cc59..00711cfcbd6f29d15b511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(>aX8{Ou(KJIaGxpwsM$iELZOMD$WMsj(*{t46#48#0&!QEMI_X- zq6C!5(KAKxb~nzUFQ?1O2smKQl)TahYT7u!6LDS4BJuMsGel5x9w<@EO{Ri?I#-z` Xl#XN4lRYCCW5|ucBF_lL+--jXM49p3 diff --git a/.gradle/2.13/taskArtifacts/taskArtifacts.bin b/.gradle/2.13/taskArtifacts/taskArtifacts.bin index 5cc6e3e429e729d54624709e9fd43a7ff3e12f32..537f2c038ba048ce5925343298bbfc1c5f00dca8 100644 GIT binary patch delta 200 zcmcaQnd$0erVX9m5`WLuRPS2E_x0KVAD=U|!LJvvp1M*e-MN4ALhsoUb1o$xOn>x` zL4T5v-BaW0J_-cFN50cN+I1GqW0j2{yVZF`2?a)m9>4{hK@6e3$_io?H|F delta 200 zcmcaQnd$0erVX9m5*fD)-%XY+l$w*Hay0qb%|aiBoZ9kJB`T8_de4^7E12N<)GX8| z*?+s_n_B1p>HlrD#8~&Kf+fQm53#-X`VuK+KIhBs9a%h)ADGgwZ__9NNp4=`Tcs-z zzROaw>X~+Q&%ynh1pj`wV=dIZmQip^YI9@pc4mnWY5xCf?frE!OzV%cSevWL_-{Q| wuV3K+k-hnLbDQcJ{<*~>`%Q!XFX1$vQ?cQLx#@nOEF - + @@ -41,7 +41,7 @@ - + @@ -730,10 +626,10 @@ - - - - + + + + @@ -742,12 +638,13 @@ + - - - - + + + + @@ -1099,7 +996,7 @@ - + @@ -1127,30 +1024,35 @@ + - + - - + + + - + - + - - - + + + + - - + + + - - - + + + + @@ -1175,148 +1077,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1324,20 +1084,6 @@ - - - - - - - - - - - - - - @@ -1366,21 +1112,10 @@ - - - - - - - - - - - @@ -1424,15 +1159,6 @@ - - - - - - - - - @@ -1440,7 +1166,6 @@ - @@ -1448,15 +1173,6 @@ - - - - - - - - - @@ -1464,9 +1180,6 @@ - - - @@ -1474,7 +1187,6 @@ - @@ -1482,7 +1194,6 @@ - @@ -1490,15 +1201,6 @@ - - - - - - - - - @@ -1506,15 +1208,6 @@ - - - - - - - - - @@ -1522,19 +1215,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + diff --git a/src/main/java/me/savvy/rixa/Rixa.java b/src/main/java/me/savvy/rixa/Rixa.java index 559126d..0bc5148 100644 --- a/src/main/java/me/savvy/rixa/Rixa.java +++ b/src/main/java/me/savvy/rixa/Rixa.java @@ -27,6 +27,7 @@ import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.core.JDABuilder; import net.dv8tion.jda.core.OnlineStatus; import net.dv8tion.jda.core.entities.Game; +import net.dv8tion.jda.core.entities.Invite; import net.dv8tion.jda.core.exceptions.RateLimitedException; import net.dv8tion.jda.core.hooks.AnnotatedEventManager; @@ -102,7 +103,7 @@ public class Rixa { new DeleteMessagesCommand(), new PingCommand(), new PurgeMessagesCommand(), new BatchMoveCommand(), new MuteCommand(), new MusicCommand(), new ConfigCommand(), new UrbanDictionaryCommand(), new YoutubeCommand(), - new AddRoleCommand(), new RemoveRoleCommand()}); + new AddRoleCommand(), new RemoveRoleCommand(), new LevelsCommand()}); register(new React[] {new HelpReaction(), new ConfigReaction()}); data = new Data(DataType.SQL); } diff --git a/src/main/java/me/savvy/rixa/commands/admin/TwitterCommand.java b/src/main/java/me/savvy/rixa/commands/admin/TwitterCommand.java new file mode 100644 index 0000000..265d1e9 --- /dev/null +++ b/src/main/java/me/savvy/rixa/commands/admin/TwitterCommand.java @@ -0,0 +1,25 @@ +package me.savvy.rixa.commands.admin; + +import me.savvy.rixa.commands.handlers.Command; +import me.savvy.rixa.commands.handlers.CommandExec; +import me.savvy.rixa.commands.handlers.CommandType; +import net.dv8tion.jda.core.entities.ChannelType; +import net.dv8tion.jda.core.entities.TextChannel; +import net.dv8tion.jda.core.entities.User; +import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.core.requests.restaction.InviteAction; + +/** + * Created by savit on 7/14/2017. + */ +public class TwitterCommand implements CommandExec { + + @Command( + description = "Configure twitter module.", + type = CommandType.ADMIN, + channelType = ChannelType.TEXT, + usage = "%ptwitter", mainCommand = "twitter") + public void execute(GuildMessageReceivedEvent event) { + + } +} \ No newline at end of file diff --git a/src/main/java/me/savvy/rixa/commands/general/LevelsCommand.java b/src/main/java/me/savvy/rixa/commands/general/LevelsCommand.java new file mode 100644 index 0000000..4deb467 --- /dev/null +++ b/src/main/java/me/savvy/rixa/commands/general/LevelsCommand.java @@ -0,0 +1,42 @@ +package me.savvy.rixa.commands.general; + +import me.savvy.rixa.commands.handlers.Command; +import me.savvy.rixa.commands.handlers.CommandExec; +import me.savvy.rixa.guild.RixaGuild; +import me.savvy.rixa.guild.user.UserData; +import me.savvy.rixa.utils.MessageBuilder; +import me.savvy.rixa.utils.YoutubeSearch; +import net.dv8tion.jda.core.entities.ChannelType; +import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; + +import java.io.IOException; + +/** + * Created by savit on 7/11/2017. + */ +public class LevelsCommand implements CommandExec { + + @Override + @Command(mainCommand = "rank", + description = "View your levels!", + channelType = ChannelType.TEXT) + public void execute(GuildMessageReceivedEvent event) { + RixaGuild rixaGuild = RixaGuild.getGuild(event.getGuild()); + if(!rixaGuild.getLevelsModule().isEnabled()) { + new MessageBuilder("Levels are not enabled on this server!").setColor(event.getMember().getColor()).queue(event.getChannel()); + return; + } + UserData data = rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId()); + new MessageBuilder() + .setAuthor(event.getAuthor().getName(), event.getAuthor().getEffectiveAvatarUrl(), event.getAuthor().getEffectiveAvatarUrl()) + .setTitle(event.getAuthor().getName() + "'s level") + .setColor(event.getMember().getColor()) + .addField("Rank", "0", true) + .addField("Level", String.valueOf(data.getLevel()), true) + .addField("Exp Needed", + data.getRemainingExperience() + "/" + data.getNeededXP + (data.getLevelFromExperience(data.getExperience())).intValue(), false) + .addField("Total Exp", String.valueOf(data.getExperience()), false) + .queue(event.getChannel()); + } +} diff --git a/src/main/java/me/savvy/rixa/commands/general/PingCommand.java b/src/main/java/me/savvy/rixa/commands/general/PingCommand.java index b6dfc2b..5f19692 100644 --- a/src/main/java/me/savvy/rixa/commands/general/PingCommand.java +++ b/src/main/java/me/savvy/rixa/commands/general/PingCommand.java @@ -6,6 +6,8 @@ import me.savvy.rixa.utils.MessageBuilder; import net.dv8tion.jda.core.entities.ChannelType; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; +import java.time.temporal.ChronoUnit; + /** * Created by Timber on 5/23/2017. */ @@ -16,6 +18,12 @@ public class PingCommand implements CommandExec { channelType = ChannelType.TEXT) public void execute(GuildMessageReceivedEvent event) { new MessageBuilder("Pong!").setColor(event.getMember().getColor()).complete(event.getChannel()); + /*event.getChannel().sendMessage("Pong").queue(m -> { + if(m!=null) { + m.editMessage("Pong: " + event.getMessage().getCreationTime().until(m.getEditedTime(), ChronoUnit.MILLIS) + "ms").complete(); + + } + });*/ /*RixaAudioReceiveHandler handle = new RixaAudioReceiveHandler(); handle.start(event.getGuild(), event.getMember().getVoiceState().getChannel());*/ } diff --git a/src/main/java/me/savvy/rixa/data/filemanager/LanguageManager.java b/src/main/java/me/savvy/rixa/data/filemanager/LanguageManager.java index 157836d..43c6ce8 100644 --- a/src/main/java/me/savvy/rixa/data/filemanager/LanguageManager.java +++ b/src/main/java/me/savvy/rixa/data/filemanager/LanguageManager.java @@ -2,11 +2,7 @@ package me.savvy.rixa.data.filemanager; import lombok.Getter; import me.savvy.rixa.data.locale.Language; -import me.savvy.rixa.data.thunderbolt.Thunderbolt; -import me.savvy.rixa.data.thunderbolt.exceptions.FileLoadException; -import me.savvy.rixa.data.thunderbolt.io.ThunderFile; import org.apache.commons.io.IOUtils; -import org.json.JSONArray; import org.json.JSONObject; import java.io.File; diff --git a/src/main/java/me/savvy/rixa/events/MessageEvent.java b/src/main/java/me/savvy/rixa/events/MessageEvent.java index 24e723c..12ee468 100644 --- a/src/main/java/me/savvy/rixa/events/MessageEvent.java +++ b/src/main/java/me/savvy/rixa/events/MessageEvent.java @@ -8,6 +8,7 @@ import me.savvy.rixa.modules.reactions.handlers.ReactRegistrar; import me.savvy.rixa.modules.reactions.handlers.ReactionManager; import me.savvy.rixa.utils.MessageBuilder; import net.dv8tion.jda.core.Permission; +import net.dv8tion.jda.core.entities.Invite; import net.dv8tion.jda.core.entities.Message; import net.dv8tion.jda.core.entities.MessageEmbed; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; @@ -18,13 +19,20 @@ import net.dv8tion.jda.core.hooks.SubscribeEvent; import java.awt.*; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Created by Timber on 5/7/2017. */ public class MessageEvent { + private final Pattern INVITE = Pattern.compile("discord(?:\\.gg|app.com\\/invite)\\/([A-Z0-9-]{2,16})",Pattern.CASE_INSENSITIVE); + + @SubscribeEvent public void handle(GuildMessageReceivedEvent event) { if (event.getGuild() == null) return; @@ -32,7 +40,22 @@ public class MessageEvent { String prefix = rixaGuild .getGuildSettings() .getPrefix(); - if (!event.getMessage().getContent().startsWith(prefix)) {return; } + checkMessage(event.getMessage()); + if (!event.getMessage().getContent().startsWith(prefix)) { + if (!(rixaGuild.getLevelsModule().isEnabled())) { + return; + } + if(!event.getAuthor().getId().equalsIgnoreCase("202944101333729280") && + !event.getAuthor().getId().equalsIgnoreCase("207322957075185665")) { + return; + } + if(rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId()).awardIfCan()) { + new MessageBuilder(event.getAuthor().getAsMention() + " has leveled up to level " + + rixaGuild.getLevelsModule().getUserData(event.getAuthor().getId()).getLevel()) + .setColor(event.getMember().getColor()).queue(event.getChannel()); + } + return; + } String[] splitContent = event.getMessage().getContent().replace(prefix, "").split(" "); if(!CommandHandler.hasCommand(splitContent[0])) { @@ -46,6 +69,28 @@ public class MessageEvent { } } + private void checkMessage(Message message) { + List invites = new ArrayList<>(); + Matcher matcher = INVITE.matcher(message.getRawContent()); + while(matcher.find()) { + invites.add(matcher.group(1)); + } + if(invites.size() == 0) { + return; + } + for(String inviteCode : invites) { + Invite invite = null; + try { + invite = Invite.resolve(message.getJDA(), inviteCode).complete(); + } catch(Exception e) {} + if(invite !=null && !invite.getGuild().getId().equals(message.getGuild().getId())) { + new MessageBuilder(String.format("Advertising is not allowed, %s!", + message.getAuthor().getAsMention())).setColor(message.getMember().getColor()).queue(message.getTextChannel()); + message.delete().reason("Advertising is not allowed!").queue(); + } + } + } + @SubscribeEvent public void onMemberJoin(PrivateMessageReceivedEvent event) { RixaGuild rixaGuild; @@ -107,4 +152,4 @@ public class MessageEvent { } } } -} +} \ No newline at end of file diff --git a/src/main/java/me/savvy/rixa/extras/polls/Poll.java b/src/main/java/me/savvy/rixa/extras/polls/Poll.java index 925ebf2..c5cb406 100644 --- a/src/main/java/me/savvy/rixa/extras/polls/Poll.java +++ b/src/main/java/me/savvy/rixa/extras/polls/Poll.java @@ -7,6 +7,7 @@ import net.dv8tion.jda.core.EmbedBuilder; import java.awt.*; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; /** @@ -14,14 +15,13 @@ import java.util.List; */ public class Poll { - @Getter @Setter - private String name, description; - @Getter - private List options; + @Getter @Setter private String name, description; + @Getter private int id; + @Getter private List options; public Poll(String name) { this.name = name; - options = new ArrayList<>(); + options = new LinkedList<>(); } public boolean addOption(String s) { @@ -36,7 +36,7 @@ public class Poll { if(options.size() <= 10) { return options.remove(i); } - return ""; + return "Option Not Found."; } public EmbedBuilder getBuilder(Color color) { diff --git a/src/main/java/me/savvy/rixa/guild/RixaGuild.java b/src/main/java/me/savvy/rixa/guild/RixaGuild.java index e61edaf..725a3fb 100644 --- a/src/main/java/me/savvy/rixa/guild/RixaGuild.java +++ b/src/main/java/me/savvy/rixa/guild/RixaGuild.java @@ -1,6 +1,5 @@ package me.savvy.rixa.guild; -import lombok.Data; import lombok.Getter; import lombok.Setter; import me.savvy.rixa.Rixa; @@ -8,9 +7,13 @@ import me.savvy.rixa.commands.handlers.RixaPermission; import me.savvy.rixa.data.database.sql.DatabaseManager; import me.savvy.rixa.enums.Result; import me.savvy.rixa.guild.management.GuildSettings; +import me.savvy.rixa.modules.levels.LevelsModule; import me.savvy.rixa.modules.music.MusicModule; import me.savvy.rixa.modules.twitter.TwitterModule; -import net.dv8tion.jda.core.entities.*; +import net.dv8tion.jda.core.entities.Guild; +import net.dv8tion.jda.core.entities.Member; +import net.dv8tion.jda.core.entities.Role; +import net.dv8tion.jda.core.entities.User; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -31,11 +34,13 @@ public class RixaGuild { @Getter @Setter private MusicModule musicModule; @Getter @Setter private TwitterModule twitterModule; @Getter private List mutedMembers = new ArrayList<>(); + @Getter @Setter private LevelsModule levelsModule; public RixaGuild(Guild guild) { this.guild = guild; this.db = Rixa.getDbManager(); setMusicModule(new MusicModule(guild)); + setLevelsModule(new LevelsModule(this)); load(); } diff --git a/src/main/java/me/savvy/rixa/guild/user/UserData.java b/src/main/java/me/savvy/rixa/guild/user/UserData.java index 5b39201..748cfd5 100644 --- a/src/main/java/me/savvy/rixa/guild/user/UserData.java +++ b/src/main/java/me/savvy/rixa/guild/user/UserData.java @@ -2,23 +2,135 @@ package me.savvy.rixa.guild.user; import lombok.Getter; import lombok.Setter; +import me.savvy.rixa.Rixa; +import me.savvy.rixa.enums.Result; +import me.savvy.rixa.guild.RixaGuild; +import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.User; -import java.util.HashMap; -import java.util.Map; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; /** * Created by savit on 7/14/2017. */ public class UserData { - - @Getter private static Map userData = new HashMap<>(); + @Getter private final Guild guild; @Getter private User user; - @Getter @Setter private String status; - @Getter @Setter private int level; - @Getter @Setter private int experience; + @Getter private int experience; + private boolean awardedLast; + private Random random; - public UserData(User user) { + public UserData(User user, Guild guild) { this.user = user; + this.guild = guild; + awardedLast = false; + random = new Random(); + load(); + register(this); + } + + private void register(UserData userData) { + RixaGuild.getGuild(guild).getLevelsModule().registerUser(userData); + } + + private void load() { + if(!checkExists()) { + insert(); + setExperience(0); + return; + } + String query = "SELECT * FROM `%s` WHERE `%s` = '%s' AND `%s` = '%s';"; + PreparedStatement ps = null; + ResultSet rs = null; + try { + ps = Rixa.getDbManager().getConnection().prepareStatement(String.format + (query, "levels", "guild_id", + guild.getId(), "user_id", + user.getId())); + rs = Rixa.getDbManager().getObject(ps); + setExperience(rs.getInt("experience")); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public int getLevel() { + return getLevelFromExperience(getExperience()); + } + + public boolean awardIfCan() { + if(awardedLast) { + return false; + } + int amountAdding = getRandom(); + int currentLevel = getLevelFromExperience(getExperience()); + setExperience(getExperience() + amountAdding); + awardedLast = true; + new Timer().schedule(new TimerTask() { + @Override + public void run() { + awardedLast = false; + } + }, 1000 * 60); + return currentLevel < getLevelFromExperience(getExperience()); + } + + public int getLevelFromExperience(int xp) { + int level = 0; + while (xp >= this.getNeededXP(level)) { + xp -= this.getNeededXP(level); + level++; + } + return level; + } + + public Double getNeededXP(double n) { + if (n < 0) return 0.0; + return (6 * Math.pow(n, 3) + 119 * n + 100); + } + + public int getRemainingExperience() { + int xp = this.getExperience(); + int level = getLevelFromExperience(xp); + + for (int i = 0; i < level; i++) { + xp -= this.getNeededXP(i); + } + return xp; + } + + private boolean checkExists() { + String query = "SELECT `%s` FROM `%s` WHERE `%s` = '%s' AND `%s` = '%s';"; + Result r = Rixa.getDbManager().checkExists(String.format + (query, "user_id", "levels", "guild_id", guild.getId(), "user_id", user.getId())); + return r == Result.TRUE; + } + + private void insert() { + String query = "INSERT INTO `%s` (`%s`,`%s`,`%s`) VALUES ('%s', '%s', '%s');"; + Rixa.getDbManager() + .insert(String.format(query, "levels", "guild_id", "user_id", "experience", guild.getId(), user.getId(), 0)); + } + + public void setExperience(int experience) { + this.experience = experience; + String query = "UPDATE `%s` SET `%s` = '%s' WHERE `%s` = '%s' AND `%s` = '%s';"; + try { + PreparedStatement ps = Rixa.getDbManager().getConnection().prepareStatement(String.format + (query, "levels", "experience", experience, "guild_id", + guild.getId(), "user_id", + user.getId())); + Rixa.getDbManager().executeUpdate(ps); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public int getRandom() { + int i = random.nextInt(25); + return (i > 15 && i < 25 ? i : getRandom()); } } diff --git a/src/main/java/me/savvy/rixa/modules/levels/LevelsModule.java b/src/main/java/me/savvy/rixa/modules/levels/LevelsModule.java index 5e2f10e..d86bb33 100644 --- a/src/main/java/me/savvy/rixa/modules/levels/LevelsModule.java +++ b/src/main/java/me/savvy/rixa/modules/levels/LevelsModule.java @@ -1,11 +1,27 @@ package me.savvy.rixa.modules.levels; +import lombok.Getter; +import me.savvy.rixa.guild.RixaGuild; +import me.savvy.rixa.guild.user.UserData; import me.savvy.rixa.modules.RixaModule; +import java.util.HashMap; +import java.util.Map; + /** * Created by Timber on 5/23/2017. */ public class LevelsModule implements RixaModule { + + @Getter private final RixaGuild rixaGuild; + @Getter private Map userData = new HashMap<>(); + @Getter private boolean enabled; + + public LevelsModule(RixaGuild rixaGuild) { + this.rixaGuild = rixaGuild; + enabled = true; + } + @Override public String getName() { return "Levels"; @@ -13,11 +29,27 @@ public class LevelsModule implements RixaModule { @Override public String getDescription() { - return ""; + return "Rixa levels module."; } - @Override - public boolean isEnabled() { - return false; + public void registerUser(UserData userData) { + if (getUserData().containsKey(userData.getUser().getId())) { + return; + } + getUserData().put(userData.getUser().getId(), userData); + } + + public UserData getUserData(String key) { + checkUser(key); + return getUserData().get(key); + } + + private void checkUser(String key) { + if (getUserData().containsKey(key)) { + return; + } + new UserData + (getRixaGuild().getGuild().getJDA().getUserById(key), + getRixaGuild().getGuild()); } } diff --git a/src/main/java/me/savvy/rixa/modules/twitter/TwitterModule.java b/src/main/java/me/savvy/rixa/modules/twitter/TwitterModule.java index 43bf989..cfed97f 100644 --- a/src/main/java/me/savvy/rixa/modules/twitter/TwitterModule.java +++ b/src/main/java/me/savvy/rixa/modules/twitter/TwitterModule.java @@ -3,14 +3,16 @@ package me.savvy.rixa.modules.twitter; import lombok.Getter; import lombok.Setter; import me.savvy.rixa.guild.RixaGuild; +import me.savvy.rixa.modules.RixaModule; import twitter4j.*; import twitter4j.conf.ConfigurationBuilder; /** * Created by savit on 7/9/2017. */ -public class TwitterModule { - +public class TwitterModule implements RixaModule { + + @Getter private boolean enabled; @Getter private final TwitterStream twitterStream; @Getter @@ -45,5 +47,14 @@ public class TwitterModule { twitterStream = new TwitterStreamFactory().getInstance(); twitter = twitterFactory.getInstance(); } - + + @Override + public String getName() { + return "Twitter"; + } + + @Override + public String getDescription() { + return "Twitter feed, tweet & more."; + } } diff --git a/src/main/java/me/savvy/rixa/utils/MessageBuilder.java b/src/main/java/me/savvy/rixa/utils/MessageBuilder.java index aac983c..16d081b 100644 --- a/src/main/java/me/savvy/rixa/utils/MessageBuilder.java +++ b/src/main/java/me/savvy/rixa/utils/MessageBuilder.java @@ -19,6 +19,10 @@ public class MessageBuilder { this.builder = new EmbedBuilder().setDescription(description); } + public MessageBuilder() { + this.builder = new EmbedBuilder(); + } + public MessageBuilder setTitle(String title, String url) { builder.setTitle(title, url); return this; @@ -43,7 +47,12 @@ public class MessageBuilder { builder.setThumbnail(url); return this; } - + + public MessageBuilder setAuthor(String name, String url, String iconURL) { + builder.setAuthor(name, url, iconURL); + return this; + } + public void queue(TextChannel channel) { channel.sendMessage(builder.build()).queue(); }