Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyRin committed Jul 16, 2018
1 parent 762989e commit 1ffa7a3
Show file tree
Hide file tree
Showing 3 changed files with 285 additions and 0 deletions.
85 changes: 85 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.simplyrin.discord.dropbot</groupId>
<artifactId>Dropbot</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>Dropbot</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<finalName>Dropbot</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>net.simplyrin.discord.dropbot.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<id>net.simplyrin</id>
<name>api</name>
<url>https://api.simplyrin.net/maven/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.7.0_382</version>
</dependency>
<dependency>
<groupId>net.simplyrin.config</groupId>
<artifactId>Config</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>net.simplyrin.simplelogger</groupId>
<artifactId>SimpleLogger</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
82 changes: 82 additions & 0 deletions src/main/java/net/simplyrin/discord/dropbot/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package net.simplyrin.discord.dropbot;

import java.io.File;
import java.io.IOException;

import lombok.Getter;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.md_5.bungee.config.Configuration;
import net.simplyrin.config.Config;
import net.simplyrin.discord.dropbot.listener.MessageListener;
import net.simplyrin.logger.SimpleLogger;

/**
* Created by SimplyRin on 2018/07/16.
*
* Copyright (C) 2018 SimplyRin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
public class Main {

private static Main instance;

public static void main(String[] args) {
instance = new Main();
instance.run();
}

@Getter
private JDA jda;
@Getter
private SimpleLogger logger = new SimpleLogger(Main.class);

public void run() {
File file = new File("config.yml");
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}

Configuration config = Config.getConfig(file);
config.set("Token", "BOT_TOKEN_HERE");
Config.saveConfig(config, file);
}

Configuration config = Config.getConfig(file);

JDABuilder jdaBuilder = new JDABuilder(AccountType.BOT);
jdaBuilder.addEventListener(new MessageListener(this));

String token = config.getString("Token");
if(token.equals("BOT_TOKEN_HERE")) {
this.logger.info("Discord Bot Token を config.yml に入力してください!");
System.exit(0);
return;
}
jdaBuilder.setToken(token);

this.jda = null;
try {
this.jda = jdaBuilder.buildBlocking();
} catch (Exception e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package net.simplyrin.discord.dropbot.listener;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.simplyrin.discord.dropbot.Main;

/**
* Created by SimplyRin on 2018/07/16.
*
* Copyright (C) 2018 SimplyRin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
public class MessageListener extends ListenerAdapter {

private Main instance;

public MessageListener(Main instance) {
this.instance = instance;
}

/**
* Erangel and Miramar drop spots list from https://gist.github.com/UsefulEndymion/2096766be1eb45c209516afc214fec78#file-bot-js-L8-L9
*/
private String[] erangelDropSpots = {"Rozhok", "School", "Apartments", "Yasnaya Polyana", "Severny", "Shooting Range", "Mansion", "Prison", "Mylta", "Mylta Power", "Novolepnoye", "Military", "Ferry Pier", "Primorsk", "Hospital", "Georgopol Crates", "Georgopol South", "Georgopol North", "Zharki", "Stalber", "Kameshki", "Pochinki", "Ruins", "Water Town", "Farm"};
private String[] miramarDropSpots = {"Pecado", "San Martin", "Hacienda del Patron", "Minas Generales", "Monte Nuevo", "Chumacera", "Los Leones", "Puerto Paraiso", "Impala", "El Azahar", "Cruz del Valle", "La Cobreria", "El Pozo", "Valle del Mar", "Prison", "Los Higos", "Power Grid", "Water Treatment", "Torre Ahumada", "Campo Militar", "La Bendita", "East Islands"};

private String[] sanhokDropSpots = {"Khao", "Mongnal", "Tat Mok", "Ha Tinh", "Paradise Resort", "Camp Bravo", "Camp Alpha", "Bootcamp", "Bhan", "Lakawi", "Ruins", "Pai Nan", "Quarry", "Kampong", "Cave", "Tambang", "Na Kham", "Camp Charlie", "Sahmee", "Ban Tai", "Docks"};

@Override
public void onMessageReceived(MessageReceivedEvent event) {
MessageChannel sender = event.getChannel();
String[] args = event.getMessage().getContentRaw().split(" ");

if(args.length > 0) {
if(!args[0].equalsIgnoreCase("!drop")) {
return;
}

if(args.length > 1) {
/**
* For admin
*/
if(event.getAuthor().getId().equals("224428706209202177")) {
if(args[1].equalsIgnoreCase("shutdown")) {
sender.sendMessage("Shutting down...").complete();
this.instance.getJda().shutdown();
System.exit(0);
return;
}

if(args[1].equalsIgnoreCase("reboot")) {
sender.sendMessage("Restarting...").complete();
this.instance.getJda().shutdown();
this.instance.run();
return;
}
}

/**
* Erangel
*/
if(args[1].equalsIgnoreCase("erangel") || args[1].equalsIgnoreCase("island") || args[1].equalsIgnoreCase("e") || args[1].equalsIgnoreCase("i")) {
List<String> list = Arrays.asList(this.erangelDropSpots);
Collections.shuffle(list);
String result = list.get(0);

sender.sendMessage("[Erangel] Drop Spot: **" + result + "**").complete();
return;
}

/**
* Miramar
*/
if(args[1].equalsIgnoreCase("miramar") || args[1].equalsIgnoreCase("desert") || args[1].equalsIgnoreCase("m") || args[1].equalsIgnoreCase("d")) {
List<String> list = Arrays.asList(this.miramarDropSpots);
Collections.shuffle(list);
String result = list.get(0);

sender.sendMessage("[Miramar] Drop Spot: **" + result + "**").complete();
return;
}

/**
* Sanhok
*/
if(args[1].equalsIgnoreCase("sanhok") || args[1].equalsIgnoreCase("s") || args[1].equalsIgnoreCase("savage")) {
List<String> list = Arrays.asList(this.sanhokDropSpots);
Collections.shuffle(list);
String result = list.get(0);

sender.sendMessage("[Sanhok] Drop Spot: **" + result + "**").complete();
return;
}
}

sender.sendMessage("Usage: !drop <erangel,miramar,sanhok>").complete();
return;
}
}

}

0 comments on commit 1ffa7a3

Please sign in to comment.