mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-21 21:17:44 +01:00
Add config to validate admin discord commands with discord links and admin ranks (#73818)
This adds a config to secure discord chat commands used by admins. When enabled it compares the discord id the chat command came from with the linked discords db to find their ckey, then checks they have the correct admin rights. The check automatically self disables if the db is down or if legacy admin ranks are enabled. (There is no config for discord account linking or i'd just use that.) Moved non-admin discord commands out of the admin modules folder and into the discord modules folder. Deleted some defunct shit. There was a global list and admin only notify command that was used by nothing. There was a whole discord config section that was used by nothing.
This commit is contained in:
committed by
GitHub
parent
1f532aeacd
commit
57db2c1cd1
@@ -100,7 +100,7 @@ SUBSYSTEM_DEF(discord)
|
||||
* * lookup_ckey A string representing the ckey to search on
|
||||
*/
|
||||
/datum/controller/subsystem/discord/proc/lookup_id(lookup_ckey)
|
||||
var/datum/discord_link_record/link = find_discord_link_by_ckey(lookup_ckey)
|
||||
var/datum/discord_link_record/link = find_discord_link_by_ckey(lookup_ckey, only_valid = TRUE)
|
||||
if(link)
|
||||
return link.discord_id
|
||||
|
||||
@@ -113,7 +113,7 @@ SUBSYSTEM_DEF(discord)
|
||||
* * lookup_id The discord id as a string
|
||||
*/
|
||||
/datum/controller/subsystem/discord/proc/lookup_ckey(lookup_id)
|
||||
var/datum/discord_link_record/link = find_discord_link_by_discord_id(lookup_id)
|
||||
var/datum/discord_link_record/link = find_discord_link_by_discord_id(lookup_id, only_valid = TRUE)
|
||||
if(link)
|
||||
return link.ckey
|
||||
|
||||
@@ -219,12 +219,15 @@ SUBSYSTEM_DEF(discord)
|
||||
*
|
||||
* Returns a [/datum/discord_link_record]
|
||||
*/
|
||||
/datum/controller/subsystem/discord/proc/find_discord_link_by_ckey(ckey, timebound = FALSE)
|
||||
/datum/controller/subsystem/discord/proc/find_discord_link_by_ckey(ckey, timebound = FALSE, only_valid = FALSE)
|
||||
var/timeboundsql = ""
|
||||
if(timebound)
|
||||
timeboundsql = "AND timestamp >= Now() - INTERVAL 4 HOUR"
|
||||
var/validsql = ""
|
||||
if(only_valid)
|
||||
validsql = "AND valid = 1"
|
||||
|
||||
var/query = "SELECT CAST(discord_id AS CHAR(25)), ckey, MAX(timestamp), one_time_token FROM [format_table_name("discord_links")] WHERE ckey = :ckey [timeboundsql] GROUP BY ckey, discord_id, one_time_token LIMIT 1"
|
||||
var/query = "SELECT CAST(discord_id AS CHAR(25)), ckey, MAX(timestamp), one_time_token FROM [format_table_name("discord_links")] WHERE ckey = :ckey [timeboundsql] [validsql] GROUP BY ckey, discord_id, one_time_token LIMIT 1"
|
||||
var/datum/db_query/query_get_discord_link_record = SSdbcore.NewQuery(
|
||||
query,
|
||||
list("ckey" = ckey)
|
||||
@@ -254,12 +257,15 @@ SUBSYSTEM_DEF(discord)
|
||||
*
|
||||
* Returns a [/datum/discord_link_record]
|
||||
*/
|
||||
/datum/controller/subsystem/discord/proc/find_discord_link_by_discord_id(discord_id, timebound = FALSE)
|
||||
/datum/controller/subsystem/discord/proc/find_discord_link_by_discord_id(discord_id, timebound = FALSE, only_valid = FALSE)
|
||||
var/timeboundsql = ""
|
||||
if(timebound)
|
||||
timeboundsql = "AND timestamp >= Now() - INTERVAL 4 HOUR"
|
||||
var/validsql = ""
|
||||
if(only_valid)
|
||||
validsql = "AND valid = 1"
|
||||
|
||||
var/query = "SELECT CAST(discord_id AS CHAR(25)), ckey, MAX(timestamp), one_time_token FROM [format_table_name("discord_links")] WHERE discord_id = :discord_id [timeboundsql] GROUP BY ckey, discord_id, one_time_token LIMIT 1"
|
||||
var/query = "SELECT CAST(discord_id AS CHAR(25)), ckey, MAX(timestamp), one_time_token FROM [format_table_name("discord_links")] WHERE discord_id = :discord_id [timeboundsql] [validsql] GROUP BY ckey, discord_id, one_time_token LIMIT 1"
|
||||
var/datum/db_query/query_get_discord_link_record = SSdbcore.NewQuery(
|
||||
query,
|
||||
list("discord_id" = discord_id)
|
||||
@@ -274,3 +280,22 @@ SUBSYSTEM_DEF(discord)
|
||||
|
||||
//Make sure we clean up the query
|
||||
qdel(query_get_discord_link_record)
|
||||
|
||||
|
||||
/**
|
||||
* Extract a discord id from a mention string
|
||||
*
|
||||
* This will regex out the mention <@num> block to extract the discord id
|
||||
*
|
||||
* Arguments:
|
||||
* * discord_id The users discord mention string (string)
|
||||
*
|
||||
* Returns a text string with the discord id or null
|
||||
*/
|
||||
/datum/controller/subsystem/discord/proc/get_discord_id_from_mention(mention)
|
||||
var/static/regex/discord_mention_extraction_regex = regex(@"<@([0-9]+)>")
|
||||
discord_mention_extraction_regex.Find(mention)
|
||||
if (length(discord_mention_extraction_regex.group) == 1)
|
||||
return discord_mention_extraction_regex.group[1]
|
||||
return null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user