Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord Integration! Sync your roles between your NamelessMC site and your Discord Guild. #1764

Merged
merged 23 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
af07152
Initial commit, big additions. Linking/verifying discord id is complete
tadhgboyle Jul 21, 2020
36497b7
Update admin.php
KaspianDev Jul 21, 2020
fc1ec5e
Merge pull request #1757 from kacperleague9/patch-1
tadhgboyle Jul 21, 2020
54b2b70
Better validation errors + language updating
tadhgboyle Jul 21, 2020
9e7505e
Apply role change on user edit page - still some things to flush out …
tadhgboyle Jul 21, 2020
5f5b9fd
flush out some edge cases
tadhgboyle Jul 21, 2020
010aee0
Add role in discord upon account validation & more
tadhgboyle Jul 21, 2020
68c3f84
Add api endpoint (need to test) & a lot of TODOs
tadhgboyle Jul 22, 2020
921787b
Merge in announcements branch
tadhgboyle Jul 22, 2020
51ef1ad
fix announcements a bit on Default template
tadhgboyle Jul 22, 2020
b43053a
define bot url for easier move to self-hosting
tadhgboyle Jul 22, 2020
50460e2
Add discord->website (adding) sync & lots of the TODOs
tadhgboyle Jul 22, 2020
f78b6bf
Add discord role removal api endpoint
tadhgboyle Jul 22, 2020
55851bc
Add logging od discord role add/remove & fix log table
tadhgboyle Jul 22, 2020
eb6a7c9
Add api_url to discord request for extra security & add todo's for er…
tadhgboyle Jul 24, 2020
d8206fa
More API error handling for discord bot
tadhgboyle Jul 24, 2020
e2490e1
Add boilerplate error handling if bot throws error
tadhgboyle Jul 24, 2020
4df7177
oops
tadhgboyle Jul 24, 2020
e01722f
Add error messages for all discord linking
tadhgboyle Jul 24, 2020
558c35a
If they have a role on the site, give it to them when they verify the…
tadhgboyle Jul 24, 2020
6ea9787
Resolve Sam's review
tadhgboyle Jul 25, 2020
16239ef
Add info msgs so people know where to get discord IDs
tadhgboyle Jul 25, 2020
8b7eeff
Add all language translations and update NMC version strings
tadhgboyle Jul 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/classes/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ class Log{
'api' => [
//TODO API STUFF
],
'discord' => [
'role_add' => 'discord_role_add',
'role_remove' => 'discord_role_remove'
]
];

