mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-14 18:11:23 +01:00
Customizable msg posting timeout and msg length
This commit is contained in:
parent
18f25d0852
commit
e8424a63c8
@ -19,6 +19,8 @@ class Guilds(Base):
|
||||
owner_id = db.Column(db.BigInteger) # Snowflake of the owner
|
||||
icon = db.Column(db.String(255)) # The icon string, null if none
|
||||
invite_link = db.Column(db.String(255)) # Custom Discord Invite Link
|
||||
post_timeout = db.Column(db.Integer, nullable=False, server_default="5") # Seconds to elapse before another message can be posted from the widget
|
||||
max_message_length = db.Column(db.Integer, nullable=False, server_default="300") # Chars length the message should be before being rejected by the server
|
||||
|
||||
def __init__(self, guild_id, name, roles, channels, webhooks, emojis, owner_id, icon):
|
||||
self.guild_id = guild_id
|
||||
|
@ -0,0 +1,30 @@
|
||||
"""Add post_timeout and max_message_length columns to guilds
|
||||
|
||||
Revision ID: 176d26252734
|
||||
Revises: b18fcc759865
|
||||
Create Date: 2018-03-25 04:04:11.000997
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '176d26252734'
|
||||
down_revision = 'b18fcc759865'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('guilds', sa.Column('max_message_length', sa.Integer(), server_default='300', nullable=False))
|
||||
op.add_column('guilds', sa.Column('post_timeout', sa.Integer(), server_default='5', nullable=False))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('guilds', 'post_timeout')
|
||||
op.drop_column('guilds', 'max_message_length')
|
||||
# ### end Alembic commands ###
|
@ -178,6 +178,8 @@ def administrate_guild(guild_id):
|
||||
"icon": db_guild.icon,
|
||||
"invite_link": db_guild.invite_link if db_guild.invite_link != None else "",
|
||||
"guest_icon": db_guild.guest_icon if db_guild.guest_icon != None else "",
|
||||
"post_timeout": db_guild.post_timeout,
|
||||
"max_message_length": db_guild.max_message_length,
|
||||
}
|
||||
return render_template("administrate_guild.html.j2", guild=dbguild_dict, members=users, permissions=permissions, cosmetics=cosmetics)
|
||||
|
||||
@ -192,6 +194,8 @@ def update_administrate_guild(guild_id):
|
||||
db_guild.bracket_links = request.form.get("bracket_links", db_guild.bracket_links) in ["true", True]
|
||||
db_guild.mentions_limit = request.form.get("mentions_limit", db_guild.mentions_limit)
|
||||
db_guild.unauth_captcha = request.form.get("unauth_captcha", db_guild.unauth_captcha) in ["true", True]
|
||||
db_guild.post_timeout = request.form.get("post_timeout", db_guild.post_timeout)
|
||||
db_guild.max_message_length = request.form.get("max_message_length", db_guild.max_message_length)
|
||||
invite_link = request.form.get("invite_link", db_guild.invite_link)
|
||||
if invite_link != None and invite_link.strip() == "":
|
||||
invite_link = None
|
||||
@ -212,6 +216,8 @@ def update_administrate_guild(guild_id):
|
||||
invite_link=db_guild.invite_link,
|
||||
guest_icon=db_guild.guest_icon,
|
||||
unauth_captcha=db_guild.unauth_captcha,
|
||||
post_timeout=db_guild.post_timeout,
|
||||
max_message_length=db_guild.max_message_length,
|
||||
)
|
||||
|
||||
@admin.route("/guilds")
|
||||
|
@ -38,6 +38,11 @@ def format_post_content(guild_id, channel_id, message, dbUser):
|
||||
|
||||
dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
|
||||
|
||||
max_len = get_post_content_max_len(guild_id)
|
||||
if len(message) > max_len:
|
||||
illegal_post = True
|
||||
illegal_reasons.append("Exceeded the following message length: {} characters".format(max_len))
|
||||
|
||||
links = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', message)
|
||||
if not dbguild.chat_links and len(links) > 0:
|
||||
illegal_post = True
|
||||
@ -244,10 +249,35 @@ def fetch_visitor():
|
||||
response.status_code = status_code
|
||||
return response
|
||||
|
||||
def get_guild_specific_post_limit():
|
||||
guild_id = request.form.get("guild_id", None)
|
||||
try:
|
||||
guild_id = int(guild_id)
|
||||
except:
|
||||
guild_id = None
|
||||
seconds = 5
|
||||
if guild_id:
|
||||
dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
|
||||
if dbguild:
|
||||
seconds = dbguild.post_timeout
|
||||
return "1 per {} second".format(seconds)
|
||||
|
||||
def get_post_content_max_len(guild_id):
|
||||
try:
|
||||
guild_id = int(guild_id)
|
||||
except:
|
||||
guild_id = None
|
||||
length = 350
|
||||
if guild_id:
|
||||
dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
|
||||
if dbguild:
|
||||
length = dbguild.max_message_length
|
||||
return length
|
||||
|
||||
@api.route("/post", methods=["POST"])
|
||||
@valid_session_required(api=True)
|
||||
@abort_if_guild_disabled()
|
||||
@rate_limiter.limit("1 per 5 second", key_func = channel_ratelimit_key)
|
||||
@rate_limiter.limit(get_guild_specific_post_limit, key_func = channel_ratelimit_key)
|
||||
def post():
|
||||
guild_id = request.form.get("guild_id")
|
||||
channel_id = request.form.get('channel_id')
|
||||
|
@ -70,6 +70,7 @@ def guild_embed(guild_id):
|
||||
"icon": guild.icon,
|
||||
"invite_link": guild.invite_link,
|
||||
"invite_domain": parse_url_domain(guild.invite_link),
|
||||
"post_timeout": guild.post_timeout,
|
||||
}
|
||||
customcss = get_custom_css()
|
||||
return render_template("embed.html.j2",
|
||||
|
@ -215,6 +215,8 @@ def administrate_guild(guild_id):
|
||||
"icon": db_guild.icon,
|
||||
"invite_link": db_guild.invite_link if db_guild.invite_link != None else "",
|
||||
"guest_icon": db_guild.guest_icon if db_guild.guest_icon != None else "",
|
||||
"post_timeout": db_guild.post_timeout,
|
||||
"max_message_length": db_guild.max_message_length,
|
||||
}
|
||||
return render_template("administrate_guild.html.j2", guild=dbguild_dict, members=users, permissions=permissions, cosmetics=cosmetics, disabled=(guild_id in list_disabled_guilds()))
|
||||
|
||||
@ -237,6 +239,8 @@ def update_administrate_guild(guild_id):
|
||||
db_guild.bracket_links = request.form.get("bracket_links", db_guild.bracket_links) in ["true", True]
|
||||
db_guild.mentions_limit = request.form.get("mentions_limit", db_guild.mentions_limit)
|
||||
db_guild.unauth_captcha = request.form.get("unauth_captcha", db_guild.unauth_captcha) in ["true", True]
|
||||
db_guild.post_timeout = request.form.get("post_timeout", db_guild.post_timeout)
|
||||
db_guild.max_message_length = request.form.get("max_message_length", db_guild.max_message_length)
|
||||
|
||||
invite_link = request.form.get("invite_link", db_guild.invite_link)
|
||||
if invite_link != None and invite_link.strip() == "":
|
||||
@ -260,6 +264,8 @@ def update_administrate_guild(guild_id):
|
||||
invite_link=db_guild.invite_link,
|
||||
guest_icon=guest_icon,
|
||||
unauth_captcha=db_guild.unauth_captcha,
|
||||
post_timeout=db_guild.post_timeout,
|
||||
max_message_length=db_guild.max_message_length,
|
||||
)
|
||||
|
||||
@user.route("/add-bot/<guild_id>")
|
||||
|
@ -19,6 +19,8 @@ class Guilds(db.Model):
|
||||
owner_id = db.Column(db.BigInteger, nullable=False) # Snowflake of the owner
|
||||
icon = db.Column(db.String(255)) # The icon string, null if none
|
||||
invite_link = db.Column(db.String(255)) # Custom Discord Invite Link
|
||||
post_timeout = db.Column(db.Integer, nullable=False, server_default="5") # Seconds to elapse before another message can be posted from the widget
|
||||
max_message_length = db.Column(db.Integer, nullable=False, server_default="300") # Chars length the message should be before being rejected by the server
|
||||
|
||||
def __init__(self, guild_id, name, roles, channels, webhooks, emojis, owner_id, icon):
|
||||
self.guild_id = guild_id
|
||||
|
@ -54,6 +54,28 @@ $("#mentions_limit").keyup(function(event){
|
||||
}
|
||||
});
|
||||
|
||||
$("#post_timeout").keyup(function(event){
|
||||
if(event.keyCode == 13){
|
||||
var pathname = window.location.pathname;
|
||||
var value = $("#post_timeout").val()
|
||||
var payload = {"post_timeout": value}
|
||||
$.post(pathname, payload, function(data) {
|
||||
Materialize.toast('Updated post timeout setting!', 2000)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("#max_message_length").keyup(function(event){
|
||||
if(event.keyCode == 13){
|
||||
var pathname = window.location.pathname;
|
||||
var value = $("#max_message_length").val()
|
||||
var payload = {"max_message_length": value}
|
||||
$.post(pathname, payload, function(data) {
|
||||
Materialize.toast('Updated max message length setting!', 2000)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("#invite_link").keyup(function(event){
|
||||
if(event.keyCode == 13){
|
||||
var pathname = window.location.pathname;
|
||||
|
@ -19,6 +19,7 @@
|
||||
/* global disabled */
|
||||
/* global wdtEmojiBundle */
|
||||
/* global EmojiConvertor */
|
||||
/* global post_timeout */
|
||||
|
||||
(function () {
|
||||
const theme_options = ["DiscordDark", "MetroEdge", "BetterTitan"]; // All the avaliable theming names
|
||||
@ -1589,7 +1590,7 @@
|
||||
if (event.keyCode == 16) {
|
||||
shift_pressed = true;
|
||||
}
|
||||
if(event.keyCode == 13 && !shift_pressed && $(this).val().length >= 1 && $(this).val().length <= 350) {
|
||||
if(event.keyCode == 13 && !shift_pressed && $(this).val().length >= 1) {
|
||||
$(this).val($.trim($(this).val()));
|
||||
$(this).blur();
|
||||
$("#messagebox").attr('readonly', true);
|
||||
@ -1613,15 +1614,13 @@
|
||||
});
|
||||
funct.catch(function(data) {
|
||||
if (data.status == 429) {
|
||||
Materialize.toast('You are sending messages too fast! 1 message per 5 seconds', 10000);
|
||||
Materialize.toast('You are sending messages too fast! 1 message per ' + post_timeout + ' seconds', 10000);
|
||||
}
|
||||
});
|
||||
funct.always(function() {
|
||||
$("#messagebox").attr('readonly', false);
|
||||
$("#messagebox").focus();
|
||||
});
|
||||
} else if (event.keyCode == 13 && !shift_pressed && $(this).val().length > 350) {
|
||||
Materialize.toast('You are sending messages too long! 350 characters limit.', 10000);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -134,6 +134,18 @@
|
||||
|
||||
<br>
|
||||
|
||||
<p class="flow-text">Send Message Timeout</p>
|
||||
<p>(0 seconds to have no limit - enter to submit)</p>
|
||||
<input id="post_timeout" type="number" value="{{ guild['post_timeout'] }}">
|
||||
|
||||
<br>
|
||||
|
||||
<p class="flow-text">Maximum Message Length</p>
|
||||
<p>(No more than 2000 characters - enter to submit)</p>
|
||||
<input id="max_message_length" type="number" value="{{ guild['max_message_length'] }}">
|
||||
|
||||
<br>
|
||||
|
||||
<p class="flow-text">Custom Invite Link</p>
|
||||
<p>Have a permanent invite that you really want to use? Something like discord.io on your mind? Enter your custom invite link here to replace the default one on the embed!</p>
|
||||
<p>(Leave blank if none - enter to submit)</p>
|
||||
|
@ -463,6 +463,7 @@
|
||||
const disabled = {{ disabled|tojson|safe }};
|
||||
const guild_id = "{{ guild_id }}";
|
||||
const bot_client_id = "{{ client_id }}";
|
||||
const post_timeout = {{ guild["post_timeout"]|tojson|safe }};
|
||||
const visitors_enabled = {% if visitors_enabled %}true{% else %}false{% endif %};
|
||||
const unauth_captcha_enabled = {% if unauth_captcha_enabled %}true{% else %}false{% endif %};
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user