/[sudobot]/trunk/lib/common/commands/settings/about.c
ViewVC logotype

Annotation of /trunk/lib/common/commands/settings/about.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 575 - (hide annotations)
Mon Jul 29 17:59:26 2024 UTC (8 months ago) by rakinar2
File MIME type: text/x-c
File size: 3142 byte(s)
chore: add trunk
1 rakinar2 575 #define _GNU_SOURCE
2    
3     #include <concord/discord.h>
4     #include <string.h>
5     #include <stdio.h>
6     #include "about.h"
7     #include "../../utils/strutils.h"
8     #include "../../utils/defs.h"
9     #include "../../utils/utils.h"
10     #include "../../io/printf.h"
11    
12     void command_about(struct discord *client, cmdctx_t context)
13     {
14     struct discord_user user = { 0 };
15     struct discord_ret_user ret_user = {
16     .sync = &user
17     };
18    
19     discord_get_current_user(client, &ret_user);
20    
21     const char *avatar = user.avatar;
22     bool avatar_is_animated = avatar[0] == 'a' && avatar[1] == '_';
23     const char *avatar_extension = avatar_is_animated ? "gif" : "png";
24     char *icon_url = casprintf("https://cdn.discordapp.com/avatars/%lu/%s.%s",
25     user.id, avatar, avatar_extension);
26    
27     struct discord_embed_field embed_fields[] = {
28     { .name = "Version", .value = SUDOBOT_VERSION, .Inline = true },
29     { .name = "Source Code", .value = SUDOBOT_GITHUB_REPO_MD_LINK, .Inline = true },
30     { .name = "Licensed Under", .value = SUDOBOT_LICENSE_MD_LINK, .Inline = true },
31     { .name = "Author", .value = SUDOBOT_AUTHOR_MD_LINK, .Inline = true },
32     { .name = "Support", .value = SUDOBOT_SUPPORT_EMAIL, .Inline = true },
33     };
34    
35     struct discord_embeds embeds = {
36     .array = & (struct discord_embed) {
37     .author = & (struct discord_embed_author) {
38     .name = "SudoBot",
39     .icon_url = icon_url,
40     .url = SUDOBOT_GITHUB_REPO
41     },
42     .color = SUDOBOT_THEME_COLOR,
43     .description = "__**A free and open source Discord moderation bot.**__\n\
44     \n\
45     This bot is free software, and you are welcome to redistribute it under certain conditions.\n\
46     See the " SUDOBOT_LICENSE_MD_LINK " for more detailed information.\n",
47     .fields = & (struct discord_embed_fields) {
48     .array = embed_fields,
49     .size = sizeof (embed_fields) / sizeof (embed_fields[0])
50     },
51     .footer = & (struct discord_embed_footer) {
52     .text = "Copyright © OSN Developers 2022-2023. All rights reserved."
53     }
54     },
55     .size = 1
56     };
57    
58     if (context.type == CMDCTX_LEGACY)
59     {
60     struct discord_create_message params = {
61     .embeds = &embeds,
62     .message_reference = & (struct discord_message_reference) {
63     .channel_id = context.message->channel_id,
64     .fail_if_not_exists = false,
65     .guild_id = context.message->guild_id,
66     .message_id = context.message->id,
67     },
68     };
69    
70     discord_create_message(client, context.message->channel_id, &params, NULL);
71     }
72     else
73     {
74     struct discord_interaction_response params = {
75     .type = DISCORD_INTERACTION_CHANNEL_MESSAGE_WITH_SOURCE,
76     .data = & (struct discord_interaction_callback_data) {
77     .embeds = &embeds
78     }
79     };
80    
81     discord_create_interaction_response(client, context.interaction->id, context.interaction->token, &params, NULL);
82     }
83    
84     dealloc(icon_url);
85     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26