use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class ShitCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "image url", acceptEmpty = true, endless = true) @ImageUrl String imageUrl) {
Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("shit")).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> ImageUtility.getImageMessage(event, response).queue());
}
use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class TweetCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") Member member, @Argument(value = "text", endless = true) @Limit(max = 280) String text) {
User user = member.getUser();
Guild guild = event.getGuild();
int memberCount = guild.getMemberCount();
int likes = event.getRandom().nextInt(memberCount);
List<Member> members = guild.getMembers();
List<String> urls = new ArrayList<>();
for (int i = 0; i < Math.min(10, likes); i++) {
urls.add(members.get(event.getRandom().nextInt(memberCount)).getUser().getEffectiveAvatarUrl() + "?size=64");
}
Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("tweet")).addField("display_name", member.getEffectiveName()).addField("name", user.getName()).addField("avatar", user.getEffectiveAvatarUrl() + "?size=128").addField("retweets", event.getRandom().nextInt(memberCount)).addField("likes", likes).addField("text", ImageUtility.escapeMentions(guild, text)).addField("urls", urls).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> ImageUtility.getImageMessage(event, response).queue());
}
use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class VrCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "image url", endless = true, acceptEmpty = true) @ImageUrl String imageUrl) {
Request request = new ImageRequest(event.getConfig().getImageWebserverUrl("vr")).addQuery("image", imageUrl).build(event.getConfig().getImageWebserver());
event.getHttpClient().newCall(request).enqueue((HttpCallback) response -> ImageUtility.getImageMessage(event, response).queue());
}
use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class BanCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "user") String userArgument, @Argument(value = "reason", endless = true, nullDefault = true) Reason reason, @Option(value = "days", description = "Set how many days of messages should be deleted from the user") @DefaultNumber(1) @Limit(min = 0, max = 7) int days) {
SearchUtility.getUser(event.getShardManager(), userArgument).thenAccept(user -> {
if (user == null) {
event.replyFailure("I could not find that user").queue();
return;
}
if (user.getIdLong() == event.getSelfUser().getIdLong()) {
event.replyFailure("You cannot ban me, that is illegal").queue();
return;
}
Member member = event.getGuild().getMember(user);
if (member != null) {
if (!event.getMember().canInteract(member)) {
event.replyFailure("You cannot ban someone higher or equal than your top role").queue();
return;
}
if (!event.getSelfMember().canInteract(member)) {
event.replyFailure("I cannot ban someone higher or equal than my top role").queue();
return;
}
}
event.getGuild().retrieveBan(user).submit().whenComplete((ban, exception) -> {
if (exception instanceof ErrorResponseException && ((ErrorResponseException) exception).getErrorResponse() == ErrorResponse.UNKNOWN_BAN) {
event.getGuild().ban(user, days).reason(ModUtility.getAuditReason(reason, event.getAuthor())).queue($ -> {
event.replySuccess("**" + user.getAsTag() + "** has been banned").queue();
event.getBot().getModActionManager().onModAction(new BanEvent(event.getMember(), user, reason, member != null));
});
} else {
event.replyFailure("That user is already banned").queue();
}
});
});
}
use of com.sx4.bot.core.Sx4CommandEvent in project Sx4 by sx4-discord-bot.
the class MassMoveCommand method onCommand.
public void onCommand(Sx4CommandEvent event, @Argument(value = "from", nullDefault = true) AudioChannel from, @Argument(value = "to", endless = true) AudioChannel to) {
if (!PermissionUtility.canConnect(event.getSelfMember(), to)) {
event.replyFailure("I cannot move people to that voice channel").queue();
return;
}
if (!PermissionUtility.canConnect(event.getMember(), to)) {
event.replyFailure("You cannot move people to that voice channel").queue();
return;
}
AudioChannel channel = event.getMember().getVoiceState().getChannel();
if (from == null && channel == null) {
event.replyFailure("You are not in a voice channel").queue();
return;
}
AudioChannel effectiveFrom = from == null ? channel : from;
if (effectiveFrom.getIdLong() == to.getIdLong()) {
event.replyFailure("You cannot provide the same voice channel twice").queue();
return;
}
List<Member> members = effectiveFrom.getMembers();
if (members.isEmpty()) {
event.replyFailure("There are no users is that voice channel").queue();
return;
}
List<RestAction<Void>> actions = new ArrayList<>();
for (Member member : members) {
actions.add(event.getGuild().moveVoiceMember(member, to));
}
RestAction.allOf(actions).flatMap(completed -> event.replySuccess("Moved **" + completed.size() + "** user" + (completed.size() == 1 ? "" : "s") + " from `" + effectiveFrom.getName() + "` to `" + to.getName() + "`")).queue();
}
Aggregations