Skip to content

Commit

Permalink
Initial Commit for Bo³+t
Browse files Browse the repository at this point in the history
  • Loading branch information
VegaBobo committed Nov 23, 2019
0 parents commit 8e7a663
Show file tree
Hide file tree
Showing 37 changed files with 2,276 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.*
!/.gitignore
out/
downloads/
databases/
credentials/
configs/
build/
gradlew
gradlew.bat
bobot.log
3 changes: 3 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.vegazsdev.bobobot.Main

95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Bo³+t Bot

Just a other Telegram Bot made using [TelegramBots](https://github.com/rubenlagus/TelegramBots) Java Library

### What are the Current Supported Commands?

Default Commands:

- ChangeHotkey: Changes hotkey on current chat (!chkey)
- ChangeLang: Change language on current chat (!chlang)
- ListAllCommands: Show all commands avaiable (!comm)
- About: Shows a About info (!about)

Other Commands:

- Hello: Says a Hello! (!hello)
- Chat2Shell: Run shell commands on host computer via chat (!shell)
- SetupGDrive: Setup your Google Drive Account to send files (!setupgdrive)
- Download2GDrive: Download any directlink and send to your Google Drive (!d2gdrive)
- ErfanGSIs: Can port GSIs using [ErfanGSIs Tool](https://github.com/erfanoabdi/ErfanGSIs) (!jurl2gsi)

*More commands will be added in future, any suggestion or contributions are welcome :)*

### How to setup this bot?

Ill always offer a jar file of this bot on GitHub Releases, so, if you want to use this, without any changes, just using your bot "credentials" and other things, yeap, you can!

1. Get this bot (You can download the on Releases tab or Build it by yourself)

2. Run jar file by
```
java -jar Bobobot.jar
```

_First time you will get a error, because your bot token and bot username are not set_

3. Open config.prop (inside configs folder), and fit with your information, like that:

```
#BoboBot config file
#Wed Oct 30 15:17:09 BRT 2019
bot-token=Put your Telegram Bot Token here
bot-username=Put your Telegram Bot Username here
bot-master=You are the master of this bot, put your Telegram ID here
```

4. Run again and voila!

### Some good information

**! is ALWAYS the DEFAULT HOTKEY** (You can change this hotkey using !chkey)

**EN is ALWAYS the DEFAULT LANGUAGE** (You can change this language using !chlang)

To use anything that send files to Google Drive (like !jurl2gsi or !d2gdrive), YOU NEED TO SETUP YOUR ACCOUNT USING !setupgdrive

Strings by now are not "fully translatable", ill try to do something good in future

### How to build?

I Wrote this bot using IntelliJ IDEA, so, just git clone that repo and open this project on IDEA, and well, edit haha, good luck :)

Also, the META-INF folder is included on root of this project (may be useful while you creating artefact)

### How to create a new command?

This bot tries to be most modular as possible, so, we use Reflection on Main class to "track" for all classes inside Command package, so, open Hello.java, see how it works and make a other class (inside Commands package), extends Command and start your new command :)

### About

This is just mine "personal" bot for telegram haha

### Credits and Libraries

