#include <WiFi.h>
#include <Wire.h>
#include <HTTPClient.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with I2C address 0x27 and dimensions 20x4
LiquidCrystal_I2C lcd(0x27, 20, 4);
byte panahbengkok[] = {
B01010,
B01010,
B01011,
B01000,
B01111,
B00000,
B00000,
B00000
};
byte WL_kiri[] = {
B00111,
B01111,
B01000,
B01000,
B01111,
B01110,
B01110,
B01111
};
byte WL_kanan[] = {
B11100,
B11110,
B00010,
B00010,
B11110,
B01110,
B01110,
B11110
};
void Wifi_setup(String ssid, String password) {
// Start the Wi-Fi connection
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// Wait for the connection to establish
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
// Print the IP address
Serial.println();
Serial.println("WiFi connected.");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void LCD_setup() {
Wire.begin(21, 22); // SDA, SCL
lcd.begin(20, 4);
lcd.backlight();
}
String HTTP_get(String link) {
HTTPClient http;
Serial.print("Connecting to ");
Serial.println(link);
// Your domain name with URL path or IP address with path
http.begin(link);
// Send HTTP GET request
int httpResponseCode = http.GET();
// Check the returning code
if (httpResponseCode >= 200 && httpResponseCode <= 299) {
// Get the request response payload
String payload = http.getString();
Serial.println(httpResponseCode);
http.end(); // Close the HTTP connection
return payload;
} else {
Serial.print("Error on HTTP request: ");
Serial.println(httpResponseCode);
http.end(); // Close the HTTP connection
return ""; // Return an empty string on error
}
}
int Total_wl() {
String links = "https://discord.com/api/webhooks/1214936782345605170/cQhOQtNtxcJuJW_C7lcHj4exEa9VaoOTatl30p_Gs5p5gd7bq_sc2zBpanFlTjBQ2Y9p/messages/1215326447980253224";
String kacor = HTTP_get(links);
if (kacor){
int kabors1 = extract_text(kacor, "<:WL:880251447470596157> : ", "\\n").toInt() * 1;
int kabors2 = extract_text(kacor, "<:DL:880251434380165130> : ", "\\n").toInt() * 100;
int kabors3 = extract_text(kacor, "<:BGL:880251420413161533> : ", "\\n").toInt() * 10000;
return kabors1 + kabors2 + kabors3;
}else{
return 0;
}
}
void Total_player(int &plersss, String &plrs_Txt) {
static int Dump_Plyr = 0; // Make Dump_Plyr static to retain its value across function calls
String linkss = "https://www.growtopiagame.com/detail";
String ppleekk = HTTP_get(linkss);
if(ppleekk.length() > 0) {
int players = extract_text(ppleekk, "online_user\":\"", "\",").toInt();
if ((players - Dump_Plyr) > 10) {
plersss = players - Dump_Plyr;
plrs_Txt = "+" + String(plersss);
} else if ((Dump_Plyr - players) > 10) {
plersss = Dump_Plyr - players;
plrs_Txt = "-" + String(plersss);
}
Dump_Plyr = players; // Update Dump_Plyr after calculations
}else {
plersss = 0;
plrs_Txt = "-0";
}
}
void bot_stat(String &online, String &offline, String &banned) {
String botlink = "https://discord.com/api/webhooks/1214936782345605170/cQhOQtNtxcJuJW_C7lcHj4exEa9VaoOTatl30p_Gs5p5gd7bq_sc2zBpanFlTjBQ2Y9p/messages/1232740058461769838";
String ppleekk = HTTP_get(botlink);
if(ppleekk.length() > 0) {
online = extract_text(ppleekk, "ONLINE : ", "\\n");
offline = extract_text(ppleekk, "OFFLINE : ", "\\n");
banned = extract_text(ppleekk, "BANNED : ", "\\n");
}
}
String extract_text(String Text, String Start_from, String end_text) {
int startIndex = Text.indexOf(Start_from);
if (startIndex == -1) {
return "Not found";
}
startIndex += Start_from.length();
int endIndex = Text.indexOf(end_text, startIndex);
if (endIndex == -1) {
endIndex = Text.length();
}
String result = Text.substring(startIndex, endIndex);
result.trim();
return result;
}
void gtbot_status_4x20_I2C(){
//bot status
String online, offline, banned;
bot_stat(online, offline, banned);
String pakol;
int players;
Total_player(players,pakol);
int WL = Total_wl();
String Wifi_name = "Wokwi-GUEST";
String Wifi_pw = "";
Wifi_setup(Wifi_name, Wifi_pw);
LCD_setup();
lcd.createChar(0, panahbengkok);
lcd.createChar(1, WL_kiri);
lcd.createChar(2, WL_kanan);
lcd.setCursor(0, 0);
lcd.print(" ZUHA BOT INFO! ");
lcd.setCursor(0, 1);
lcd.print("ON : ");
lcd.setCursor(0, 1);
lcd.print("ON :" + online);
lcd.setCursor(0, 2);
lcd.print("OFF: ");
lcd.setCursor(0, 2);
lcd.print("OFF:" + offline);
lcd.setCursor(0, 3);
lcd.print("BAN: ");
lcd.setCursor(0, 3);
lcd.print("BAN:" + banned);
lcd.setCursor(8, 1);
lcd.print(" PLYR : ");
lcd.setCursor(8, 1);
lcd.print(" PLYR :" + String(players));
lcd.setCursor(8, 2);
lcd.print(" ===> ");
lcd.setCursor(8, 2);
lcd.print(" ===>" + pakol);
lcd.setCursor(9, 2);
lcd.write(0);
lcd.setCursor(8, 3);
lcd.print(" WL : ");
lcd.setCursor(8, 3);
lcd.print(" WL :" + String(WL));
lcd.setCursor(9, 3);
lcd.write(1);
lcd.write(2);
}
void setup() {
Serial.begin(115200);
}
void loop() {
gtbot_status_4x20_I2C()
delay(1000);
}