Browse Source

small improvements

Markus-Rost 4 years ago
parent
commit
5dd25d2e1e
5 changed files with 28 additions and 9 deletions
  1. 1 1
      cmds/get.js
  2. 5 0
      dashboard/src/index.css
  3. 9 0
      dashboard/src/index.js
  4. 10 6
      dashboard/verification.js
  5. 3 2
      functions/verify.js

+ 1 - 1
cmds/get.js

@@ -35,7 +35,7 @@ async function cmd_get(lang, msg, args, line, wiki) {
 			var guildchannel = ['Updates channel:', '`' + guild.channel + '`'];
 			var guildchannel = ['Updates channel:', '`' + guild.channel + '`'];
 			var guildsettings = ['Settings:', '*unknown*'];
 			var guildsettings = ['Settings:', '*unknown*'];
 			
 			
-			return db.query( 'SELECT channel, wiki, lang, role, inline, prefix FROM discord WHERE guild = $1 ORDER BY channel ASC', [guild.id] ).then( ({rows}) => {
+			return db.query( 'SELECT channel, wiki, lang, role, inline, prefix FROM discord WHERE guild = $1 ORDER BY channel ASC NULLS FIRST', [guild.id] ).then( ({rows}) => {
 				if ( rows.length ) {
 				if ( rows.length ) {
 					let row = rows.find( row => !row.channel );
 					let row = rows.find( row => !row.channel );
 					row.patreon = patreons.hasOwnProperty(guild.id);
 					row.patreon = patreons.hasOwnProperty(guild.id);

+ 5 - 0
dashboard/src/index.css

@@ -524,6 +524,11 @@ fieldset span {
 	display: inline-block;
 	display: inline-block;
 	min-width: 20%;
 	min-width: 20%;
 }
 }
+fieldset label div {
+	padding-top: 30px;
+	padding-right: 10px;
+	text-align: right;
+}
 fieldset input[type="url"] {
 fieldset input[type="url"] {
 	min-width: 30%;
 	min-width: 30%;
 	margin-right: 5px;
 	margin-right: 5px;

+ 9 - 0
dashboard/src/index.js

@@ -373,6 +373,7 @@ if ( textAreas.length ) {
 	}
 	}
 
 
 	for ( var ta = 0; ta < textAreas.length; ta++ ) {
 	for ( var ta = 0; ta < textAreas.length; ta++ ) {
+		textAreas[ta].addEventListener('keyup', updateTextLength);
 		textAreas[ta].addEventListener('keydown', allowTabs);
 		textAreas[ta].addEventListener('keydown', allowTabs);
 		textAreas[ta].onclick = function() {
 		textAreas[ta].onclick = function() {
 			if ( !textArea ) {
 			if ( !textArea ) {
@@ -421,6 +422,14 @@ if ( textAreas.length ) {
 			this.selectionStart = this.selectionEnd = start + 1;
 			this.selectionStart = this.selectionEnd = start + 1;
 		}
 		}
 	}
 	}
+
+	/**
+	 * @this HTMLTextAreaElement
+	 * @param {KeyboardEvent} e
+	 */
+	function updateTextLength(e) {
+		this.labels.item(0).children.item(0).textContent = this.value.length + ' / ' + this.maxLength;
+	}
 }
 }
 
 
 /*
 /*

+ 10 - 6
dashboard/verification.js

@@ -318,12 +318,16 @@ function dashboard_verification(res, $, guild, args, dashboardLang) {
 							)
 							)
 						),
 						),
 						$('<div>').append(
 						$('<div>').append(
-							$('<label for="wb-settings-success">').text(dashboardLang.get('verification.form.success')),
-							$('<textarea id="wb-settings-success" name="success" spellcheck="true" maxlength="500" cols="65">').attr('rows', ( row?.onsuccess || '' ).split('\n').length).attr('placeholder', dashboardLang.get('verification.form.success_placeholder')).text(row?.onsuccess || '')
+							$('<label for="wb-settings-success">').text(dashboardLang.get('verification.form.success')).append(
+								$('<div>').text(( row?.onsuccess || '' ).length + ' / 1000')
+							),
+							$('<textarea id="wb-settings-success" name="success" spellcheck="true" maxlength="1000" cols="65">').attr('rows', ( row?.onsuccess || '' ).split('\n').length + 3).attr('placeholder', dashboardLang.get('verification.form.success_placeholder')).text(row?.onsuccess || '')
 						),
 						),
 						$('<div>').append(
 						$('<div>').append(
-							$('<label for="wb-settings-match">').text(dashboardLang.get('verification.form.match')),
-							$('<textarea id="wb-settings-match" name="match" spellcheck="true" maxlength="500" cols="65">').attr('rows', ( row?.onmatch || '' ).split('\n').length).attr('placeholder', dashboardLang.get('verification.form.match_placeholder')).text(row?.onmatch || '')
+							$('<label for="wb-settings-match">').text(dashboardLang.get('verification.form.match')).append(
+								$('<div>').text(( row?.onmatch || '' ).length + ' / 1000')
+							),
+							$('<textarea id="wb-settings-match" name="match" spellcheck="true" maxlength="1000" cols="65">').attr('rows', ( row?.onmatch || '' ).split('\n').length + 3).attr('placeholder', dashboardLang.get('verification.form.match_placeholder')).text(row?.onmatch || '')
 						),
 						),
 						$('<input type="submit" id="wb-settings-save" name="save_settings">').val(dashboardLang.get('general.save'))
 						$('<input type="submit" id="wb-settings-save" name="save_settings">').val(dashboardLang.get('general.save'))
 					)
 					)
@@ -817,10 +821,10 @@ function update_notices(res, userSettings, guild, type, settings) {
 	if ( settings.channel && !/^\d+$/.test(settings.channel) ) {
 	if ( settings.channel && !/^\d+$/.test(settings.channel) ) {
 		return res(`/guild/${guild}/verification/${type}`, 'savefail');
 		return res(`/guild/${guild}/verification/${type}`, 'savefail');
 	}
 	}
-	if ( settings.success && settings.success.trim().length > 500 ) {
+	if ( settings.success && settings.success.trim().length > 1000 ) {
 		return res(`/guild/${guild}/verification/${type}`, 'savefail');
 		return res(`/guild/${guild}/verification/${type}`, 'savefail');
 	}
 	}
-	if ( settings.match && settings.match.trim().length > 500 ) {
+	if ( settings.match && settings.match.trim().length > 1000 ) {
 		return res(`/guild/${guild}/verification/${type}`, 'savefail');
 		return res(`/guild/${guild}/verification/${type}`, 'savefail');
 	}
 	}
 	settings.channel = ( settings.channel || null );
 	settings.channel = ( settings.channel || null );

+ 3 - 2
functions/verify.js

@@ -460,9 +460,10 @@ function verify(lang, channel, member, username, wiki, rows, old_username = '')
  * @returns {String}
  * @returns {String}
  */
  */
 function parseNotice(text = '', variables = {editcount: 0, postcount: 0, accountage: 0, dateformat: 'en-US'}) {
 function parseNotice(text = '', variables = {editcount: 0, postcount: 0, accountage: 0, dateformat: 'en-US'}) {
-	if ( !text.includes( '$' ) ) return text;
+	if ( !text.includes( '$' ) ) return ( text.length > 1000 ? text.substring(0, 1000) + '\u2026' : text );
 	text = text.replace( /\$(editcount|postcount|accountage)/g, (variable, key, offset, fulltext) => {
 	text = text.replace( /\$(editcount|postcount|accountage)/g, (variable, key, offset, fulltext) => {
 		var value = variables[key];
 		var value = variables[key];
+		if ( typeof value === 'string' ) return value;
 		if ( /#(?:if)?expr:[^{|}]*$/.test(fulltext.substring(0, offset)) ) return ( value > 1000000000 ? 1000000000 : value );
 		if ( /#(?:if)?expr:[^{|}]*$/.test(fulltext.substring(0, offset)) ) return ( value > 1000000000 ? 1000000000 : value );
 		return value.toLocaleString(variables.dateformat);
 		return value.toLocaleString(variables.dateformat);
 	} );
 	} );
@@ -493,7 +494,7 @@ function parseNotice(text = '', variables = {editcount: 0, postcount: 0, account
 		if ( result ) return iftrue.trim();
 		if ( result ) return iftrue.trim();
 		else return iffalse.trim();
 		else return iffalse.trim();
 	} );
 	} );
-	return text;
+	return ( text.length > 1000 ? text.substring(0, 1000) + '\u2026' : text );
 }
 }
 
 
 /**
 /**