use of me.shadorc.shadbot.exception.MissingArgumentException in project Shadbot by Shadorc.
the class HolidaysCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
Zone zone = Utils.getValueOrNull(Zone.class, context.getArg());
if (zone == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid zone. %s", context.getArg(), FormatUtils.formatOptions(Zone.class)));
}
LoadingMessage loadingMsg = new LoadingMessage("Loading holiday information...", context.getChannel());
loadingMsg.send();
try {
String holidays = StringUtils.remove(TwitterUtils.getLastTweet("Vacances_Zone" + zone), "#");
loadingMsg.edit(Emoji.BEACH + " " + holidays);
} catch (TwitterException err) {
loadingMsg.delete();
Utils.handle("getting holidays information", context, err.getCause());
}
}
use of me.shadorc.shadbot.exception.MissingArgumentException in project Shadbot by Shadorc.
the class JokeCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException {
LoadingMessage loadingMsg = new LoadingMessage("Loading joke...", context.getChannel());
loadingMsg.send();
try {
String url = String.format("http://www.une-blague.com/blagues-courtes.html?&p=%d", ThreadLocalRandom.current().nextInt(1, 6));
Document doc = NetUtils.getDoc(url);
List<String> jokes = doc.getElementsByClass("texte ").stream().map(elmt -> elmt.html()).filter(elmt -> elmt.length() < 1000).collect(Collectors.toList());
String jokeHtml = jokes.get(ThreadLocalRandom.current().nextInt(jokes.size()));
String joke = FormatUtils.format(jokeHtml.split("<br>"), line -> Jsoup.parse(line).text().trim(), "\n");
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Blague").withAuthorUrl("http://www.une-blague.com/").appendDescription(joke);
loadingMsg.edit(embed.build());
} catch (IOException err) {
loadingMsg.delete();
Utils.handle("getting a joke", context, err);
}
}
use of me.shadorc.shadbot.exception.MissingArgumentException in project Shadbot by Shadorc.
the class DatabaseCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
List<String> splitArgs = StringUtils.split(context.getArg());
if (splitArgs.size() > 2) {
throw new MissingArgumentException();
}
Long guildID = CastUtils.asPositiveLong(splitArgs.get(0));
if (guildID == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid guild ID.", splitArgs.get(0)));
}
IGuild guild = context.getClient().getGuildByID(guildID);
if (guild == null) {
throw new IllegalCmdArgumentException("Guild not found.");
}
String json = null;
if (splitArgs.size() == 1) {
DBGuild dbGuild = Database.getDBGuild(guild);
json = dbGuild.toJSON().toString(Config.JSON_INDENT_FACTOR);
} else if (splitArgs.size() == 2) {
Long userID = CastUtils.asPositiveLong(splitArgs.get(1));
if (userID == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid user ID.", splitArgs.get(0)));
}
DBUser dbUser = new DBUser(guild, userID);
json = dbUser.toJSON().toString(Config.JSON_INDENT_FACTOR);
}
if (json == null || json.length() == 2) {
BotUtils.sendMessage(Emoji.MAGNIFYING_GLASS + " Nothing found.", context.getChannel());
} else {
BotUtils.sendMessage(json, context.getChannel());
}
}
use of me.shadorc.shadbot.exception.MissingArgumentException in project Shadbot by Shadorc.
the class GenerateRelicCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
RelicType type = Utils.getValueOrNull(RelicType.class, context.getArg());
if (type == null) {
throw new IllegalCmdArgumentException(String.format("`%s`in not a valid type. %s", context.getArg(), FormatUtils.formatOptions(RelicType.class)));
}
Relic relic = PremiumManager.generateRelic(type);
BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " %s relic generated: **%s**", StringUtils.capitalize(type.toString()), relic.getRelicID()), context.getChannel());
}
use of me.shadorc.shadbot.exception.MissingArgumentException in project Shadbot by Shadorc.
the class SendMessageCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
List<String> splitArgs = StringUtils.split(context.getArg(), 2);
if (splitArgs.size() != 2) {
throw new MissingArgumentException();
}
Long userID = CastUtils.asPositiveLong(splitArgs.get(0));
if (userID == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid user ID.", splitArgs.get(0)));
}
IUser user = Shadbot.getClient().getUserByID(userID);
if (user == null) {
BotUtils.sendMessage(Emoji.GREY_EXCLAMATION + " User not found.", context.getChannel());
return;
}
if (user.equals(context.getOurUser())) {
throw new IllegalCmdArgumentException("I can't send a private message to myself.");
}
if (user.isBot()) {
throw new IllegalCmdArgumentException("I can't send private message to other bots.");
}
context.getClient().getOrCreatePMChannel(user).sendMessage(splitArgs.get(1));
BotUtils.sendMessage(Emoji.CHECK_MARK + " Message sent.", context.getChannel());
}
Aggregations