Skip to content

Commit

Permalink
added basic playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
at-elcapitan committed Jan 28, 2025
1 parent 09672cf commit 336cad4
Show file tree
Hide file tree
Showing 13 changed files with 552 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Setting up external lib's files for not appliying for repo statistics
src/map/map.c linguist-generated=true
src/map/map.h linguist-generated=true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The bot is designed to provide a seamless music streaming experience on Discord,
### Dependencies
- [Concord](https://github.com/Cogmasters/concord)
- [CogLink](https://github.com/PerformanC/CogLink)
- [rxi/map](https://github.com/rxi/map)

#### Installing build dependencies

Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ endif

exec = executable(
'tnic',
['src/main.c', 'src/database.c', 'src/playlist.c', 'src/music.c', 'src/embeds.c'],
['src/main.c', 'src/database.c', 'src/playlist.c', 'src/music.c', 'src/embeds.c', 'src/map/map.c'],
c_args: arguments,
link_args: [ '-lcoglink', '-pthread', '-ldiscord', '-lcurl' ]
)
5 changes: 5 additions & 0 deletions src/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <coglink/lavalink.h>
#include <stdbool.h>

#include "playlist.h"

typedef struct {
u64snowflake botId;
char *botGameName;
Expand All @@ -14,8 +16,11 @@ typedef struct {
typedef struct {
bool botReady;
bool coglinkReady;

struct discord *bot;
struct coglink_client *client;

tnic_playlist_controller *playlistController;
tnic_applicationConfig *config;
} tnic_application;

Expand Down
46 changes: 41 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ tnic_application app = {
};

// Events
void on_coglink_ready(struct coglink_client *client, struct coglink_node *node, struct coglink_ready *ready) {
void on_coglink_ready(struct coglink_client *client, struct coglink_node *node,
struct coglink_ready *ready) {
log_info("[COGLINK] Node connected [%s]", ready->session_id);
app.botReady = true;
}
Expand Down Expand Up @@ -53,17 +54,23 @@ void on_ready(struct discord *bot, const struct discord_ready *event) {
}

void on_interaction(struct discord *bot, const struct discord_interaction *event) {
if (!app.botReady) {
tnic_sendErrorEmbed(app, event, "#e001x1 coglink_not_ready", "Application not ready. Waiting for nodes to connect");
/* if (!app.botReady) {
tnic_sendErrorEmbed(app, event, "#e001x1 coglink_not_ready",
"Application not ready. Waiting for nodes to connect");
return;
}

*/
if (event->type == DISCORD_INTERACTION_APPLICATION_COMMAND) {
tnic_proccessApplicationCommand(app, event);
return;
}
}

void on_coglink_track_end(struct coglink_client *c_client, struct coglink_node *node,
struct coglink_track_end *trackEnd) {
tnic_cmusicProcessEvent(app, c_client, node, trackEnd);
}

void applicationClean(tnic_application app) {
discord_cleanup(app.bot);
ccord_shutdown_async();
Expand All @@ -84,6 +91,12 @@ void applicationClean(tnic_application app) {
free(app.config->botGameName);
}

if (app.playlistController->playlist != NULL) {
playlist_clearPlaylist(app.playlistController->playlist);
free(app.playlistController->playlist);
}

free(app.playlistController);
free(app.config);
}

Expand All @@ -99,6 +112,9 @@ void botPrepear(struct discord *bot) {
discord_add_intents(bot, DISCORD_GATEWAY_MESSAGE_CONTENT);
discord_add_intents(bot, DISCORD_GATEWAY_GUILDS);

// Setting global
discord_set_data(bot, &app);

// Adding application commands
discord_set_on_ready(bot, &on_ready);
discord_set_on_interaction_create(bot, &on_interaction);
Expand Down Expand Up @@ -146,7 +162,7 @@ int main(void) {
struct coglink_client *client;
struct discord *bot;

puts("AT PROJECT Limited, 2021 - 2025; ATNiC-270120250817JST");
puts("AT PROJECT Limited, 2021 - 2025; ATNiC-290120250759JST");
puts("Product licensed by GPLv3, file `LICENSE`");
puts("This is a prototype version and should not be used in production environments");
puts("by Vladislav 'ElCapitan' Nazarov");
Expand All @@ -159,6 +175,8 @@ int main(void) {
app.bot = bot;
app.client = client;
app.config = (tnic_applicationConfig*)malloc(sizeof(tnic_applicationConfig));
app.playlistController = (tnic_playlist_controller*)malloc(sizeof(tnic_playlist_controller));
app.playlistController->playlist = NULL;

// Checking wether variables was initialized
if (bot == NULL) {
Expand All @@ -174,6 +192,18 @@ int main(void) {
return -1;
}

if (app.config == NULL) {
log_fatal("[TNiC] Config initialization failed");
applicationClean(app);
return -1;
}

if (app.playlistController == NULL) {
log_fatal("[TNiC] Playlist controller initialization failed");
applicationClean(app);
return -1;
}

// Prepearing application
botPrepear(app.bot);
if (loadApplicationConfig(app) == tnic_VALUE_NOT_FOUND) {
Expand Down Expand Up @@ -201,6 +231,12 @@ int main(void) {
};
app.client->num_shards = "1";

// Connecting events
struct coglink_events events = {
.on_track_end = &on_coglink_track_end
};
app.client->events = &events;

// Connecting nodes
if (coglink_connect_nodes(app.client, app.bot, &nodes) == COGLINK_FAILED) {
log_fatal("[COGLINK] Can't connect nodes");
Expand Down
20 changes: 20 additions & 0 deletions src/map/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2014 rxi


Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
193 changes: 193 additions & 0 deletions src/map/map.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 336cad4

Please sign in to comment.