/
MyAnimeListCommand.java
99 lines (88 loc) · 3.02 KB
/
MyAnimeListCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Copyright 2015-2016 Austin Keener
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dv8tion.discord.commands;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.dv8tion.discord.util.Downloader;
import net.dv8tion.discord.util.GoogleSearch;
import net.dv8tion.jda.events.message.MessageReceivedEvent;
import org.apache.commons.lang3.StringUtils;
public class MyAnimeListCommand extends Command
{
public static final String ANIME_URL = "http://myanimelist.net/anime/";
public static final String MANGA_URL = "http://myanimelist.net/manga/";
public static final String CHARACTER_URL = "http://myanimelist.net/character/";
@Override
public void onCommand(MessageReceivedEvent e, String[] args)
{
GoogleSearch search = new GoogleSearch(
String.format("%s+%s",
StringUtils.join(args, "+", 1, args.length),
"site:myanimelist.net"));
sendMessage(e, search.getSuggestedReturn());
}
@Override
public List<String> getAliases()
{
return Arrays.asList(".mal");
}
@Override
public String getDescription()
{
return "Searches the <http://myanimelist.net> anime/manga database for anime and manga.";
}
@Override
public String getName()
{
return "MyAnimeList Search";
}
@Override
public List<String> getUsageInstructions()
{
return Collections.singletonList(
".mal *<search terms>*\n"
+ "__Example:__ .mal sao\n"
+ " - This will return the entry for Sword Art Online.\n"
+ "__Example 2:__ .mal magi kingdom of magic\n"
+ " - This will return the entry for Magi - The Kingdom of Magic.");
}
@SuppressWarnings("unused")
private String handleSearch(GoogleSearch search)
{
String url = search.getUrl(0);
if (url.contains(ANIME_URL))
{
System.out.println("this is anime");
String webpage = Downloader.webpage("http://myanimelist.net/manga/75989/");
System.out.println(webpage);
}
else if (url.contains(MANGA_URL))
{
System.out.println("this is manga");
String webpage = Downloader.webpage(url);
System.out.println(webpage);
}
else if (url.contains(CHARACTER_URL))
{
System.out.println("this is character");
}
else
{
}
return null;
}
}