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

Commit

Permalink
Trying to center.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZastrixArundell committed Aug 12, 2019
1 parent e1bca10 commit 2d2c961
Show file tree
Hide file tree
Showing 12 changed files with 412 additions and 142 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

### 5.4.0
- Added **_vote_** command.
- Added discord bot list api.
- Added support for multiple dye images.

### 5.3.6
- Added the StatusImage object, will need to add a
RESTful api in order to use it, most likely will use
spring boot for this.

### 5.3.5
- Renamed bot and changes some picture URLs.

Expand Down
21 changes: 19 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

<groupId>com.gmail.zastrixarundell</groupId>
<artifactId>ToramBot</artifactId>
<version>5.3.5</version>
<version>5.4.0</version>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
Expand Down Expand Up @@ -34,7 +41,17 @@
<version>2.10.3</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.discordbots</groupId>
<artifactId>DBL-Java-Library</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.github.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
<scope>compile</scope>
</dependency>
</dependencies>


Expand Down
196 changes: 128 additions & 68 deletions src/main/java/com/github/zastrixarundell/torambot/ToramBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
import com.github.zastrixarundell.torambot.commands.search.items.gear.ShieldCommand;
import com.github.zastrixarundell.torambot.commands.search.items.gear.SpecialCommand;

import com.github.zastrixarundell.torambot.commands.torambot.VoteCommand;
import com.github.zastrixarundell.torambot.entities.ToramForumsUser;
import com.github.zastrixarundell.torambot.utils.AESHelper;
import org.discordbots.api.client.DiscordBotListAPI;
import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import org.javacord.api.entity.server.Server;
Expand All @@ -41,7 +44,7 @@ public static void main(String[] args)
if(args.length == 0)
{
System.out.println("The token is not specified... shutting down!");
return;
System.exit(-1);
}

if(args.length > 1) { Values.setPrefix(args[1]); }
Expand All @@ -64,53 +67,14 @@ public static void main(String[] args)

bot.updateActivity("Starting up! Please wait!");

//Crafting
bot.addListener(new ProficiencyCommand());
bot.addListener(new CookingCommand());
bot.addListener(new MatsCommand());
updateCount(bot);
addCommands(bot);

//items
bot.addListener(new ItemCommand());
bot.addListener(new AdditionalCommand());
bot.addListener(new ArmorCommand());
bot.addListener(new ArrowCommand());
bot.addListener(new BowCommand());
bot.addListener(new BowGunCommand());
bot.addListener(new DaggerCommand());
bot.addListener(new GemCommand());
bot.addListener(new HalberdCommand());
bot.addListener(new KatanaCommand());
bot.addListener(new KnucklesCommand());
bot.addListener(new MagicDeviceCommand());
bot.addListener(new OneHandedSwordCommand());
bot.addListener(new ShieldCommand());
bot.addListener(new SpecialCommand());
bot.addListener(new StaffCommand());
bot.addListener(new TwoHandedSwordCommand());
bot.addListener(new XtalCommand());
bot.addListener(new UpgradeCommand());
//vote command is here
setupDiscordBotListApi(bot);

//monsters
bot.addListener(new MonsterCommand());
bot.addListener(new NormalMonsterComand());
bot.addListener(new MiniBossCommand());
bot.addListener(new BossCommand());

//player
bot.addListener(new LevelCommand());
bot.addListener(new PointsCommand());

//torambot
bot.addListener(new HelpCommand());
bot.addListener(new InviteCommand());
bot.addListener(new DonateCommand());
bot.addListener(new SupportCommand());

//gameinfo
bot.addListener(new NewsCommand());
bot.addListener(new LatestCommand());
bot.addListener(new MaintenanceCommand());
bot.addListener(new EventsCommand());
//Just to refresh
updateCount(bot);

System.out.println("Started! Type in \"stop\" to stop the bot!");

Expand All @@ -129,7 +93,7 @@ public static void main(String[] args)
bot.disconnect();
activity.cancel();
dyeImage.cancel();
return;
System.exit(0);
}
}
}
Expand All @@ -145,34 +109,27 @@ private static Timer updateActivity(DiscordApi bot)
@Override
public void run()
{
updateCount(bot);

if(Values.getApi() != null)
Values.getApi().setStats(bot.getServers().size());

switch(status)
{
case 0:

List<String> doNotCheckThese =Arrays.asList
(
"264445053596991498",
"446425626988249089"
);

long userCount = 0;

for (Server server : bot.getServers())
if(!doNotCheckThese.contains(server.getIdAsString()))
for (User user : server.getMembers())
if (!user.isBot())
userCount++;

bot.updateActivity(Values.getPrefix() + "help | " + userCount + " users!");
bot.updateActivity(Values.getPrefix() + "help | " + Values.getUserCount() + " users!");
break;
case 1:
bot.updateActivity(Values.getPrefix() + "invite | " + bot.getServers().size() + " servers!");
bot.updateActivity(Values.getPrefix() + "invite | " + Values.getGuildCount() + " servers!");
break;
case 2:
Values.getApi().getBot("600302983305101323").whenComplete((bot1, throwable) -> bot.updateActivity(Values.getPrefix() + "vote | " + bot1.getMonthlyPoints() + " votes this month!"));
}

status ++;
status = status % 2;
status = status % (Values.getApi() != null ? 3 : 2);

System.gc();
}
};

