Adds a round notify system

This commit is contained in:
AffectedArc07
2019-01-26 21:23:10 +00:00
parent 693eae879a
commit 3b75eaaba3
9 changed files with 152 additions and 3 deletions
+14
View File
@@ -521,3 +521,17 @@ CREATE TABLE `memo` (
PRIMARY KEY (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `discord`
--
DROP TABLE IF EXISTS `discord`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `discord` (
`ckey` varchar(32) NOT NULL,
`discord_id` bigint(20) NOT NULL,
`notify` int(11) NOT NULL,
PRIMARY KEY (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
+14
View File
@@ -520,3 +520,17 @@ CREATE TABLE `SS13_memo` (
PRIMARY KEY (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `SS13_discord`
--
DROP TABLE IF EXISTS `SS13_discord`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `SS13_discord` (
`ckey` varchar(32) NOT NULL,
`discord_id` bigint(20) NOT NULL,
`notify` int(11) NOT NULL,
PRIMARY KEY (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
+9
View File
@@ -0,0 +1,9 @@
#Updating the SQL from version 4 to version 5. -AffectedArc07
#Creating a table to track discord IDs for round notifying
DROP TABLE IF EXISTS `discord`;
CREATE TABLE IF NOT EXISTS `discord` (
`ckey` varchar(32) NOT NULL,
`discord_id` bigint(20) NOT NULL,
`notify` int(11) NOT NULL,
PRIMARY KEY (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+1 -1
View File
@@ -366,7 +366,7 @@
#define INVESTIGATE_BOMB "bombs"
// The SQL version required by this version of the code
#define SQL_VERSION 4
#define SQL_VERSION 5
// Vending machine stuff
#define CAT_NORMAL 1
+49
View File
@@ -0,0 +1,49 @@
// DONT TOUCH ANYTHING IN HERE UNLESS YOU KNOW WHAT YOU ARE DOING -affected
/client/verb/linkdiscord()
set category = "OOC"
set name = "Link Discord Account"
set desc = "Link your discord account to your BYOND account."
ckey = sanitizeSQL(usr.ckey) // Probably not neccassary but better safe than sorry
if(!config.sql_enabled)
to_chat(src, "<span class='warning'>This is feature requires the SQL backend</span>")
return
var/DBQuery/db_discord_id = dbcon.NewQuery("SELECT discord_id FROM [format_table_name("discord")] WHERE ckey = '[ckey]'")
if(!db_discord_id.Execute())
var/err = db_discord_id.ErrorMsg()
log_game("SQL ERROR while selecting discord account. Error : \[[err]\]\n")
to_chat(src, "<span class='warning'>Error checking Discord account. Please inform an administrator</span>")
return
var/stored_id
while(db_discord_id.NextRow())
stored_id = db_discord_id.item[1]
if(!stored_id) // Not linked
var/entered_id = input("Please enter your Discord ID. Instructions can be found at https://bit.ly/2AfUu40", "Enter Discord ID", null, null) as text|null
var/sql_id = sanitizeSQL(entered_id)
var/DBQuery/store_discord_id = dbcon.NewQuery("INSERT INTO [format_table_name("discord")] (ckey, discord_id, notify) VALUES ('[ckey]', [sql_id], 0)")
if(!store_discord_id.Execute())
var/err = db_discord_id.ErrorMsg()
log_game("SQL ERROR while linking discord account. Error : \[[err]\]\n")
to_chat(src, "<span class='warning'>Error linking Discord account. Please inform an administrator</span>")
return
to_chat(src, "<span class='notice'>Successfully linked discord account [entered_id] to [ckey]</span>")
else // Linked
var/choice = alert("You already have the Discord Account [stored_id] linked to [ckey]. Would you like to unlink or replace","Already Linked","Unlink","Replace")
switch(choice)
if("Unlink")
var/DBQuery/unlink_discord_id = dbcon.NewQuery("DELETE FROM [format_table_name("discord")] WHERE ckey = '[ckey]'")
if(!unlink_discord_id.Execute())
var/err = unlink_discord_id.ErrorMsg()
log_game("SQL ERROR while unlinking discord account. Error : \[[err]\]\n")
to_chat(src, "<span class='warning'>Error unlinking Discord account. Please inform an administrator</span>")
return
to_chat(src, "<span class='notice'>Successfully unlinked discord account</span>")
if("Replace")
var/entered_id = input("Please enter your Discord ID. Instructions can be found at https://bit.ly/2AfUu40", "Enter Discord ID", null, null) as text|null
var/sql_id = sanitizeSQL(entered_id)
var/DBQuery/store_discord_id = dbcon.NewQuery("UPDATE [format_table_name("discord")] SET discord_id = '[sql_id]' WHERE ckey='[ckey]'")
if(!store_discord_id.Execute())
var/err = db_discord_id.ErrorMsg()
to_chat(src, "<span class='warning'>Error replacing Discord account. Please inform an administrator</span>")
log_game("SQL ERROR while linking discord account. Error : \[[err]\]\n")
return
to_chat(src, "<span class='notice'>Successfully linked discord account [entered_id] to [ckey]</span>")
+48
View File
@@ -0,0 +1,48 @@
// DONT TOUCH ANYTHING IN HERE UNLESS YOU KNOW WHAT YOU ARE DOING -affected
/client/verb/notify_restart()
set category = "OOC"
set name = "Notify Restart"
set desc = "Notifies you on Discord when the server restarts."
if(!config.sql_enabled)
to_chat(src, "<span class='warning'>This is feature requires the SQL backend</span>")
return
var/DBQuery/db_discord_id = dbcon.NewQuery("SELECT discord_id FROM [format_table_name("discord")] WHERE ckey = '[ckey]'")
if(!db_discord_id.Execute())
var/err = db_discord_id.ErrorMsg()
log_game("SQL ERROR while selecting discord account. Error : \[[err]\]\n")
to_chat(src, "<span class='warning'>Error checking Discord account. Please inform an administrator</span>")
return
var/stored_id
while(db_discord_id.NextRow())
stored_id = db_discord_id.item[1]
if(!stored_id) // Not linked
to_chat(src, "<span class='warning'>This requires you to link your Discord account with the \"Link Discord Account\" verb.</span>")
return
else // Linked
var/DBQuery/toggle_status = dbcon.NewQuery("SELECT notify FROM [format_table_name("discord")] WHERE ckey = '[ckey]'")
if(!toggle_status.Execute())
var/err = toggle_status.ErrorMsg()
log_game("SQL ERROR while getting discord account. Error : \[[err]\]\n")
var/notify_status
while(toggle_status.NextRow())
notify_status = toggle_status.item[1]
if(notify_status) // Data is there
switch(notify_status)
if("0")
var/DBQuery/update_notify = dbcon.NewQuery("UPDATE [format_table_name("discord")] SET notify = 1 WHERE ckey='[ckey]'")
if(!update_notify.Execute())
var/err = db_discord_id.ErrorMsg()
to_chat(src, "<span class='warning'>Error updating notify status. Please inform an administrator</span>")
log_game("SQL ERROR while updating notify status. Error : \[[err]\]\n")
return
to_chat(src, "<span class='notice'>You will now be notified on discord when the next round is starting</span>")
if("1")
var/DBQuery/update_notify = dbcon.NewQuery("UPDATE [format_table_name("discord")] SET notify = 0 WHERE ckey='[ckey]'")
if(!update_notify.Execute())
var/err = db_discord_id.ErrorMsg()
to_chat(src, "<span class='warning'>Error updating notify status. Please inform an administrator</span>")
log_game("SQL ERROR while updating notify status. Error : \[[err]\]\n")
return
to_chat(src, "<span class='notice'>You will no longer be notified on discord when the next round is starting</span>")
else // Oh fuck what the hell happened
to_chat(src, "<span class='danger'>Something has gone VERY wrong, or affected cant code.</span>")
+14 -1
View File
@@ -17,5 +17,18 @@
return
/hook/startup/proc/ircNotify()
send2mainirc("Server starting up on [station_name()]. Connect to: [config.server? "[config.server]" : "[world.address]:[world.port]"]")
var/people_to_ping = ""
var/DBQuery/pull_notify = dbcon.NewQuery("SELECT discord_id FROM [format_table_name("discord")] WHERE notify = 1")
if(!pull_notify.Execute())
var/err = pull_notify.ErrorMsg()
log_game("SQL ERROR while pulling notify people. Error : \[[err]\]\n")
else
while(pull_notify.NextRow())
people_to_ping += "<@" + pull_notify.item[1] + "> "
send2mainirc("Server starting up on [station_name()]. Connect to: <byond://[config.server? "[config.server]" : "[world.address]:[world.port]"]> "+people_to_ping)
// Set notify to 0 so people arent pinged round after round
var/DBQuery/reset_notify = dbcon.NewQuery("UPDATE [format_table_name("discord")] SET notify = 0 WHERE notify = 1")
if(!reset_notify.Execute())
var/err = reset_notify.ErrorMsg()
log_game("SQL ERROR while resetting notify status. Error : \[[err]\]\n")
return 1
+1 -1
View File
@@ -9,7 +9,7 @@
## This value must be set to the version of the paradise schema in use.
## If this value does not match, the SQL database will not be loaded and an error will be generated.
## Roundstart will be delayed.
DB_VERSION 4
DB_VERSION 5
## Server the MySQL database can be found at.
# Examples: localhost, 200.135.5.43, www.mysqldb.com, etc.
+2
View File
@@ -1343,6 +1343,8 @@
#include "code\modules\detective_work\evidence.dm"
#include "code\modules\detective_work\footprints_and_rag.dm"
#include "code\modules\detective_work\scanner.dm"
#include "code\modules\discord\accountlink.dm"
#include "code\modules\discord\notify.dm"
#include "code\modules\economy\Accounts.dm"
#include "code\modules\economy\Accounts_DB.dm"
#include "code\modules\economy\ATM.dm"