Bot is now basically functional
Big tidy up, new question source.
This commit is contained in:
81
TriviaBot/bot/data_structures/Channel.hpp
Normal file
81
TriviaBot/bot/data_structures/Channel.hpp
Normal file
@ -0,0 +1,81 @@
|
||||
#ifndef BOT_DATA__STRUCTURES_CHANNEL
|
||||
#define BOT_DATA__STRUCTURES_CHANNEL
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../json/json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace DiscordObjects {
|
||||
/*
|
||||
=============================================================== CHANNEL OBJECT ==============================================================
|
||||
|Field |Type |Description |Present |
|
||||
|-----------------------|---------------|---------------------------------------------------------------------------------------|-----------|
|
||||
|id |snowflake |the id of this channel (will be equal to the guild if it's the "general" channel) |Always |
|
||||
|guild_id |snowflake |the id of the guild |Always |
|
||||
|name |string |the name of the channel (2-100 characters) |Always |
|
||||
|type |string |"text" or "voice" |Always |
|
||||
|position |integer |the ordering position of the channel |Always |
|
||||
|is_private |bool |should always be false for guild channels |Always |
|
||||
|permission_overwrites |array |an array of overwrite objects |Always |
|
||||
|topic |string |the channel topic (0-1024 characters) |Text only |
|
||||
|last_message_id |snowflake |the id of the last message sent in this channel |Text only |
|
||||
|bitrate |integer |the bitrate (in bits) of the voice channel |Voice only |
|
||||
|user_limit |integer |the user limit of the voice channel |Voice only |
|
||||
---------------------------------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class Channel {
|
||||
public:
|
||||
Channel();
|
||||
Channel(json data);
|
||||
|
||||
void load_from_json(json data);
|
||||
|
||||
bool operator==(Channel rhs);
|
||||
|
||||
std::string id;
|
||||
std::string guild_id;
|
||||
std::string name;
|
||||
std::string type;
|
||||
int position;
|
||||
bool is_private;
|
||||
// TODO: Implement permission overwrites
|
||||
// std::vector<Permission_Overwrite> permission_overwrites;
|
||||
std::string topic;
|
||||
std::string last_message_id;
|
||||
int bitrate;
|
||||
int user_limit;
|
||||
};
|
||||
|
||||
inline Channel::Channel() {
|
||||
id = guild_id = name = topic = last_message_id = "null";
|
||||
position = bitrate = user_limit = -1;
|
||||
is_private = false;
|
||||
type = "text";
|
||||
}
|
||||
|
||||
inline Channel::Channel(json data) {
|
||||
load_from_json(data);
|
||||
}
|
||||
|
||||
inline void Channel::load_from_json(json data) {
|
||||
id = data.value("id", "null");
|
||||
guild_id = data.value("guild_id", "null");
|
||||
name = data.value("name", "null");
|
||||
type = data.value("type", "text");
|
||||
position = data.value("position", -1);
|
||||
is_private = data.value("is_private", false);
|
||||
topic = data.value("topic", "null");
|
||||
last_message_id = data.value("last_message_id", "null");
|
||||
bitrate = data.value("bitrate", -1);
|
||||
user_limit = data.value("user_limit", -1);
|
||||
}
|
||||
|
||||
inline bool Channel::operator==(Channel rhs) {
|
||||
return id == rhs.id && id != "null";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
105
TriviaBot/bot/data_structures/Guild.hpp
Normal file
105
TriviaBot/bot/data_structures/Guild.hpp
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef BOT_DATA__STRUCTURES_Guild
|
||||
#define BOT_DATA__STRUCTURES_Guild
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include "../json/json.hpp"
|
||||
|
||||
#include "Channel.hpp"
|
||||
#include "User.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace DiscordObjects {
|
||||
/*
|
||||
=================================== GUILD OBJECT ====================================
|
||||
|Field |Type |Description |
|
||||
|-------------------|---------------|-----------------------------------------------|
|
||||
|id |snowflake |guild id |
|
||||
|name |string |guild name (2-100 characters) |
|
||||
|icon |string |icon hash |
|
||||
|splash |string |splash hash |
|
||||
|owner_id |snowflake |id of owner |
|
||||
|region |string |{voice_region.id} |
|
||||
|afk_channel_id |snowflake |id of afk channel |
|
||||
|afk_timeout |integer |afk timeout in seconds |
|
||||
|embed_enabled |bool |is this guild embeddable (e.g. widget) |
|
||||
|embed_channel_id |snowflake |id of embedded channel |
|
||||
|verification_level |integer |level of verification |
|
||||
|voice_states |array |array of voice state objects (w/o guild_id) |
|
||||
|roles |array |array of role objects |
|
||||
|emojis |array |array of emoji objects |
|
||||
|features |array |array of guild features |
|
||||
-------------------------------------------------------------------------------------
|
||||
|
||||
Custom fields:
|
||||
------------------------------------------------------------------------------------
|
||||
|Field |Type |Description |
|
||||
|-------------------|---------------|-----------------------------------------------|
|
||||
|channels |array |array of channel object ptrs |
|
||||
|users |array |array of user objects ptrs |
|
||||
-------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class Guild {
|
||||
public:
|
||||
Guild();
|
||||
Guild(json data);
|
||||
|
||||
void load_from_json(json data);
|
||||
|
||||
bool operator==(Guild rhs);
|
||||
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string icon;
|
||||
std::string splash;
|
||||
std::string owner_id;
|
||||
std::string region;
|
||||
std::string afk_channel_id;
|
||||
int afk_timeout;
|
||||
// bool embed_enabled;
|
||||
// std::string embed_channel_id;
|
||||
int verification_level;
|
||||
// TODO: Implement all guil fields
|
||||
// std::vector<?> voice_states
|
||||
// std::vector<?> roles
|
||||
// std::vector<?> emojis
|
||||
// std::vector<?> features
|
||||
|
||||
std::vector<std::shared_ptr<Channel>> channels;
|
||||
//std::vector<std::unique_ptr<DiscordObjects::User>> users;
|
||||
};
|
||||
|
||||
inline Guild::Guild() {
|
||||
id = name = icon = splash = owner_id = region = afk_channel_id = "null";
|
||||
afk_timeout = verification_level = -1;
|
||||
}
|
||||
|
||||
inline Guild::Guild(json data) {
|
||||
load_from_json(data);
|
||||
}
|
||||
|
||||
inline void Guild::load_from_json(json data) {
|
||||
Guild();
|
||||
std::cout << data.dump(4) << std::endl;
|
||||
|
||||
|
||||
id = data.value("id", "null");
|
||||
name = data.value("name", "null");
|
||||
icon = data.value("icon", "null");
|
||||
splash = data.value("spash", "null");
|
||||
owner_id = data.value("owner_id", "null");
|
||||
region = data.value("region", "null");
|
||||
afk_channel_id = data.value("afk_channel_id", "null");
|
||||
afk_timeout = data.value("afk_timeout", -1);
|
||||
verification_level = data.value("verification_level", -1);
|
||||
}
|
||||
|
||||
inline bool Guild::operator==(Guild rhs) {
|
||||
return id == rhs.id && id != "null";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
125
TriviaBot/bot/data_structures/Text.txt
Normal file
125
TriviaBot/bot/data_structures/Text.txt
Normal file
@ -0,0 +1,125 @@
|
||||
Example data:
|
||||
|
||||
!!!!!!!!!!!!!!!!! GUILD_CREATE Event
|
||||
{
|
||||
"afk_channel_id": null,
|
||||
"afk_timeout": 300,
|
||||
"channels": [
|
||||
{
|
||||
"id": "200398901767962624",
|
||||
"is_private": false,
|
||||
"last_message_id": "201355522635595776",
|
||||
"name": "general",
|
||||
"permission_overwrites": [],
|
||||
"position": 0,
|
||||
"topic": "",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"bitrate": 64000,
|
||||
"id": "200398901767962625",
|
||||
"is_private": false,
|
||||
"name": "General",
|
||||
"permission_overwrites": [],
|
||||
"position": 0,
|
||||
"type": "voice",
|
||||
"user_limit": 0
|
||||
}
|
||||
],
|
||||
"default_message_notifications": 0,
|
||||
"emojis": [],
|
||||
"features": [],
|
||||
"icon": null,
|
||||
"id": "200398901767962624",
|
||||
"joined_at": "2016-07-06T23:54:20.824000+00:00",
|
||||
"large": false,
|
||||
"member_count": 2,
|
||||
"members": [
|
||||
{
|
||||
"deaf": false,
|
||||
"joined_at": "2016-07-06T23:53:41.425000+00:00",
|
||||
"mute": false,
|
||||
"roles": [
|
||||
"200399346498273280"
|
||||
],
|
||||
"user": {
|
||||
"avatar": "1dc076d2d273615dd23546c86dbdfd9c",
|
||||
"discriminator": "8212",
|
||||
"id": "82232146579689472",
|
||||
"username": "Jack"
|
||||
}
|
||||
},
|
||||
{
|
||||
"deaf": false,
|
||||
"joined_at": "2016-07-06T23:54:20.824000+00:00",
|
||||
"mute": false,
|
||||
"roles": [
|
||||
"200399601507893248"
|
||||
],
|
||||
"user": {
|
||||
"avatar": "e871ceecaa362718af6d3174bc941977",
|
||||
"bot": true,
|
||||
"discriminator": "8194",
|
||||
"id": "199657095258177539",
|
||||
"username": "trivia-bot"
|
||||
}
|
||||
}
|
||||
],
|
||||
"mfa_level": 0,
|
||||
"name": "EleGiggle",
|
||||
"owner_id": "82232146579689472",
|
||||
"presences": [
|
||||
{
|
||||
"game": null,
|
||||
"status": "online",
|
||||
"user": {
|
||||
"id": "82232146579689472"
|
||||
}
|
||||
},
|
||||
{
|
||||
"game": null,
|
||||
"status": "online",
|
||||
"user": {
|
||||
"id": "199657095258177539"
|
||||
}
|
||||
}
|
||||
],
|
||||
"region": "london",
|
||||
"roles": [
|
||||
{
|
||||
"color": 0,
|
||||
"hoist": false,
|
||||
"id": "200398901767962624",
|
||||
"managed": false,
|
||||
"mentionable": false,
|
||||
"name": "@everyone",
|
||||
"permissions": 36953089,
|
||||
"position": 0
|
||||
},
|
||||
{
|
||||
"color": 3066993,
|
||||
"hoist": true,
|
||||
"id": "200399346498273280",
|
||||
"managed": false,
|
||||
"mentionable": false,
|
||||
"name": "All Perms",
|
||||
"permissions": 506715199,
|
||||
"position": 1
|
||||
},
|
||||
{
|
||||
"color": 15844367,
|
||||
"hoist": true,
|
||||
"id": "200399601507893248",
|
||||
"managed": false,
|
||||
"mentionable": false,
|
||||
"name": "Robot",
|
||||
"permissions": 536083519,
|
||||
"position": 1
|
||||
}
|
||||
],
|
||||
"splash": null,
|
||||
"unavailable": false,
|
||||
"verification_level": 0,
|
||||
"voice_states": []
|
||||
}
|
||||
|
65
TriviaBot/bot/data_structures/User.hpp
Normal file
65
TriviaBot/bot/data_structures/User.hpp
Normal file
@ -0,0 +1,65 @@
|
||||
#ifndef BOT_DATA__STRUCTURES_USER
|
||||
#define BOT_DATA__STRUCTURES_USER
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../json/json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace DiscordObjects {
|
||||
/*
|
||||
==================================================== USER OBJECT =======================================================
|
||||
Field Type Description Required OAuth2 Scope
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
id snowflake the users id identify
|
||||
username string the users username, not unique across the platform identify
|
||||
discriminator string the users 4-digit discord-tag identify
|
||||
avatar string the users avatar hash identify
|
||||
bot bool whether the user belongs to a OAuth2 application identify
|
||||
mfa_enabled bool whether the user has two factor enabled on their account identify
|
||||
verified bool whether the email on this account has been verified email
|
||||
email string the users email email
|
||||
*/
|
||||
|
||||
class User {
|
||||
public:
|
||||
User();
|
||||
User(json data);
|
||||
|
||||
void load_from_json(json data);
|
||||
|
||||
bool operator==(User rhs);
|
||||
|
||||
std::string id;
|
||||
std::string username;
|
||||
std::string discriminator;
|
||||
std::string avatar;
|
||||
bool bot;
|
||||
bool mfa_enabled;
|
||||
};
|
||||
|
||||
inline User::User() {
|
||||
id = username = discriminator = avatar = "null";
|
||||
bot = mfa_enabled = false;
|
||||
}
|
||||
|
||||
inline User::User(json data) {
|
||||
load_from_json(data);
|
||||
}
|
||||
|
||||
inline void User::load_from_json(json data) {
|
||||
id = data.value("id", "null");
|
||||
username = data.value("username", "null");
|
||||
discriminator = data.value("discriminator", "null");
|
||||
avatar = data.value("avatar", "null");
|
||||
bot = data.value("bot", false);
|
||||
mfa_enabled = data.value("mfa_enabled", false);
|
||||
}
|
||||
|
||||
inline bool User::operator==(User rhs) {
|
||||
return id == rhs.id && id != "null";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user