mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Added /twitter (twitterbot)
This commit is contained in:
parent
8939b7e728
commit
d020293a26
@ -64,3 +64,8 @@ auto_protect_radius: 25.0
|
||||
host_sender_names:
|
||||
- rcon
|
||||
- remotebukkit
|
||||
|
||||
# TwitterBot - Used to allow superadmins to verify themselves using twitter
|
||||
twitterbot_enabled: false
|
||||
twitterbot_url: 'http://tftwitter.darthcraft.net/'
|
||||
twitterbot_secret: ''
|
||||
|
@ -1,22 +1,128 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_TwitterHandler;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Command_twitter
|
||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME, ignore_permissions = false)
|
||||
public class Command_twitter extends TFM_Command
|
||||
{
|
||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME, ignore_permissions = false)
|
||||
public class Command_cmdlist extends TFM_Command
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
if (!TotalFreedomMod.twitterbotEnabled)
|
||||
{
|
||||
if (args.length < 1) {
|
||||
TFM_Util.playerMsg(sender, "TwitterBot has been disabled in config.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TFM_TwitterHandler twitterbot = TFM_TwitterHandler.getInstance(plugin);
|
||||
|
||||
if ("set".equals(args[0]))
|
||||
{
|
||||
if (args.length != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(args[1].startsWith("@"))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "Please do not prefix your twitter username with '@'");
|
||||
return true;
|
||||
}
|
||||
|
||||
String reply = twitterbot.setTwitter(sender.getName(), args[1]);
|
||||
|
||||
if ("ok".equals(reply))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "Your twitter handle has been set to: " + ChatColor.AQUA + "@" + args[1] + ChatColor.GRAY + ".");
|
||||
}
|
||||
else if ("disabled".equals(reply))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "TwitterBot has been temporarily disabled,, please wait until it get re-enabled", ChatColor.RED);
|
||||
}
|
||||
else if ("failed".equals(reply))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED);
|
||||
}
|
||||
else if ("false".equals(reply))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED);
|
||||
}
|
||||
else if ("cannotauth".equals(reply))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "An unknown error occurred, please contact a developer", ChatColor.RED);
|
||||
TFM_Util.playerMsg(sender, "Response code: " + reply);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("info".equals(args[0]))
|
||||
{
|
||||
String reply = twitterbot.getTwitter(sender.getName());
|
||||
TFM_Util.playerMsg(sender, "-- Twitter Information --", ChatColor.BLUE);
|
||||
TFM_Util.playerMsg(sender, "Using this feature, you can re-super yourself using twitter.");
|
||||
TFM_Util.playerMsg(sender, "You can set your twitter handle using " + ChatColor.AQUA + "/twitter set [twittername]");
|
||||
TFM_Util.playerMsg (sender, "Then, you can verify yourself by tweeting " + ChatColor.AQUA + "@TFUpdates #superme");
|
||||
if ("notfound".equals(reply)) {
|
||||
TFM_Util.playerMsg(sender, "You currently have " + ChatColor.RED + "no" + ChatColor.BLUE + " Twitter handle set.", ChatColor.BLUE);
|
||||
}
|
||||
else if ("disabled".equals(reply))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "TwitterBot has been temporarily disabled, please wait until re-enabled", ChatColor.RED);
|
||||
}
|
||||
else if ("failed".equals(reply))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "There was a problem querying the database, please let a developer know.", ChatColor.RED);
|
||||
}
|
||||
else if ("false".equals(reply))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "There was a problem with the database, please let a developer know.", ChatColor.RED);
|
||||
}
|
||||
else if ("cannotauth".equals(reply))
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "The database password is incorrect, please let a developer know.", ChatColor.RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
TFM_Util.playerMsg(sender, "Your current twitter handle: " + ChatColor.AQUA + "@" + reply + ChatColor.BLUE + ".", ChatColor.BLUE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if ("enable".equals(args[0]) || "disable".equals(args[0]))
|
||||
{
|
||||
if (!sender.getName().equalsIgnoreCase("DarthSalamon"))
|
||||
{
|
||||
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
|
||||
return true;
|
||||
}
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), ("enable".equals(args[0]) ? "Ena" : "Disa") + "bling Twitterbot", true);
|
||||
String reply = twitterbot.setEnabled(args[0] + "d");
|
||||
TFM_Util.playerMsg(sender, "Reply: " + reply);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Command not recognised
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
67
src/me/StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java
Normal file
67
src/me/StevenLawson/TotalFreedomMod/TFM_TwitterHandler.java
Normal file
@ -0,0 +1,67 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
|
||||
|
||||
public class TFM_TwitterHandler {
|
||||
|
||||
private TotalFreedomMod plugin;
|
||||
|
||||
private TFM_TwitterHandler(TotalFreedomMod plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public String getTwitter(String player)
|
||||
{
|
||||
return request("action=gettwitter&player=" + player);
|
||||
}
|
||||
|
||||
public String setTwitter(String player, String twitter)
|
||||
{
|
||||
if (twitter.startsWith("@"))
|
||||
{
|
||||
twitter = twitter.replaceAll("@", "");
|
||||
}
|
||||
return request("action=settwitter&player=" + player + "&twitter=" + twitter);
|
||||
}
|
||||
|
||||
public String delTwitter(String player) {
|
||||
return request("action=deltwitter&player=" + player);
|
||||
}
|
||||
|
||||
public String isEnabled() {
|
||||
return request("action=getstatus");
|
||||
}
|
||||
|
||||
public String setEnabled(String status) {
|
||||
return request("action=setstatus&status=" + status);
|
||||
}
|
||||
|
||||
private String request(String queryString) {
|
||||
String line = "failed";
|
||||
try
|
||||
{
|
||||
URL getUrl = new URL(TotalFreedomMod.twitterbotUrl + "?auth=" + TotalFreedomMod.twitterbotSecret + "&" + queryString);
|
||||
URLConnection urlConnection = getUrl.openConnection();
|
||||
// Read the response
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
line = in.readLine();
|
||||
in.close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TFM_Log.severe(ExceptionUtils.getFullStackTrace(ex));
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
public static TFM_TwitterHandler getInstance(TotalFreedomMod plugin) {
|
||||
return new TFM_TwitterHandler(plugin);
|
||||
}
|
||||
|
||||
}
|
@ -221,6 +221,9 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
public static boolean autoProtectSpawnpoints = true;
|
||||
public static double autoProtectRadius = 25.0D;
|
||||
public static List<String> host_sender_names = Arrays.asList("rcon", "remotebukkit");
|
||||
public static boolean twitterbotEnabled = false;
|
||||
public static String twitterbotUrl = "http://tftwitter.darthcraft.net/";
|
||||
public static String twitterbotSecret = "";
|
||||
|
||||
public static void loadMainConfig()
|
||||
{
|
||||
@ -262,6 +265,9 @@ public class TotalFreedomMod extends JavaPlugin
|
||||
autoProtectSpawnpoints = config.getBoolean("auto_protect_spawnpoints", autoProtectSpawnpoints);
|
||||
autoProtectRadius = config.getDouble("auto_protect_radius", autoProtectRadius);
|
||||
host_sender_names = config.getStringList("host_sender_names");
|
||||
twitterbotEnabled = config.getBoolean("twitterbot_enabled");
|
||||
twitterbotUrl = config.getString("twitterbot_url");
|
||||
twitterbotSecret = config.getString("twitterbot_secret");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user