-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36e0716
commit 0f749a4
Showing
6 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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>id.frostfire</groupId> | ||
<artifactId>BotIoT</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
<repository> | ||
<id>Central</id> | ||
<url>https://repo1.maven.org/maven2/</url> | ||
</repository> | ||
</repositories> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.javacord</groupId> | ||
<artifactId>javacord</artifactId> | ||
<version>3.8.0</version> | ||
<type>pom</type> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.auties00</groupId> | ||
<artifactId>whatsappweb4j</artifactId> | ||
<version>3.4.8</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.pengrad</groupId> | ||
<artifactId>java-telegram-bot-api</artifactId> | ||
<version>6.7.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sparkjava</groupId> | ||
<artifactId>spark-core</artifactId> | ||
<version>2.9.4</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>id.frostfire.BotIoT.Main</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package id.frostfire.BotIoT.Discord; | ||
|
||
import org.javacord.api.DiscordApi; | ||
import org.javacord.api.DiscordApiBuilder; | ||
import org.javacord.api.entity.channel.TextChannel; | ||
import org.javacord.api.entity.message.MessageBuilder; | ||
|
||
public class Discord { | ||
public static DiscordApi api; | ||
public static void Inisialize(String token){ | ||
api = new DiscordApiBuilder().setToken(token).login().join(); | ||
System.out.println("invite Link Discord Bot : " + api.createBotInvite()); | ||
} | ||
public static String pesandc(String pesan, String id){ | ||
new MessageBuilder().setContent(pesan).send((TextChannel) api.getChannelById(id).get()); | ||
return "Mengirim Pesan Discord dengan pesan " + pesan; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/id/frostfire/BotIoT/EndpointAPI/Publish.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package id.frostfire.BotIoT.EndpointAPI; | ||
|
||
|
||
import id.frostfire.BotIoT.Discord.Discord; | ||
import id.frostfire.BotIoT.Main; | ||
import id.frostfire.BotIoT.Telegram.Telegram; | ||
import id.frostfire.BotIoT.WhatsApp.WhatsApp; | ||
import it.auties.whatsapp.api.Whatsapp; | ||
|
||
import static spark.Spark.*; | ||
public class Publish { | ||
public static void event() { | ||
get("/", (req, res) -> "Hello World"); | ||
post("/sendwa", (req, res) -> { | ||
|
||
return WhatsApp.pesan(Whatsapp.webBuilder().lastConnection().build().connect().join(), | ||
req.params("pesan"); | ||
req.params("nomer"); | ||
}); | ||
post("senddc", (request, response) -> { | ||
response.status(201); | ||
return Discord.pesandc(request.queryParams("pesan"), Main.DcChnId); | ||
}); | ||
post("sendtele", (request, response) -> { | ||
response.status(201); | ||
return Telegram.pesan(request.queryParams("pesan")); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package id.frostfire.BotIoT; | ||
|
||
import id.frostfire.BotIoT.Discord.Discord; | ||
import id.frostfire.BotIoT.EndpointAPI.Publish; | ||
import id.frostfire.BotIoT.Telegram.Telegram; | ||
import id.frostfire.BotIoT.WhatsApp.WhatsApp; | ||
import it.auties.whatsapp.api.Whatsapp; | ||
|
||
import java.util.Scanner; | ||
|
||
import static spark.Spark.port; | ||
|
||
public class Main { | ||
public static String DcChnId; | ||
public static long TeleId; | ||
public static Boolean usewhatsapp = false; | ||
public static Boolean usediscord = false; | ||
public static boolean usetelegram = false; | ||
|
||
public static String Teletoken; | ||
|
||
public static void main(String[] args){ | ||
port(80); | ||
Scanner scn = new Scanner(System.in); | ||
System.out.println("Are You using WhatsApp?"); | ||
String wa = scn.nextLine(); | ||
if(wa.equals("y") || wa.equals("yes") || wa.equals("true")){ WhatsApp.client(); usewhatsapp = true;} | ||
System.out.println("Are You using Discord?"); | ||
String dc = scn.nextLine(); | ||
if(dc.equals("yes") || dc.equals("y") || dc.equals("true")){ | ||
usediscord = true; | ||
System.out.println("Please Insert your Discord Bot Token :"); | ||
String token = scn.nextLine(); | ||
Discord.Inisialize(token); | ||
System.out.println("Please Insert your ChannelID :"); | ||
DcChnId = scn.nextLine(); | ||
} | ||
System.out.println("Are you using Telegram?"); | ||
String tele = scn.nextLine(); | ||
if(tele.equals("y") || tele.equals("yes") || tele.equals("true")){ | ||
System.out.println("Please Insert your Telegram Bot Token :"); | ||
Teletoken = scn.nextLine(); | ||
Telegram.inisialize(); | ||
System.out.println("Please Insert your IDcontact :"); | ||
TeleId = scn.nextLong(); | ||
usetelegram = true; | ||
} | ||
Publish.event(); | ||
if(usewhatsapp) System.out.println(WhatsApp.pesan(Whatsapp.webBuilder().lastConnection().build().connect().join(), | ||
"+6285236486026", | ||
"Server Menyala")); | ||
System.out.println("Server Menyala"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package id.frostfire.BotIoT.Telegram; | ||
|
||
import com.pengrad.telegrambot.TelegramBot; | ||
import com.pengrad.telegrambot.UpdatesListener; | ||
import com.pengrad.telegrambot.request.SendMessage; | ||
import com.pengrad.telegrambot.response.SendResponse; | ||
import id.frostfire.BotIoT.Main; | ||
|
||
public class Telegram { | ||
public static TelegramBot bot; | ||
public static void inisialize(){ | ||
bot = new TelegramBot(Main.Teletoken); | ||
bot.setUpdatesListener(updates -> { | ||
return UpdatesListener.CONFIRMED_UPDATES_ALL; | ||
}, e -> { | ||
if (e.response() != null) { | ||
e.response().errorCode(); | ||
e.response().description(); | ||
} else { | ||
e.printStackTrace(); | ||
} | ||
}); | ||
} | ||
public static String pesan(String Pesan){ | ||
SendResponse response = bot.execute(new SendMessage(Main.TeleId, Pesan)); | ||
return "Mengirim Pesan Telegram dengan pesan " + Pesan; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package id.frostfire.BotIoT.WhatsApp; | ||
|
||
import it.auties.whatsapp.api.QrHandler; | ||
import it.auties.whatsapp.api.Whatsapp; | ||
import it.auties.whatsapp.model.contact.ContactJid; | ||
|
||
|
||
public class WhatsApp { | ||
public static void client(){ | ||
Whatsapp.webBuilder().newConnection().qrHandler(QrHandler.toTerminal()).name("FrostFireIoT Bot").build().connect().join(); | ||
} | ||
public static String pesan(Whatsapp api, String nomer, String pesan){ | ||
api.sendMessage(ContactJid.of(nomer),pesan); | ||
return "Mengirim pesan ke " + nomer + " Dengan pesan " + pesan; | ||
} | ||
} |