Discord library in plain C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // Created by Memer on 24.08.18.
  3. // Copyright (c) 2018 Alexander Memer. All rights reserved.
  4. //
  5. #include <discord.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <log.h>
  9. #include <getopt.h>
  10. int main(int argc, char **argv)
  11. {
  12. struct ld_context_info info;
  13. info.log_level = 0;
  14. while (1)
  15. {
  16. int c;
  17. static struct option long_options[] =
  18. {
  19. {"bot-token", required_argument, 0, 't'},
  20. {"help", no_argument, 0, 'h'},
  21. {"log-level", required_argument, 0, 'l'},
  22. {0, 0, 0, 0}
  23. };
  24. int option_index = 0;
  25. c = getopt_long(argc, argv, "t:hl:", long_options, &option_index);
  26. if (c == -1)
  27. {
  28. break;
  29. }
  30. switch (c) {
  31. case 'h':
  32. printf("%s: [-t bot_token]\n");
  33. return 0;
  34. case 't':
  35. info.bot_token = strdup(optarg);
  36. break;
  37. case 'l':
  38. info.log_level = atoi(optarg);
  39. break;
  40. default:
  41. abort();
  42. }
  43. }
  44. if (!info.bot_token)
  45. {
  46. log_fatal("no bot token specified");
  47. return -1;
  48. }
  49. struct ld_context *ctx;
  50. ctx = ld_create_context(&info);
  51. if (ctx == NULL)
  52. {
  53. fprintf(stderr, "Failed to create libdiscord context");
  54. return -1;
  55. }
  56. /*
  57. printf("%s\n", ld_get_gateway(ctx));
  58. struct ld_gateway_bot_resp *r = ld_get_gateway_bot(ctx);
  59. if (!r)
  60. {
  61. printf("Error (%d): %s", ctx->last_rest_status->what, ctx->last_rest_status->text);
  62. return -1;
  63. }
  64. printf("%s:%d\n", r->url, r->shards);
  65. free(r);
  66. int a = ld_create_message(ctx, "444130990252752898", "test");
  67. if (a)
  68. {
  69. return -1;
  70. }
  71. */
  72. guild_channel_t channel;
  73. ld_get_channel(ctx, "444130990252752898", &channel);
  74. log_trace(channel.guild_id);
  75. struct ld_modify_channel_obj *m = malloc(sizeof(struct ld_modify_channel_obj));
  76. memset(m, 0, sizeof(struct ld_modify_channel_obj));
  77. m->name = "основной2";
  78. m->user_limit = -1;
  79. m->bitrate = -1;
  80. m->nsfw = -1;
  81. m->position = -1;
  82. m->permission_overwrites = calloc(1, sizeof(overwrite_t));
  83. m->overwrites_size = 1;
  84. m->permission_overwrites[0].id = "472393766989201408";
  85. m->permission_overwrites[0].type = "member";
  86. m->permission_overwrites[0].deny = 0;
  87. m->permission_overwrites[0].allow = 2048;
  88. guild_channel_t c;
  89. ld_modify_channel_result(ctx, "444130990252752898", m, &c);
  90. free(m);
  91. ld_delete_channel(ctx, "482874514124832779");
  92. return 0;
  93. }