Revert previous commit due to discovered bugs
This commit is contained in:
parent
f7f91000ef
commit
eacc53532f
4
API.md
4
API.md
@ -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.
|
||||
|
||||
### `discord.send(message, id)`
|
||||
Sends `message` to Discord, with an optional target channel ID or user ID `id`.
|
||||
### `discord.send(message)`
|
||||
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.**
|
||||
|
||||
### `discord.register_on_message(function(name, message))`
|
||||
|
27
server.py
27
server.py
@ -62,21 +62,12 @@ authenticated_users = {}
|
||||
def check_timeout():
|
||||
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):
|
||||
user = bot.get_channel(user_id)
|
||||
user = bot.get_user(user_id)
|
||||
if user is None:
|
||||
user = await bot.fetch_channel(user_id)
|
||||
user = await bot.fetch_user(user_id)
|
||||
if user is None:
|
||||
print(f'Failed to fetch channel {user_id!r}.')
|
||||
print(f'Failed to fetch user {user_id!r}.')
|
||||
|
||||
return user
|
||||
|
||||
@ -92,9 +83,9 @@ async def handle(request):
|
||||
msg = r.sub('', msg)
|
||||
if 'context' in data.keys():
|
||||
id = int(data['context'])
|
||||
target_channel = await get_or_fetch_channel(id)
|
||||
if target_channel is not None:
|
||||
await target_channel.send(msg)
|
||||
user = await get_or_fetch_user(id)
|
||||
if user is not None:
|
||||
await user.send(msg)
|
||||
else:
|
||||
await channel.send(msg)
|
||||
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:
|
||||
return
|
||||
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)
|
||||
try:
|
||||
await ctx.message.delete()
|
||||
except:
|
||||
print(f"Unable to delete possible password leak by user ID {ctx.author.id} due to insufficient permissions.")
|
||||
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)
|
||||
return
|
||||
login_queue.add({
|
||||
'username' : username,
|
||||
|
Loading…
x
Reference in New Issue
Block a user