private $_db;
Expand Down
4 changes: 2 additions & 2 deletions core/classes/Queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function dbInitialise($charset = 'latin1', $engine = 'InnoDB'){
$data = $this->_db->createTable("forums_reactions", " `id` int(11) NOT NULL AUTO_INCREMENT, `post_id` int(11) NOT NULL, `user_received` int(11) NOT NULL, `user_given` int(11) NOT NULL, `reaction_id` int(11) NOT NULL, `time` int(11) NOT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("forums_topic_labels", " `id` int(11) NOT NULL AUTO_INCREMENT, `fids` varchar(128) NOT NULL, `name` varchar(32) NOT NULL, `label` varchar(20) NOT NULL, `gids` varchar(128) DEFAULT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("friends", " `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `friend_id` int(11) NOT NULL, `notify` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("groups", "`id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, `group_html` varchar(1024) NOT NULL, `group_html_lg` varchar(1024) NOT NULL, `group_username_css` varchar(256) DEFAULT NULL, `mod_cp` tinyint(1) NOT NULL DEFAULT '0', `admin_cp` tinyint(1) NOT NULL DEFAULT '0', `staff` tinyint(1) NOT NULL DEFAULT '0', `permissions` mediumtext, `default_group` tinyint(1) NOT NULL DEFAULT '0', `order` int(11) NOT NULL DEFAULT '1', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("groups", "`id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, `group_html` varchar(1024) NOT NULL, `group_html_lg` varchar(1024) NOT NULL, `group_username_css` varchar(256) DEFAULT NULL, `mod_cp` tinyint(1) NOT NULL DEFAULT '0', `admin_cp` tinyint(1) NOT NULL DEFAULT '0', `staff` tinyint(1) NOT NULL DEFAULT '0', `permissions` mediumtext, `default_group` tinyint(1) NOT NULL DEFAULT '0', `order` int(11) NOT NULL DEFAULT '1', `discord_group_id` bigint(18) DEFAULT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("groups_templates", " `id` int(11) NOT NULL AUTO_INCREMENT, `group_id` int(11) NOT NULL, `template_id` int(11) NOT NULL, `can_use_template` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("group_sync", " `id` int(11) NOT NULL AUTO_INCREMENT, `ingame_rank_name` varchar(64) NOT NULL, `website_group_id` int(11) NOT NULL, `primary` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("ip_bans", " `id` int(11) NOT NULL AUTO_INCREMENT, `ip` varchar(128) NOT NULL, `banned_by` int(11) NOT NULL, `banned_at` int(11) NOT NULL, `reason` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
Expand All @@ -145,7 +145,7 @@ public function dbInitialise($charset = 'latin1', $engine = 'InnoDB'){
$data = $this->_db->createTable("templates", " `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL, `enabled` tinyint(1) NOT NULL DEFAULT '0', `is_default` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("topics", " `id` int(11) NOT NULL AUTO_INCREMENT, `forum_id` int(11) NOT NULL, `topic_title` varchar(150) NOT NULL, `topic_creator` int(11) NOT NULL, `topic_last_user` int(11) NOT NULL, `topic_date` int(11) NOT NULL, `topic_reply_date` int(11) NOT NULL, `topic_views` int(11) NOT NULL DEFAULT '0', `locked` tinyint(1) NOT NULL DEFAULT '0', `sticky` tinyint(1) NOT NULL DEFAULT '0', `label` int(11) DEFAULT NULL, `deleted` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("topics_following", "`id` int(11) NOT NULL AUTO_INCREMENT, `topic_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `existing_alerts` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("users", " `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(20) NOT NULL, `nickname` varchar(20) NOT NULL, `password` varchar(255) NOT NULL, `pass_method` varchar(12) NOT NULL DEFAULT 'default', `uuid` varchar(32) NOT NULL, `joined` int(11) NOT NULL, `group_id` int(11) NOT NULL, `secondary_groups` varchar(64) DEFAULT NULL, `email` varchar(64) NOT NULL, `isbanned` tinyint(1) NOT NULL DEFAULT '0', `lastip` varchar(128) DEFAULT NULL, `active` tinyint(1) NOT NULL DEFAULT '0', `signature` mediumtext, `profile_views` int(11) NOT NULL DEFAULT '0', `reputation` int(11) NOT NULL DEFAULT '0', `reset_code` varchar(60) DEFAULT NULL, `has_avatar` tinyint(1) NOT NULL DEFAULT '0', `gravatar` tinyint(1) NOT NULL DEFAULT '0', `topic_updates` tinyint(1) NOT NULL DEFAULT '1', `private_profile` tinyint(1) NOT NULL DEFAULT '0', `last_online` int(11) DEFAULT NULL, `user_title` varchar(64) DEFAULT NULL, `theme_id` int(11) DEFAULT NULL, `language_id` int(11) DEFAULT NULL, `warning_points` int(11) NOT NULL DEFAULT '0', `night_mode` tinyint(1) NOT NULL DEFAULT '0', `last_username_update` int(11) NOT NULL DEFAULT '0', `tfa_enabled` tinyint(1) NOT NULL DEFAULT '0', `tfa_type` int(11) NOT NULL DEFAULT '0', `tfa_secret` varchar(256) DEFAULT NULL, `tfa_complete` tinyint(1) NOT NULL DEFAULT '0', `banner` varchar(64) DEFAULT NULL, `timezone` varchar(32) NOT NULL DEFAULT 'Europe/London', `avatar_updated` int(11) DEFAULT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("users", " `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(20) NOT NULL, `nickname` varchar(20) NOT NULL, `password` varchar(255) NOT NULL, `pass_method` varchar(12) NOT NULL DEFAULT 'default', `uuid` varchar(32) NOT NULL, `joined` int(11) NOT NULL, `group_id` int(11) NOT NULL, `secondary_groups` varchar(64) DEFAULT NULL, `email` varchar(64) NOT NULL, `isbanned` tinyint(1) NOT NULL DEFAULT '0', `lastip` varchar(128) DEFAULT NULL, `active` tinyint(1) NOT NULL DEFAULT '0', `signature` mediumtext, `profile_views` int(11) NOT NULL DEFAULT '0', `reputation` int(11) NOT NULL DEFAULT '0', `reset_code` varchar(60) DEFAULT NULL, `has_avatar` tinyint(1) NOT NULL DEFAULT '0', `gravatar` tinyint(1) NOT NULL DEFAULT '0', `topic_updates` tinyint(1) NOT NULL DEFAULT '1', `private_profile` tinyint(1) NOT NULL DEFAULT '0', `last_online` int(11) DEFAULT NULL, `user_title` varchar(64) DEFAULT NULL, `theme_id` int(11) DEFAULT NULL, `language_id` int(11) DEFAULT NULL, `warning_points` int(11) NOT NULL DEFAULT '0', `night_mode` tinyint(1) NOT NULL DEFAULT '0', `last_username_update` int(11) NOT NULL DEFAULT '0', `tfa_enabled` tinyint(1) NOT NULL DEFAULT '0', `tfa_type` int(11) NOT NULL DEFAULT '0', `tfa_secret` varchar(256) DEFAULT NULL, `tfa_complete` tinyint(1) NOT NULL DEFAULT '0', `banner` varchar(64) DEFAULT NULL, `timezone` varchar(32) NOT NULL DEFAULT 'Europe/London', `avatar_updated` int(11) DEFAULT NULL, `discord_id` bigint(18) NULL DEFAULT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("users_admin_session", " `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `hash` varchar(64) NOT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("users_ips", " `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `ip` varchar(128) NOT NULL, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
$data = $this->_db->createTable("users_profile_fields", " `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `field_id` int(11) NOT NULL, `value` mediumtext, PRIMARY KEY (`id`)", "ENGINE=$engine DEFAULT CHARSET=$charset");
Expand Down
30 changes: 25 additions & 5 deletions core/includes/updates/200-pr7.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,31 @@
echo $e->getMessage() . '<br />';
}

// Discord Integration
try {
$queries->create('settings', array(
'name' => 'discord_integration',
'value' => 0,
));
} catch (Exception $e) {
echo $e->getMessage() . '<br />';
}
try {
$queries->alterTable('groups', '`discord_role_id`', "bigint(18) NULL DEFAULT NULL");
} catch (Exception $e) {
echo $e->getMessage() . '<br />';
}
try {
$queries->alterTable('users', '`discord_id`', "bigint(18) NULL DEFAULT NULL");
} catch (Exception $e) {
echo $e->getMessage() . '<br />';
}

// Announcements

// Reset panel_sidebar cache so that the orders do not interfere on upgrade
$cache->setCache('panel_sidebar');
$cache->eraseAll();
try {
DB::getInstance()->query("CREATE TABLE `nl2_custom_announcements` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand All @@ -53,10 +77,6 @@
`message` varchar(1024) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=$db_engine DEFAULT CHARSET=$db_charset");

// Reset panel_sidebar cache so that the orders do not interfere on upgrade
$cache->setCache('panel_sidebar');
$cache->eraseAll();
} catch (Exception $e) {
echo $e->getMessage() . '<br />';
}
}
3 changes: 3 additions & 0 deletions core/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
// Friendly URLs?
define('FRIENDLY_URLS', Config::get('core/friendly'));

// Define discord bot url for easy change if they choose to selfhost
define('BOT_URL', 'http://bot.tadhgboyle.dev:8001');
tadhgboyle marked this conversation as resolved.
Show resolved Hide resolved

// Set up cache
$cache = new Cache(array('name' => 'nameless', 'extension' => '.cache', 'path' => ROOT_PATH . '/cache/'));

Expand Down
9 changes: 7 additions & 2 deletions core/installation/views/installer.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@
'group_username_css' => '#ff0000',
'mod_cp' => 1,
'admin_cp' => 1,
'permissions' => '{"admincp.core":1,"admincp.core.api":1,"admincp.core.general":1,"admincp.core.avatars":1,"admincp.core.fields":1,"admincp.core.debugging":1,"admincp.core.emails":1,"admincp.core.navigation":1,"admincp.core.announcements":1,"admincp.core.reactions":1,"admincp.core.registration":1,"admincp.core.social_media":1,"admincp.core.terms":1,"admincp.errors":1,"admincp.integrations":1,"admincp.minecraft":1,"admincp.minecraft.authme":1,"admincp.minecraft.verification":1,"admincp.minecraft.servers":1,"admincp.minecraft.query_errors":1,"admincp.minecraft.banners":1,"admincp.modules":1,"admincp.pages":1,"admincp.pages.metadata":1,"admincp.security":1,"admincp.security.acp_logins":1,"admincp.security.template":1,"admincp.sitemap":1,"admincp.styles":1,"admincp.styles.panel_templates":1,"admincp.styles.templates":1,"admincp.styles.templates.edit":1,"admincp.styles.images":1,"admincp.update":1,"admincp.users":1,"admincp.users.edit":1,"admincp.groups":1,"admincp.groups.self":1,"admincp.widgets":1,"modcp.ip_lookup":1,"modcp.punishments":1,"modcp.punishments.warn":1,"modcp.punishments.ban":1,"modcp.punishments.banip":1,"modcp.punishments.revoke":1,"modcp.reports":1,"modcp.profile_banner_reset":1,"usercp.messaging":1,"usercp.signature":1,"admincp.forums":1,"usercp.private_profile":1,"usercp.nickname":1,"usercp.profile_banner":1,"profile.private.bypass":1, "admincp.security.all":1,"admincp.core.hooks":1}',
'permissions' => '{"admincp.core":1,"admincp.core.api":1,"admincp.core.general":1,"admincp.core.avatars":1,"admincp.core.fields":1,"admincp.core.debugging":1,"admincp.core.emails":1,"admincp.core.navigation":1,"admincp.core.announcements":1,"admincp.core.reactions":1,"admincp.core.registration":1,"admincp.core.social_media":1,"admincp.core.terms":1,"admincp.errors":1,"admincp.integrations":1,"admincp.discord":1,"admincp.minecraft":1,"admincp.minecraft.authme":1,"admincp.minecraft.verification":1,"admincp.minecraft.servers":1,"admincp.minecraft.query_errors":1,"admincp.minecraft.banners":1,"admincp.modules":1,"admincp.pages":1,"admincp.pages.metadata":1,"admincp.security":1,"admincp.security.acp_logins":1,"admincp.security.template":1,"admincp.sitemap":1,"admincp.styles":1,"admincp.styles.panel_templates":1,"admincp.styles.templates":1,"admincp.styles.templates.edit":1,"admincp.styles.images":1,"admincp.update":1,"admincp.users":1,"admincp.users.edit":1,"admincp.groups":1,"admincp.groups.self":1,"admincp.widgets":1,"modcp.ip_lookup":1,"modcp.punishments":1,"modcp.punishments.warn":1,"modcp.punishments.ban":1,"modcp.punishments.banip":1,"modcp.punishments.revoke":1,"modcp.reports":1,"modcp.profile_banner_reset":1,"usercp.messaging":1,"usercp.signature":1,"admincp.forums":1,"usercp.private_profile":1,"usercp.nickname":1,"usercp.profile_banner":1,"profile.private.bypass":1, "admincp.security.all":1,"admincp.core.hooks":1}',
tadhgboyle marked this conversation as resolved.
Show resolved Hide resolved
'order' => 1,
'staff' => 1
));
Expand Down Expand Up @@ -897,7 +897,12 @@
$queries->create('settings', array(
'name' => 'mc_integration',
'value' => 1
));
));

tadhgboyle marked this conversation as resolved.
Show resolved Hide resolved
$queries->create('settings', array(
'name' => 'discord_integration',
'value' => 0
));

$queries->create('settings', array(
'name' => 'avatar_type',
Expand Down
11 changes: 11 additions & 0 deletions custom/languages/EnglishUK/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,15 @@
'message_required' => 'Message is required',
'background_colour_required' => 'Background Colour is required',
'text_colour_required' => 'Text Colour is required',

// Discord
'discord' => 'Discord',
'enable_discord_integration' => 'Enable Discord integration?',
'discord_role_id' => 'Discord Role ID',
'discord_role_id_numeric' => 'Discord Role ID must be numeric.',
'discord_role_id_length' => 'Discord Role ID must be 18 digits long.',
'discord_guild_id_updated' => 'Discord Server ID was updated successfully.',
'discord_guild_id_required' => 'Please enter your Discord Server ID for Discord integration to work.',
'discord_invalid_api_url' => 'Looks like your API URL has changed. Please get the guild owner to update the URL with the Nameless Link bot.'
// TODO: All language files
tadhgboyle marked this conversation as resolved.
Show resolved Hide resolved
);
2 changes: 2 additions & 0 deletions custom/languages/EnglishUK/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
'unable_to_update_server_info' => 'Unable to update server info',
'invalid_server_id' => 'Invalid server ID',
'invalid_code' => 'Invalid code provided',
'discord_integration_disabled' => 'Discord integration is disabled.',
'unable_to_set_discord_id' => 'Unable to set Discord ID.',

// Success messages
'finish_registration_link' => 'Please click on the following link to complete registration:',
Expand Down
16 changes: 15 additions & 1 deletion custom/languages/EnglishUK/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,19 @@
/*
* Hooks
*/
'user_x_has_registered' => '{x} has joined ' . SITE_NAME . '!'
'user_x_has_registered' => '{x} has joined ' . SITE_NAME . '!',

// Discord
'discord_link' => 'Discord Link',
'linked' => 'Linked',
'not_linked' => 'Not Linked',
'discord_id' => 'Discord User ID',
'discord_id_unlinked' => 'Successfully unlinked your Discord User ID.',
'discord_id_confirm' => 'Please send a private message containing only your username to "Nameless Link#0761" to confirm your Discord User ID.',
'pending_link' => 'Pending',
'discord_id_taken' => 'That Discord User ID has already been taken.',
'discord_invalid_id' => 'That Discord User ID is invalid.',
'discord_already_pending' => 'You already have a pending verification.',
'discord_database_error' => 'The Nameless Link database is currently down. Please try again later.',
'discord_unknown_error' => 'There was an unknown error while communicating with the bot. Please contact an administrator.',
);
Loading