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

Commit

Permalink
added botstats command, updated waframe alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
zekroTJA committed Jul 5, 2017
1 parent 03e2f63 commit 4b0e399
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 3 deletions.
Binary file not shown.
15 changes: 13 additions & 2 deletions src/main/java/commands/administration/Stop.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package commands.administration;

import commands.Command;
import commands.etc.BotStats;
import core.Perms;
import core.coreCommands;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import utils.STATICS;

import java.io.IOException;
import java.text.ParseException;
import java.util.Timer;
import java.util.TimerTask;

/**
* Created by zekro on 23.03.2017 / 21:13
Expand All @@ -27,8 +30,16 @@ public void action(String[] args, MessageReceivedEvent event) throws ParseExcept

if (!Perms.isOwner(event.getAuthor(), event.getTextChannel())) return;

event.getTextChannel().sendMessage(":warning: :mobile_phone_off: " + event.getAuthor().getAsMention() + " shut down " + event.getJDA().getSelfUser().getAsMention() + " because of maintenance or an unexpected behavior.").queue();
System.exit(0);
BotStats.save();

//event.getTextChannel().sendMessage(":warning: :mobile_phone_off: " + event.getAuthor().getAsMention() + " shut down " + event.getJDA().getSelfUser().getAsMention() + " because of maintenance or an unexpected behavior.").queue();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
System.exit(0);
}
}, 1000);

}

@Override
Expand Down
136 changes: 136 additions & 0 deletions src/main/java/commands/etc/BotStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package commands.etc;

import com.moandjiezana.toml.TomlWriter;
import commands.Command;
import core.Main;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import utils.STATICS;

import java.awt.*;
import java.io.*;
import java.text.ParseException;

/**
* Created by zekro on 05.07.2017 / 20:53
* DiscordBot.commands.etc
* dev.zekro.de - github.zekro.de
* © zekro 2017
*/


public class BotStats implements Command {

static File f = new File("botstatics.donotdelete");

public static long messagesProcessed = 0;
public static long commandsExecuted = 0;

private int membersDeserving = 0;

public static void save() {

if (!f.exists())
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}

try {

BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write(messagesProcessed + "\n" + commandsExecuted);
bw.close();

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

}

public static long[] stats() {

if (!f.exists())
return new long[] {0, 0};

try {

BufferedReader br = new BufferedReader(new FileReader(f));
return new long[] {Long.parseLong(br.readLine()), Long.parseLong(br.readLine())};

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return new long[] {0, 0};
}

public static void load() {
messagesProcessed = stats()[0];
commandsExecuted = stats()[1];
}

private void countUpMembers() {
membersDeserving++;
}


@Override
public boolean called(String[] args, MessageReceivedEvent event) {
return false;
}

@Override
public void action(String[] args, MessageReceivedEvent event) throws ParseException, IOException {

int commandsSize = Main.commands.size();
int serversRunning = event.getJDA().getGuilds().size();

event.getJDA().getGuilds().forEach(g -> g.getMembers().forEach(m -> countUpMembers()));

event.getTextChannel().sendMessage(
new EmbedBuilder()
.setColor(Color.cyan)
.setDescription(
"**zekroBot STATS**\n\n" +
"```\n" +
"Registered commands: " + commandsSize + "\n" +
"Running on servers: " + serversRunning + "\n" +
"Deserving members: " + membersDeserving + "\n" +
"Messages processed: " + messagesProcessed + "\n" +
"Commands executed: " + commandsExecuted + "\n" +
"```"
).build()
).queue();

membersDeserving = 0;

}

@Override
public void executed(boolean success, MessageReceivedEvent event) {

}

@Override
public String help() {
return null;
}

@Override
public String description() {
return null;
}

@Override
public String commandType() {
return STATICS.CMDTYPE.etc;
}

@Override
public int permission() {
return 0;
}
}
4 changes: 4 additions & 0 deletions src/main/java/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static void main(String[] args) throws IOException {

settings.loadSettings();

BotStats.load();

try {
if (!settings.testForToken()) {
System.out.println("[ERROR] PLEASE ENTER YOUR DISCORD API TOKEN FROM 'https://discordapp.com/developers/applications/me' IN THE TEXTFILE 'SETTINGS.txt' AND RESTART!");
Expand Down Expand Up @@ -136,6 +138,7 @@ public static void initializeCommands() {
commands.put("bug", new Bug());
commands.put("suggestion", new Bug());
commands.put("spacer", new Spacer());
commands.put("botstats", new BotStats());

}

Expand All @@ -157,6 +160,7 @@ public static void handleCommand(CommandParser.CommandContainer cmd) throws Pars

if (commands.containsKey(cmd.invoke)) {

BotStats.commandsExecuted++;
boolean safe = commands.get(cmd.invoke).called(cmd.args, cmd.event);

if (!safe) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/listeners/botListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package listeners;

import commands.etc.BotStats;
import commands.etc.CmdLog;
import core.Main;
import core.SSSS;
Expand All @@ -25,6 +26,8 @@ public class botListener extends ListenerAdapter{
@Override
public void onMessageReceived(MessageReceivedEvent e) {

BotStats.messagesProcessed++;

if (e.getChannelType().equals(ChannelType.PRIVATE)) return;

if (e.getMessage().getContent().startsWith(SSSS.getPREFIX(e.getGuild())) && e.getMessage().getAuthor().getId() != e.getJDA().getSelfUser().getId()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/utils/STATICS.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class STATICS {
//######### GENERAL BOT SETTINGS #########//


public static String VERSION = "1.31.1.0";
public static String VERSION = "1.32.0.0";
public static String THISBUILD = BUILDTYPE.STABLE;

public static class BUILDTYPE {
Expand Down

0 comments on commit 4b0e399

Please sign in to comment.