Expand All @@ -190,14 +147,16 @@ public void run()
{
try
{
System.out.println("Starting dye!");
System.out.println("Starting user!");
ToramForumsUser user = new ToramForumsUser(token);
System.out.println("Starting dye!");
user.setDye();
System.out.println("Finished dye!");
user.close();

if(Values.getDyeImage() == null)
if(Values.getDyeImages() == null)
{
System.out.println("An error happened while updating the dye data!");
System.out.println("There are no dyes!");

if(DyeCommand.instance != null)
{
Expand All @@ -214,6 +173,7 @@ public void run()
}
catch (Exception e)
{
Values.setDyeImages(null);
System.out.println("An error happened while updating the dye data!");
e.printStackTrace();

Expand All @@ -223,11 +183,111 @@ public void run()
DyeCommand.instance = null;
}
}

System.gc();
}
};

timer.schedule(task,0, 250*60*60*24);
return timer;
}

private static void updateCount(DiscordApi bot)
{
List<String> doNotCheckThese =Arrays.asList
(
"264445053596991498",
"446425626988249089"
);

int userCount = 0;

for (Server server : bot.getServers())
if(!doNotCheckThese.contains(server.getIdAsString()))
for (User user : server.getMembers())
if (!user.isBot())
userCount++;

Values.setUserCount(userCount);

Values.setGuildCount(bot.getServers().size());

Values.setCommandCount(bot.getListeners().size());
}

private static void addCommands(DiscordApi bot)
{
//Crafting
bot.addListener(new ProficiencyCommand());
bot.addListener(new CookingCommand());
bot.addListener(new MatsCommand());

//items
bot.addListener(new ItemCommand());
bot.addListener(new AdditionalCommand());
bot.addListener(new ArmorCommand());
bot.addListener(new ArrowCommand());
bot.addListener(new BowCommand());
bot.addListener(new BowGunCommand());
bot.addListener(new DaggerCommand());
bot.addListener(new GemCommand());
bot.addListener(new HalberdCommand());
bot.addListener(new KatanaCommand());
bot.addListener(new KnucklesCommand());
bot.addListener(new MagicDeviceCommand());
bot.addListener(new OneHandedSwordCommand());
bot.addListener(new ShieldCommand());
bot.addListener(new SpecialCommand());
bot.addListener(new StaffCommand());
bot.addListener(new TwoHandedSwordCommand());
bot.addListener(new XtalCommand());
bot.addListener(new UpgradeCommand());

//monsters
bot.addListener(new MonsterCommand());
bot.addListener(new NormalMonsterComand());
bot.addListener(new MiniBossCommand());
bot.addListener(new BossCommand());

//player
bot.addListener(new LevelCommand());
bot.addListener(new PointsCommand());

//torambot
bot.addListener(new HelpCommand());
bot.addListener(new InviteCommand());
bot.addListener(new DonateCommand());
bot.addListener(new SupportCommand());

//gameinfo
bot.addListener(new NewsCommand());
bot.addListener(new LatestCommand());
bot.addListener(new MaintenanceCommand());
bot.addListener(new EventsCommand());
}

private static void setupDiscordBotListApi(DiscordApi bot)
{
try
{
AESHelper aesHelper = new AESHelper(bot.getToken());
String token = aesHelper.decryptData("OjImYbN/dPbEBjjxc+X5sjV5dHC+lU95tnSXwpt2PmQlJXwaXgBRAwdpZtmAGmkYEuu5PU+GMD/+RFibTqrM0367bNnkEE2Hrr77BtP7zyvXocbkRW8G0BRedaLf3EMndt0G/39av7zbWCo2RVYQ99LYhzG8gXWbfd04pJtd6JaXILD0Z3VBfElICQm7D/lS/WufLRG7n2YZsC+jrURXfg==");

DiscordBotListAPI api = new DiscordBotListAPI.Builder()
.token(token)
.botId("600302983305101323")
.build();

Values.setApi(api);

api.setStats(bot.getServers().size());

if(Values.getApi() != null)
bot.addListener(new VoteCommand());
}
catch (Exception ignore)
{

}
}
}

0 comments on commit 2d2c961

Please sign in to comment.