Browse Source

Fixed compilation

master
Alexander Memer 1 year ago
parent
commit
4dff087d3a
10 changed files with 13 additions and 280 deletions
  1. 0
    25
      include/client.h
  2. 0
    10
      include/events.h
  3. 0
    37
      include/log.h
  4. 0
    13
      include/rest.h
  5. 0
    182
      include/types.h
  6. 4
    4
      src/client.c
  7. 2
    2
      src/events.c
  8. 1
    1
      src/log.c
  9. 3
    3
      src/rest.c
  10. 3
    3
      src/types.c

+ 0
- 25
include/client.h View File

@@ -1,25 +0,0 @@
#ifndef _CLIENT_H_
#define _CLIENT_H_
#include "../deps/libwsclient/wsclient.h"
#include "types.h"
typedef struct Client {
wsclient *ws;
char *session_id;
int done;
int hello;
int hrtb_interval;
int hrtb_acks;
int seq;
user_t self;
void (*on_message)(struct Client *client, message_t msg);
void (*on_ready)(struct Client *client);
} client_t;
int client_init(client_t *client);
void client_run(client_t *client);
void client_finish(client_t *client);
void heartbeat(client_t *client);
#endif // _CLIENT_H_

+ 0
- 10
include/events.h View File

@@ -1,10 +0,0 @@
#ifndef _EVENTS_H_
#define _EVENTS_H_
#include <json.h>
#include "client.h"
void dispatch(client_t *bot, json_object *data);
#endif // _EVENTS_H_

+ 0
- 37
include/log.h View File

@@ -1,37 +0,0 @@
/**
* Copyright (c) 2017 rxi
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MIT license. See `log.c` for details.
*/

#ifndef LOG_H
#define LOG_H

#define LOG_USE_COLOR

#include <stdio.h>
#include <stdarg.h>

#define LOG_VERSION "0.1.0"

typedef void (*log_LockFn)(void *udata, int lock);

enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };

#define log_trace(...) log_log(LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__)
#define log_debug(...) log_log(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
#define log_info(...) log_log(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
#define log_warn(...) log_log(LOG_WARN, __FILE__, __LINE__, __VA_ARGS__)
#define log_error(...) log_log(LOG_ERROR, __FILE__, __LINE__, __VA_ARGS__)
#define log_fatal(...) log_log(LOG_FATAL, __FILE__, __LINE__, __VA_ARGS__)

void log_set_udata(void *udata);
void log_set_lock(log_LockFn fn);
void log_set_fp(FILE *fp);
void log_set_level(int level);
void log_set_quiet(int enable);

void log_log(int level, const char *file, int line, const char *fmt, ...);

#endif

+ 0
- 13
include/rest.h View File

@@ -1,13 +0,0 @@
#ifndef _REST_H_
#define _REST_H_

#include <curl/curl.h>
#include <json.h>

#include "types.h"

void send_message(char *channel_id, char *text);
void add_reaction(char* channel_id, char *message_id, char *emoji);
guild_channel_t get_channel(char *channel_id);

#endif

+ 0
- 182
include/types.h View File

@@ -1,182 +0,0 @@
#ifndef _TYPES_H_
#define _TYPES_H_
#include "../deps/libwsclient/wsclient.h"
#include <unistd.h>
#include <json.h>
enum game_types {
GAME = 0,
STREAMING = 1
};
enum channel_types {
TEXT = 0,
VOICE = 1
};
enum {
DISPATCH,
HEARTBEAT,
IDENTIFY,
PRESENCE,
VOICE_STATE,
VOICE_PING,
RESUME,
RECONNECT,
REQUEST_MEMBERS,
INVALIDATE_SESSION,
HELLO,
HEARTBEAT_ACK
};
typedef struct curl_fetch_st {
char *payload;
size_t size;
} curl_fetch_t;
typedef struct guild_channel {
char *id;
char *guild_id;
char *name;
int type;
int position;
int is_private;
/* TODO permission_overwrites */
char *topic;
char *last_message_id;
int bitrate;
int user_limit;
} guild_channel_t;
typedef struct thumbnail {
char* url;
char* proxy_url;
int height;
int width;
} thumbnail_t;
typedef struct video {
char* url;
int height;
int width;
} video_t;
typedef struct image {
char* url;
char* proxy_url;
int height;
int width;
} image_t;
typedef struct provider {
char* name;
char* url;
} provider_t;
typedef struct author {
char* name;
char* url;
char* icon_url;
char* proxy_icon_url;
} author_t;
typedef struct footer {
char* text;
char* icon_url;
char* proxy_icon_url;
} footer_t;
typedef struct field {
char* name;
char* value;
int _inline;
} field_t;
typedef struct embed {
char* title;
char* type;
char* description;
char* url;
char* timestamp;
int color;
footer_t footer;
image_t image;
thumbnail_t thumbnail;
video_t video;
provider_t provider;
author_t author;
field_t fields;
} embed_t;
typedef struct user {
char* id;
char* username;
char* discriminator;
char* avatar;
int bot;
int mfa_enabled;
int verified;
char* email;
} user_t;
typedef struct dm_channel {
char *id;
int is_private;
user_t recipient;
char *last_message_id;
} dm_channel_t;
typedef struct game {
char *name;
int type;
char *url; // Only if type is STREAMING (1)
} game_t;
typedef struct presence_update {
user_t user; // Can be partial
game_t game; // May be null
char *guild_id;
char *status;
char *roles[200];
} presence_update_t;
typedef struct emoji {
char* id;
char* name;
} emoji_t;
typedef struct reaction {
int counter;
int me;
emoji_t _emoji;
} reaction_t;
typedef struct message {
char* id;
char* channel_id;
user_t author;
char* content;
char* timestamp;
char* edited_timestamp;
int tts;
int mention_everyone;
user_t mentions[1024];
/*
TODO:
mention_roles
attachments
embeds
nonce
*/
embed_t embeds[1024];
reaction_t reactions[1024];
int pinned;
char* webhook_id;
} message_t;
user_t user(json_object *raw);
message_t message(json_object *raw);
#endif // TYPES_H_

+ 4
- 4
src/client.c View File

@@ -1,8 +1,8 @@
#include "../include/client.h"
#include "../include/events.h"
#include "../include/log.h"
#include <crow/client.h>
#include <crow/events.h>
#include <crow/log.h>
#include <json.h>
#include <json-c/json.h>
client_t *g_client;

+ 2
- 2
src/events.c View File

@@ -1,5 +1,5 @@
#include "../include/events.h"
#include "../include/log.h"
#include <crow/events.h>
#include <crow/log.h>
void dispatch(client_t *bot, json_object *data) {

+ 1
- 1
src/log.c View File

@@ -26,7 +26,7 @@
#include <string.h>
#include <time.h>

#include "../include/log.h"
#include <crow/log.h>

static struct {
void *udata;

+ 3
- 3
src/rest.c View File

@@ -1,6 +1,6 @@
#include "../include/rest.h"
#include "../include/log.h"
#include "../deps/librequests/include/requests.h"
#include <crow/rest.h>
#include <crow/log.h>
#include <requests.h>

void
send_message(char* channel_id, char* text) {

+ 3
- 3
src/types.c View File

@@ -1,7 +1,7 @@
#include "../include/types.h"
#include "../include/log.h"
#include <crow/types.h>
#include <crow/log.h>
#include <json.h>
#include <json-c/json.h>
user_t user(json_object *raw) {
user_t u;

Loading…
Cancel
Save