use of net.dv8tion.jda.core.entities.Channel in project Saber-Bot by notem.
the class InitCommand method action.
@Override
public void action(String prefix, String[] args, MessageReceivedEvent event) {
String body;
if (args.length > 0) {
boolean isAChannel = false;
TextChannel chan = null;
String chanId = null;
try {
chanId = args[0].replaceAll("[^\\d]", "");
chan = event.getGuild().getTextChannelById(chanId);
if (chan != null)
isAChannel = true;
} catch (Exception ignored) {
}
if (// use the argument as the new channel's name
!isAChannel) {
String chanTitle = args[0].replaceAll("[^A-Za-z0-9_ \\-]", "").replaceAll("[ ]", "_");
Main.getScheduleManager().createSchedule(event.getGuild().getId(), chanTitle);
body = "A new schedule channel named **" + chanTitle.toLowerCase() + "** has been created!\n" + "You can now use the create command to create events on that schedule, or the sync command to sync " + "that schedule to a Google Calendar.";
} else // convert the channel to a schedule
{
if (Main.getScheduleManager().isASchedule(chan.getId())) {
// clear the channel of events
TextChannel finalChan = chan;
Main.getDBDriver().getEventCollection().find(eq("channelId", chan.getId())).forEach((Consumer<? super Document>) document -> {
String msgId = document.getString("messageId");
finalChan.deleteMessageById(msgId).complete();
Main.getEntryManager().removeEntry(document.getInteger("_id"));
});
body = "The schedule <#" + chanId + "> has been cleared!";
} else {
// create a new schedule
Main.getScheduleManager().createSchedule(chan);
body = "The channel <#" + chanId + "> has been converted to a schedule channel!\n" + "You can now use the create command to create events on that schedule, or the sync " + "command to sync that schedule to a Google Calendar.";
}
}
} else // create a new schedule using the default name
{
Main.getScheduleManager().createSchedule(event.getGuild().getId(), null);
body = "A new schedule channel named **new_schedule** has been created!\n" + "You can now use the create command to create events on that schedule, or the sync command" + " to sync that schedule to a Google Calendar.";
}
MessageUtilities.sendMsg(body, event.getChannel(), null);
}
use of net.dv8tion.jda.core.entities.Channel in project Saber-Bot by notem.
the class PurgeCommand method action.
@Override
public void action(String prefix, String[] args, MessageReceivedEvent event) {
TextChannel channel = event.getGuild().getJDA().getTextChannelById(args[0].replaceAll("[^\\d]", ""));
// number of messages to remove
Integer[] count = { 100 };
// ID of bot to check messages against
String botId = event.getJDA().getSelfUser().getId();
processing.put(event.getGuild().getId(), channel.getId());
channel.getIterableHistory().stream().filter(message -> message.getAuthor().getId().equals(botId) && (count[0]-- > 0)).forEach((message -> {
message.getChannel().sendTyping().queue();
// sleep for half a second before continuing
try {
Thread.sleep(500);
} catch (InterruptedException ignored) {
}
Bson query = eq("messageId", message.getId());
if (Main.getDBDriver().getEventCollection().count(query) == 0) {
MessageUtilities.deleteMsg(message);
}
}));
processing.remove(event.getGuild().getId(), channel.getId());
// send success message
String content = "Finished purging old message.";
MessageUtilities.sendMsg(content, event.getTextChannel(), null);
}
use of net.dv8tion.jda.core.entities.Channel in project FredBoat by Frederikam.
the class AkinatorListener method onGuildMessageReceived.
@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
Channel channel = event.getChannel();
if (!channel.getId().equals(channelId)) {
return;
}
byte answer;
// <editor-fold defaultstate="collapsed" desc="switch">
switch(event.getMessage().getContentStripped().trim().toLowerCase()) {
case "yes":
answer = 0;
break;
case "y":
answer = 0;
break;
case "no":
answer = 1;
break;
case "n":
answer = 1;
break;
case "idk":
answer = 2;
break;
case "p":
answer = 3;
break;
case "probably":
answer = 3;
break;
case "pn":
answer = 4;
break;
case "probably not":
answer = 4;
break;
default:
answer = -1;
break;
}
if (answer == -1) {
return;
}
lastActionReceived = System.currentTimeMillis();
if (lastQuestionWasGuess) {
if (answer != 0 && answer != 1) {
return;
}
context.sendTyping();
answerGuess(answer);
} else {
context.sendTyping();
answerQuestion(answer);
}
}
use of net.dv8tion.jda.core.entities.Channel in project Saber-Bot by notem.
the class PurgeCommand method verify.
@Override
public String verify(String prefix, String[] args, MessageReceivedEvent event) {
String head = prefix + this.name();
int index = 0;
// verify current argument count
if (args.length != 1) {
return "This command requires a channel as an argument!";
}
// verify argument 1 is properly formed
if (!args[index].matches("<#[\\d]+>")) {
return "Your channel name, *" + args[index] + "*, looks malformed!";
}
// verify that argument is a proper link to a channel
Channel channel = event.getJDA().getTextChannelById(args[index].replaceAll("[^\\d]", ""));
if (channel == null) {
return "I could not find " + args[index] + " on your guild!";
}
// basic protection against misuse
if (limiter.isOnCooldown(event.getGuild().getId())) {
return "The purge command has been used on your guild recently.\n" + "Please wait at least one minute before reusing the command!";
}
if (processing.keySet().contains(event.getGuild().getId())) {
return "I am still purging messages from <#" + processing.getOrDefault(event.getGuild().getId(), "0") + ">.\n" + "You may not issue another purge command until this finishes.";
}
return "";
}
use of net.dv8tion.jda.core.entities.Channel in project Rubicon by Rubicon-Bot.
the class CommandAutochannel method createChannel.
private void createChannel(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
String[] args = parsedCommandInvocation.getArgs();
Guild guild = parsedCommandInvocation.getMessage().getGuild();
StringBuilder names = new StringBuilder();
for (int i = 1; i < args.length; i++) {
names.append(args[i]).append(" ");
}
String name = names.toString();
name = names.replace(name.lastIndexOf(" "), name.lastIndexOf(" ") + 1, "").toString();
Channel channel = guild.getController().createVoiceChannel(name).complete();
String oldEntry = RubiconBot.getMySQL().getGuildValue(guild, "autochannels");
String newEntry = oldEntry + ", " + channel.getId();
RubiconBot.getMySQL().updateGuildValue(guild, "autochannels", newEntry);
Message mymsg = parsedCommandInvocation.getMessage().getTextChannel().sendMessage(EmbedUtil.success("Created Autochannel", "Successfully created autochannel -> " + channel.getName() + "").build()).complete();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
mymsg.delete().queue();
}
}, 5000);
}
Aggregations