Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Commit

Permalink
Merge branch 'dev' of https://github.com/zekroTJA/DiscordBot into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ゼクロ committed Sep 11, 2017
2 parents fbd016c + 6d2f118 commit ab42b0b
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 136 deletions.
5 changes: 5 additions & 0 deletions CMDLOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@
[15.08.2017 - 01:12:10] [Developing Test Server (287535046762561536)] [zekro (221905671296253953)] '.ping'
[15.08.2017 - 01:12:57] [Developing Test Server (287535046762561536)] [zekro (221905671296253953)] '.ping'
[15.08.2017 - 01:16:30] [Developing Test Server (287535046762561536)] [zekro (221905671296253953)] '.ping'
[15.08.2017 - 13:19:14] [Developing Test Server (287535046762561536)] [zekro (221905671296253953)] '.update'
[15.08.2017 - 13:20:41] [Developing Test Server (287535046762561536)] [zekro (221905671296253953)] '.update'
[15.08.2017 - 13:21:00] [Developing Test Server (287535046762561536)] [zekro (221905671296253953)] '.update'
[15.08.2017 - 13:22:25] [Developing Test Server (287535046762561536)] [zekro (221905671296253953)] '.update'
[15.08.2017 - 13:22:47] [Developing Test Server (287535046762561536)] [zekro (221905671296253953)] '.update'
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2017 zekro Development
Copyright 2017 Ringo Hoffmann (zekro Development)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
56 changes: 33 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,52 @@
[![GitHub release](https://img.shields.io/github/release/zekrotja/DiscordBot.svg)](https://github.com/zekroTJA/DiscordBot/releases) 
[![GitHub (pre-)release](https://img.shields.io/github/release/zekrotja/DiscordBot/all.svg)](https://github.com/zekroTJA/DiscordBot/releases) 
<a href="https://discordapp.com/oauth2/authorize?client_id=272336949841362944&scope=bot&permissions=1882582134">
<img src="https://img.shields.io/badge/currently%20running%20on-1.32.2.0-3cd0d8.svg"></a><br>
<img src="https://img.shields.io/badge/currently%20running%20on-1.38.2.0-3cd0d8.svg"></a><br>

-----

If you want to use the code of this project for your own ones, please read **[this](http://s.zekro.de/codepolicy)** before!

So you have some questions or want to join my developer community discord? Take a look! :^)
<br/><a href="http://discord.zekro.de"><img src="https://discordapp.com/api/guilds/307084334198816769/embed.png"/></a>

-----
### Get it!
<img src="https://img.shields.io/badge/Status-up-green.svg">&nbsp;<img src="https://img.shields.io/badge/Server%20Capacity-24%2F25-3cc482.svg"><br>
<img src="https://img.shields.io/badge/Server%20Capacity-32%2F250-3cc482.svg"><br>
<a href="https://discordapp.com/oauth2/authorize?client_id=272336949841362944&scope=bot&permissions=1882582134"><img src="https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/add_to_discord.png?raw=true" width="300"/></a>

> INFO: Because of my low end vServer the bot is running on, there is currently a limited server capacity depending on current demand.
-----
### Features

- **Server administration** </br> Typical commands like `-kick`, `-vkick` (voice channel kick), `-clear` and some more!

- **Fun commands** </br> Chat commands like `-vote`, `-8ball` (yes/no - generator), `-cat` (also with the feature to spam cats in a defined period of time with command `-cat spam <time>`) and some server info commands like `-userinfo` or `-stats` (Server statistics)
</br><img src="http://image.prntscr.com/image/755bdfce30de4ea8bd40d174d77a53f5.png"/>

- **Warframe alerts** </br> Create a text channel where the bot will post warframe alerts in (name of channel defined in SETTINGS.txt). You can also enter there the ID of a public google docs document where you can enter item filters for the alerts.
</br><img src="http://image.prntscr.com/image/cc2e323ef8c04123971062fcbe493024.png"/>

- **Voicelog** </br> Do you want to have a nice voice channel log like in teamspeak chat? So just create a text channel (name definable in SETTINGS.txt) and the bot will log all voice channel activity in that channel.
</br><img src="http://image.prntscr.com/image/2aef2f6f55de4aaaa806fe2fbf57988d.png"/>

- **Music** </br> Yay! Now you can also play msuic with the command `-music play <yt-url>` (or `-m play <yt-url>`)! Get more information about in in commands document or use `-music help`.

- **TTT Server Listener** </br> You can enter your Gmod Server IP and port in the settings file to auto send a message when the server is online for members. Also usable with command `-tttserver`.
```
Here are just listed some of the various functions and 57 commands of the bot.
```
**Here you can find a full list of commands:**<br><br>
<a href="https://docs.google.com/spreadsheets/d/1vDsZgn49s6D1OCfyJE0aAixgbMfHb1n6ybHPG8g2Ing/edit?usp=sharing" target="_blank"><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/1033926355/original/GoogleSheets.png" width="150"/></a><br><br>

- **Fun / Chat commands**
- `-8ball` - typical 8ball yes/no generator
- `-cat` - send cute cat pictures (also with a spam function to send them in time periods)
- `-clear` - typical clear command to clear messages
- `-joke` - throw a yomama joke :^)
- `-quote` - quote messages from channels on the guild<br>
&nbsp;![](https://image.prntscr.com/image/g3-ctAYBSlu1eS9qoFTSSQ.png)
- `-stups` - nudge someone on the guild
- `-vote` - create polls<br>
&nbsp;![](https://image.prntscr.com/image/5_avzZNQRUijY2rUgc1XgQ.png)


- **Server administration**
- `-kick` - kick someone from the server
- `-vkick` - kick someone out of the voice channel, also for a specific time period
- `-mute` - mute members in text channels
- `-blacklist` - disallow users to use the bot

- **Other functions**
- `-music` - Music player with many functions
- `-scpacer` - Create spacer voice channels wich can not be joined
- `-rand6` - Random operators for rainbow six<br>
&nbsp;![](https://image.prntscr.com/image/WHZh5l76TKupvWUmoIQBpA.png)

-----
### Installation
Expand Down Expand Up @@ -74,11 +89,6 @@ sudo screen -L -S zekroBot sudo java -jar DiscordBot.jar
After that, use the guild settings commands to configure the bot for your guild(s)
![img](https://image.prntscr.com/image/VKw6mpxPS8in40ZB4sTOMQ.png)

-----
### Commands

<a href="https://docs.google.com/spreadsheets/d/1vDsZgn49s6D1OCfyJE0aAixgbMfHb1n6ybHPG8g2Ing/edit?usp=sharing" target="_blank"><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/1033926355/original/GoogleSheets.png" width="200"/></a>

-----
### Latest Changelogs

Expand Down
6 changes: 3 additions & 3 deletions SETTINGS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# GENERAL SERVER SETTINGS #

# Enter here your Discord API Token you'll get from here: https://discordapp.com/developers/applications/me
TOKEN = "Mjg3NTM4NDM1NjU1MjA0ODY0.DHG07g.UN_vBfvOF-LA52-3JxEhSLWOKAY"
TOKEN = "##############"
# Prefix to send bot commands (like -help or ~help or .help, what ever you want)
CMD_PREFIX = "."

BOT_OWNER_ID = 221905671296253953
# ID of your discord account to identify who is the owner / host of this bot
BOT_OWNER_ID = 123456789013370420
# Custom message shown as "Now Playing: ..." text
CUSTOM_PLAYING_MESSAGE = "???"
# Log entered command in console of the bot
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/commands/essentials/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ public void action(String[] args, MessageReceivedEvent event) {
String version = "NOT AVAILABLE";
try {

URL url = new URL(UpdateClient.versionURL);
Scanner s = new Scanner(url.openStream());
version = s.nextLine();
//URL url = new URL(UpdateClient.versionURL);
//Scanner s = new Scanner(url.openStream());
version = "null"; //s.nextLine();

} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static void initializeCommands() {
commands.put("user", new UserInfo());
commands.put("nudge", new Stups());
commands.put("stups", new Stups());
commands.put("UpdateClient", new Update());
commands.put("update", new Update());
commands.put("restart", new Restart());
commands.put("kick", new Kick());
commands.put("vkick", new VoiceKick());
Expand Down
168 changes: 69 additions & 99 deletions src/main/java/core/UpdateClient.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package core;

import com.sun.org.apache.xpath.internal.SourceTree;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.Channel;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.PrivateChannel;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.events.ReadyEvent;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import utils.Logger;
import utils.STATICS;

import java.awt.*;
Expand All @@ -17,6 +21,7 @@
import java.net.URL;
import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Created by zekro on 22.03.2017 / 15:59
Expand All @@ -29,134 +34,99 @@ public class UpdateClient {

private static String lastUpdate = "";

public static String versionURL = "https://raw.githubusercontent.com/zekroTJA/DiscordBot/master/LATESTVERSION.txt";
private static final String API_URL = "https://api.github.com/repos/zekrotja/DiscordBot/releases";

private static HashMap<String, Map.Entry<String, String>> getVersionInfo() throws IOException {
private static final Release PRE = new Release(getRelease(true));
private static final Release STABLE = new Release(getRelease(false));

String API_URL = "https://api.github.com/repos/zekrotja/DiscordBot/releases";
static class Release {

HashMap<String, Map.Entry<String, String>> out = new HashMap<>();
private String tag;
private String url;

URL url = new URL(API_URL);
Scanner s = new Scanner(url.openStream());
String output = "";
while (s.hasNextLine()) {
output += s.nextLine();
private Release(JSONObject object) {
tag = object.getString("tag_name");
url = object.getString("html_url");
}

try {

JSONArray jsonarray = new JSONArray(output);

List<JSONObject> jsonobs = new ArrayList<>();
for (int i = 0; i < jsonarray.length(); i++) {
jsonobs.add(jsonarray.getJSONObject(i));
}


JSONObject pre = jsonobs.stream().filter(j -> {
try {
return j.getBoolean("prerelease");
} catch (JSONException e) {
e.printStackTrace();
return false;
}
}).findFirst().orElse(null);

JSONObject stable = jsonobs.stream().filter(j -> {
try {
return !j.getBoolean("prerelease");
} catch (JSONException e) {
return false;
}
}).findFirst().orElse(null);


out.put("pre", new AbstractMap.SimpleEntry<>(pre.getString("tag_name"), pre.getString("html_url")));
out.put("stable", new AbstractMap.SimpleEntry<>(stable.getString("tag_name"), stable.getString("html_url")));

}

private static JSONObject getRelease(boolean prerelease) {

} catch (JSONException e) {
Scanner sc;
try {
sc = new Scanner(new URL(API_URL).openStream());
} catch (IOException e) {
e.printStackTrace();
return null;
}

return out;
}
StringBuilder output = new StringBuilder();
sc.forEachRemaining(output::append);

public static void manualCheck(TextChannel channel) {
JSONArray jsonarray = new JSONArray(output.toString());

try {

if (!getVersionInfo().get("pre").getKey().equals(STATICS.VERSION)) {
List<JSONObject> jsonobs = new ArrayList<>();
for (int i = 0; i < jsonarray.length(); i++)
jsonobs.add(jsonarray.getJSONObject(i));

if ( STATICS.BOT_OWNER_ID != 0) {

channel.sendMessage(
new EmbedBuilder()
.setColor(new Color(0x7EFF00))
.setDescription(
"**New bot UpdateClient is available!**\n" +
"Download the latest version and install it manually on your vServer.\n\n" +
"You are currently running on version: **" + STATICS.VERSION + "**\n\n")
.addField("Latest Prerelease Build", "Version: " + getVersionInfo().get("pre").getKey() + "\nDownload: " + getVersionInfo().get("pre").getValue(), false)
.addField("Latest Stable Build", "Version: " + getVersionInfo().get("stable").getKey() + "\nDownload: " + getVersionInfo().get("stable").getValue(), false)
.setFooter("Enter '-disable' to disable this message on new updates.", null)
.build()
).queue();
return jsonobs.stream().filter(o -> {
try {
return prerelease == o.getBoolean("prerelease");
} catch (JSONException e) {
return false;
}
}).findFirst().orElse(null);

}
} else {
}

channel.sendMessage(new EmbedBuilder().setColor(Color.green)
.setDescription("The bot is currently up to date!")
.build()
).queue();
public static void manualCheck(TextChannel channel) {

}
if (isUdate())
sendUpdateMsg(channel);
else
channel.sendMessage(new EmbedBuilder().setColor(Color.green).setDescription("Your bor version is up to date!").build()).queue();

} catch (IOException e) {
e.printStackTrace();
}

}

private static boolean isUdate() {
return !PRE.tag.equals(STATICS.VERSION);
}

public static boolean checkIfUpdate(JDA jda) {

if (new File("SERVER_SETTINGS/no_update_info").exists())
return false;
private static void sendUpdateMsg(Object channel) {
EmbedBuilder eb = new EmbedBuilder()
.setColor(Color.cyan)
.setTitle("New bot update is available!")
.setDescription("Download the latest version and install it manually on your vServer.\n\n**Current version: ** `" + STATICS.VERSION + "`")
.addField("Latest Pre Release Build", String.format(
"Version: `%s`\n" +
"Download & Changelogs: [GitHub Release](%s)\n", PRE.tag, PRE.url
), false)
.addField("Latest Stable Release Build", String.format(
"Version: `%s`\n" +
"Download & Changelogs: [GitHub Release](%s)\n", STABLE.tag, STABLE.url
), false)
.setFooter("Enter '-disable' to disable this message on new updates.", null);

try {
TextChannel tc = (TextChannel) channel;
tc.sendMessage(eb.build()).queue();
} catch (Exception e) {
PrivateChannel pc = (PrivateChannel) channel;
pc.sendMessage(eb.build()).queue();
}

if (!getVersionInfo().get("pre").getKey().equals(STATICS.VERSION) && !lastUpdate.equals(getVersionInfo().get("pre").getKey())) {
lastUpdate = getVersionInfo().get("pre").getKey();

if (STATICS.BOT_OWNER_ID != 0) {

jda.getUserById(STATICS.BOT_OWNER_ID).openPrivateChannel().complete().sendMessage(
new EmbedBuilder()
.setColor(new Color(0x7EFF00))
.setDescription(
"**New bot UpdateClient is available!**\n" +
"Download the latest version and install it manually on your vServer.\n\n" +
"You are currently running on version: **" + STATICS.VERSION + "**\n\n")
.addField("Latest Prerelease Build", "Version: " + getVersionInfo().get("pre").getKey() + "\nDownload: " + getVersionInfo().get("pre").getValue(), false)
.addField("Latest Stable Build", "Version: " + getVersionInfo().get("stable").getKey() + "\nDownload: " + getVersionInfo().get("stable").getValue(), false)
.setFooter("Enter '-disable' to disable this message on new updates.", null)
.build()
).queue();

}
}

return true;
}
public static void checkIfUpdate(JDA jda) {

} catch (IOException e) {
e.printStackTrace();
if (new File("SERVER_SETTINGS/no_update_info").exists())
return;

if (STATICS.BOT_OWNER_ID != 0 && isUdate()) {
jda.getUserById(STATICS.BOT_OWNER_ID).openPrivateChannel().queue(c -> sendUpdateMsg(c));
}

return false;
}
}
6 changes: 3 additions & 3 deletions src/main/java/utils/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class Logger {
public static String Underline = (char)27 + "[4m";
public static String StopUnderline = (char)27 + "[24m";

public static void ERROR(String message) { System.out.println(Red + message + Reset); }
public static void DEBUG(String message) { System.out.println(Cyan + message + Reset); }
public static void SUCCESS(String message) { System.out.println(Green + message + Reset); }
public static void ERROR(Object message) { System.out.println(Red + message.toString() + Reset); }
public static void DEBUG(Object message) { System.out.println(Cyan + message.toString() + Reset); }
public static void SUCCESS(Object message) { System.out.println(Green + message.toString() + Reset); }

}

0 comments on commit ab42b0b

Please sign in to comment.