[TelegramBots (by rubenlagus)](https://github.com/rubenlagus/TelegramBots)

[Apache Commons](https://commons.apache.org/)

[Apache Log4j 2 (API/Core)](https://logging.apache.org/log4j/)

[Google API Client](https://developers.google.com/api-client-library)

[Google OAuth Client](https://developers.google.com/api-client-library/java/google-oauth-java-client)

[Google Drive API](https://developers.google.com/drive)

[Google Guava](https://github.com/google/guava)

[SQLite JDBC Driver (by xerial)](https://github.com/xerial/sqlite-jdbc)

### Also:

[Java Quickstart](https://developers.google.com/drive/api/v3/quickstart/java)

[Manipulating files.. on Google Drive using Java by o7planning](https://o7planning.org/en/11889/manipulating-files-and-folders-on-google-drive-using-java)
25 changes: 25 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
plugins {
id 'java'
}

group 'com.vegazsdev.bobobot'
version '1'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
compile group: 'org.telegram', name: 'telegrambots', version: '4.4.0.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
compile group: 'com.google.api-client', name: 'google-api-client', version: '1.30.5'
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.30.4'
compile group: 'com.google.apis', name: 'google-api-services-drive', version: 'v3-rev173-1.25.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.12.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.12.1'
compile group: 'com.google.guava', name: 'guava', version: '11.0.2'
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Oct 30 03:23:02 BRT 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'BoboBot'

Empty file added src/META-INF/ECLIPSEF.RSA
Empty file.
Empty file added src/META-INF/ECLIPSEF.SF
Empty file.
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.vegazsdev.bobobot.Main

104 changes: 104 additions & 0 deletions src/main/java/com/vegazsdev/bobobot/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.vegazsdev.bobobot;

import com.google.common.reflect.ClassPath;
import com.vegazsdev.bobobot.core.Bot;
import com.vegazsdev.bobobot.db.DbThings;
import com.vegazsdev.bobobot.utils.Config;
import com.vegazsdev.bobobot.utils.FileTools;
import com.vegazsdev.bobobot.utils.XMLs;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.telegram.telegrambots.ApiContextInitializer;
import org.telegram.telegrambots.meta.TelegramBotsApi;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Objects;

public class Main {

private static final Logger LOGGER = (Logger) LogManager.getLogger(Main.class);

public static String DEF_CORE_STRINGS_XML = "core-strings.xml";

public static void main(String[] args) {

LOGGER.info(XMLs.getFromStringsXML(DEF_CORE_STRINGS_XML, "bot_init"));

// detect config file

if (!new FileTools().checkFileExistsCurPath("configs/" + XMLs.getFromStringsXML(DEF_CORE_STRINGS_XML, "config_file"))) {
LOGGER.info(XMLs.getFromStringsXML(DEF_CORE_STRINGS_XML, "config_file_not_found"));
new Config().createDefConfig();
LOGGER.warn(XMLs.getFromStringsXML(DEF_CORE_STRINGS_XML, "config_file_info"));
System.exit(0);
}

// initialize all commands inside commands package

ArrayList<Class> commandClasses = new ArrayList<>();

final ClassLoader loader = Thread.currentThread().getContextClassLoader();

try {
for (final ClassPath.ClassInfo info : ClassPath.from(loader).getTopLevelClasses()) {
if (info.getName().startsWith("com.vegazsdev.bobobot.commands")) {
final Class<?> clazz = info.load();
try {
Object instance = ((Class<?>) clazz).getDeclaredConstructor().newInstance();
Method method = ((Class<?>) clazz).getSuperclass().getDeclaredMethod("getAlias");
method.invoke(instance);
commandClasses.add(clazz);
LOGGER.info(Objects.requireNonNull(
XMLs.getFromStringsXML(DEF_CORE_STRINGS_XML, "cc_init_cmd"))
.replace("%1", clazz.getSimpleName()));
} catch (Exception e) {
// by now, ignoring exceptions here
// LOGGER.error(e.getMessage(), e);
}
}
}
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}

// create a bot object

if ((Config.getDefConfig("bot-token") != null && Objects.requireNonNull(Config.getDefConfig("bot-token")).contains(" "))
|| (Config.getDefConfig("bot-username") != null && Objects.requireNonNull(Config.getDefConfig("bot-username")).contains(" "))) {
LOGGER.warn(XMLs.getFromStringsXML(DEF_CORE_STRINGS_XML, "config_file_info"));
System.exit(0);
}

Bot bot =
new Bot(
Config.getDefConfig("bot-token"),
Config.getDefConfig("bot-username"));

// database
// create a new database if current one doesn't exists

if (!new FileTools().checkFileExistsCurPath("databases/prefs.db")) {
DbThings.createNewDatabase("prefs.db");
DbThings.createTable("prefs.db",
"CREATE TABLE IF NOT EXISTS chat_prefs ("
+ "group_id real UNIQUE PRIMARY KEY,"
+ "hotkey text DEFAULT '!',"
+ "lang text DEFAULT 'strings-en.xml'"
+ ");");
}

ApiContextInitializer.init();
TelegramBotsApi botsApi = new TelegramBotsApi();

try {
botsApi.registerBot(new TelegramBot(bot, commandClasses));
LOGGER.info(XMLs.getFromStringsXML(DEF_CORE_STRINGS_XML, "bot_started"));
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}

}

}
Loading

0 comments on commit 8e7a663

Please sign in to comment.