Search in sources :

Example 1 with WikiFetcher

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));
    }
}
Also used : CommandContext(toby.command.CommandContext) WikiFetcher(toby.helpers.WikiFetcher) Arrays(java.util.Arrays) List(java.util.List) UserDto(toby.jpa.dto.UserDto) ICommand(toby.command.ICommand) Cache(toby.helpers.Cache) IOException(java.io.IOException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) RandomCommand(toby.command.commands.misc.RandomCommand) TextChannel(net.dv8tion.jda.api.entities.TextChannel) WikiFetcher(toby.helpers.WikiFetcher) IOException(java.io.IOException)

Example 2 with WikiFetcher

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);
}
Also used : WikiFetcher(toby.helpers.WikiFetcher) Cache(toby.helpers.Cache) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with WikiFetcher

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);
}
Also used : WikiFetcher(toby.helpers.WikiFetcher) Cache(toby.helpers.Cache) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with WikiFetcher

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));
    }
}
Also used : CommandContext(toby.command.CommandContext) WikiFetcher(toby.helpers.WikiFetcher) Arrays(java.util.Arrays) List(java.util.List) UserDto(toby.jpa.dto.UserDto) ICommand(toby.command.ICommand) Cache(toby.helpers.Cache) IOException(java.io.IOException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) RandomCommand(toby.command.commands.misc.RandomCommand) TextChannel(net.dv8tion.jda.api.entities.TextChannel) WikiFetcher(toby.helpers.WikiFetcher) IOException(java.io.IOException)

Aggregations

Cache (toby.helpers.Cache)4 WikiFetcher (toby.helpers.WikiFetcher)4 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 List (java.util.List)2 TextChannel (net.dv8tion.jda.api.entities.TextChannel)2 Disabled (org.junit.jupiter.api.Disabled)2 Test (org.junit.jupiter.api.Test)2 CommandContext (toby.command.CommandContext)2 ICommand (toby.command.ICommand)2 RandomCommand (toby.command.commands.misc.RandomCommand)2 UserDto (toby.jpa.dto.UserDto)2