- Notifications
You must be signed in to change notification settings - Fork1
markbeep/Disco-C
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Disco-C is a part-time project to practice writing bigger projects in C and getting more experience in multiple directions (requests, websockets, APIs, etc.). It is also a nice way to learn about how Discord really works.
The library is built to work async, which means that every received event is handled in its own thread. The idea behind this is, that in a single function you want to work sequentially, but you also don't want functions like sending a message (which does a HTTP request that takes around ~200ms) block the whole bot from receiving anything anymore in that time. Another option would have been to make the HTTP request itself be async, but this then doesn't give you the guarantee that a message has been sent once the message-send function is done.
The wiki is still under developement, but it is available here:https://markc.su/Disco-C/
Usegit clone --recurse-submodules git@github.com:markbeep/Disco-C.git
to clone the submodules as well.
- https://libwebsockets.org/
sudo apt install libwebsockets-dev
- https://curl.se/libcurl/c/
sudo apt install libcurl4-gnutls-dev
- https://github.com/DaveGamble/cJSON/
- https://github.com/sheredom/hashmap.h/
- https://github.com/ThrowTheSwitch/Unity (optional for testing)
Note: When building the project yourself, make sure to add-Iinclude -Iexternal -I.
to add those three include directories. The local include path is because theconfig.h
with the bot token will be in the local directory. Additionally you'll find thecJSON.c
andunity.c
files in theexternal
directory.
The file layout is intended to follow the Pitchfork standard. Some things aren't yet done (like the main.c file being out in the open), but it's in the making.
- src/web/
- websocket: Contains the required methods to abstract the background websocket connection.
- gateway: Handles the websocket connection to the Discord Gateway. Making sure the heartbeat is regularly sent and the incoming responses are all properly handled.
- request: Helper file that abstracts the HTTP GET/POST/PATCH/etc. requests.
- src/utils
- cache: The cache uses the
hashmap.h
library to create a linked hashmap for messages, channels and guilds. - disco_logging: Personalized logging library which can be used to log messages to the console. The file path is additionally added to each message.
- prio_queue: O(n) lazy priority queue implementation. Currently there's no use for this anymore.
- t_pool: Thread pool library to manage the multiple threads which will then be distributed for each fired event.
- cache: The cache uses the
- src/discord/
- disco: The main functions of Disco-C. It contains the highest level of abstraction for running the bot.
- event: Handles received Discord events.
- structures: All of the Discord structure definitions.
- Structure specific functions are all defined in their corresponding source files.
- examples: Example implementations of how the bot syntax looks like.
- include: All of the header definitions are in this folder.
- external: External libraries that are required.
- docs: Configuration files to automatically generate the wiki.
- tests: Basic tests which don't really test a lot.
There exists a cache which will keep track of messages, channels and guilds so that when they are updated/deleted, you still get access to the data instead of simply an ID. To not have the cache completely overfill there is a max amount of items that are stored in the cache. The default is a size of 1000 items for each data type. The last used item will be removed once a new item is added and there are 1000 items in the cache. Per default the removed items will simply be destroyed. If you want to do something else with them, you can pass in a different callback in thediscord_config
struct which can be passed in upon starting the bot withdiscord_start_bot
.
Even though there is a cache that retreives already existing structures, every event will always provide a newly allocated structure. Meaning you will always have to free the received structures in every event callback. This is for consistency and thread safety reasons, so that a specific message struct doesn't get freed while another event still uses it.
- Interactions
- Application Command Object
- Application Command Option Object
- Register Commands
- Global
- Guild
- Send interaction response
- Components (untested, but implementation exists)
- Commands (API Calls)
- Channel
- Get channel
- Edit channel
- Basic stuff (name, desc)
- Add permissions
- Remove permissions
- Delete channel
- Get channel message
- Send message
- Content
- Embeds
- Components
- Attachments
- Edit message
- Delete message
- Bulk delete messages
- Add reaction
- View reactions
- Delete reactions
- Own
- User
- All
- Create channel invite
- Get channel invites
- Trigger typing indicator
- Get pinned messages
- Pin message
- Unpin message
- Group DM add/remove recipient
- Thread
- Start thread from message
- Start thread without message
- Start thread in forum channel
- Join thread
- Leave thread
- Add thread member
- Remove thread member
- Get thread member
- List thread members
- List public threads
- List private threads
- List joined private threads
- Emoji
- List guild emojis
- Get guild emoji
- Create guild emoji
- Modify guild emoji
- Delete guild emoji
- Guild (way too many functions to list)
- Guild Scheduled Event
- Create guild event
- Get guild event
- Edit guild event
- Delete guild event
- Get event users
- User
- Get (current) user
- Modify current user
- Get current guilds
- Get current guild member
- Leave guild
- Create DM
- Create group DM
- ... (no complete list of methods yet)
- Channel
- Events
- READY
- RESUMED
- RECONNECT
- INVALID_SESSION
- APPLICATION_COMMAND_PERMISSIONS_UPDATE
- CHANNEL_CREATE
- CHANNEL_UPDATE
- CHANNEL_DELETE
- CHANNEL_PINS_UPDATE
- THREAD_CREATE
- THREAD_UPDATE
- THREAD_DELETE
- THREAD_LIST_SYNC
- THREAD_MEMBER_UPDATE
- THREAD_MEMBERS_UPDATE
- GUILD_CREATE
- GUILD_UPDATE
- GUILD_DELETE
- GUILD_BAN_ADD
- GUILD_BAN_REMOVE
- GUILD_EMOJIS_UPDATE
- GUILD_STICKERS_UPDATE
- GUILD_INTEGRATIONS_UPDATE
- GUILD_MEMBER_ADD
- GUILD_MEMBER_REMOVE
- GUILD_MEMBER_UPDATE
- GUILD_MEMBERS_CHUNK
- GUILD_ROLE_CREATE
- GUILD_ROLE_UPDATE
- GUILD_ROLE_DELETE
- GUILD_SCHEDULED_EVENT_CREATE
- GUILD_SCHEDULED_EVENT_UPDATE
- GUILD_SCHEDULED_EVENT_DELETE
- GUILD_SCHEDULED_EVENT_USER_ADD
- GUILD_SCHEDULED_EVENT_USER_REMOVE
- INTEGRATION_CREATE
- INTEGRATION_UPDATE
- INTEGRATION_CREATE
- INVITE_CREATE
- INVITE_DELETE
- MESSAGE_CREATE
- MESSAGE_UPDATE
- MESSAGE_DELETE
- MESSAGE_DELETE_BULK
- MESSAGE_REACTION_ADD
- MESSAGE_REACTION_REMOVE
- MESSAGE_REACTION_REMOVE_ALL
- MESSAGE_REACTION_REMOVE_EMOJI
- PRESENCE_UPDATE
- STAGE_INSTANCE_CREATE
- STAGE_INSTANCE_DELETE
- STAGE_INSTANCE_UPDATE
- TYPING_START
- USER_UPDATE
- VOICE_STATE_UPDATE
- VOICE_SERVER_UPDATE
- WEBHOOKS_UPDATE
- INTERACTION_CREATE