use of toby.helpers.WikiFetcher in project toby-bot by ml404.
the class DbdRandomKillerCommand method handle.
@Override
@SuppressWarnings("unchecked")
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
final TextChannel channel = ctx.getChannel();
try {
WikiFetcher wikiFetcher = new WikiFetcher(cache);
List<String> dbdKillers = wikiFetcher.fetchFromWiki(cacheName, dbdWebUrl, className, cssQuery);
channel.sendMessage(RandomCommand.getRandomElement(dbdKillers)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
} catch (IOException ignored) {
channel.sendMessage("Huh, the website I pull data from must have returned something unexpected.").queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
}
use of toby.helpers.WikiFetcher in project toby-bot by ml404.
the class WikiFetcherTest method testDeadByDaylightKillerFetcher.
@Test
@Disabled
public void testDeadByDaylightKillerFetcher() throws Exception {
final String dbdWebUrl = "https://deadbydaylight.fandom.com/wiki/Killers";
final String cacheName = "dbdKillers";
final String className = "mw-content-ltr";
final String cssQuery = "<div style=\"color: #fff;\">";
var cache = new Cache(86400, 3600, 2);
WikiFetcher wikiFetcher = new WikiFetcher(cache);
List<String> mapStrings = wikiFetcher.fetchFromWiki(cacheName, dbdWebUrl, className, cssQuery);
assertNotNull(mapStrings);
assertEquals(mapStrings.size(), 26);
}
use of toby.helpers.WikiFetcher in project toby-bot by ml404.
the class WikiFetcherTest method testKf2WikiFetcher.
@Test
@Disabled
public void testKf2WikiFetcher() throws Exception {
final String kf2WebUrl = "https://wiki.killingfloor2.com/index.php?title=Maps_(Killing_Floor_2)";
final String cacheName = "kf2Maps";
final String className = "mw-parser-output";
var cache = new Cache(86400, 3600, 2);
WikiFetcher wikiFetcher = new WikiFetcher(cache);
List<String> mapStrings = wikiFetcher.fetchFromWiki(cacheName, kf2WebUrl, className, "b");
assertNotNull(mapStrings);
assertEquals(mapStrings.size(), 35);
}
use of toby.helpers.WikiFetcher in project toby-bot by ml404.
the class Kf2RandomMapCommand method handle.
@Override
@SuppressWarnings("unchecked")
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
final TextChannel channel = ctx.getChannel();
try {
WikiFetcher wikiFetcher = new WikiFetcher(cache);
List<String> kf2Maps = wikiFetcher.fetchFromWiki(cacheName, kf2WebUrl, className, "b");
channel.sendMessage(RandomCommand.getRandomElement(kf2Maps)).queue(message -> ICommand.deleteAfter(message, deleteDelay));
} catch (IOException ignored) {
channel.sendMessage("Huh, the website I pull data from must have returned something unexpected.").queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
}
Aggregations