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

@ -36,6 +36,37 @@ class Commands():
await message.channel.send(message.author.mention + " " + j["success"]) await message.channel.send(message.author.mention + " " + j["success"])
return return
await message.channel.send("Unhandled webservice error in banning guest user!") await message.channel.send("Unhandled webservice error in banning guest user!")
async def unban(self, message):
if not message.author.guild_permissions.ban_members:
await message.channel.send(message.author.mention + " I'm sorry, but you do not have permissions to unban guest members.")
return
content = message.content.strip()
if len(content.split()) == 2:
await message.channel.send(message.author.mention + " Please provide a username-query (or optionally a discriminator) to unban a guest user.\nExample: `unban Titan#0001`")
return
content = content.split()
username = content[2][:content[2].find("#")] if "#" in content[2] else content[2]
discriminator = int(content[2][content[2].find("#") + 1:]) if "#" in content[2] else None
headers = {"Authorization": self.config["titan-web-app-secret"]}
payload = {
"guild_id": message.guild.id,
"lifter_id": message.author.id,
"username": username
}
if discriminator:
payload["discriminator"] = discriminator
url = self.config["titan-web-url"] + "api/bot/unban"
async with aiohttp.ClientSession() as aioclient:
async with aioclient.post(url, json=payload, headers=headers) as resp:
j = await resp.json()
if "error" in j:
await message.channel.send(message.author.mention + " Unban error! " + j["error"])
return
if "success" in j:
await message.channel.send(message.author.mention + " " + j["success"])
return
await message.channel.send("Unhandled webservice error in unbanning guest user!")
async def kick(self, message): async def kick(self, message):
if not message.author.guild_permissions.kick_members: if not message.author.guild_permissions.kick_members:

View File

@ -634,6 +634,41 @@ def bot_ban():
db.session.add(dbban) db.session.add(dbban)
db.session.commit() db.session.commit()
return jsonify(success="Guest user, **{}#{}**, has successfully been added to the ban list!".format(dbban.last_username, dbban.last_discriminator)) 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"]) @api.route("/bot/revoke", methods=["POST"])
def bot_revoke(): def bot_revoke():

View File

@ -8,6 +8,7 @@
<h4>General</h4> <h4>General</h4>
<p>For your information needs.</p> <p>For your information needs.</p>
<ul class="collection"> <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>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>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> <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> <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"> <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>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> <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> </ul>
</div> </div>