ChristopherBThai / Discord-OwO-Bot

A Discord bot that will keep track of your OwO
https://discordapp.com/oauth2/authorize?client_id=408785106942164992&permissions=1074120776&scope=bot
Other
561 stars 404 forks source link

added support for scheduling events (specials) and announcements in the database #240

Open sfk-steelsong opened 2 years ago

sfk-steelsong commented 2 years ago

adds two new tables: events and eventtype

SQL is at the end.

be careful because "events" is a reserved word and may cause anger if not wrapped in quotes. works on my machine but please double check :). Tried to keep it vague so we can use the table for other scheduled stuff (double exp weekends?). It supports multiple sets of specials active at one time if that happens (holiday and milestone pet, for example). You'll still need to add info on the specials in the list object in the json file but now we can deploy them early and schedule them to go live later.

Also, using adate on announcement for when the announcement should be available; current behaviour is preserved in that if you don't put a date it'll go live immediately like it already does, but if you put a date in the future it won't show up until after that time has passed.

SQL:

table creation:

DROP TABLE IF EXISTS `eventtype`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `eventtype` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `type` varchar(25) NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `type` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

DROP TABLE IF EXISTS `events`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `events` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `eventtype` varchar(25) NOT NULL,
    `starttime` timestamp NOT NULL DEFAULT '2001-01-01 08:00:00',
    `endtime` timestamp NOT NULL DEFAULT '2001-01-01 08:00:00',
    `config` varchar(1500) DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `typeandtime` (`eventtype`, `starttime`, `endtime`),
    CONSTRAINT `event_ibfk_1` FOREIGN KEY (`eventtype`) REFERENCES `eventtype` (`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

type table data contents:

INSERT INTO `eventtype` (`type`) VALUES ('SPECIAL');

Example event data (config based on an attempt to reverse engineer the contents of specialRate in the json file since I don't have a sample):

INSERT INTO `events` (eventtype, starttime, endtime, config) values ('SPECIAL', NOW(), date_add(NOW(), INTERVAL 1 HOUR), '[{"animal":":mouse2:", "rate":0.1},{"animal":":baby_chick:", "rate":0.1}]');
INSERT INTO `events` (eventtype, starttime, endtime, config) values ('SPECIAL', NOW(), date_add(NOW(), INTERVAL 1 HOUR), '[{"animal":":sheep:", "rate":0.1},{"animal":":pig2:", "rate":0.1}]');