use of net.kodehawa.mantarobot.db.entities.DBGuild in project MantaroBot by Mantaro.
the class OptsCmd method register.
@Subscribe
public void register(CommandRegistry registry) {
registry.register("opts", optsCmd = new SimpleCommand(Category.MODERATION, CommandPermission.ADMIN) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (args.length == 0) {
OptsCmd.onHelp(event);
return;
}
if (args.length == 1 && args[0].equalsIgnoreCase("list") || args[0].equalsIgnoreCase("ls")) {
StringBuilder builder = new StringBuilder();
for (String s : Option.getAvaliableOptions()) {
builder.append(s).append("\n");
}
List<String> m = DiscordUtils.divideString(builder);
List<String> messages = new LinkedList<>();
boolean hasReactionPerms = event.getGuild().getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_ADD_REACTION);
for (String s1 : m) {
messages.add("**Mantaro's Options List**\n" + (hasReactionPerms ? "Use the arrow reactions to change pages. " : "Use &page >> and &page << to change pages and &cancel to end") + "*All options must be prefixed with `~>opts` when running them*\n" + String.format("```prolog\n%s```", s1));
}
if (hasReactionPerms) {
DiscordUtils.list(event, 45, false, messages);
} else {
DiscordUtils.listText(event, 45, false, messages);
}
return;
}
if (args.length < 2) {
event.getChannel().sendMessage(help(event)).queue();
return;
}
StringBuilder name = new StringBuilder();
if (args[0].equalsIgnoreCase("help")) {
for (int i = 1; i < args.length; i++) {
String s = args[i];
if (name.length() > 0)
name.append(":");
name.append(s);
Option option = Option.getOptionMap().get(name.toString());
if (option != null) {
try {
EmbedBuilder builder = new EmbedBuilder().setAuthor(option.getOptionName(), null, event.getAuthor().getEffectiveAvatarUrl()).setDescription(option.getDescription()).setThumbnail("https://cdn.pixabay.com/photo/2012/04/14/16/26/question-34499_960_720.png").addField("Type", option.getType().toString(), false);
event.getChannel().sendMessage(builder.build()).queue();
} catch (IndexOutOfBoundsException ignored) {
}
return;
}
}
event.getChannel().sendMessage(EmoteReference.ERROR + "Invalid option help name.").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
return;
}
for (int i = 0; i < args.length; i++) {
String s = args[i];
if (name.length() > 0)
name.append(":");
name.append(s);
Option option = Option.getOptionMap().get(name.toString());
if (option != null) {
BiConsumer<GuildMessageReceivedEvent, String[]> callable = Option.getOptionMap().get(name.toString()).getEventConsumer();
try {
String[] a;
if (++i < args.length)
a = Arrays.copyOfRange(args, i, args.length);
else
a = new String[0];
callable.accept(event, a);
Player p = MantaroData.db().getPlayer(event.getAuthor());
if (p.getData().addBadgeIfAbsent(Badge.DID_THIS_WORK)) {
p.saveAsync();
}
} catch (IndexOutOfBoundsException ignored) {
}
return;
}
}
event.getChannel().sendMessage(EmoteReference.ERROR + "Invalid option or arguments.").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
event.getChannel().sendMessage(help(event)).queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Options and Configurations Command").setDescription("**This command allows you to change Mantaro settings for this server.**\n" + "All values set are local rather than global, meaning that they will only effect this server.").addField("Usage", "The command is so big that we moved the description to the wiki. [Click here](https://github.com/Mantaro/MantaroBot/wiki/Configuration) to go to the Wiki Article.", false).build();
}
}).addOption("check:data", new Option("Data check.", "Checks the data values you have set on this server. **THIS IS NOT USER-FRIENDLY**", OptionType.GENERAL).setAction(event -> {
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData guildData = dbGuild.getData();
// Map as follows: name, value
Map<String, Object> fieldMap = mapObjects(guildData);
if (fieldMap == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Cannot retrieve values. Weird thing...").queue();
return;
}
StringBuilder show = new StringBuilder();
show.append("Options set for server **").append(event.getGuild().getName()).append("**\n\n");
AtomicInteger ai = new AtomicInteger();
for (Entry e : fieldMap.entrySet()) {
if (e.getKey().equals("localPlayerExperience")) {
continue;
}
show.append(ai.incrementAndGet()).append(".- `").append(e.getKey()).append("`");
if (e.getValue() == null) {
show.append(" **is not set to anything.").append("**\n");
} else {
show.append(" is set to: **").append(e.getValue()).append("**\n");
}
}
List<String> toSend = DiscordUtils.divideString(1600, show);
toSend.forEach(message -> event.getChannel().sendMessage(message).queue());
}).setShortDescription("Checks the data values you have set on this server.")).addOption("reset:all", new Option("Options reset.", "Resets all options set on this server.", OptionType.GENERAL).setAction(event -> {
// Temporary stuff.
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData temp = MantaroData.db().getGuild(event.getGuild()).getData();
// The persistent data we wish to maintain.
String premiumKey = temp.getPremiumKey();
long quoteLastId = temp.getQuoteLastId();
long ranPolls = temp.getQuoteLastId();
String gameTimeoutExpectedAt = temp.getGameTimeoutExpectedAt();
long cases = temp.getCases();
// Assign everything all over again
DBGuild newDbGuild = DBGuild.of(dbGuild.getId(), dbGuild.getPremiumUntil());
GuildData newTmp = newDbGuild.getData();
newTmp.setGameTimeoutExpectedAt(gameTimeoutExpectedAt);
newTmp.setRanPolls(ranPolls);
newTmp.setCases(cases);
newTmp.setPremiumKey(premiumKey);
newTmp.setQuoteLastId(quoteLastId);
// weee
newDbGuild.saveAsync();
event.getChannel().sendMessage(EmoteReference.CORRECT + "Correctly reset your options!").queue();
}));
}
use of net.kodehawa.mantarobot.db.entities.DBGuild in project MantaroBot by Mantaro.
the class UtilsCmds method dateGMT.
protected static String dateGMT(Guild guild, String tz) {
DateFormat format = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Date date = new Date();
DBGuild dbGuild = MantaroData.db().getGuild(guild.getId());
GuildData guildData = dbGuild.getData();
if (guildData.getTimeDisplay() == 1) {
format = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss a");
}
format.setTimeZone(TimeZone.getTimeZone(tz));
return format.format(date);
}
use of net.kodehawa.mantarobot.db.entities.DBGuild in project MantaroBot by Mantaro.
the class Poll method startPoll.
public void startPoll() {
try {
if (!isCompliant) {
getChannel().sendMessage(EmoteReference.WARNING + "This poll cannot build. " + "**Remember that the options must be a maximum of 9 and a minimum of 2 and the timeout must be a maximum of 45m and a minimum of 30s.**\n" + "Options are separated with a comma, for example `1,2,3`. For spaced stuff use quotation marks at the start and end of the sentence.").queue();
getRunningPolls().remove(getChannel().getId());
return;
}
if (isPollAlreadyRunning(getChannel())) {
getChannel().sendMessage(EmoteReference.WARNING + "There seems to be another poll running here...").queue();
return;
}
if (!getGuild().getSelfMember().hasPermission(getChannel(), Permission.MESSAGE_ADD_REACTION)) {
getChannel().sendMessage(EmoteReference.ERROR + "Seems like I cannot add reactions here...").queue();
getRunningPolls().remove(getChannel().getId());
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(getGuild());
GuildData data = dbGuild.getData();
AtomicInteger at = new AtomicInteger();
data.setRanPolls(data.getRanPolls() + 1L);
dbGuild.saveAsync();
String toShow = Stream.of(options).map(opt -> String.format("#%01d.- %s", at.incrementAndGet(), opt)).collect(Collectors.joining("\n"));
if (toShow.length() > 1014) {
toShow = "This was too long to show, so I pasted it: " + Utils.paste(toShow);
}
User author = MantaroBot.getInstance().getUserById(owner);
EmbedBuilder builder = new EmbedBuilder().setAuthor(String.format("Poll #%1d created by %s", data.getRanPolls(), author.getName()), null, author.getAvatarUrl()).setDescription("**Poll started. React to the number to vote.**\n*" + name + "*\n" + "Type &cancelpoll to cancel a running poll.").addField("Options", "```md\n" + toShow + "```", false).setColor(Color.CYAN).setThumbnail("https://cdn.pixabay.com/photo/2012/04/14/16/26/question-34499_960_720.png").setFooter("You have " + Utils.getHumanizedTime(timeout) + " to vote.", author.getAvatarUrl());
getChannel().sendMessage(builder.build()).queue(this::createPoll);
InteractiveOperations.createOverriding(getChannel(), timeout, e -> {
if (e.getAuthor().getId().equals(owner)) {
if (e.getMessage().getContentRaw().equalsIgnoreCase("&cancelpoll")) {
runningPoll.cancel(true);
return Operation.COMPLETED;
}
}
return Operation.IGNORED;
});
runningPolls.put(getChannel().getId(), this);
} catch (Exception e) {
getChannel().sendMessage(EmoteReference.ERROR + "An unknown error has occurred while setting up a poll. Maybe try again?").queue();
}
}
use of net.kodehawa.mantarobot.db.entities.DBGuild in project MantaroBot by Mantaro.
the class ModLog method logUnban.
public static void logUnban(Member author, String target, String reason) {
DBGuild guildDB = MantaroData.db().getGuild(author.getGuild());
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.addField("Responsible Moderator", author.getEffectiveName(), true);
embedBuilder.addField("Member ID", target, true);
embedBuilder.addField("Reason", reason, false);
embedBuilder.setAuthor("Unban", null, author.getUser().getEffectiveAvatarUrl());
if (guildDB.getData().getGuildLogChannel() != null) {
MantaroBot.getInstance().getTextChannelById(guildDB.getData().getGuildLogChannel()).sendMessage(embedBuilder.build()).queue();
}
}
use of net.kodehawa.mantarobot.db.entities.DBGuild in project MantaroBot by Mantaro.
the class ModLog method log.
public static void log(Member author, User target, String reason, ModAction action, long caseN, String... time) {
DBGuild guildDB = db.getGuild(author.getGuild());
Player player = db.getPlayer(author);
PlayerData playerData = player.getData();
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.addField("Responsible Moderator", author.getEffectiveName(), true);
if (target != null)
embedBuilder.addField("Member", target.getName(), true);
embedBuilder.addField("Reason", reason, false);
if (target != null) {
embedBuilder.setThumbnail(target.getEffectiveAvatarUrl());
} else {
embedBuilder.setThumbnail(author.getUser().getEffectiveAvatarUrl());
}
switch(action) {
case BAN:
embedBuilder.setAuthor("Ban | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
case TEMP_BAN:
embedBuilder.setAuthor("Temp Ban | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl()).addField("Time", time[0], true);
break;
case KICK:
embedBuilder.setAuthor("Kick | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
case MUTE:
embedBuilder.setAuthor("Mute | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
case UNMUTE:
embedBuilder.setAuthor("Un-mute | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
case PRUNE:
embedBuilder.setAuthor("Prune | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
case WARN:
embedBuilder.setAuthor("Warn | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
}
if (!playerData.hasBadge(Badge.POWER_USER)) {
playerData.addBadgeIfAbsent(Badge.POWER_USER);
player.saveAsync();
}
if (guildDB.getData().getGuildLogChannel() != null) {
if (MantaroBot.getInstance().getTextChannelById(guildDB.getData().getGuildLogChannel()) != null) {
MantaroBot.getInstance().getTextChannelById(guildDB.getData().getGuildLogChannel()).sendMessage(embedBuilder.build()).queue();
}
}
}
Aggregations