Skip to content

Commit

Permalink
New Update
Browse files Browse the repository at this point in the history
1. Фикс
  • Loading branch information
megoRU committed Apr 20, 2024
1 parent 22af835 commit 6431163
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 48 deletions.
95 changes: 95 additions & 0 deletions DiscordBotGiveaway.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
-- MariaDB dump 10.19 Distrib 10.11.6-MariaDB, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: DiscordBotGiveaway
-- ------------------------------------------------------
-- Server version 10.11.6-MariaDB-0+deb12u1

DROP SEQUENCE IF EXISTS `sequence_id_auto_gen`;
CREATE SEQUENCE `sequence_id_auto_gen` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 100 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`sequence_id_auto_gen`, 1000, 0);

DROP TABLE IF EXISTS `active_giveaways`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `active_giveaways` (
`guild_id` bigint(20) NOT NULL,
`channel_id` bigint(20) NOT NULL,
`count_winners` int(10) DEFAULT NULL,
`date_end` datetime(6) DEFAULT NULL,
`title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'Giveaway',
`message_id` bigint(20) NOT NULL,
`is_for_specific_role` bit(1) DEFAULT NULL,
`role_id` bigint(20) DEFAULT NULL,
`created_user_id` bigint(20) NOT NULL,
`url_image` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
`min_participants` int(11) DEFAULT NULL,
`finish` tinyint(1) NOT NULL DEFAULT 0,
`forbidden_role` bigint(20) DEFAULT NULL,
PRIMARY KEY (`guild_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;


DROP TABLE IF EXISTS `list_users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `list_users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`giveaway_id` bigint(20) NOT NULL,
`guild_id` bigint(20) NOT NULL,
`created_user_id` bigint(20) NOT NULL,
`nick_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`user_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=126 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;


DROP TABLE IF EXISTS `participants`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `participants` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`nick_name` varchar(255) NOT NULL,
`user_id` bigint(20) NOT NULL,
`guild_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK9edsvtap9uhuikihdsv3c74rv` (`guild_id`),
CONSTRAINT `FK9edsvtap9uhuikihdsv3c74rv` FOREIGN KEY (`guild_id`) REFERENCES `active_giveaways` (`guild_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=600002 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

-- Table structure for table `scheduling`
--

DROP TABLE IF EXISTS `scheduling`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `scheduling` (
`guild_id` bigint(20) NOT NULL,
`channel_id` bigint(20) NOT NULL,
`count_winners` int(11) DEFAULT NULL,
`create_giveaway` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`date_end` timestamp NULL DEFAULT NULL,
`title` varchar(255) DEFAULT 'Giveaway',
`is_for_specific_role` tinyint(1) DEFAULT NULL,
`role_id` bigint(20) DEFAULT NULL,
`created_user_id` bigint(20) NOT NULL,
`url_image` varchar(255) DEFAULT NULL,
`min_participants` int(11) DEFAULT NULL,
`forbidden_role` bigint(20) DEFAULT NULL,
PRIMARY KEY (`guild_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;


DROP TABLE IF EXISTS `settings`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `settings` (
`server_id` bigint(20) NOT NULL,
`language` varchar(255) NOT NULL,
`color_hex` varchar(255) DEFAULT NULL,
PRIMARY KEY (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This work is licensed under a [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.

1. Move `docker-compose.yml` at the root `/root` VPS server.
2. Fill it with your data.
3. Import tables to your MySQL: `DiscordBotGiveaway_DB.sql`
3. Import tables to your MariaDB: `DiscordBotGiveaway.sql`
4. Launch the container: `docker-compose up -d`
5. If you need to update the repository: `docker-compose pull`
6. If you need to stop: `docker-compose stop`
Expand Down
4 changes: 0 additions & 4 deletions build-and-push.bat

This file was deleted.

16 changes: 13 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
version: '3.9'
version: '3'

services:
giveaway:
image: megoru/giveaway
restart: always
container_name: giveaway_bot
image: megoru/giveaway:latest
restart: always
volumes:
- ./giveaway_logs:/app/logs
environment:
DATABASE_URL: jdbc:mariadb:// IP :3306/ YOUR_USER ?useSSL=false&serverTimezone=UTC&characterEncoding=utf8
DATABASE_USER: YOUR_USER
DATABASE_PASS: YOUR_PASSWORD
TOKEN: OUR_BOT_TOKEN #see https://discord.com/developers/applications

# YOUR_IP and YOUR_USER don't forget to remove the spaces
23 changes: 11 additions & 12 deletions src/main/java/main/config/BotStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ public class BotStart {
private static JDA jda;
private final JDABuilder jdaBuilder = JDABuilder.createDefault(Config.getTOKEN());

//API
private final BotiCordAPI api = new BotiCordAPI.Builder()
.token(Config.getBoticord())
.build();

//REPOSITORY
private final ActiveGiveawayRepository activeGiveawayRepository;
private final UpdateController updateController;
Expand Down Expand Up @@ -376,16 +371,20 @@ private void updateSlashCommands() {

@Scheduled(fixedDelay = 120, initialDelay = 8, timeUnit = TimeUnit.SECONDS)
private void topGGAndStatcord() {
if (!Config.isIsDev()) {
try {
int serverCount = BotStart.jda.getGuilds().size();
int serverCount = BotStart.jda.getGuilds().size();
BotStart.jda.getPresence().setActivity(Activity.playing(BotStart.activity + serverCount + " guilds"));
AtomicInteger usersCount = new AtomicInteger();
BotStart.jda.getGuilds().forEach(g -> usersCount.addAndGet(g.getMembers().size()));

BotStart.jda.getPresence().setActivity(Activity.playing(BotStart.activity + serverCount + " guilds"));
String boticord = Config.getBoticord();
if (boticord == null) return;

//BOTICORD API
AtomicInteger usersCount = new AtomicInteger();
BotStart.jda.getGuilds().forEach(g -> usersCount.addAndGet(g.getMembers().size()));
BotiCordAPI api = new BotiCordAPI.Builder()
.token(boticord)
.build();

if (!Config.isIsDev()) {
try {
BotStats botStats = new BotStats(usersCount.get(), serverCount, 1);
api.setBotStats(Config.getBotId(), botStats);
} catch (Exception e) {
Expand Down
28 changes: 0 additions & 28 deletions src/main/java/main/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@ public class Config {
private static final String DEV_BOT_TOKEN = System.getenv("DEV_TOKEN");
private static final String PRODUCTION_BOT_TOKEN = System.getenv("TOKEN");
private static final String TOKEN = PRODUCTION_BOT_TOKEN;
private static final String TOP_GG_API_TOKEN = System.getenv("TOP_GG_API_TOKEN");
private static final String BOT_ID = "808277484524011531"; //megoDev: 780145910764142613 //giveaway: 808277484524011531

private static final String DATABASE_URL_DEV = System.getenv("DATABASE_URL_DEV");
private static final String DATABASE_URL = System.getenv("DATABASE_URL");

private static final String DATABASE_USER_DEV = System.getenv("DATABASE_USER_DEV");
private static final String DATABASE_USER = System.getenv("DATABASE_USER");

private static final String DATABASE_PASS = System.getenv("DATABASE_PASS");

private static final String BOTICORD = System.getenv("BOTICORD");

private static volatile boolean IS_DEV = true;
Expand All @@ -26,28 +16,10 @@ public class Config {
}
}

public static String getDatabaseUrl() {
if (IS_DEV) return DATABASE_URL_DEV;
else return DATABASE_URL;
}

public static String getDatabaseUser() {
if (IS_DEV) return DATABASE_USER_DEV;
else return DATABASE_USER;
}

public static String getDatabasePass() {
return DATABASE_PASS;
}

public static String getTOKEN() {
return TOKEN;
}

public static String getTopGgApiToken() {
return TOP_GG_API_TOKEN;
}

public static String getBotId() {
return BOT_ID;
}
Expand Down

0 comments on commit 6431163

Please sign in to comment.