mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
Merge pull request #7943 from VOREStation/Arokha/botreg
Semi-automate discord ID registration
This commit is contained in:
@@ -61,8 +61,10 @@ CREATE TABLE `erro_player` (
|
||||
`ip` varchar(18) NOT NULL,
|
||||
`computerid` varchar(32) NOT NULL,
|
||||
`lastadminrank` varchar(32) NOT NULL DEFAULT 'Player',
|
||||
`discord_id` varchar(64) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `ckey` (`ckey`)
|
||||
UNIQUE KEY `ckey` (`ckey`),
|
||||
KEY `discord_id` (`discord_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;
|
||||
|
||||
CREATE TABLE `erro_poll_option` (
|
||||
@@ -123,5 +125,6 @@ CREATE TABLE `vr_player_hours` (
|
||||
`ckey` varchar(32) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||
`department` varchar(64) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||
`hours` double NOT NULL,
|
||||
`total_hours` double NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`ckey`,`department`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
@@ -105,7 +105,7 @@ datum/admins/proc/notes_gethtml(var/ckey)
|
||||
|
||||
message_admins("<font color='blue'>[key_name_admin(user)] has edited [key]'s notes.</font>")
|
||||
log_admin("[key_name(user)] has edited [key]'s notes.")
|
||||
admin_action_message(user.key, key, "added note on", note, 0) //VOREStation Add
|
||||
admin_action_message(P.author, key, "added note on", note, 0) //VOREStation Add
|
||||
del(info) // savefile, so NOT qdel
|
||||
|
||||
//Updating list of keys with notes on them
|
||||
|
||||
@@ -65,6 +65,42 @@
|
||||
send2adminirc(href_list["irc_msg"])
|
||||
return
|
||||
|
||||
//VOREStation Add
|
||||
if(href_list["discord_reg"])
|
||||
var/their_id = html_decode(href_list["discord_reg"])
|
||||
var/sane = FALSE
|
||||
for(var/item in GLOB.pending_discord_registrations)
|
||||
var/list/L = item
|
||||
if(!islist(L))
|
||||
GLOB.pending_discord_registrations -= item
|
||||
continue
|
||||
if(L["ckey"] == ckey && L["id"] == their_id)
|
||||
GLOB.pending_discord_registrations -= list(item)
|
||||
var/time = L["time"]
|
||||
if((world.realtime - time) > 10 MINUTES)
|
||||
to_chat(src, "<span class='warning'>Sorry, that link has expired. Please request another on Discord.</span>")
|
||||
return
|
||||
sane = TRUE
|
||||
break
|
||||
|
||||
if(!sane)
|
||||
to_chat(src, "<span class='warning'>Sorry, that link doesn't appear to be valid. Please try again.</span>")
|
||||
return
|
||||
|
||||
var/sql_discord = sql_sanitize_text(their_id)
|
||||
var/sql_ckey = sql_sanitize_text(ckey)
|
||||
var/DBQuery/query = dbcon.NewQuery("UPDATE erro_player SET discord_id = '[sql_discord]' WHERE ckey = '[sql_ckey]'")
|
||||
if(query.Execute())
|
||||
to_chat(src, "<span class='notice'>Registration complete! Thank you for taking the time to register your Discord ID.</span>")
|
||||
log_and_message_admins("[ckey] has registered their Discord ID to obtain the Crew Member role. Their Discord snowflake ID is: [their_id]")
|
||||
admin_chat_message(message = "[ckey] has registered their Discord ID to obtain the Crew Member role. Their Discord is: <@[their_id]>", color = "#4eff22")
|
||||
notes_add(ckey, "Discord ID: [their_id]")
|
||||
else
|
||||
to_chat(src, "<span class='warning'>There was an error registering your Discord ID in the database. Contact an administrator.</span>")
|
||||
log_and_message_admins("[ckey] failed to register their Discord ID. Their Discord snowflake ID is: [their_id]. Is the database connected?")
|
||||
return
|
||||
//VOREStation Add End
|
||||
|
||||
//Logs all hrefs
|
||||
if(config && config.log_hrefs && href_logfile)
|
||||
WRITE_LOG(href_logfile, "[src] (usr:[usr])</small> || [hsrc ? "[hsrc] " : ""][href]")
|
||||
|
||||
@@ -61,4 +61,59 @@
|
||||
var/other_msg = english_list(other_keys, "-None-")
|
||||
|
||||
message += "**Admins:** [admin_msg]\n**Mods/GMs:** [mod_msg]\n**Devs:** [dev_msg]\n**Other:** [other_msg]\n**Total:** [count] online"
|
||||
return message
|
||||
return message
|
||||
|
||||
GLOBAL_LIST_EMPTY(pending_discord_registrations)
|
||||
/datum/tgs_chat_command/register
|
||||
name = "register"
|
||||
help_text = "Registers your chat username with your Byond username"
|
||||
admin_only = FALSE
|
||||
|
||||
/datum/tgs_chat_command/register/Run(datum/tgs_chat_user/sender, params)
|
||||
// Try to find if that ID is registered to someone already
|
||||
var/sql_discord = sql_sanitize_text(sender.id)
|
||||
var/DBQuery/query = dbcon.NewQuery("SELECT discord_id FROM erro_player WHERE discord_id = '[sql_discord]'")
|
||||
query.Execute()
|
||||
if(query.NextRow())
|
||||
return "[sender.friendly_name], your Discord ID is already registered to a Byond username. Please contact an administrator if you changed your Byond username or Discord ID."
|
||||
|
||||
var/key_to_find = "[ckey(params)]"
|
||||
|
||||
// They didn't provide anything worth looking up.
|
||||
if(!length(key_to_find))
|
||||
return "[sender.friendly_name], you need to provide your Byond username at the end of the command. It can be in 'key' format (with spaces and characters) or 'ckey' format (without spaces or special characters)."
|
||||
|
||||
// Try to find their client.
|
||||
var/client/user
|
||||
for(var/client/C in GLOB.clients)
|
||||
if(C.ckey == key_to_find)
|
||||
user = C
|
||||
break
|
||||
|
||||
// Couldn't find them logged in.
|
||||
if(!user)
|
||||
return "[sender.friendly_name], I couldn't find a logged-in user with the username of '[key_to_find]', which is what you provided after conversion to Byond's \"ckey\" format. Please connect to the game server and try again."
|
||||
|
||||
var/sql_ckey = sql_sanitize_text(key_to_find)
|
||||
query = dbcon.NewQuery("SELECT discord_id FROM erro_player WHERE ckey = '[sql_ckey]'")
|
||||
query.Execute()
|
||||
|
||||
// We somehow found their client, BUT they don't exist in the database
|
||||
if(!query.NextRow())
|
||||
return "[sender.friendly_name], the server's database is either not responding or there's no evidence you've ever logged in. Please contact an administrator."
|
||||
|
||||
// We found them in the database, AND they already have a discord ID assigned
|
||||
if(query.item[1])
|
||||
return "[sender.friendly_name], it appears you've already registered your chat and game IDs. If you've changed game or chat usernames, please contact an administrator for help."
|
||||
|
||||
// Okay. We found them, they're in the DB, and they have no discord ID set.
|
||||
var/message = "<span class='notice'>A request has been sent from Discord to validate your Byond username, by '[sender.friendly_name]' in '[sender.channel.friendly_name]'</span>\
|
||||
<br><span class='warning'>If you did not send this request, do not click the link below, and do notify an administrator in-game or on Discord ASAP.</span>\
|
||||
<br><a href='byond://?src=\ref[user];discord_reg=[html_encode(sender.id)]'>Click Here</a> if you authorized this registration attempt. This link is valid for 10 minutes."
|
||||
to_chat(user, message)
|
||||
|
||||
// To stifle href hacking
|
||||
GLOB.pending_discord_registrations.len++
|
||||
GLOB.pending_discord_registrations[GLOB.pending_discord_registrations.len] = list("ckey" = key_to_find, "id" = sender.id, "time" = world.realtime)
|
||||
|
||||
return "[sender.friendly_name], I've sent you a message in-game. Please verify your username there to complete your registration within 10 minutes."
|
||||
|
||||
Reference in New Issue
Block a user