Revert previous commit due to discovered bugs

This commit is contained in:
archfan 2021-07-04 16:09:00 +00:00 committed by GitHub
parent f7f91000ef
commit eacc53532f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 23 deletions

4
API.md
View File

@ -4,8 +4,8 @@
It does not expose the command interface or logins to the API, and `discord.register_on_message` events will *not* recieve login information. It does not expose the command interface or logins to the API, and `discord.register_on_message` events will *not* recieve login information.
### `discord.send(message, id)` ### `discord.send(message)`
Sends `message` to Discord, with an optional target channel ID or user ID `id`. Sends `message` to Discord.
This function makes an HTTP request; therefore the sending of large volumes of data might be better grouped into a single request. **Do note that Discord limits messages to 2,000 characters, and the relay automatically cuts off messages.** This function makes an HTTP request; therefore the sending of large volumes of data might be better grouped into a single request. **Do note that Discord limits messages to 2,000 characters, and the relay automatically cuts off messages.**
### `discord.register_on_message(function(name, message))` ### `discord.register_on_message(function(name, message))`

View File

@ -62,22 +62,13 @@ authenticated_users = {}
def check_timeout(): def check_timeout():
return time.time() - last_request <= 1 return time.time() - last_request <= 1
async def get_or_fetch_channel(id):
target_channel = bot.get_channel(id)
if target_channel is None:
target_channel = await bot.fetch_channel(id)
if target_channel is None:
print(f'Failed to fetch channel {id!r}.')
return target_channel
async def get_or_fetch_user(user_id): async def get_or_fetch_user(user_id):
user = bot.get_channel(user_id) user = bot.get_user(user_id)
if user is None: if user is None:
user = await bot.fetch_channel(user_id) user = await bot.fetch_user(user_id)
if user is None: if user is None:
print(f'Failed to fetch channel {user_id!r}.') print(f'Failed to fetch user {user_id!r}.')
return user return user
async def handle(request): async def handle(request):
@ -92,9 +83,9 @@ async def handle(request):
msg = r.sub('', msg) msg = r.sub('', msg)
if 'context' in data.keys(): if 'context' in data.keys():
id = int(data['context']) id = int(data['context'])
target_channel = await get_or_fetch_channel(id) user = await get_or_fetch_user(id)
if target_channel is not None: if user is not None:
await target_channel.send(msg) await user.send(msg)
else: else:
await channel.send(msg) await channel.send(msg)
return web.Response(text = 'Acknowledged') # discord.send should NOT block extensively on the Lua side return web.Response(text = 'Acknowledged') # discord.send should NOT block extensively on the Lua side
@ -169,11 +160,7 @@ async def login(ctx, username, password=''):
if not logins_allowed: if not logins_allowed:
return return
if ctx.guild is not None: if ctx.guild is not None:
await ctx.send(ctx.author.mention+' You\'ve quite possibly just leaked your password by using this command outside of DMs; it is advised that you change it at once.\n*This message will be automatically deleted.*', delete_after = 10) await ctx.send(ctx.author.mention+' You\'ve quite possibly just leaked your password; it is advised that you change it at once.\n*This message will be automatically deleted*', delete_after = 10)
try:
await ctx.message.delete()
except:
print(f"Unable to delete possible password leak by user ID {ctx.author.id} due to insufficient permissions.")
return return
login_queue.add({ login_queue.add({
'username' : username, 'username' : username,