Send slack messages for bad sound mappings

Messages are only sent once per mapping
This commit is contained in:
Dan Mulloy 2018-05-18 14:39:42 -04:00 committed by Alexander Meech
parent 0f8765d0c5
commit e01af5edab
4 changed files with 75 additions and 2 deletions

View File

@ -9,6 +9,9 @@ import java.net.URL;
import java.net.URLEncoder;
import com.google.gson.JsonObject;
import org.bukkit.Bukkit;
import mineplex.core.thread.ThreadPool;
/**
@ -36,7 +39,7 @@ public class SlackAPI
*/
public void sendMessage(SlackTeam team, String channel, SlackMessage message, boolean customTitle)
{
ThreadPool.ASYNC.execute(() ->
Runnable send = () ->
{
// Set message title.
if (!customTitle)
@ -51,7 +54,15 @@ public class SlackAPI
// Run the call.
runWebCall(team, msg);
});
};
if (Bukkit.isPrimaryThread())
{
ThreadPool.ASYNC.execute(send);
} else
{
send.run();
}
}
/**

View File

@ -0,0 +1,58 @@
package mineplex.core.sound;
import com.mineplex.spigot.MissingSoundEvent;
import org.bukkit.event.EventHandler;
import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.slack.SlackAPI;
import mineplex.core.slack.SlackMessage;
import mineplex.core.slack.SlackTeam;
import mineplex.core.thread.ThreadPool;
import mineplex.serverdata.Region;
import mineplex.serverdata.redis.atomic.RedisStringRepository;
import mineplex.serverdata.servers.ServerManager;
/**
* Notifies #pc-sound-logging when we detect a bad sound mapping
* @author Dan
*/
@ReflectivelyCreateMiniPlugin
public class SoundNotifier extends MiniPlugin
{
private RedisStringRepository _repo;
private SoundNotifier()
{
super("Sound Notifier");
_repo = new RedisStringRepository(
ServerManager.getMasterConnection(),
ServerManager.getSlaveConnection(),
Region.ALL,
"missingSounds"
);
}
@EventHandler
public void onMissingSound(MissingSoundEvent event)
{
final String message = event.getMessage();
ThreadPool.ASYNC.execute(() ->
{
if (_repo.get(message) == null)
{
sendSlackMessage(event.getMessage());
_repo.set(message, "sent");
}
});
}
private void sendSlackMessage(String message)
{
SlackMessage slackMsg = new SlackMessage("Sound Bot", "notes", message);
SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, "#pc-sound-logging", slackMsg, true);
}
}

View File

@ -55,6 +55,7 @@ import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.resourcepack.ResourcePackManager;
import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.sound.SoundNotifier;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.teamspeak.TeamspeakManager;
@ -204,6 +205,7 @@ public class Hub extends JavaPlugin implements IRelation
require(TeamspeakManager.class);
new WebsiteLinkManager(this, clientManager);
require(TwitchIntegrationFix.class);
require(SoundNotifier.class);
new AdminCommands();
}

View File

@ -69,6 +69,7 @@ import mineplex.core.recharge.Recharge;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.sound.SoundNotifier;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.teleport.Teleport;
@ -227,6 +228,7 @@ public class Arcade extends JavaPlugin
AprilFoolsManager.getInstance();
require(CustomItemFrames.class);
require(SoundNotifier.class);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);