Discord library in plain C
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. printf("%s\n", ld_get_gateway(ctx));
  57. struct ld_gateway_bot_resp *r = ld_get_gateway_bot(ctx);
  58. if (!r)
  59. {
  60. printf("Error (%d): %s", ctx->last_rest_status->what, ctx->last_rest_status->text);
  61. return -1;
  62. }
  63. printf("%s:%d\n", r->url, r->shards);
  64. free(r);
  65. int a = ld_create_message(ctx, "444130990252752898", "test");
  66. if (a)
  67. {
  68. return -1;
  69. }
  70. guild_channel_t channel;
  71. ld_get_channel(ctx, "444130990252752898", &channel);
  72. log_trace(channel.guild_id);
  73. return 0;
  74. }