mirror of
https://github.com/WCBROW01/zblock.git
synced 2025-12-12 04:28:07 -05:00
[main.c] Immediately remembered why I didn't register the timers on ready
This commit is contained in:
63
main.c
63
main.c
@ -516,18 +516,6 @@ static struct bot_command commands[] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// delay before the first feed retrieval (in ms)
|
|
||||||
#define FEED_TIMER_DELAY 15000
|
|
||||||
|
|
||||||
// interval for the feed retrieval timer (in ms)
|
|
||||||
#define FEED_TIMER_INTERVAL 600000
|
|
||||||
|
|
||||||
// seconds in a day
|
|
||||||
#define ONE_DAY_SEC 86400
|
|
||||||
|
|
||||||
// milliseconds in a week
|
|
||||||
#define ONE_WEEK_MS 604800000
|
|
||||||
|
|
||||||
static void on_ready(struct discord *client, const struct discord_ready *event) {
|
static void on_ready(struct discord *client, const struct discord_ready *event) {
|
||||||
log_info("Logged in as %s!", event->user->username);
|
log_info("Logged in as %s!", event->user->username);
|
||||||
|
|
||||||
@ -535,25 +523,6 @@ static void on_ready(struct discord *client, const struct discord_ready *event)
|
|||||||
for (struct bot_command *i = commands; i < commands + sizeof(commands) / sizeof(*commands); ++i) {
|
for (struct bot_command *i = commands; i < commands + sizeof(commands) / sizeof(*commands); ++i) {
|
||||||
discord_create_global_application_command(client, event->application->id, &i->cmd, NULL);
|
discord_create_global_application_command(client, event->application->id, &i->cmd, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// feed timer
|
|
||||||
discord_timer_interval(client, timer_retrieve_feeds, NULL, NULL, FEED_TIMER_DELAY, FEED_TIMER_INTERVAL, -1);
|
|
||||||
|
|
||||||
// find the next tueday and start the timer for the tuesday event
|
|
||||||
if (zblock_config.tuesday_enable) {
|
|
||||||
time_t current_time = time(NULL);
|
|
||||||
struct tm midnight_tm;
|
|
||||||
gmtime_r(¤t_time, &midnight_tm);
|
|
||||||
// set it to midnight
|
|
||||||
midnight_tm.tm_sec = 0;
|
|
||||||
midnight_tm.tm_min = 0;
|
|
||||||
midnight_tm.tm_hour = 0;
|
|
||||||
time_t midnight_time = timegm(&midnight_tm);
|
|
||||||
// find next tuesday and add it to the time
|
|
||||||
time_t next_tuesday = midnight_time + ONE_DAY_SEC * (((1 - midnight_tm.tm_wday + 7) % 7) + 1);
|
|
||||||
// set a timer that starts midnight next tuesday and triggers every week
|
|
||||||
discord_timer_interval(client, timer_tuesday_event, NULL, NULL, (next_tuesday - current_time) * 1000, ONE_WEEK_MS, -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_interaction(struct discord *client, const struct discord_interaction *event) {
|
static void on_interaction(struct discord *client, const struct discord_interaction *event) {
|
||||||
@ -591,6 +560,18 @@ static void on_guild_delete(struct discord *client, const struct discord_guild *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// delay before the first feed retrieval (in ms)
|
||||||
|
#define FEED_TIMER_DELAY 15000
|
||||||
|
|
||||||
|
// interval for the feed retrieval timer (in ms)
|
||||||
|
#define FEED_TIMER_INTERVAL 600000
|
||||||
|
|
||||||
|
// seconds in a day
|
||||||
|
#define ONE_DAY_SEC 86400
|
||||||
|
|
||||||
|
// milliseconds in a week
|
||||||
|
#define ONE_WEEK_MS 604800000
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
|
|
||||||
@ -617,6 +598,26 @@ int main(void) {
|
|||||||
discord_set_on_ready(client, &on_ready);
|
discord_set_on_ready(client, &on_ready);
|
||||||
discord_set_on_interaction_create(client, &on_interaction);
|
discord_set_on_interaction_create(client, &on_interaction);
|
||||||
discord_set_on_guild_delete(client, &on_guild_delete);
|
discord_set_on_guild_delete(client, &on_guild_delete);
|
||||||
|
|
||||||
|
// register timers
|
||||||
|
discord_timer_interval(client, timer_retrieve_feeds, NULL, NULL, FEED_TIMER_DELAY, FEED_TIMER_INTERVAL, -1);
|
||||||
|
|
||||||
|
// find the next tueday and start the timer for the tuesday event
|
||||||
|
if (zblock_config.tuesday_enable) {
|
||||||
|
time_t current_time = time(NULL);
|
||||||
|
struct tm midnight_tm;
|
||||||
|
gmtime_r(¤t_time, &midnight_tm);
|
||||||
|
// set it to midnight
|
||||||
|
midnight_tm.tm_sec = 0;
|
||||||
|
midnight_tm.tm_min = 0;
|
||||||
|
midnight_tm.tm_hour = 0;
|
||||||
|
time_t midnight_time = timegm(&midnight_tm);
|
||||||
|
// find next tuesday and add it to the time
|
||||||
|
time_t next_tuesday = midnight_time + ONE_DAY_SEC * (((1 - midnight_tm.tm_wday + 7) % 7) + 1);
|
||||||
|
// set a timer that starts midnight next tuesday and triggers every week
|
||||||
|
discord_timer_interval(client, timer_tuesday_event, NULL, NULL, (next_tuesday - current_time) * 1000, ONE_WEEK_MS, -1);
|
||||||
|
}
|
||||||
|
|
||||||
discord_run(client);
|
discord_run(client);
|
||||||
|
|
||||||
PQfinish(database_conn);
|
PQfinish(database_conn);
|
||||||
|
|||||||
Reference in New Issue
Block a user