Renaming config methods to match keys

This commit is contained in:
Norbi Peti 2019-05-20 13:07:20 +02:00
parent b396ec47b4
commit 9e8f988ea6
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
9 changed files with 30 additions and 30 deletions

View file

@ -89,7 +89,7 @@ public final class DPUtils {
*/
public static String botmention() {
if (DiscordPlugin.plugin == null) return "#bot";
return channelMention(DiscordPlugin.plugin.CommandChannel().get());
return channelMention(DiscordPlugin.plugin.commandChannel().get());
}
/**

View file

@ -54,31 +54,31 @@ public class DiscordPlugin extends ButtonPlugin {
@Getter
private Command2DC manager;
private ConfigData<Character> Prefix() {
private ConfigData<Character> prefix() {
return getIConfig().getData("prefix", '/', str -> ((String) str).charAt(0), Object::toString);
}
public static char getPrefix() {
if (plugin == null) return '/';
return plugin.Prefix().get();
return plugin.prefix().get();
}
private ConfigData<Guild> MainServer() {
private ConfigData<Guild> mainServer() {
return getIConfig().getDataPrimDef("mainServer", 219529124321034241L, id -> dc.getGuildById(Snowflake.of((long) id)).block(), g -> g.getId().asLong());
}
public ConfigData<Snowflake> CommandChannel() {
public ConfigData<Snowflake> commandChannel() {
return DPUtils.snowflakeData(getIConfig(), "commandChannel", 239519012529111040L);
}
public ConfigData<Mono<Role>> ModRole() {
public ConfigData<Mono<Role>> modRole() {
return DPUtils.roleData(getIConfig(), "modRole", "Moderator");
}
/**
* The invite link to show by /discord invite. If empty, it defaults to the first invite if the bot has access.
*/
public ConfigData<String> InviteLink() {
public ConfigData<String> inviteLink() {
return getIConfig().getData("inviteLink", "");
}
@ -127,7 +127,7 @@ public class DiscordPlugin extends ButtonPlugin {
private void handleReady(List<GuildCreateEvent> event) {
try {
mainServer = MainServer().get(); //Shouldn't change afterwards
mainServer = mainServer().get(); //Shouldn't change afterwards
if (mainServer == null) {
if (event.size() == 0) {
getLogger().severe("Main server not found! Invite the bot and do /discord reset");
@ -136,7 +136,7 @@ public class DiscordPlugin extends ButtonPlugin {
}
mainServer = event.get(0).getGuild();
getLogger().warning("Main server set to first one: " + mainServer.getName());
MainServer().set(mainServer); //Save in config
mainServer().set(mainServer); //Save in config
}
if (!TBMCCoreAPI.IsTestServer()) { //Don't change conditions here, see mainServer=devServer=null in onDisable()
dc.updatePresence(Presence.online(Activity.playing("Minecraft"))).subscribe();
@ -144,7 +144,7 @@ public class DiscordPlugin extends ButtonPlugin {
dc.updatePresence(Presence.online(Activity.playing("testing"))).subscribe();
}
SafeMode = false;
DPUtils.disableIfConfigError(null, CommandChannel(), ModRole()); //Won't disable, just prints the warning here
DPUtils.disableIfConfigError(null, commandChannel(), modRole()); //Won't disable, just prints the warning here
Component.registerComponent(this, new GeneralEventBroadcasterModule());
Component.registerComponent(this, new MinecraftChatModule());

View file

@ -43,11 +43,11 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
return getConfig().getData("keepPinned", (short) 40);
}
private ConfigData<Long> lastannouncementtime() {
private ConfigData<Long> lastAnnouncementTime() {
return getConfig().getData("lastAnnouncementTime", 0L);
}
private ConfigData<Long> lastseentime() {
private ConfigData<Long> lastSeenTime() {
return getConfig().getData("lastSeenTime", 0L);
}
@ -63,10 +63,10 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
Flux<Message> msgs = channel().get().flatMapMany(MessageChannel::getPinnedMessages);
msgs.subscribe(Message::unpin);
val yc = YamlConfiguration.loadConfiguration(new File("plugins/DiscordPlugin", "config.yml")); //Name change
if (lastannouncementtime().get() == 0) //Load old data
lastannouncementtime().set(yc.getLong("lastannouncementtime"));
if (lastseentime().get() == 0)
lastseentime().set(yc.getLong("lastseentime"));
if (lastAnnouncementTime().get() == 0) //Load old data
lastAnnouncementTime().set(yc.getLong("lastannouncementtime"));
if (lastSeenTime().get() == 0)
lastSeenTime().set(yc.getLong("lastseentime"));
new Thread(this::AnnouncementGetterThreadMethod).start();
}
@ -87,7 +87,7 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
.get("children").getAsJsonArray();
StringBuilder msgsb = new StringBuilder();
StringBuilder modmsgsb = new StringBuilder();
long lastanntime = lastannouncementtime().get();
long lastanntime = lastAnnouncementTime().get();
for (int i = json.size() - 1; i >= 0; i--) {
JsonObject item = json.get(i).getAsJsonObject();
final JsonObject data = item.get("data").getAsJsonObject();
@ -100,9 +100,9 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
distinguished = distinguishedjson.getAsString();
String permalink = "https://www.reddit.com" + data.get("permalink").getAsString();
long date = data.get("created_utc").getAsLong();
if (date > lastseentime().get())
lastseentime().set(date);
else if (date > lastannouncementtime().get()) {
if (date > lastSeenTime().get())
lastSeenTime().set(date);
else if (date > lastAnnouncementTime().get()) {
do {
val reddituserclass = ChromaGamerBase.getTypeForFolder("reddit");
if (reddituserclass == null)
@ -126,8 +126,8 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
if (modmsgsb.length() > 0)
modChannel().get().flatMap(ch -> ch.createMessage(modmsgsb.toString()))
.flatMap(Message::pin).subscribe();
if (lastannouncementtime().get() != lastanntime)
lastannouncementtime().set(lastanntime); // If sending succeeded
if (lastAnnouncementTime().get() != lastanntime)
lastAnnouncementTime().set(lastanntime); // If sending succeeded
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -13,7 +13,7 @@ public class Command2DC extends Command2<ICommand2DC, Command2DCSender> {
@Override
public boolean hasPermission(Command2DCSender sender, ICommand2DC command, Method method) {
//return !command.isModOnly() || sender.getMessage().getAuthor().hasRole(DiscordPlugin.plugin.ModRole().get()); //TODO: ModRole may be null; more customisable way?
//return !command.isModOnly() || sender.getMessage().getAuthor().hasRole(DiscordPlugin.plugin.modRole().get()); //TODO: modRole may be null; more customisable way?
return true;
}
}

View file

@ -12,7 +12,7 @@ public class DebugCommand extends ICommand2DC {
@Command2.Subcommand
public boolean def(Command2DCSender sender, String args) {
sender.getMessage().getAuthorAsMember()
.flatMap(m -> DiscordPlugin.plugin.ModRole().get()
.flatMap(m -> DiscordPlugin.plugin.modRole().get()
.map(mr -> m.getRoleIds().stream().anyMatch(r -> r.equals(mr.getId()))))
.subscribe(success -> {
if (success)

View file

@ -45,7 +45,7 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
/**
* Questions that the bot will choose a random answer to give to.
*/
private ConfigData<String[]> serverReadyQuestions() {
private ConfigData<String[]> serverReady() {
return getConfig().getData("serverReady", () -> new String[]{"when will the server be open",
"when will the server be ready", "when will the server be done", "when will the server be complete",
"when will the server be finished", "when's the server ready", "when's the server open",
@ -100,7 +100,7 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
}
lastlistp = (short) Bukkit.getOnlinePlayers().size(); //Didn't handle
if (!TBMCCoreAPI.IsTestServer()
&& Arrays.stream(fm.serverReadyQuestions().get()).anyMatch(msglowercased::contains)) {
&& Arrays.stream(fm.serverReady().get()).anyMatch(msglowercased::contains)) {
int next;
if (usableServerReadyStrings.size() == 0)
fm.createUsableServerReadyStrings();

View file

@ -30,7 +30,7 @@ public class CommandListener {
if (!mentionedonly) { //mentionedonly conditions are in CommonListeners
if (!(channel instanceof PrivateChannel)
&& !(content.charAt(0) == DiscordPlugin.getPrefix()
&& channel.getId().asString().equals(DiscordPlugin.plugin.CommandChannel().get().asString()))) //
&& channel.getId().asString().equals(DiscordPlugin.plugin.commandChannel().get().asString()))) //
return ret;
tmp = ret.then(channel.type()); // Fun
}

View file

@ -39,8 +39,8 @@ public class CommonListeners {
//System.out.println("Bot: "+author.get().isBot());
if (FunModule.executeMemes(event.getMessage()))
return def;
val commandChannel = DiscordPlugin.plugin.CommandChannel().get();
val commandCh = DPUtils.getMessageChannel(DiscordPlugin.plugin.CommandChannel());
val commandChannel = DiscordPlugin.plugin.commandChannel().get();
val commandCh = DPUtils.getMessageChannel(DiscordPlugin.plugin.commandChannel());
return commandCh.filter(ch -> (commandChannel != null && event.getMessage().getChannelId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat
|| event.getMessage().getContent().orElse("").contains("channelcon")) //Only 'channelcon' is allowed in other channels
.filterWhen(ch -> { //Only continue if this doesn't handle the event

View file

@ -97,7 +97,7 @@ public class DiscordMCCommand extends ICommand2MC {
"Shows an invite link to the server"
})
public void invite(CommandSender sender) {
String invi = DiscordPlugin.plugin.InviteLink().get();
String invi = DiscordPlugin.plugin.inviteLink().get();
if (invi.length() > 0) {
sender.sendMessage("§bInvite link: " + invi);
return;