Merge branch 'master' into i18n

This commit is contained in:
Skidder 2020-03-14 21:43:55 +01:00 committed by GitHub
commit 6d766f9150
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 213 additions and 45 deletions

22
pom.xml
View file

@ -5,9 +5,19 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Hadder</groupId>
<artifactId>Hadder</artifactId>
<version>1.1.0</version>
<version>1.1.3</version>
<name>Hadder</name>
<inceptionYear>2019</inceptionYear>
<description>Hadder is a multi-purpose Discord bot.</description>
<url>https://github.com/BigBotNetwork/Hadder</url>
<licenses>
<license>
<name>GNU Affero General Public License v3.0</name>
<url>https://www.gnu.org/licenses/agpl-3.0.en.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -56,7 +66,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.1.1_108</version>
<version>4.1.1_113</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
@ -81,7 +91,7 @@
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.106</version>
<version>1.108</version>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
@ -91,7 +101,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.10.2</version>
<version>2.10.3</version>
</dependency>
</dependencies>
@ -132,7 +142,7 @@
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.8.2</version>
<version>3.9.0</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>

View file

@ -126,7 +126,9 @@ public class Hadder {
new EchoCommand(),
new ServerStatsCommand(),
new ProfileCommand(),
new CodeCommand()), config, helpCommand);
new CodeCommand(),
new MoveAllCommand(),
new CoronaCommand()), config, helpCommand);
builder.addEventListeners(
new MentionListener(rethink),

View file

@ -162,5 +162,4 @@ public class AudioManager {
s = s - (minutes * 60);
return (hours == 0 ? "" : hours + ":") + String.format("%02d", minutes) + ":" + String.format("%02d", s);
}
}

View file

@ -66,9 +66,7 @@ public class ClydeCommand implements Command {
}
webhook.delete().queue();
e.getMessage().delete().queue();
} else {
e.getTextChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.NO_SELF_PERMISSION).build()).queue();
}
} else e.getTextChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.NO_SELF_PERMISSION).build()).queue();
} else e.getHelpCommand().sendHelp(this, e);
}

View file

@ -16,7 +16,6 @@
package com.bbn.hadder.commands.general;
import com.bbn.hadder.Hadder;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor;
@ -32,8 +31,8 @@ public class InviteCommand implements Command {
"",
"commands.general.invite.success.description",
"(https://discordapp.com/oauth2/authorize?client_id="
+ Hadder.shardManager.getGuilds().get(0).getSelfMember().getId()
+ "&scope=bot&permissions=470133879)")
+ e.getJDA().getSelfUser().getId()
+ "&scope=bot&permissions=1043852663)")
.build()).queue();
}

View file

