Unban command

This commit is contained in:
Jeremy Zhang
2019-01-10 02:07:12 +00:00
parent 3159b9c0f5
commit 790dca1766
3 changed files with 68 additions and 0 deletions

View File

@ -634,6 +634,41 @@ def bot_ban():
db.session.add(dbban)
db.session.commit()
return jsonify(success="Guest user, **{}#{}**, has successfully been added to the ban list!".format(dbban.last_username, dbban.last_discriminator))
@api.route("/bot/unban", methods=["POST"])
def bot_unban():
if request.headers.get("Authorization", "") != config.get("app-secret", ""):
return jsonify(error="Authorization header does not match."), 403
incoming = request.get_json()
guild_id = incoming.get("guild_id", None)
lifter_id = incoming.get("lifter_id", None)
username = incoming.get("username", None)
discriminator = incoming.get("discriminator", None)
if not guild_id or not lifter_id or not username:
return jsonify(error="Missing required parameters."), 400
if discriminator:
dbuser = db.session.query(UnauthenticatedUsers) \
.filter(UnauthenticatedUsers.guild_id == str(guild_id)) \
.filter(UnauthenticatedUsers.username.ilike("%" + username + "%")) \
.filter(UnauthenticatedUsers.discriminator == discriminator) \
.order_by(UnauthenticatedUsers.id.desc()).first()
else:
dbuser = db.session.query(UnauthenticatedUsers) \
.filter(UnauthenticatedUsers.guild_id == str(guild_id)) \
.filter(UnauthenticatedUsers.username.ilike("%" + username + "%")) \
.order_by(UnauthenticatedUsers.id.desc()).first()
if not dbuser:
return jsonify(error="Guest user cannot be found."), 404
dbban = db.session.query(UnauthenticatedBans) \
.filter(UnauthenticatedBans.guild_id == str(guild_id)) \
.filter(UnauthenticatedBans.ip_address == dbuser.ip_address).first()
if dbban is None:
return jsonify(error="Guest user **{}#{}** has not been banned.".format(dbuser.username, dbuser.discriminator)), 404
if dbban.lifter_id is not None:
return jsonify(error="Guest user **{}#{}** ban has already been removed.".format(dbuser.username, dbuser.discriminator)), 409
dbban.liftBan(int(lifter_id))
db.session.commit()
return jsonify(success="Guest user, **{}#{}**, has successfully been removed from the ban list!".format(dbuser.username, dbuser.discriminator))
@api.route("/bot/revoke", methods=["POST"])
def bot_revoke():

View File

@ -8,6 +8,7 @@
<h4>General</h4>
<p>For your information needs.</p>
<ul class="collection">
<li class="collection-item"><strong>help</strong> <br> Replies with a URL to the about page and user dashboard.</li>
<li class="collection-item"><strong>invite</strong> <br> Replies with an OAuth URL used to invite the bot to your server.</li>
<li class="collection-item"><strong>members</strong> <br> Replies with a list of members logged into your Titan Embed.</li>
<li class="collection-item"><strong>server</strong> <br> Replies with an instant invite to the Titan Embeds support server.</li>
@ -16,6 +17,7 @@
<p>All guest users are denoted by <strong>square brackets</strong> (or Titan's logo as avatar if enabled Webhook Messages) around their username in the Discord channel, when sending messages.</p>
<ul class="collection">
<li class="collection-item"><strong>ban &lt;username-query&gt;[#&lt;discriminator&gt;]</strong> <br> Bans the user by the username. The username does not need to be the full string. The discriminator is optional. <br> <em>Eg: ban Titan#0001</em></li>
<li class="collection-item"><strong>unban &lt;username-query&gt;[#&lt;discriminator&gt;]</strong> <br> Unbans the user by the username. The username does not need to be the full string. The discriminator is optional. <br> <em>Eg: unban Titan#0001</em></li>
<li class="collection-item"><strong>kick &lt;username-query&gt;[#&lt;discriminator&gt;]</strong> <br> Kicks the user by the username. The username does not need to be the full string. The discriminator is optional. <br> <em>Eg: kick Titan#0001</em></li>
</ul>
</div>