diff options
Diffstat (limited to 'npc/commands')
-rw-r--r-- | npc/commands/discord.txt | 92 |
1 files changed, 82 insertions, 10 deletions
diff --git a/npc/commands/discord.txt b/npc/commands/discord.txt index 2f7feb494..0f4f7e8c7 100644 --- a/npc/commands/discord.txt +++ b/npc/commands/discord.txt @@ -16,38 +16,109 @@ OnCall: close; } - if (!validatepin()) - close; + // Live server only + if (debug || $@GM_OVERRIDE) { + dispbottom l("This command cannot be used on test servers."); + end; + } + // Bot cannot (or should not) alter staff data + if (is_staff()) { + dispbottom l("Staff is not allowed to use this command."); + end; + } + + // Minimum account requeriments + if (#REG_DATE < (gettimetick(2)+259200) && BaseLevel < 15) { + dispbottom l("Your account must be at least 72 hours old or have level 15+ to use this command."); + end; + } + + // Use this instead of min acc req if desired + //if (!validatepin()) + // close; + + // Prevent reusing the command on same session @discord=1; - .@nb = query_sql("select `discord_name` from `discord` WHERE `account_id`='"+getcharid(3)+"'", .@discord$); + .@link=true; + + // Search on cache + .@key$=str(getcharid(3)); + .@m$ = htget(.discmem$, .@key$, "Not found"); + + if (.@m$ == "Not found") { + // Only do SQL query if not in cache + .@nb = query_sql("select `discord_name` from `discord` WHERE `account_id`='"+getcharid(3)+"' limit 1", .@discord$); + // Override default behavior + if (.@discord$ == "") { + .@discord$="Not Linked"; + .@link=false; + } + // Add to Cache + htput(.discmem$, str(getcharid(3)), .@discord$); + } + // Doublecheck it worked properly + if (.@discord$ == "") { + .@discord$="Not Linked"; + .@link=false; + } + do { mesn "Lawn Cable"; mesq l("Current linked Discord account: @@", .@discord$); next; select - l("Change Linked Discord Account"), - l("Disconnect"), + rif(DISCTRL < gettimeparam(GETTIME_DAYOFMONTH), l("Change Linked Discord Account")), + rif(.@link, l("Disconnect")), l("Quit"); switch (@menu) { case 1: + if (DISCTRL >= gettimeparam(GETTIME_DAYOFMONTH)) + atcommand("@ban 7d "+strcharinfo(0)); + mesc l("Please insert your Discord ID, on the following format: "), 1; mesc l("Usename#0000"), 2; input .@discord$; - .@discord$=escape_sql(.@discord$); + if (.@discord$ == "") close; mes ""; - query_sql("UPDATE `discord` SET `discord_name` = '"+.@discord$+"' WHERE `account_id`='"+getcharid(3)+"'"); - query_sql("UPDATE `discord` SET `verified` = '0' WHERE `account_id`='"+getcharid(3)+"'"); - query_sql("UPDATE `discord` SET `discord_id` = '' WHERE `account_id`='"+getcharid(3)+"'"); - mesc l("You must send ##B/verify##b to Discord bot for the linking be complete."), 1; + + // Run SQL query + if (.@link) { + query_sql(sprintf("UPDATE `discord` SET `discord_name` = '%s', `verified` = '0', `discord_id` = '' WHERE `account_id`='%d'", + escape_sql(.@discord$), getcharid(3))); + } else { + query_sql(sprintf("INSERT INTO `discord` (`discord_name`, `verified`, `discord_id`, `account_id`) VALUES ('%s', '0', '', '%d')", + escape_sql(.@discord$), getcharid(3))); + } + + // Encode JSON data + .@p$=json_encode("name", strcharinfo(0), + "accId", getcharid(3), + "disc", .@discord$); + + // Send to API and update cache + api_send(API_DISCORD, .@p$); + htput(.discmem$, str(getcharid(3)), .@discord$); + + // Prevent changing for the next 3 days + DISCTRL=gettimeparam(GETTIME_DAYOFMONTH)+3; + mesc l("Linking requested."), 1; + mesc l("This setting can only be changed every %d days.", 3), 1; break; + ///////////////////////////////////////////////////////////////////// case 2: query_sql("DELETE FROM `discord` WHERE `account_id`='"+getcharid(3)+"'"); .@discord$=""; + // Prevent setting a new linking right away + DISCTRL=gettimeparam(GETTIME_DAYOFMONTH)+1; + // Update Cache + htput(.discmem$, str(getcharid(3)), ""); + // TODO: Remove Adventurer role? + logmes(sprintf("User %d \"%s\" unlinked Discord account!", getcharid(3), strcharinfo(0))); break; } @@ -56,6 +127,7 @@ OnCall: OnInit: bindatcmd "discord", "@discord::OnCall", 0, 0, 1; + .discmem$ = htnew; end; } |