@ -0,0 +1,69 @@
/*
* Copyright 2019-2020 GregTCLTK and Schlauer-Hax
*
* Licensed under the GNU Affero General Public License, Version 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/agpl-3.0.en.html
*
* 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 com.bbn.hadder.commands.misc;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.json.JSONObject;
import java.io.IOException;
public class CoronaCommand implements Command {
@Override
public void executed(String[] args, CommandEvent e) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("https://api.covid.stream/latest/numbers").build();
try {
Response response = client.newCall(request).execute();
JSONObject json = new JSONObject(response.body().string()).getJSONObject("data");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("`Confirmed cases:` **").append(json.get("totalConfirmedNumbers")).append("**\n").append("`Deaths:` **").append(json.get("totalDeathNumbers")).append("** \n").append("`Recovered:` **").append(json.get("totalRecoveredNumbers")).append("** \n");
e.getTextChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.INFO).setDescription(stringBuilder).build()).queue();
} catch (IOException ex) {
e.getTextChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR)
.setTitle("API Error")
.setDescription("Try again later!")
.build()).queue();
}
}
@Override
public String[] labels() {
return new String[]{"corona"};
}
@Override
public String description() {
return "commands.misc.corona.help.description";
}
@Override
public String usage() {
return null;
}
@Override
public String example() {
return null;
}
}

View file

@ -54,12 +54,10 @@ public class GitHubCommand implements Command {
String website = "None";
try {
bio = json.getString("bio");
} catch (JSONException ignored) {
}
} catch (JSONException ignored) {}
try {
location = json.getString("location");
} catch (JSONException ignored) {
}
} catch (JSONException ignored) {}
if (!json.getString("blog").equals("")) website = json.getString("blog");

View file

@ -0,0 +1,60 @@
/*
* Copyright 2019-2020 GregTCLTK and Schlauer-Hax
*
* Licensed under the GNU Affero General Public License, Version 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/agpl-3.0.en.html
*
* 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 com.bbn.hadder.commands.misc;
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.core.Perm;
import com.bbn.hadder.core.Perms;
import com.bbn.hadder.utils.MessageEditor;
@Perms(Perm.VOICE_MOVE_OTHERS)
public class MoveAllCommand implements Command {
@Override
public void executed(String[] args, CommandEvent e) {
if (args.length == 2) {
int count = e.getGuild().getVoiceChannelById(args[0]).getMembers().size();
e.getGuild().getVoiceChannelById(args[0]).getMembers().forEach(
member -> e.getGuild().moveVoiceMember(member, e.getGuild().getVoiceChannelById(args[1])).queue()
);
e.getChannel().sendMessage(e.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.misc.moveall.success.title", "",
"commands.misc.moveall.success.description", String.valueOf(count))
.build()).queue();
} else e.getHelpCommand().sendHelp(this, e);
}
@Override
public String[] labels() {
return new String[]{"moveall", "move-all", "ma"};
}
@Override
public String description() {
return "commands.misc.moveall.help.description";
}
@Override
public String usage() {
return "[source-channel] [target-channel]";
}
@Override
public String example() {
return "452806287307046923 452858405212782623";
}
}

View file

@ -56,7 +56,7 @@ public class RulesCommand implements Command {
try {
TextChannel channel = e1.getGuild().getTextChannelsByName(e1.getMessage().getContentRaw(), true).get(0);
createRules(e, e1, channel);
} catch (NullPointerException ex) {
} catch (NullPointerException | IndexOutOfBoundsException ex) {
e.getTextChannel().sendMessage(
e.getMessageEditor().getMessage(
MessageEditor.MessageType.ERROR,

View file

@ -70,17 +70,22 @@ public class Config {
.key("Tokens").object()
.key("BotToken").value(null)
.key("Giphy").value(null)
.key("GitHub").value(null)
.key("MythicalBotList").value(null)
.key("BotsForDiscord").value(null)
.key("DiscordBotList").value(null)
.key("DiscordBestBots").value(null)
.key("DiscordBoats").value(null)
.key("YetAnotherBotList").value(null)
.value("DiscordExtremeList").value(null)
.value("DiscordBotReviews").value(null)
.value("DiscordBots").value(null)
.value("BotListSpace").value(null)
.endObject().endObject().toString();
.key("DiscordExtremeList").value(null)
.key("DiscordBotReviews").value(null)
.key("DiscordBots").value(null)
.key("BotListSpace").value(null)
.key("DiscordBots2").value(null)
.key("CloudList").value(null)
.key("Arcane").value(null)
.endObject()
.key("Clyde").value("Clyde")
.endObject().toString();
}
public String getBotToken() {
@ -143,10 +148,6 @@ public class Config {
return config.getJSONObject("Tokens").getString("DiscordExtremeList");
}
public String getDiscordBotReviewsToken() {
return config.getJSONObject("Tokens").getString("DiscordBotReviews");
}
public String getDiscordBotsToken() {
return config.getJSONObject("Tokens").getString("DiscordBots");
}
@ -163,6 +164,10 @@ public class Config {
return config.getJSONObject("Tokens").getString("CloudList");
}
public String getArcaneToken() {
return config.getJSONObject("Tokens").getString("Arcane");
}
public String getClydeName() {
return config.getString("Clyde");
}

View file

@ -74,6 +74,12 @@ public enum Perm {
public boolean check(CommandEvent e) {
return e.getMember().hasPermission(Permission.MANAGE_WEBHOOKS) || e.getConfig().getOwners().contains(e.getAuthor().getIdLong());
}
},
VOICE_MOVE_OTHERS {
@Override
public boolean check(CommandEvent e) {
return e.getMember().hasPermission(Permission.VOICE_MOVE_OTHERS) || e.getConfig().getOwners().contains(e.getAuthor().getIdLong());
}
};
public abstract boolean check(CommandEvent e);

View file

@ -25,6 +25,7 @@ import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import java.awt.*;
@ -64,6 +65,7 @@ public class CommandListener extends ListenerAdapter {
}
}
} else {
try {
e.getAuthor().openPrivateChannel().complete().sendMessage(new EmbedBuilder()
.setTitle("No permission")
.setDescription("I need the `MESSAGE EMBED LINKS` permission in order to work!")
@ -71,6 +73,9 @@ public class CommandListener extends ListenerAdapter {
.setFooter("Hadder", "https://bigbotnetwork.com/images/Hadder.png")
.setTimestamp(Instant.now())
.build()).queue();
} catch (ErrorResponseException ex) {
e.getTextChannel().sendMessage("I need the `MESSAGE EMBED LINKS` permission in order to work!").queue();
}
}
} else {
e.getAuthor().openPrivateChannel().complete().sendMessage(new EmbedBuilder()

View file

@ -50,7 +50,7 @@ public class MentionListener extends ListenerAdapter {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = null;
try {
model = reader.read(this.getClass().getClassLoader().getResourceAsStream("pom.xml"));
model = reader.read(getClass().getResourceAsStream("pom.xml"));
} catch (IOException | XmlPullParserException ex) {
ex.printStackTrace();
}

View file

@ -40,6 +40,7 @@ public class BotList {
private static String BotListSpace = "https://api.botlist.space/v1/bots/637002314162372639";
private static String DiscordBots2 = "https://discord.bots.gg/api/v1/bots/637002314162372639/stats";
private static String CloudList = "https://www.cloudlist.xyz/api/stats/637002314162372639";
private static String ArcaneBotCenter = "https://arcane-botcenter.xyz/api/637002314162372639/stats";
private Config config;
@ -57,6 +58,7 @@ public class BotList {
json.put("users", Hadder.shardManager.getUsers().size());
json.put("shard_count", Hadder.shardManager.getShards().size());
json.put("shardCount", Hadder.shardManager.getShards().size());
json.put("member_count", Hadder.shardManager.getUsers().size());
RequestBody body = RequestBody.create(MediaType.parse("application/json"), json.toString());
@ -209,6 +211,21 @@ public class BotList {
} catch (IOException e) {
e.printStackTrace();
}
// Arcane Bot Center
Request arcane = new Request.Builder()
.url(ArcaneBotCenter)
.post(body)
.addHeader("Authorization", config.getArcaneToken())
.build();
try {
new OkHttpClient().newCall(arcane).execute().close();
System.out.println("Successfully posted count to the Arcane Bot Center!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}