+Added Fetch command
Added Fetch command Refactored AddGuildRole and AllowedGuildRole to be standard Added GuildRoleRemove
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package commands;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandFetch extends Command
|
||||
{
|
||||
public CommandFetch(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return LocStrings.Stub("FetchInfo"); }
|
||||
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String emote = input.args.split(" ")[0];
|
||||
if(emote.startsWith("<") && emote.endsWith(">"))
|
||||
{
|
||||
int num = (int)(Math.random() * 6) + 1;
|
||||
switch(num)
|
||||
{
|
||||
case 1:
|
||||
res.Call(String.format(LocStrings.Stub("FetchBringBack"), emote));
|
||||
break;
|
||||
case 2:
|
||||
res.Call(String.format(LocStrings.Stub("FetchRunAway")));
|
||||
break;
|
||||
case 3:
|
||||
res.Call(String.format(LocStrings.Stub("FetchBringBackWrong"), guild.emoji.get((int)(Math.random() * guild.emoji.size()) + 1)));
|
||||
break;
|
||||
case 4:
|
||||
res.Call(String.format(LocStrings.Stub("FetchEat"), emote));
|
||||
break;
|
||||
case 5:
|
||||
res.Call(String.format(LocStrings.Stub("FetchCatchRun"), emote));
|
||||
break;
|
||||
case 6:
|
||||
res.Call(String.format(LocStrings.Stub("FetchStare"), user.name));
|
||||
break;
|
||||
default:
|
||||
res.Call("" + num);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("FetchError")));
|
||||
System.out.println(emote);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,12 @@ import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandAddGuildRole extends Command
|
||||
public class CommandGuildRoleAdd extends Command
|
||||
{
|
||||
public CommandAddGuildRole(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
public CommandGuildRoleAdd(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return LocStrings.Stub("AddGuildRoleInfo"); };
|
||||
public String HelpText() { return LocStrings.Stub("GuildRoleAddInfo"); };
|
||||
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
@@ -25,16 +25,16 @@ public class CommandAddGuildRole extends Command
|
||||
{
|
||||
if(guild.control.addRole(user.discordID, role))
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("AddGuildRoleSuccess"), role, user.name));
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleAddSuccess"), role, user.name));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("AddGuildRoleFailure"), role, user.name));
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleAddFailure"), role, user.name));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("AddGuildRoleNotAllowed"), role));
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleAddNotAllowed"), role));
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -10,12 +10,12 @@ import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandAllowedGuildRole extends Command
|
||||
public class CommandGuildRoleAllowed extends Command
|
||||
{
|
||||
public CommandAllowedGuildRole(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
public CommandGuildRoleAllowed(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return LocStrings.Stub("AllowedGuildRoleInfo"); }
|
||||
public String HelpText() { return LocStrings.Stub("GuildRoleAllowedInfo"); }
|
||||
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
@@ -27,12 +27,12 @@ public class CommandAllowedGuildRole extends Command
|
||||
role = roles[i].trim();
|
||||
if(guild.allowedRole.contains(role))
|
||||
{
|
||||
res.Call(LocStrings.Stub("AllowedGuildRoleDuplicate"));
|
||||
res.Call(LocStrings.Stub("GuildRoleAllowedDuplicate"));
|
||||
}
|
||||
else
|
||||
{
|
||||
guild.allowedRole.add(role);
|
||||
res.Call(String.format(LocStrings.Stub("AllowedGuildRoleSuccess"), role));
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleAllowedSuccess"), role));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package commands;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandGuildRoleRemove extends Command
|
||||
{
|
||||
public CommandGuildRoleRemove(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String HelpText() { return LocStrings.Stub("GuildRoleRemoveInfo"); };
|
||||
|
||||
@Override
|
||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String role = input.args.split(" ")[0];
|
||||
if(guild.allowedRole.contains(role))
|
||||
{
|
||||
if(guild.control.removeRole(user.discordID, role))
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleRemoveSuccess"), role, user.name));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleRemoveFailure"), role, user.name));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.Call(String.format(LocStrings.Stub("GuildRoleRemoveNotAllowed"), role));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,13 @@
|
||||
package core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import commands.CommandAddGuildRole;
|
||||
import commands.CommandAllowedGuildRole;
|
||||
import commands.CommandBeansShow;
|
||||
import commands.CommandBetBeans;
|
||||
import commands.CommandBlurry;
|
||||
import commands.CommandBoop;
|
||||
import commands.CommandChangeIndicator;
|
||||
import commands.CommandChoose;
|
||||
import commands.CommandColiru;
|
||||
import commands.CommandDoWork;
|
||||
import commands.CommandEightBall;
|
||||
import commands.CommandGiveBeans;
|
||||
import commands.CommandHelp;
|
||||
import commands.CommandHelpBuilder;
|
||||
import commands.CommandInfo;
|
||||
import commands.CommandInvite;
|
||||
import commands.CommandJDoodle;
|
||||
import commands.CommandMap;
|
||||
import commands.CommandPerish;
|
||||
import commands.CommandPing;
|
||||
import commands.CommandPollManage;
|
||||
import commands.CommandPollResults;
|
||||
import commands.CommandPollShow;
|
||||
import commands.CommandPollVote;
|
||||
import commands.CommandRPEnd;
|
||||
import commands.CommandRPG;
|
||||
import commands.CommandRPStart;
|
||||
import commands.CommandRating;
|
||||
import commands.CommandRole;
|
||||
import commands.CommandRoll;
|
||||
import commands.CommandShutdown;
|
||||
import commands.CommandStark;
|
||||
import commands.CommandStats;
|
||||
import commands.CommandTeey;
|
||||
import commands.CommandTweet;
|
||||
import commands.CommandWolfram;
|
||||
import commands.CommandYeet;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import commands.*;
|
||||
import dataStructures.*;
|
||||
import net.dv8tion.jda.core.entities.Emote;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import utils.AdminControl;
|
||||
@@ -136,6 +99,17 @@ public class ObjectBuilderFactory
|
||||
// look up the guild.
|
||||
String uid = event.getGuild().getId();
|
||||
|
||||
List<Emote> emotes = event.getGuild().getEmotes();
|
||||
ArrayList<String> emotesString = new ArrayList<String>();
|
||||
String emote;
|
||||
String emoteFix;
|
||||
for(int i = 0; i < emotes.size(); i++)
|
||||
{
|
||||
emote = emotes.get(i).toString();
|
||||
emoteFix = "<:" + emote.substring(2, emote.indexOf("("));
|
||||
emoteFix += ":" + emote.substring(emote.indexOf("(")+1, emote.length()-1) + ">";
|
||||
emotesString.add(emoteFix);
|
||||
}
|
||||
// once we're lazily initialized, we can synchronize w/ the
|
||||
// guildCache object now instead of having to use a mutex.
|
||||
KittyGuild guild = null;
|
||||
@@ -149,7 +123,7 @@ public class ObjectBuilderFactory
|
||||
else
|
||||
{
|
||||
// Construct a new guild with defaults
|
||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()));
|
||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString);
|
||||
DatabaseManager.instance.Register(guild);
|
||||
guildCache.put(uid, guild);
|
||||
}
|
||||
@@ -363,13 +337,15 @@ public class ObjectBuilderFactory
|
||||
|
||||
manager.Register(LocCommands.Stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("allowedguildrole"), new CommandAllowedGuildRole(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("guildroleallowed"), new CommandGuildRoleAllowed(KittyRole.Admin, KittyRating.Safe));
|
||||
|
||||
manager.Register(LocCommands.Stub("poll"), new CommandPollManage(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe));
|
||||
|
||||
manager.Register(LocCommands.Stub("addguildrole"), new CommandAddGuildRole(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("fetch"), new CommandFetch(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("guildroleadd"), new CommandGuildRoleAdd(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("guildroleremove"), new CommandGuildRoleRemove(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("teey"), new CommandTeey(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("perish, thenperish"), new CommandPerish(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("yeet"), new CommandYeet(KittyRole.General, KittyRating.Safe));
|
||||
|
||||
@@ -14,19 +14,21 @@ public class KittyGuild extends DatabaseTrackedObject
|
||||
public String poll;
|
||||
public ArrayList<String> hasVoted = new ArrayList<String>();
|
||||
public ArrayList<String> allowedRole = new ArrayList<String>();
|
||||
public ArrayList<String> emoji = new ArrayList<String>();
|
||||
public ArrayList <KittyPoll> choices = new ArrayList<KittyPoll>();
|
||||
public AdminControl control;
|
||||
|
||||
private String commandIndicator;
|
||||
|
||||
// Default content for a guild
|
||||
public KittyGuild(String uniqueID, AdminControl adminControl)
|
||||
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji)
|
||||
{
|
||||
super(uniqueID);
|
||||
control = adminControl;
|
||||
this.uniqueID = uniqueID;
|
||||
this.contentRating = KittyRating.Safe;
|
||||
this.polling = false;
|
||||
this.emoji = emoji;
|
||||
SetCommandIndicator("!");
|
||||
}
|
||||
|
||||
|
||||
@@ -26,4 +26,17 @@ public class AdminControl
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removeRole(String memberID, String roleName)
|
||||
{
|
||||
try
|
||||
{
|
||||
guildCon.removeRolesFromMember(guild.getMemberById(memberID), guild.getRolesByName(roleName, true)).complete();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user